Refactored and reformatted code to use less static variables
This commit is contained in:
@@ -1,26 +1,5 @@
|
||||
package eu.crushedpixel.replaymod.events;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Point;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiChat;
|
||||
import net.minecraft.client.gui.GuiDisconnected;
|
||||
import net.minecraft.client.gui.GuiIngameMenu;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiOptions;
|
||||
import net.minecraft.client.gui.GuiVideoSettings;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.client.settings.GameSettings.Options;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.GuiCancelRender;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
@@ -42,175 +21,183 @@ import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import eu.crushedpixel.replaymod.utils.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.video.VideoWriter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.*;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiEventHandler {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
private static final Color DARK_RED = Color.decode("#DF0101");
|
||||
private static final Color DARK_GREEN = Color.decode("#01DF01");
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private final List<Class> allowedGUIs = new ArrayList<Class>() {
|
||||
{
|
||||
add(GuiReplaySettings.class);
|
||||
add(GuiReplaySaving.class);
|
||||
add(GuiIngameMenu.class);
|
||||
add(GuiOptions.class);
|
||||
add(GuiVideoSettings.class);
|
||||
}
|
||||
};
|
||||
private int replayCount = 0;
|
||||
private GuiButton editorButton;
|
||||
|
||||
private static int replayCount = 0;
|
||||
|
||||
private static List<Class> allowedGUIs = new ArrayList<Class>() {
|
||||
{
|
||||
add(GuiReplaySettings.class);
|
||||
add(GuiReplaySaving.class);
|
||||
add(GuiIngameMenu.class);
|
||||
add(GuiOptions.class);
|
||||
add(GuiVideoSettings.class);
|
||||
}
|
||||
};
|
||||
@SubscribeEvent
|
||||
public void onGui(GuiOpenEvent event) {
|
||||
if(VideoWriter.isRecording() && !(event.gui instanceof GuiCancelRender)) {
|
||||
event.gui = null;
|
||||
return;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGui(GuiOpenEvent event) {
|
||||
if(VideoWriter.isRecording() && !(event.gui instanceof GuiCancelRender)) {
|
||||
event.gui = null;
|
||||
return;
|
||||
}
|
||||
if(!(event.gui instanceof GuiReplayViewer || event.gui instanceof GuiUploadFile))
|
||||
ResourceHelper.freeAllResources();
|
||||
|
||||
if(!(event.gui instanceof GuiReplayViewer || event.gui instanceof GuiUploadFile)) ResourceHelper.freeAllResources();
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(ReplayMod.firstMainMenu) {
|
||||
ReplayMod.firstMainMenu = false;
|
||||
event.gui = new GuiLoginPrompt(event.gui, event.gui);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
MCTimerHandler.setTimerSpeed(1);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(ReplayMod.firstMainMenu) {
|
||||
ReplayMod.firstMainMenu = false;
|
||||
event.gui = new GuiLoginPrompt(event.gui, event.gui);
|
||||
return;
|
||||
} else {
|
||||
try {
|
||||
MCTimerHandler.setTimerSpeed(1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!AuthenticationHandler.isAuthenticated()) return;
|
||||
if(event.gui != null && GuiReplaySaving.replaySaving && !allowedGUIs.contains(event.gui.getClass())) {
|
||||
event.gui = new GuiReplaySaving(event.gui);
|
||||
return;
|
||||
}
|
||||
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
||||
if(ReplayHandler.isInReplay()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
} else if(event.gui instanceof GuiDisconnected) {
|
||||
if(!ReplayHandler.isInReplay() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!AuthenticationHandler.isAuthenticated()) return;
|
||||
if(event.gui != null && GuiReplaySaving.replaySaving && !allowedGUIs.contains(event.gui.getClass())) {
|
||||
event.gui = new GuiReplaySaving(event.gui);
|
||||
return;
|
||||
}
|
||||
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
||||
if(ReplayHandler.isInReplay()) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onDraw(DrawScreenEvent e) {
|
||||
if(e.gui instanceof GuiMainMenu) {
|
||||
e.gui.drawString(mc.fontRendererObj, "Replay Mod:", 5, 5, Color.WHITE.getRGB());
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
e.gui.drawString(mc.fontRendererObj, "LOGGED IN", 5, 15, DARK_GREEN.getRGB());
|
||||
} else {
|
||||
e.gui.drawString(mc.fontRendererObj, "LOGGED OUT", 5, 15, DARK_RED.getRGB());
|
||||
}
|
||||
|
||||
else if(event.gui instanceof GuiDisconnected) {
|
||||
if(!ReplayHandler.isInReplay() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(replayCount == 0) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
e.gui.drawCenteredString(mc.fontRendererObj, "At least one Replay required", (int) mouse.getX(), (int) mouse.getY() + 4, Color.RED.getRGB());
|
||||
}
|
||||
} else if(!VersionValidator.isValid) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
e.gui.drawCenteredString(mc.fontRendererObj, "Java 1.7 or newer required", (int) mouse.getX(), (int) mouse.getY() + 4, Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Color DARK_RED = Color.decode("#DF0101");
|
||||
private static final Color DARK_GREEN = Color.decode("#01DF01");
|
||||
@SubscribeEvent
|
||||
public void onInit(InitGuiEvent event) {
|
||||
if(event.gui instanceof GuiIngameMenu && ReplayHandler.isInReplay()) {
|
||||
for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) {
|
||||
if(b.id == 1) {
|
||||
b.displayString = "Exit Replay";
|
||||
b.yPosition -= 24 * 2;
|
||||
b.id = GuiConstants.EXIT_REPLAY_BUTTON;
|
||||
} else if(b.id >= 5 && b.id <= 7) {
|
||||
event.buttonList.remove(b);
|
||||
} else if(b.id != 4) {
|
||||
b.yPosition -= 24 * 2;
|
||||
}
|
||||
}
|
||||
} else if(event.gui instanceof GuiMainMenu) {
|
||||
int i1 = event.gui.height / 4 + 24 + 10;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDraw(DrawScreenEvent e) {
|
||||
if(e.gui instanceof GuiMainMenu) {
|
||||
e.gui.drawString(mc.fontRendererObj, "Replay Mod:", 5, 5, Color.WHITE.getRGB());
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
e.gui.drawString(mc.fontRendererObj, "LOGGED IN", 5, 15, DARK_GREEN.getRGB());
|
||||
} else {
|
||||
e.gui.drawString(mc.fontRendererObj, "LOGGED OUT", 5, 15, DARK_RED.getRGB());
|
||||
}
|
||||
|
||||
if(replayCount == 0) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
e.gui.drawCenteredString(mc.fontRendererObj, "At least one Replay required", (int)mouse.getX(), (int)mouse.getY()+4, Color.RED.getRGB());
|
||||
}
|
||||
} else if(!VersionValidator.isValid) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
e.gui.drawCenteredString(mc.fontRendererObj, "Java 1.7 or newer required", (int)mouse.getX(), (int)mouse.getY()+4, Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(GuiButton b : (List<GuiButton>) event.buttonList) {
|
||||
if(b.id != 0 && b.id != 4 && b.id != 5) {
|
||||
b.yPosition = b.yPosition - 2 * 24 + 10;
|
||||
}
|
||||
}
|
||||
|
||||
private GuiButton editorButton;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInit(InitGuiEvent event) {
|
||||
if(event.gui instanceof GuiIngameMenu && ReplayHandler.isInReplay()) {
|
||||
for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) {
|
||||
if(b.id == 1) {
|
||||
b.displayString = "Exit Replay";
|
||||
b.yPosition -= 24*2;
|
||||
b.id = GuiConstants.EXIT_REPLAY_BUTTON;
|
||||
} else if(b.id >= 5 && b.id <= 7) {
|
||||
event.buttonList.remove(b);
|
||||
} else if(b.id != 4) {
|
||||
b.yPosition -= 24*2;
|
||||
}
|
||||
}
|
||||
} else if(event.gui instanceof GuiMainMenu) {
|
||||
int i1 = event.gui.height / 4 + 24 + 10;
|
||||
GuiButton rm = new GuiButton(GuiConstants.REPLAY_MANAGER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 2 * 24, "Replay Viewer");
|
||||
rm.width = rm.width / 2 - 2;
|
||||
//rm.enabled = AuthenticationHandler.isAuthenticated();
|
||||
event.buttonList.add(rm);
|
||||
|
||||
for(GuiButton b : (List<GuiButton>)event.buttonList) {
|
||||
if(b.id != 0 && b.id != 4 && b.id != 5) {
|
||||
b.yPosition = b.yPosition - 2*24 + 10;
|
||||
}
|
||||
}
|
||||
replayCount = ReplayFileIO.getAllReplayFiles().size();
|
||||
|
||||
GuiButton rm = new GuiButton(GuiConstants.REPLAY_MANAGER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 2*24, "Replay Viewer");
|
||||
rm.width = rm.width/2 - 2;
|
||||
//rm.enabled = AuthenticationHandler.isAuthenticated();
|
||||
event.buttonList.add(rm);
|
||||
GuiButton re = new GuiButton(GuiConstants.REPLAY_EDITOR_BUTTON_ID, event.gui.width / 2 + 2, i1 + 2 * 24, "Replay Editor");
|
||||
re.width = re.width / 2 - 2;
|
||||
re.enabled = VersionValidator.isValid && replayCount > 0;
|
||||
event.buttonList.add(re);
|
||||
|
||||
replayCount = ReplayFileIO.getAllReplayFiles().size();
|
||||
|
||||
GuiButton re = new GuiButton(GuiConstants.REPLAY_EDITOR_BUTTON_ID, event.gui.width / 2 + 2, i1 + 2*24, "Replay Editor");
|
||||
re.width = re.width/2 - 2;
|
||||
re.enabled = VersionValidator.isValid && replayCount > 0;
|
||||
event.buttonList.add(re);
|
||||
|
||||
editorButton = re;
|
||||
|
||||
GuiButton rc = new GuiButton(GuiConstants.REPLAY_CENTER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 3*24, "Replay Center");
|
||||
rc.enabled = true;
|
||||
event.buttonList.add(rc);
|
||||
|
||||
} else if(event.gui instanceof GuiOptions) {
|
||||
event.buttonList.add(new GuiButton(GuiConstants.REPLAY_OPTIONS_BUTTON_ID,
|
||||
event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
||||
}
|
||||
}
|
||||
editorButton = re;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onButton(ActionPerformedEvent event) {
|
||||
if(!event.button.enabled) return;
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(event.button.id == GuiConstants.REPLAY_MANAGER_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplayViewer());
|
||||
} else if(event.button.id == GuiConstants.REPLAY_CENTER_BUTTON_ID) {
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
mc.displayGuiScreen(new GuiReplayCenter());
|
||||
} else {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(event.gui, new GuiReplayCenter()));
|
||||
}
|
||||
} else if(event.button.id == GuiConstants.REPLAY_EDITOR_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplayStudio());
|
||||
}
|
||||
} else if(event.gui instanceof GuiOptions && event.button.id == GuiConstants.REPLAY_OPTIONS_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplaySettings(event.gui));
|
||||
}
|
||||
GuiButton rc = new GuiButton(GuiConstants.REPLAY_CENTER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 3 * 24, "Replay Center");
|
||||
rc.enabled = true;
|
||||
event.buttonList.add(rc);
|
||||
|
||||
if(ReplayHandler.isInReplay() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) {
|
||||
if(ReplayHandler.isInPath()) ReplayProcess.stopReplayProcess(false);
|
||||
ReplayHandler.endReplay();
|
||||
|
||||
event.button.enabled = false;
|
||||
|
||||
LightingHandler.setLighting(false);
|
||||
} else if(event.gui instanceof GuiOptions) {
|
||||
event.buttonList.add(new GuiButton(GuiConstants.REPLAY_OPTIONS_BUTTON_ID,
|
||||
event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, "Replay Mod Settings..."));
|
||||
}
|
||||
}
|
||||
|
||||
ReplayHandler.lastExit = System.currentTimeMillis();
|
||||
@SubscribeEvent
|
||||
public void onButton(ActionPerformedEvent event) {
|
||||
if(!event.button.enabled) return;
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(event.button.id == GuiConstants.REPLAY_MANAGER_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplayViewer());
|
||||
} else if(event.button.id == GuiConstants.REPLAY_CENTER_BUTTON_ID) {
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
mc.displayGuiScreen(new GuiReplayCenter());
|
||||
} else {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(event.gui, new GuiReplayCenter()));
|
||||
}
|
||||
} else if(event.button.id == GuiConstants.REPLAY_EDITOR_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplayStudio());
|
||||
}
|
||||
} else if(event.gui instanceof GuiOptions && event.button.id == GuiConstants.REPLAY_OPTIONS_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplaySettings(event.gui));
|
||||
}
|
||||
|
||||
mc.theWorld.sendQuittingDisconnectingPacket();
|
||||
mc.loadWorld((WorldClient)null);
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
|
||||
ReplayGuiRegistry.show();
|
||||
}
|
||||
}
|
||||
if(ReplayHandler.isInReplay() && event.gui instanceof GuiIngameMenu && event.button.id == GuiConstants.EXIT_REPLAY_BUTTON) {
|
||||
if(ReplayHandler.isInPath()) ReplayProcess.stopReplayProcess(false);
|
||||
ReplayHandler.endReplay();
|
||||
|
||||
event.button.enabled = false;
|
||||
|
||||
LightingHandler.setLighting(false);
|
||||
|
||||
ReplayHandler.lastExit = System.currentTimeMillis();
|
||||
|
||||
mc.theWorld.sendQuittingDisconnectingPacket();
|
||||
mc.loadWorld((WorldClient) null);
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
|
||||
ReplayGuiRegistry.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,119 +1,113 @@
|
||||
package eu.crushedpixel.replaymod.events;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiIngame;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiYesNoCallback;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity.MoveDirection;
|
||||
import eu.crushedpixel.replaymod.gui.GuiCancelRender;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.gui.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayProcess;
|
||||
import eu.crushedpixel.replaymod.replay.spectate.SpectateHandler;
|
||||
import eu.crushedpixel.replaymod.video.ReplayScreenshot;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeyInputHandler {
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private boolean escDown = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onKeyInput(KeyInputEvent event) {
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
if(mc.currentScreen != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(Keyboard.getEventKeyState() && !Keyboard.isRepeatEvent() && Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)
|
||||
&& ReplayHandler.isInPath() && ReplayProcess.isVideoRecording()
|
||||
&& mc.currentScreen == null && !escDown) {
|
||||
mc.displayGuiScreen(new GuiCancelRender());
|
||||
}
|
||||
|
||||
escDown = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && Keyboard.getEventKeyState();
|
||||
|
||||
boolean found = false;
|
||||
|
||||
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
|
||||
for(KeyBinding kb : keyBindings) {
|
||||
if(!kb.isKeyDown()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
boolean speedup = false;
|
||||
|
||||
if(ReplayHandler.isCamera()) {
|
||||
if(kb.getKeyDescription().equals("key.forward")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.FORWARD);
|
||||
speedup = true;
|
||||
}
|
||||
private boolean escDown = false;
|
||||
|
||||
if(kb.getKeyDescription().equals("key.back")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.BACKWARD);
|
||||
speedup = true;
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onKeyInput(KeyInputEvent event) {
|
||||
|
||||
if(kb.getKeyDescription().equals("key.jump")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.UP);
|
||||
speedup = true;
|
||||
}
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
if(mc.currentScreen != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.left")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.LEFT);
|
||||
speedup = true;
|
||||
}
|
||||
if(Keyboard.getEventKeyState() && !Keyboard.isRepeatEvent() && Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)
|
||||
&& ReplayHandler.isInPath() && ReplayProcess.isVideoRecording()
|
||||
&& mc.currentScreen == null && !escDown) {
|
||||
mc.displayGuiScreen(new GuiCancelRender());
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.right")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.RIGHT);
|
||||
speedup = true;
|
||||
}
|
||||
}
|
||||
if(kb.getKeyDescription().equals("key.sneak")) {
|
||||
if(ReplayHandler.isCamera()) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.DOWN);
|
||||
speedup = true;
|
||||
} else {
|
||||
ReplayHandler.spectateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
if(speedup) {
|
||||
ReplayHandler.getCameraEntity().speedUp();
|
||||
}
|
||||
escDown = Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) && Keyboard.getEventKeyState();
|
||||
|
||||
if(kb.getKeyDescription().equals("key.chat")) {
|
||||
mc.displayGuiScreen(new GuiMouseInput());
|
||||
break;
|
||||
}
|
||||
boolean found = false;
|
||||
|
||||
//Custom registered handlers
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && kb.isPressed() && !found) {
|
||||
TickAndRenderListener.requestScreenshot();
|
||||
//TODO: Make this properly work
|
||||
}
|
||||
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
|
||||
for(KeyBinding kb : keyBindings) {
|
||||
if(!kb.isKeyDown()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
boolean speedup = false;
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SPECTATE) && kb.isPressed() && !found) {
|
||||
SpectateHandler.openSpectateSelection();
|
||||
}
|
||||
if(ReplayHandler.isCamera()) {
|
||||
if(kb.getKeyDescription().equals("key.forward")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.FORWARD);
|
||||
speedup = true;
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_LIGHTING) && kb.isPressed()) {
|
||||
ReplayMod.replaySettings.setLightingEnabled(!ReplayMod.replaySettings.isLightingEnabled());
|
||||
}
|
||||
if(kb.getKeyDescription().equals("key.back")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.BACKWARD);
|
||||
speedup = true;
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
if(kb.getKeyDescription().equals("key.jump")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.UP);
|
||||
speedup = true;
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.left")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.LEFT);
|
||||
speedup = true;
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.right")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.RIGHT);
|
||||
speedup = true;
|
||||
}
|
||||
}
|
||||
if(kb.getKeyDescription().equals("key.sneak")) {
|
||||
if(ReplayHandler.isCamera()) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.DOWN);
|
||||
speedup = true;
|
||||
} else {
|
||||
ReplayHandler.spectateCamera();
|
||||
}
|
||||
}
|
||||
|
||||
if(speedup) {
|
||||
ReplayHandler.getCameraEntity().speedUp();
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.chat")) {
|
||||
mc.displayGuiScreen(new GuiMouseInput());
|
||||
break;
|
||||
}
|
||||
|
||||
//Custom registered handlers
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && kb.isPressed() && !found) {
|
||||
TickAndRenderListener.requestScreenshot();
|
||||
//TODO: Make this properly work
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SPECTATE) && kb.isPressed() && !found) {
|
||||
SpectateHandler.openSpectateSelection();
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_LIGHTING) && kb.isPressed()) {
|
||||
ReplayMod.replaySettings.setLightingEnabled(!ReplayMod.replaySettings.isLightingEnabled());
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
package eu.crushedpixel.replaymod.events;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiChat;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -17,425 +13,344 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.play.client.C16PacketClientStatus;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ReportedException;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class MinecraftTicker {
|
||||
|
||||
private static Field debugCrashKeyPressTime, rightClickDelayTimer, systemTime, leftClickCounter;
|
||||
private static Method getSystemTime, updateDebugProfilerName,
|
||||
clickMouse, middleClickMouse, rightClickMouse, sendClickBlockToController;
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static float camPitch, camYaw, smoothCamPartialTicks,
|
||||
smoothCamFilterX, smoothCamFilterY;
|
||||
|
||||
static {
|
||||
try {
|
||||
debugCrashKeyPressTime = Minecraft.class.getDeclaredField(MCPNames.field("field_83002_am"));
|
||||
debugCrashKeyPressTime.setAccessible(true);
|
||||
|
||||
rightClickDelayTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71467_ac"));
|
||||
rightClickDelayTimer.setAccessible(true);
|
||||
|
||||
systemTime = Minecraft.class.getDeclaredField(MCPNames.field("field_71423_H"));
|
||||
systemTime.setAccessible(true);
|
||||
|
||||
leftClickCounter = Minecraft.class.getDeclaredField(MCPNames.field("field_71429_W"));
|
||||
leftClickCounter.setAccessible(true);
|
||||
|
||||
getSystemTime = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71386_F"));
|
||||
getSystemTime.setAccessible(true);
|
||||
|
||||
updateDebugProfilerName = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71383_b"), int.class);
|
||||
updateDebugProfilerName.setAccessible(true);
|
||||
|
||||
clickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147116_af"));
|
||||
clickMouse.setAccessible(true);
|
||||
|
||||
rightClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147121_ag"));
|
||||
rightClickMouse.setAccessible(true);
|
||||
|
||||
middleClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147112_ai"));
|
||||
middleClickMouse.setAccessible(true);
|
||||
|
||||
sendClickBlockToController = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147115_a"), boolean.class);
|
||||
sendClickBlockToController.setAccessible(true);
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runMouseKeyboardTick(Minecraft mc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
|
||||
|
||||
if(mc.thePlayer == null) return;
|
||||
try {
|
||||
mc.mcProfiler.endStartSection("mouse");
|
||||
int i;
|
||||
while(Mouse.next()) {
|
||||
i = Mouse.getEventButton();
|
||||
KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());
|
||||
|
||||
if (Mouse.getEventButtonState())
|
||||
{
|
||||
if (mc.thePlayer.isSpectator() && i == 2)
|
||||
{
|
||||
mc.ingameGUI.func_175187_g().func_175261_b();
|
||||
}
|
||||
else
|
||||
{
|
||||
KeyBinding.onTick(i - 100);
|
||||
}
|
||||
}
|
||||
|
||||
long k = (Long)getSystemTime.invoke(mc) - (Long)systemTime.get(mc);
|
||||
|
||||
if (k <= 200L)
|
||||
{
|
||||
int j = Mouse.getEventDWheel();
|
||||
|
||||
if (j != 0)
|
||||
{
|
||||
if (mc.thePlayer.isSpectator())
|
||||
{
|
||||
j = j < 0 ? -1 : 1;
|
||||
|
||||
if (mc.ingameGUI.func_175187_g().func_175262_a())
|
||||
{
|
||||
mc.ingameGUI.func_175187_g().func_175259_b(-j);
|
||||
}
|
||||
else
|
||||
{
|
||||
float f = MathHelper.clamp_float(mc.thePlayer.capabilities.getFlySpeed() + (float)j * 0.005F, 0.0F, 0.2F);
|
||||
mc.thePlayer.capabilities.setFlySpeed(f);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.thePlayer.inventory.changeCurrentItem(j);
|
||||
}
|
||||
}
|
||||
|
||||
if (mc.currentScreen == null)
|
||||
{
|
||||
if (!mc.inGameHasFocus && Mouse.getEventButtonState())
|
||||
{
|
||||
mc.setIngameFocus();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.currentScreen.handleMouseInput();
|
||||
}
|
||||
}
|
||||
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireMouseInput();
|
||||
}
|
||||
|
||||
if ((Integer)leftClickCounter.get(mc) > 0)
|
||||
{
|
||||
leftClickCounter.set(mc, (Integer)leftClickCounter.get(mc) - 1);
|
||||
}
|
||||
mc.mcProfiler.endStartSection("keyboard");
|
||||
|
||||
while (Keyboard.next())
|
||||
{
|
||||
i = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
|
||||
KeyBinding.setKeyBindState(i, Keyboard.getEventKeyState());
|
||||
|
||||
if (Keyboard.getEventKeyState())
|
||||
{
|
||||
KeyBinding.onTick(i);
|
||||
}
|
||||
|
||||
if ((Long)debugCrashKeyPressTime.get(mc) > 0L)
|
||||
{
|
||||
if ((Long)getSystemTime.invoke(mc) - (Long)debugCrashKeyPressTime.get(mc) >= 6000L)
|
||||
{
|
||||
throw new ReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
|
||||
}
|
||||
|
||||
if (!Keyboard.isKeyDown(46) || !Keyboard.isKeyDown(61))
|
||||
{
|
||||
debugCrashKeyPressTime.set(mc, -1);
|
||||
}
|
||||
}
|
||||
else if (Keyboard.isKeyDown(46) && Keyboard.isKeyDown(61))
|
||||
{
|
||||
debugCrashKeyPressTime.set(mc, getSystemTime.invoke(mc));
|
||||
}
|
||||
|
||||
mc.dispatchKeypresses();
|
||||
|
||||
if (Keyboard.getEventKeyState())
|
||||
{
|
||||
if (i == 62 && mc.entityRenderer != null)
|
||||
{
|
||||
mc.entityRenderer.switchUseShader();
|
||||
}
|
||||
|
||||
if (mc.currentScreen != null)
|
||||
{
|
||||
mc.currentScreen.handleKeyboardInput();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (i == 1)
|
||||
{
|
||||
mc.displayInGameMenu();
|
||||
}
|
||||
|
||||
if (i == 32 && Keyboard.isKeyDown(61) && mc.ingameGUI != null)
|
||||
{
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
}
|
||||
|
||||
if (i == 31 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.refreshResources();
|
||||
}
|
||||
|
||||
if (i == 17 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (i == 18 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (i == 47 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (i == 38 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (i == 22 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
if (i == 20 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.refreshResources();
|
||||
}
|
||||
|
||||
if (i == 33 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
boolean flag1 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
|
||||
mc.gameSettings.setOptionValue(GameSettings.Options.RENDER_DISTANCE, flag1 ? -1 : 1);
|
||||
}
|
||||
|
||||
if (i == 30 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.renderGlobal.loadRenderers();
|
||||
}
|
||||
|
||||
if (i == 35 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.gameSettings.advancedItemTooltips = !mc.gameSettings.advancedItemTooltips;
|
||||
mc.gameSettings.saveOptions();
|
||||
}
|
||||
|
||||
if (i == 48 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.getRenderManager().setDebugBoundingBox(!mc.getRenderManager().isDebugBoundingBox());
|
||||
}
|
||||
|
||||
if (i == 25 && Keyboard.isKeyDown(61))
|
||||
{
|
||||
mc.gameSettings.pauseOnLostFocus = !mc.gameSettings.pauseOnLostFocus;
|
||||
mc.gameSettings.saveOptions();
|
||||
}
|
||||
|
||||
if (i == 59)
|
||||
{
|
||||
mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
|
||||
}
|
||||
|
||||
if (i == 61)
|
||||
{
|
||||
mc.gameSettings.showDebugInfo = !mc.gameSettings.showDebugInfo;
|
||||
mc.gameSettings.showDebugProfilerChart = GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
|
||||
if (mc.gameSettings.keyBindTogglePerspective.isPressed())
|
||||
{
|
||||
++mc.gameSettings.thirdPersonView;
|
||||
|
||||
if (mc.gameSettings.thirdPersonView > 2)
|
||||
{
|
||||
mc.gameSettings.thirdPersonView = 0;
|
||||
}
|
||||
|
||||
if (mc.gameSettings.thirdPersonView == 0)
|
||||
{
|
||||
mc.entityRenderer.loadEntityShader(mc.getRenderViewEntity());
|
||||
}
|
||||
else if (mc.gameSettings.thirdPersonView == 1)
|
||||
{
|
||||
mc.entityRenderer.loadEntityShader((Entity)null);
|
||||
}
|
||||
}
|
||||
|
||||
if (mc.gameSettings.keyBindSmoothCamera.isPressed())
|
||||
{
|
||||
mc.gameSettings.smoothCamera = !mc.gameSettings.smoothCamera;
|
||||
}
|
||||
}
|
||||
|
||||
if (mc.gameSettings.showDebugInfo && mc.gameSettings.showDebugProfilerChart)
|
||||
{
|
||||
if (i == 11)
|
||||
{
|
||||
updateDebugProfilerName.invoke(mc, 0);
|
||||
}
|
||||
|
||||
for (int l = 0; l < 9; ++l)
|
||||
{
|
||||
if (i == 2 + l)
|
||||
{
|
||||
updateDebugProfilerName.invoke(mc, l+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireKeyInput();
|
||||
}
|
||||
|
||||
for (i = 0; i < 9; ++i)
|
||||
{
|
||||
if (mc.gameSettings.keyBindsHotbar[i].isPressed())
|
||||
{
|
||||
if (mc.thePlayer.isSpectator())
|
||||
{
|
||||
mc.ingameGUI.func_175187_g().func_175260_a(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.thePlayer.inventory.currentItem = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN;
|
||||
|
||||
while (mc.gameSettings.keyBindInventory.isPressed())
|
||||
{
|
||||
if (mc.playerController.isRidingHorse())
|
||||
{
|
||||
mc.thePlayer.sendHorseInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));
|
||||
mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
|
||||
}
|
||||
}
|
||||
|
||||
while (mc.gameSettings.keyBindDrop.isPressed())
|
||||
{
|
||||
if (!mc.thePlayer.isSpectator())
|
||||
{
|
||||
mc.thePlayer.dropOneItem(GuiScreen.isCtrlKeyDown());
|
||||
}
|
||||
}
|
||||
|
||||
while (mc.gameSettings.keyBindChat.isPressed() && flag)
|
||||
{
|
||||
mc.displayGuiScreen(new GuiChat());
|
||||
}
|
||||
|
||||
if (mc.currentScreen == null && mc.gameSettings.keyBindCommand.isPressed() && flag)
|
||||
{
|
||||
mc.displayGuiScreen(new GuiChat("/"));
|
||||
}
|
||||
|
||||
if (mc.thePlayer != null && mc.thePlayer.isUsingItem())
|
||||
{
|
||||
if (!mc.gameSettings.keyBindUseItem.isKeyDown())
|
||||
{
|
||||
mc.playerController.onStoppedUsingItem(mc.thePlayer);
|
||||
}
|
||||
|
||||
label435:
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!mc.gameSettings.keyBindAttack.isPressed())
|
||||
{
|
||||
while (mc.gameSettings.keyBindUseItem.isPressed())
|
||||
{
|
||||
;
|
||||
}
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (mc.gameSettings.keyBindPickBlock.isPressed())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
break label435;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (mc.gameSettings.keyBindAttack.isPressed())
|
||||
{
|
||||
if(mc != null)
|
||||
try {
|
||||
clickMouse.invoke(mc);
|
||||
} catch(Exception e) {}
|
||||
|
||||
}
|
||||
|
||||
while (mc.gameSettings.keyBindUseItem.isPressed())
|
||||
{
|
||||
if(mc != null)
|
||||
try {
|
||||
rightClickMouse.invoke(mc);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
while (mc.gameSettings.keyBindPickBlock.isPressed())
|
||||
{
|
||||
if(mc != null)
|
||||
try {
|
||||
middleClickMouse.invoke(mc);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
}
|
||||
|
||||
if (mc.gameSettings.keyBindUseItem.isKeyDown() && (Integer)rightClickDelayTimer.get(mc) == 0 && !mc.thePlayer.isUsingItem())
|
||||
{
|
||||
if(mc != null)
|
||||
try {
|
||||
rightClickMouse.invoke(mc);
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
|
||||
if(mc != null)
|
||||
try {
|
||||
sendClickBlockToController.invoke(mc, mc.currentScreen == null && mc.gameSettings.keyBindAttack.isKeyDown() && mc.inGameHasFocus);
|
||||
} catch(Exception e) {}
|
||||
|
||||
if(mc != null)
|
||||
systemTime.set(mc, getSystemTime.invoke(mc));
|
||||
} catch(Exception e) {}
|
||||
}
|
||||
private static Field debugCrashKeyPressTime, rightClickDelayTimer, systemTime, leftClickCounter;
|
||||
private static Method getSystemTime, updateDebugProfilerName,
|
||||
clickMouse, middleClickMouse, rightClickMouse, sendClickBlockToController;
|
||||
|
||||
static {
|
||||
try {
|
||||
debugCrashKeyPressTime = Minecraft.class.getDeclaredField(MCPNames.field("field_83002_am"));
|
||||
debugCrashKeyPressTime.setAccessible(true);
|
||||
|
||||
rightClickDelayTimer = Minecraft.class.getDeclaredField(MCPNames.field("field_71467_ac"));
|
||||
rightClickDelayTimer.setAccessible(true);
|
||||
|
||||
systemTime = Minecraft.class.getDeclaredField(MCPNames.field("field_71423_H"));
|
||||
systemTime.setAccessible(true);
|
||||
|
||||
leftClickCounter = Minecraft.class.getDeclaredField(MCPNames.field("field_71429_W"));
|
||||
leftClickCounter.setAccessible(true);
|
||||
|
||||
getSystemTime = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71386_F"));
|
||||
getSystemTime.setAccessible(true);
|
||||
|
||||
updateDebugProfilerName = Minecraft.class.getDeclaredMethod(MCPNames.method("func_71383_b"), int.class);
|
||||
updateDebugProfilerName.setAccessible(true);
|
||||
|
||||
clickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147116_af"));
|
||||
clickMouse.setAccessible(true);
|
||||
|
||||
rightClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147121_ag"));
|
||||
rightClickMouse.setAccessible(true);
|
||||
|
||||
middleClickMouse = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147112_ai"));
|
||||
middleClickMouse.setAccessible(true);
|
||||
|
||||
sendClickBlockToController = Minecraft.class.getDeclaredMethod(MCPNames.method("func_147115_a"), boolean.class);
|
||||
sendClickBlockToController.setAccessible(true);
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void runMouseKeyboardTick(Minecraft mc) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException {
|
||||
|
||||
if(mc.thePlayer == null) return;
|
||||
try {
|
||||
mc.mcProfiler.endStartSection("mouse");
|
||||
int i;
|
||||
while(Mouse.next()) {
|
||||
i = Mouse.getEventButton();
|
||||
KeyBinding.setKeyBindState(i - 100, Mouse.getEventButtonState());
|
||||
|
||||
if(Mouse.getEventButtonState()) {
|
||||
if(mc.thePlayer.isSpectator() && i == 2) {
|
||||
mc.ingameGUI.func_175187_g().func_175261_b();
|
||||
} else {
|
||||
KeyBinding.onTick(i - 100);
|
||||
}
|
||||
}
|
||||
|
||||
long k = (Long) getSystemTime.invoke(mc) - (Long) systemTime.get(mc);
|
||||
|
||||
if(k <= 200L) {
|
||||
int j = Mouse.getEventDWheel();
|
||||
|
||||
if(j != 0) {
|
||||
if(mc.thePlayer.isSpectator()) {
|
||||
j = j < 0 ? -1 : 1;
|
||||
|
||||
if(mc.ingameGUI.func_175187_g().func_175262_a()) {
|
||||
mc.ingameGUI.func_175187_g().func_175259_b(-j);
|
||||
} else {
|
||||
float f = MathHelper.clamp_float(mc.thePlayer.capabilities.getFlySpeed() + (float) j * 0.005F, 0.0F, 0.2F);
|
||||
mc.thePlayer.capabilities.setFlySpeed(f);
|
||||
}
|
||||
} else {
|
||||
mc.thePlayer.inventory.changeCurrentItem(j);
|
||||
}
|
||||
}
|
||||
|
||||
if(mc.currentScreen == null) {
|
||||
if(!mc.inGameHasFocus && Mouse.getEventButtonState()) {
|
||||
mc.setIngameFocus();
|
||||
}
|
||||
} else {
|
||||
mc.currentScreen.handleMouseInput();
|
||||
}
|
||||
}
|
||||
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireMouseInput();
|
||||
}
|
||||
|
||||
if((Integer) leftClickCounter.get(mc) > 0) {
|
||||
leftClickCounter.set(mc, (Integer) leftClickCounter.get(mc) - 1);
|
||||
}
|
||||
mc.mcProfiler.endStartSection("keyboard");
|
||||
|
||||
while(Keyboard.next()) {
|
||||
i = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter() + 256 : Keyboard.getEventKey();
|
||||
KeyBinding.setKeyBindState(i, Keyboard.getEventKeyState());
|
||||
|
||||
if(Keyboard.getEventKeyState()) {
|
||||
KeyBinding.onTick(i);
|
||||
}
|
||||
|
||||
if((Long) debugCrashKeyPressTime.get(mc) > 0L) {
|
||||
if((Long) getSystemTime.invoke(mc) - (Long) debugCrashKeyPressTime.get(mc) >= 6000L) {
|
||||
throw new ReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
|
||||
}
|
||||
|
||||
if(!Keyboard.isKeyDown(46) || !Keyboard.isKeyDown(61)) {
|
||||
debugCrashKeyPressTime.set(mc, -1);
|
||||
}
|
||||
} else if(Keyboard.isKeyDown(46) && Keyboard.isKeyDown(61)) {
|
||||
debugCrashKeyPressTime.set(mc, getSystemTime.invoke(mc));
|
||||
}
|
||||
|
||||
mc.dispatchKeypresses();
|
||||
|
||||
if(Keyboard.getEventKeyState()) {
|
||||
if(i == 62 && mc.entityRenderer != null) {
|
||||
mc.entityRenderer.switchUseShader();
|
||||
}
|
||||
|
||||
if(mc.currentScreen != null) {
|
||||
mc.currentScreen.handleKeyboardInput();
|
||||
} else {
|
||||
if(i == 1) {
|
||||
mc.displayInGameMenu();
|
||||
}
|
||||
|
||||
if(i == 32 && Keyboard.isKeyDown(61) && mc.ingameGUI != null) {
|
||||
mc.ingameGUI.getChatGUI().clearChatMessages();
|
||||
}
|
||||
|
||||
if(i == 31 && Keyboard.isKeyDown(61)) {
|
||||
mc.refreshResources();
|
||||
}
|
||||
|
||||
if(i == 17 && Keyboard.isKeyDown(61)) {
|
||||
;
|
||||
}
|
||||
|
||||
if(i == 18 && Keyboard.isKeyDown(61)) {
|
||||
;
|
||||
}
|
||||
|
||||
if(i == 47 && Keyboard.isKeyDown(61)) {
|
||||
;
|
||||
}
|
||||
|
||||
if(i == 38 && Keyboard.isKeyDown(61)) {
|
||||
;
|
||||
}
|
||||
|
||||
if(i == 22 && Keyboard.isKeyDown(61)) {
|
||||
;
|
||||
}
|
||||
|
||||
if(i == 20 && Keyboard.isKeyDown(61)) {
|
||||
mc.refreshResources();
|
||||
}
|
||||
|
||||
if(i == 33 && Keyboard.isKeyDown(61)) {
|
||||
boolean flag1 = Keyboard.isKeyDown(42) | Keyboard.isKeyDown(54);
|
||||
mc.gameSettings.setOptionValue(GameSettings.Options.RENDER_DISTANCE, flag1 ? -1 : 1);
|
||||
}
|
||||
|
||||
if(i == 30 && Keyboard.isKeyDown(61)) {
|
||||
mc.renderGlobal.loadRenderers();
|
||||
}
|
||||
|
||||
if(i == 35 && Keyboard.isKeyDown(61)) {
|
||||
mc.gameSettings.advancedItemTooltips = !mc.gameSettings.advancedItemTooltips;
|
||||
mc.gameSettings.saveOptions();
|
||||
}
|
||||
|
||||
if(i == 48 && Keyboard.isKeyDown(61)) {
|
||||
mc.getRenderManager().setDebugBoundingBox(!mc.getRenderManager().isDebugBoundingBox());
|
||||
}
|
||||
|
||||
if(i == 25 && Keyboard.isKeyDown(61)) {
|
||||
mc.gameSettings.pauseOnLostFocus = !mc.gameSettings.pauseOnLostFocus;
|
||||
mc.gameSettings.saveOptions();
|
||||
}
|
||||
|
||||
if(i == 59) {
|
||||
mc.gameSettings.hideGUI = !mc.gameSettings.hideGUI;
|
||||
}
|
||||
|
||||
if(i == 61) {
|
||||
mc.gameSettings.showDebugInfo = !mc.gameSettings.showDebugInfo;
|
||||
mc.gameSettings.showDebugProfilerChart = GuiScreen.isShiftKeyDown();
|
||||
}
|
||||
|
||||
if(mc.gameSettings.keyBindTogglePerspective.isPressed()) {
|
||||
++mc.gameSettings.thirdPersonView;
|
||||
|
||||
if(mc.gameSettings.thirdPersonView > 2) {
|
||||
mc.gameSettings.thirdPersonView = 0;
|
||||
}
|
||||
|
||||
if(mc.gameSettings.thirdPersonView == 0) {
|
||||
mc.entityRenderer.loadEntityShader(mc.getRenderViewEntity());
|
||||
} else if(mc.gameSettings.thirdPersonView == 1) {
|
||||
mc.entityRenderer.loadEntityShader((Entity) null);
|
||||
}
|
||||
}
|
||||
|
||||
if(mc.gameSettings.keyBindSmoothCamera.isPressed()) {
|
||||
mc.gameSettings.smoothCamera = !mc.gameSettings.smoothCamera;
|
||||
}
|
||||
}
|
||||
|
||||
if(mc.gameSettings.showDebugInfo && mc.gameSettings.showDebugProfilerChart) {
|
||||
if(i == 11) {
|
||||
updateDebugProfilerName.invoke(mc, 0);
|
||||
}
|
||||
|
||||
for(int l = 0; l < 9; ++l) {
|
||||
if(i == 2 + l) {
|
||||
updateDebugProfilerName.invoke(mc, l + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
net.minecraftforge.fml.common.FMLCommonHandler.instance().fireKeyInput();
|
||||
}
|
||||
|
||||
for(i = 0; i < 9; ++i) {
|
||||
if(mc.gameSettings.keyBindsHotbar[i].isPressed()) {
|
||||
if(mc.thePlayer.isSpectator()) {
|
||||
mc.ingameGUI.func_175187_g().func_175260_a(i);
|
||||
} else {
|
||||
mc.thePlayer.inventory.currentItem = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean flag = mc.gameSettings.chatVisibility != EntityPlayer.EnumChatVisibility.HIDDEN;
|
||||
|
||||
while(mc.gameSettings.keyBindInventory.isPressed()) {
|
||||
if(mc.playerController.isRidingHorse()) {
|
||||
mc.thePlayer.sendHorseInventory();
|
||||
} else {
|
||||
mc.getNetHandler().addToSendQueue(new C16PacketClientStatus(C16PacketClientStatus.EnumState.OPEN_INVENTORY_ACHIEVEMENT));
|
||||
mc.displayGuiScreen(new GuiInventory(mc.thePlayer));
|
||||
}
|
||||
}
|
||||
|
||||
while(mc.gameSettings.keyBindDrop.isPressed()) {
|
||||
if(!mc.thePlayer.isSpectator()) {
|
||||
mc.thePlayer.dropOneItem(GuiScreen.isCtrlKeyDown());
|
||||
}
|
||||
}
|
||||
|
||||
while(mc.gameSettings.keyBindChat.isPressed() && flag) {
|
||||
mc.displayGuiScreen(new GuiChat());
|
||||
}
|
||||
|
||||
if(mc.currentScreen == null && mc.gameSettings.keyBindCommand.isPressed() && flag) {
|
||||
mc.displayGuiScreen(new GuiChat("/"));
|
||||
}
|
||||
|
||||
if(mc.thePlayer != null && mc.thePlayer.isUsingItem()) {
|
||||
if(!mc.gameSettings.keyBindUseItem.isKeyDown()) {
|
||||
mc.playerController.onStoppedUsingItem(mc.thePlayer);
|
||||
}
|
||||
|
||||
label435:
|
||||
|
||||
while(true) {
|
||||
if(!mc.gameSettings.keyBindAttack.isPressed()) {
|
||||
while(mc.gameSettings.keyBindUseItem.isPressed()) {
|
||||
;
|
||||
}
|
||||
|
||||
while(true) {
|
||||
if(mc.gameSettings.keyBindPickBlock.isPressed()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
break label435;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while(mc.gameSettings.keyBindAttack.isPressed()) {
|
||||
if(mc != null)
|
||||
try {
|
||||
clickMouse.invoke(mc);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
while(mc.gameSettings.keyBindUseItem.isPressed()) {
|
||||
if(mc != null)
|
||||
try {
|
||||
rightClickMouse.invoke(mc);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
while(mc.gameSettings.keyBindPickBlock.isPressed()) {
|
||||
if(mc != null)
|
||||
try {
|
||||
middleClickMouse.invoke(mc);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mc.gameSettings.keyBindUseItem.isKeyDown() && (Integer) rightClickDelayTimer.get(mc) == 0 && !mc.thePlayer.isUsingItem()) {
|
||||
if(mc != null)
|
||||
try {
|
||||
rightClickMouse.invoke(mc);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
if(mc != null)
|
||||
try {
|
||||
sendClickBlockToController.invoke(mc, mc.currentScreen == null && mc.gameSettings.keyBindAttack.isKeyDown() && mc.inGameHasFocus);
|
||||
} catch(Exception e) {
|
||||
}
|
||||
|
||||
if(mc != null)
|
||||
systemTime.set(mc, getSystemTime.invoke(mc));
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,17 @@
|
||||
package eu.crushedpixel.replaymod.events;
|
||||
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.Packet;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.network.play.server.S04PacketEntityEquipment;
|
||||
import net.minecraft.network.play.server.S0APacketUseBed;
|
||||
import net.minecraft.network.play.server.S0BPacketAnimation;
|
||||
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
|
||||
import net.minecraft.network.play.server.S0DPacketCollectItem;
|
||||
import net.minecraft.network.play.server.S12PacketEntityVelocity;
|
||||
import net.minecraft.network.play.server.S13PacketDestroyEntities;
|
||||
import net.minecraft.network.play.server.*;
|
||||
import net.minecraft.network.play.server.S14PacketEntity.S17PacketEntityLookMove;
|
||||
import net.minecraft.network.play.server.S18PacketEntityTeleport;
|
||||
import net.minecraft.network.play.server.S19PacketEntityHeadLook;
|
||||
import net.minecraft.network.play.server.S19PacketEntityStatus;
|
||||
import net.minecraft.network.play.server.S1BPacketEntityAttach;
|
||||
import net.minecraft.network.play.server.S38PacketPlayerListItem;
|
||||
import net.minecraft.network.play.server.S38PacketPlayerListItem.Action;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
@@ -38,190 +24,190 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.ItemPickupEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordingHandler {
|
||||
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
public static final int entityID = Integer.MIN_VALUE + 9001;
|
||||
private static Field dataWatcherField;
|
||||
|
||||
public static final int entityID = Integer.MIN_VALUE+9001;
|
||||
static {
|
||||
try {
|
||||
dataWatcherField = S0CPacketSpawnPlayer.class.getDeclaredField(MCPNames.field("field_148960_i"));
|
||||
dataWatcherField.setAccessible(true);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerJoin(EntityJoinWorldEvent e) {
|
||||
try {
|
||||
if(e.entity != mc.thePlayer) return;
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private Double lastX = null, lastY = null, lastZ = null;
|
||||
private List<Integer> lastEffects = new ArrayList<Integer>();
|
||||
private ItemStack[] playerItems = new ItemStack[5];
|
||||
private int ticksSinceLastCorrection = 0;
|
||||
private boolean wasSleeping = false;
|
||||
private int lastRiding = -1;
|
||||
|
||||
EntityPlayer player = (EntityPlayer)e.entity;
|
||||
@SubscribeEvent
|
||||
public void onPlayerJoin(EntityJoinWorldEvent e) {
|
||||
try {
|
||||
if(e.entity != mc.thePlayer) return;
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
|
||||
S38PacketPlayerListItem ppli = new S38PacketPlayerListItem();
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
EntityPlayer player = (EntityPlayer) e.entity;
|
||||
|
||||
pbuf.writeEnumValue(Action.ADD_PLAYER);
|
||||
pbuf.writeVarIntToBuffer(1);
|
||||
pbuf.writeUuid(e.entity.getUniqueID());
|
||||
S38PacketPlayerListItem ppli = new S38PacketPlayerListItem();
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeString(player.getName());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
pbuf.writeVarIntToBuffer(mc.playerController.getCurrentGameType().getID());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
pbuf.writeEnumValue(Action.ADD_PLAYER);
|
||||
pbuf.writeVarIntToBuffer(1);
|
||||
pbuf.writeUuid(e.entity.getUniqueID());
|
||||
|
||||
pbuf.writeBoolean(true);
|
||||
pbuf.writeChatComponent(player.getDisplayName());
|
||||
pbuf.writeString(player.getName());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
pbuf.writeVarIntToBuffer(mc.playerController.getCurrentGameType().getID());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
|
||||
ppli.readPacketData(pbuf);
|
||||
ConnectionEventHandler.insertPacket(ppli);
|
||||
pbuf.writeBoolean(true);
|
||||
pbuf.writeChatComponent(player.getDisplayName());
|
||||
|
||||
ConnectionEventHandler.insertPacket(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
ppli.readPacketData(pbuf);
|
||||
ConnectionEventHandler.insertPacket(ppli);
|
||||
|
||||
private static Field dataWatcherField;
|
||||
ConnectionEventHandler.insertPacket(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
static {
|
||||
try {
|
||||
dataWatcherField = S0CPacketSpawnPlayer.class.getDeclaredField(MCPNames.field("field_148960_i"));
|
||||
dataWatcherField.setAccessible(true);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private S0CPacketSpawnPlayer spawnPlayer(EntityPlayer player) {
|
||||
try {
|
||||
S0CPacketSpawnPlayer packet = new S0CPacketSpawnPlayer();
|
||||
private S0CPacketSpawnPlayer spawnPlayer(EntityPlayer player) {
|
||||
try {
|
||||
S0CPacketSpawnPlayer packet = new S0CPacketSpawnPlayer();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeUuid(player.getUUID(player.getGameProfile()));
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeUuid(player.getUUID(player.getGameProfile()));
|
||||
|
||||
pb.writeInt(MathHelper.floor_double(player.posX * 32.0D));
|
||||
pb.writeInt(MathHelper.floor_double(player.posY * 32.0D));
|
||||
pb.writeInt(MathHelper.floor_double(player.posZ * 32.0D));
|
||||
pb.writeByte((byte)((int)(player.rotationYaw * 256.0F / 360.0F)));
|
||||
pb.writeByte((byte)((int)(player.rotationPitch * 256.0F / 360.0F)));
|
||||
pb.writeInt(MathHelper.floor_double(player.posX * 32.0D));
|
||||
pb.writeInt(MathHelper.floor_double(player.posY * 32.0D));
|
||||
pb.writeInt(MathHelper.floor_double(player.posZ * 32.0D));
|
||||
pb.writeByte((byte) ((int) (player.rotationYaw * 256.0F / 360.0F)));
|
||||
pb.writeByte((byte) ((int) (player.rotationPitch * 256.0F / 360.0F)));
|
||||
|
||||
ItemStack itemstack = player.inventory.getCurrentItem();
|
||||
pb.writeShort(itemstack == null ? 0 : Item.getIdFromItem(itemstack.getItem()));
|
||||
|
||||
player.getDataWatcher().writeTo(pb);
|
||||
ItemStack itemstack = player.inventory.getCurrentItem();
|
||||
pb.writeShort(itemstack == null ? 0 : Item.getIdFromItem(itemstack.getItem()));
|
||||
|
||||
packet.readPacketData(pb);
|
||||
|
||||
dataWatcherField.set(packet, player.getDataWatcher());
|
||||
|
||||
return packet;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
player.getDataWatcher().writeTo(pb);
|
||||
|
||||
private Double lastX = null, lastY = null, lastZ = null;
|
||||
private List<Integer> lastEffects = new ArrayList<Integer>();
|
||||
packet.readPacketData(pb);
|
||||
|
||||
private ItemStack[] playerItems = new ItemStack[5];
|
||||
dataWatcherField.set(packet, player.getDataWatcher());
|
||||
|
||||
public void resetVars() {
|
||||
lastX = lastY = lastZ = null;
|
||||
lastEffects = new ArrayList<Integer>();
|
||||
playerItems = new ItemStack[5];
|
||||
}
|
||||
return packet;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int ticksSinceLastCorrection = 0;
|
||||
public void resetVars() {
|
||||
lastX = lastY = lastZ = null;
|
||||
lastEffects = new ArrayList<Integer>();
|
||||
playerItems = new ItemStack[5];
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(PlayerTickEvent e) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(e.player != mc.thePlayer) return;
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
@SubscribeEvent
|
||||
public void onPlayerTick(PlayerTickEvent e) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(e.player != mc.thePlayer) return;
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
|
||||
boolean force = false;
|
||||
if(lastX == null || lastY == null || lastZ == null) {
|
||||
force = true;
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastZ = e.player.posZ;
|
||||
}
|
||||
boolean force = false;
|
||||
if(lastX == null || lastY == null || lastZ == null) {
|
||||
force = true;
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastZ = e.player.posZ;
|
||||
}
|
||||
|
||||
ticksSinceLastCorrection++;
|
||||
if(ticksSinceLastCorrection >= 100) {
|
||||
ticksSinceLastCorrection = 0;
|
||||
force = true;
|
||||
}
|
||||
ticksSinceLastCorrection++;
|
||||
if(ticksSinceLastCorrection >= 100) {
|
||||
ticksSinceLastCorrection = 0;
|
||||
force = true;
|
||||
}
|
||||
|
||||
double dx = e.player.posX - lastX;
|
||||
double dy = e.player.posY - lastY;
|
||||
double dz = e.player.posZ - lastZ;
|
||||
double dx = e.player.posX - lastX;
|
||||
double dy = e.player.posY - lastY;
|
||||
double dz = e.player.posZ - lastZ;
|
||||
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastZ = e.player.posZ;
|
||||
lastX = e.player.posX;
|
||||
lastY = e.player.posY;
|
||||
lastZ = e.player.posZ;
|
||||
|
||||
Packet packet = null;
|
||||
if(force || Math.abs(dx) > 4.0 || Math.abs(dy) > 4.0 || Math.abs(dz) > 4.0) {
|
||||
int x = MathHelper.floor_double(e.player.posX * 32.0D);
|
||||
int y = MathHelper.floor_double(e.player.posY * 32.0D);
|
||||
int z = MathHelper.floor_double(e.player.posZ * 32.0D);
|
||||
byte yaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte pitch = (byte)((int)(e.player.rotationPitch * 256.0F / 360.0F));
|
||||
packet = new S18PacketEntityTeleport(entityID, x, y, z, yaw, pitch, e.player.onGround);
|
||||
} else {
|
||||
byte oldYaw = (byte)((int)(e.player.prevRotationYaw * 256.0F / 360.0F));
|
||||
byte newYaw = (byte)((int)(e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte oldPitch = (byte)((int)(e.player.prevRotationPitch * 256.0F / 360.0F));
|
||||
byte newPitch = (byte)((int)(e.player.rotationPitch * 256.0F / 360.0F));
|
||||
Packet packet = null;
|
||||
if(force || Math.abs(dx) > 4.0 || Math.abs(dy) > 4.0 || Math.abs(dz) > 4.0) {
|
||||
int x = MathHelper.floor_double(e.player.posX * 32.0D);
|
||||
int y = MathHelper.floor_double(e.player.posY * 32.0D);
|
||||
int z = MathHelper.floor_double(e.player.posZ * 32.0D);
|
||||
byte yaw = (byte) ((int) (e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte pitch = (byte) ((int) (e.player.rotationPitch * 256.0F / 360.0F));
|
||||
packet = new S18PacketEntityTeleport(entityID, x, y, z, yaw, pitch, e.player.onGround);
|
||||
} else {
|
||||
byte oldYaw = (byte) ((int) (e.player.prevRotationYaw * 256.0F / 360.0F));
|
||||
byte newYaw = (byte) ((int) (e.player.rotationYaw * 256.0F / 360.0F));
|
||||
byte oldPitch = (byte) ((int) (e.player.prevRotationPitch * 256.0F / 360.0F));
|
||||
byte newPitch = (byte) ((int) (e.player.rotationPitch * 256.0F / 360.0F));
|
||||
|
||||
byte dPitch = (byte)(newPitch-oldPitch);
|
||||
byte dYaw = (byte)(newYaw-oldYaw);
|
||||
byte dPitch = (byte) (newPitch - oldPitch);
|
||||
byte dYaw = (byte) (newYaw - oldYaw);
|
||||
|
||||
packet = new S17PacketEntityLookMove(entityID,
|
||||
(byte)Math.round(dx*32), (byte)Math.round(dy*32), (byte)Math.round(dz*32),
|
||||
newYaw, newPitch, e.player.onGround);
|
||||
}
|
||||
packet = new S17PacketEntityLookMove(entityID,
|
||||
(byte) Math.round(dx * 32), (byte) Math.round(dy * 32), (byte) Math.round(dz * 32),
|
||||
newYaw, newPitch, e.player.onGround);
|
||||
}
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
|
||||
//HEAD POS
|
||||
S19PacketEntityHeadLook head = new S19PacketEntityHeadLook();
|
||||
ByteBuf bb1 = Unpooled.buffer();
|
||||
PacketBuffer pb1 = new PacketBuffer(bb1);
|
||||
//HEAD POS
|
||||
S19PacketEntityHeadLook head = new S19PacketEntityHeadLook();
|
||||
ByteBuf bb1 = Unpooled.buffer();
|
||||
PacketBuffer pb1 = new PacketBuffer(bb1);
|
||||
|
||||
pb1.writeVarIntToBuffer(entityID);
|
||||
pb1.writeByte(((int)(e.player.rotationYawHead * 256.0F / 360.0F)));
|
||||
pb1.writeVarIntToBuffer(entityID);
|
||||
pb1.writeByte(((int) (e.player.rotationYawHead * 256.0F / 360.0F)));
|
||||
|
||||
head.readPacketData(pb1);
|
||||
head.readPacketData(pb1);
|
||||
|
||||
ConnectionEventHandler.insertPacket(head);
|
||||
ConnectionEventHandler.insertPacket(head);
|
||||
|
||||
S12PacketEntityVelocity vel = new S12PacketEntityVelocity(entityID, e.player.motionX, e.player.motionY, e.player.motionZ);
|
||||
ConnectionEventHandler.insertPacket(vel);
|
||||
S12PacketEntityVelocity vel = new S12PacketEntityVelocity(entityID, e.player.motionX, e.player.motionY, e.player.motionZ);
|
||||
ConnectionEventHandler.insertPacket(vel);
|
||||
|
||||
//Animation Packets
|
||||
//Swing Animation
|
||||
if(e.player.swingProgressInt == 1) {
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
//Animation Packets
|
||||
//Swing Animation
|
||||
if(e.player.swingProgressInt == 1) {
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(0);
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(0);
|
||||
|
||||
pac.readPacketData(pb);
|
||||
pac.readPacketData(pb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
}
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
}
|
||||
|
||||
/*
|
||||
//Potion Effect Handling
|
||||
//Potion Effect Handling
|
||||
List<Integer> found = new ArrayList<Integer>();
|
||||
for(PotionEffect pe : (Collection<PotionEffect>)e.player.getActivePotionEffects()) {
|
||||
found.add(pe.getPotionID());
|
||||
@@ -240,243 +226,243 @@ public class RecordingHandler {
|
||||
lastEffects = found;
|
||||
*/
|
||||
|
||||
//Inventory Handling
|
||||
if(playerItems[0] != mc.thePlayer.getHeldItem()) {
|
||||
playerItems[0] = mc.thePlayer.getHeldItem();
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 0, playerItems[0]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
//Inventory Handling
|
||||
if(playerItems[0] != mc.thePlayer.getHeldItem()) {
|
||||
playerItems[0] = mc.thePlayer.getHeldItem();
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 0, playerItems[0]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
if(playerItems[1] != mc.thePlayer.inventory.armorInventory[0]) {
|
||||
playerItems[1] = mc.thePlayer.inventory.armorInventory[0];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 1, playerItems[1]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
if(playerItems[1] != mc.thePlayer.inventory.armorInventory[0]) {
|
||||
playerItems[1] = mc.thePlayer.inventory.armorInventory[0];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 1, playerItems[1]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
if(playerItems[2] != mc.thePlayer.inventory.armorInventory[1]) {
|
||||
playerItems[2] = mc.thePlayer.inventory.armorInventory[1];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 2, playerItems[2]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
if(playerItems[2] != mc.thePlayer.inventory.armorInventory[1]) {
|
||||
playerItems[2] = mc.thePlayer.inventory.armorInventory[1];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 2, playerItems[2]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
if(playerItems[3] != mc.thePlayer.inventory.armorInventory[2]) {
|
||||
playerItems[3] = mc.thePlayer.inventory.armorInventory[2];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 3, playerItems[3]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
if(playerItems[3] != mc.thePlayer.inventory.armorInventory[2]) {
|
||||
playerItems[3] = mc.thePlayer.inventory.armorInventory[2];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 3, playerItems[3]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
if(playerItems[4] != mc.thePlayer.inventory.armorInventory[3]) {
|
||||
playerItems[4] = mc.thePlayer.inventory.armorInventory[3];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 4, playerItems[4]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
if(playerItems[4] != mc.thePlayer.inventory.armorInventory[3]) {
|
||||
playerItems[4] = mc.thePlayer.inventory.armorInventory[3];
|
||||
S04PacketEntityEquipment pee = new S04PacketEntityEquipment(entityID, 4, playerItems[4]);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
//Leaving Ride
|
||||
//Leaving Ride
|
||||
|
||||
if((!mc.thePlayer.isRiding() && lastRiding != -1) ||
|
||||
(mc.thePlayer.isRiding() && lastRiding != mc.thePlayer.ridingEntity.getEntityId())) {
|
||||
if(!mc.thePlayer.isRiding()) {
|
||||
lastRiding = -1;
|
||||
} else {
|
||||
lastRiding = mc.thePlayer.ridingEntity.getEntityId();
|
||||
}
|
||||
if((!mc.thePlayer.isRiding() && lastRiding != -1) ||
|
||||
(mc.thePlayer.isRiding() && lastRiding != mc.thePlayer.ridingEntity.getEntityId())) {
|
||||
if(!mc.thePlayer.isRiding()) {
|
||||
lastRiding = -1;
|
||||
} else {
|
||||
lastRiding = mc.thePlayer.ridingEntity.getEntityId();
|
||||
}
|
||||
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(lastRiding);
|
||||
pbuf.writeBoolean(false);
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(lastRiding);
|
||||
pbuf.writeBoolean(false);
|
||||
|
||||
pea.readPacketData(pbuf);
|
||||
pea.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
}
|
||||
|
||||
//Sleeping
|
||||
if(!mc.thePlayer.isPlayerSleeping() && wasSleeping) {
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
}
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
//Sleeping
|
||||
if(!mc.thePlayer.isPlayerSleeping() && wasSleeping) {
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(2);
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pac.readPacketData(pb);
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(2);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
|
||||
wasSleeping = false;
|
||||
}
|
||||
pac.readPacketData(pb);
|
||||
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPickupItem(ItemPickupEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
ConnectionEventHandler.insertPacket(new S0DPacketCollectItem(event.pickedUp.getEntityId(), entityID));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
wasSleeping = false;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
//destroy entity, then respawn
|
||||
ConnectionEventHandler.insertPacket(new S13PacketDestroyEntities(entityID));
|
||||
ConnectionEventHandler.insertPacket(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onHurt(LivingHurtEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
};
|
||||
@SubscribeEvent
|
||||
public void onPickupItem(ItemPickupEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
ConnectionEventHandler.insertPacket(new S0DPacketCollectItem(event.pickedUp.getEntityId(), entityID));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
@SubscribeEvent
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
//destroy entity, then respawn
|
||||
ConnectionEventHandler.insertPacket(new S13PacketDestroyEntities(entityID));
|
||||
ConnectionEventHandler.insertPacket(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
@SubscribeEvent
|
||||
public void onHurt(LivingHurtEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(2);
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
|
||||
packet.readPacketData(pbuf);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(2);
|
||||
|
||||
//Damage Animation
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
packet.readPacketData(pbuf);
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(1);
|
||||
//Damage Animation
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
|
||||
pac.readPacketData(pb);
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(1);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDeath(LivingDeathEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
};
|
||||
pac.readPacketData(pb);
|
||||
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
@SubscribeEvent
|
||||
public void onDeath(LivingDeathEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(3);
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
|
||||
packet.readPacketData(pbuf);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(3);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onStartEating(PlayerUseItemEvent.Start event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(!event.entityPlayer.isEating()) return;
|
||||
S0BPacketAnimation packet = new S0BPacketAnimation();
|
||||
packet.readPacketData(pbuf);
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(3);
|
||||
@SubscribeEvent
|
||||
public void onStartEating(PlayerUseItemEvent.Start event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(!event.entityPlayer.isEating()) return;
|
||||
S0BPacketAnimation packet = new S0BPacketAnimation();
|
||||
|
||||
packet.readPacketData(pb);
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean wasSleeping = false;
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(3);
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSleep(PlayerSleepInBedEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entityPlayer != mc.thePlayer) {
|
||||
return;
|
||||
};
|
||||
packet.readPacketData(pb);
|
||||
|
||||
System.out.println(event.getResult());
|
||||
S0APacketUseBed pub = new S0APacketUseBed();
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
@SubscribeEvent
|
||||
public void onSleep(PlayerSleepInBedEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entityPlayer != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
pbuf.writeVarIntToBuffer(entityID);
|
||||
pbuf.writeBlockPos(event.pos);
|
||||
System.out.println(event.getResult());
|
||||
S0APacketUseBed pub = new S0APacketUseBed();
|
||||
|
||||
pub.readPacketData(pbuf);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pub);
|
||||
pbuf.writeVarIntToBuffer(entityID);
|
||||
pbuf.writeBlockPos(event.pos);
|
||||
|
||||
wasSleeping = true;
|
||||
pub.readPacketData(pbuf);
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ConnectionEventHandler.insertPacket(pub);
|
||||
|
||||
private int lastRiding = -1;
|
||||
wasSleeping = true;
|
||||
|
||||
@SubscribeEvent
|
||||
public void enterMinecart(MinecartInteractEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.player != mc.thePlayer) {
|
||||
return;
|
||||
};
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
@SubscribeEvent
|
||||
public void enterMinecart(MinecartInteractEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.player != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
;
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(event.minecart.getEntityId());
|
||||
pbuf.writeBoolean(false);
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pea.readPacketData(pbuf);
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(event.minecart.getEntityId());
|
||||
pbuf.writeBoolean(false);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
pea.readPacketData(pbuf);
|
||||
|
||||
lastRiding = event.minecart.getEntityId();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
|
||||
lastRiding = event.minecart.getEntityId();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package eu.crushedpixel.replaymod.events;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageRequests;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
import eu.crushedpixel.replaymod.gui.GuiCancelRender;
|
||||
import eu.crushedpixel.replaymod.gui.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayProcess;
|
||||
import eu.crushedpixel.replaymod.video.ReplayScreenshot;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||
@@ -16,92 +15,82 @@ import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||
import eu.crushedpixel.replaymod.gui.GuiCancelRender;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayProcess;
|
||||
import eu.crushedpixel.replaymod.video.ReplayScreenshot;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class TickAndRenderListener {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private double lastX, lastY, lastZ;
|
||||
private float lastPitch, lastYaw;
|
||||
|
||||
private static Field isGamePaused;
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
static {
|
||||
try {
|
||||
isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n"));
|
||||
isGamePaused.setAccessible(true);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
private static Field isGamePaused;
|
||||
private static int requestScreenshot = 0;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderWorld(RenderWorldLastEvent event) throws
|
||||
InvocationTargetException, IOException, IllegalAccessException, IllegalArgumentException {
|
||||
if(!ReplayHandler.isInReplay()) return; //If not in Replay, cancel
|
||||
static {
|
||||
try {
|
||||
isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n"));
|
||||
isGamePaused.setAccessible(true);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
if(requestScreenshot == 1) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ChatMessageRequests.addChatMessage("Saving Thumbnail...", ChatMessageRequests.ChatMessageType.INFORMATION);
|
||||
ReplayScreenshot.prepareScreenshot();
|
||||
requestScreenshot = 2;
|
||||
}
|
||||
});
|
||||
} else if(requestScreenshot == 2) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayScreenshot.saveScreenshot();
|
||||
}
|
||||
});
|
||||
}
|
||||
//private boolean f1Down = false;
|
||||
|
||||
if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick(false);
|
||||
if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
|
||||
if(ReplayHandler.isInReplay() && ReplayHandler.isPaused()) {
|
||||
if(mc != null && mc.thePlayer != null)
|
||||
MinecraftTicker.runMouseKeyboardTick(mc);
|
||||
}
|
||||
if((mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive())
|
||||
&& ReplayHandler.getCameraEntity() != null && !ReplayHandler.isInPath()) {
|
||||
ReplayHandler.spectateCamera();
|
||||
} else if(!ReplayHandler.isCamera()) {
|
||||
lastX = mc.getRenderViewEntity().posX;
|
||||
lastY = mc.getRenderViewEntity().posY;
|
||||
lastZ = mc.getRenderViewEntity().posZ;
|
||||
lastPitch = mc.getRenderViewEntity().rotationPitch;
|
||||
lastYaw = mc.getRenderViewEntity().rotationYaw;
|
||||
}
|
||||
public static void requestScreenshot() {
|
||||
if(requestScreenshot == 0) requestScreenshot = 1;
|
||||
}
|
||||
|
||||
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
|
||||
isGamePaused.set(mc, false);
|
||||
}
|
||||
}
|
||||
|
||||
//private boolean f1Down = false;
|
||||
public static void finishScreenshot() {
|
||||
requestScreenshot = 0;
|
||||
}
|
||||
|
||||
private static int requestScreenshot = 0;
|
||||
@SubscribeEvent
|
||||
public void onRenderWorld(RenderWorldLastEvent event) throws
|
||||
InvocationTargetException, IOException, IllegalAccessException, IllegalArgumentException {
|
||||
if(!ReplayHandler.isInReplay()) return; //If not in Replay, cancel
|
||||
|
||||
public static void requestScreenshot() {
|
||||
if(requestScreenshot == 0) requestScreenshot = 1;
|
||||
}
|
||||
if(requestScreenshot == 1) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayMod.chatMessageHandler.addChatMessage("Saving Thumbnail...", ChatMessageHandler.ChatMessageType.INFORMATION);
|
||||
ReplayScreenshot.prepareScreenshot();
|
||||
requestScreenshot = 2;
|
||||
}
|
||||
});
|
||||
} else if(requestScreenshot == 2) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayScreenshot.saveScreenshot();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void finishScreenshot() {
|
||||
requestScreenshot = 0;
|
||||
}
|
||||
if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick(false);
|
||||
if(ReplayHandler.isCamera()) ReplayHandler.setCameraEntity(ReplayHandler.getCameraEntity());
|
||||
if(ReplayHandler.isInReplay() && ReplayMod.replaySender.paused()) {
|
||||
if(mc != null && mc.thePlayer != null)
|
||||
MinecraftTicker.runMouseKeyboardTick(mc);
|
||||
}
|
||||
if((mc.getRenderViewEntity() == mc.thePlayer || !mc.getRenderViewEntity().isEntityAlive())
|
||||
&& ReplayHandler.getCameraEntity() != null && !ReplayHandler.isInPath()) {
|
||||
ReplayHandler.spectateCamera();
|
||||
}
|
||||
|
||||
if(mc.isGamePaused() && ReplayHandler.isInPath()) {
|
||||
isGamePaused.set(mc, false);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(TickEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(TickEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
|
||||
/*
|
||||
if(Keyboard.getEventKeyState() && Keyboard.isKeyDown(Keyboard.KEY_F1)
|
||||
&& ReplayHandler.isInPath() && !ReplayProcess.isVideoRecording()
|
||||
@@ -111,52 +100,48 @@ public class TickAndRenderListener {
|
||||
|
||||
f1Down = Keyboard.isKeyDown(Keyboard.KEY_F1) && Keyboard.getEventKeyState();
|
||||
*/
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null)
|
||||
ReplayHandler.getCameraEntity().updateMovement();
|
||||
if(ReplayHandler.isInPath()) {
|
||||
ReplayProcess.unblockAndTick(true);
|
||||
if(ReplayProcess.isVideoRecording() &&
|
||||
!(mc.currentScreen instanceof GuiMouseInput || mc.currentScreen instanceof GuiCancelRender)) {
|
||||
mc.displayGuiScreen(new GuiMouseInput());
|
||||
}
|
||||
}
|
||||
else onMouseMove(new MouseEvent());
|
||||
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouseMove(MouseEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
boolean flag = Display.isActive();
|
||||
flag = true;
|
||||
|
||||
mc.mcProfiler.startSection("mouse");
|
||||
if(ReplayHandler.getCameraEntity() != null)
|
||||
ReplayHandler.getCameraEntity().updateMovement();
|
||||
if(ReplayHandler.isInPath()) {
|
||||
ReplayProcess.unblockAndTick(true);
|
||||
if(ReplayProcess.isVideoRecording() &&
|
||||
!(mc.currentScreen instanceof GuiMouseInput || mc.currentScreen instanceof GuiCancelRender)) {
|
||||
mc.displayGuiScreen(new GuiMouseInput());
|
||||
}
|
||||
} else onMouseMove(new MouseEvent());
|
||||
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
|
||||
}
|
||||
|
||||
if (flag && Minecraft.isRunningOnMac && mc.inGameHasFocus && !Mouse.isInsideWindow())
|
||||
{
|
||||
Mouse.setGrabbed(false);
|
||||
Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
|
||||
Mouse.setGrabbed(true);
|
||||
}
|
||||
@SubscribeEvent
|
||||
public void onMouseMove(MouseEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
boolean flag = Display.isActive();
|
||||
flag = true;
|
||||
|
||||
if (mc.inGameHasFocus && flag && !(ReplayHandler.isInPath()))
|
||||
{
|
||||
mc.mouseHelper.mouseXYChange();
|
||||
float f1 = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
|
||||
float f2 = f1 * f1 * f1 * 8.0F;
|
||||
float f3 = (float)mc.mouseHelper.deltaX * f2;
|
||||
float f4 = (float)mc.mouseHelper.deltaY * f2;
|
||||
byte b0 = 1;
|
||||
mc.mcProfiler.startSection("mouse");
|
||||
|
||||
if (mc.gameSettings.invertMouse)
|
||||
{
|
||||
b0 = -1;
|
||||
}
|
||||
if(flag && Minecraft.isRunningOnMac && mc.inGameHasFocus && !Mouse.isInsideWindow()) {
|
||||
Mouse.setGrabbed(false);
|
||||
Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
|
||||
Mouse.setGrabbed(true);
|
||||
}
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null) {
|
||||
ReplayHandler.getCameraEntity().setAngles(f3, f4 * (float)b0);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(mc.inGameHasFocus && flag && !(ReplayHandler.isInPath())) {
|
||||
mc.mouseHelper.mouseXYChange();
|
||||
float f1 = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F;
|
||||
float f2 = f1 * f1 * f1 * 8.0F;
|
||||
float f3 = (float) mc.mouseHelper.deltaX * f2;
|
||||
float f4 = (float) mc.mouseHelper.deltaY * f2;
|
||||
byte b0 = 1;
|
||||
|
||||
if(mc.gameSettings.invertMouse) {
|
||||
b0 = -1;
|
||||
}
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null) {
|
||||
ReplayHandler.getCameraEntity().setAngles(f3, f4 * (float) b0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user