Added PathPreviewRenderer to draw a Preview of the current Camera Path into the World
Added KeyframesModifyEvent to be dispatched whenever the ReplayHandler's Keyframe List is changed Refactored Event package Reworked Settings GUI
This commit is contained in:
184
src/main/java/eu/crushedpixel/replaymod/events/handlers/GuiEventHandler.java
Executable file
184
src/main/java/eu/crushedpixel/replaymod/events/handlers/GuiEventHandler.java
Executable file
@@ -0,0 +1,184 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiLoginPrompt;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiReplayCenter;
|
||||
import eu.crushedpixel.replaymod.gui.replayeditor.GuiReplayEditor;
|
||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.registry.LightingHandler;
|
||||
import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayProcess;
|
||||
import eu.crushedpixel.replaymod.studio.VersionValidator;
|
||||
import eu.crushedpixel.replaymod.timer.MCTimerHandler;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.*;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
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 org.lwjgl.util.Point;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiEventHandler {
|
||||
|
||||
private static final Color DARK_RED = Color.decode("#DF0101");
|
||||
private static final Color DARK_GREEN = Color.decode("#01DF01");
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
public int replayCount = 0;
|
||||
private GuiButton editorButton;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGui(GuiOpenEvent event) {
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(ReplayMod.firstMainMenu) {
|
||||
ReplayMod.firstMainMenu = false;
|
||||
if(!AuthenticationHandler.isAuthenticated()) {
|
||||
event.gui = new GuiLoginPrompt(event.gui, event.gui);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
MCTimerHandler.setTimerSpeed(1);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if(ReplayHandler.isInReplay()) ReplayHandler.setInReplay(false);
|
||||
}
|
||||
|
||||
if(!AuthenticationHandler.isAuthenticated()) 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDraw(DrawScreenEvent e) {
|
||||
if(e.gui instanceof GuiMainMenu) {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.title")+":", 5, 5, Color.WHITE.getRGB());
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedin").toUpperCase(), 5, 15, DARK_GREEN.getRGB());
|
||||
} else {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedout").toUpperCase(), 5, 15, DARK_RED.getRGB());
|
||||
}
|
||||
|
||||
if(replayCount == 0) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouse.getX(), mouse.getY(), I18n.format("replaymod.gui.morereplays"), e.gui, Color.RED);
|
||||
}
|
||||
} else if(!VersionValidator.isValid) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
Point mouse = MouseUtils.getMousePos();
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouse.getX(), mouse.getY(), I18n.format("replaymod.gui.java"), e.gui, Color.RED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onInit(InitGuiEvent event) {
|
||||
if(event.gui instanceof GuiIngameMenu && ReplayHandler.isInReplay()) {
|
||||
ReplayMod.replaySender.setReplaySpeed(0);
|
||||
for(GuiButton b : new ArrayList<GuiButton>(event.buttonList)) {
|
||||
if(b.id == 1) {
|
||||
b.displayString = I18n.format("replaymod.gui.exit");
|
||||
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;
|
||||
|
||||
for(GuiButton b : (List<GuiButton>) event.buttonList) {
|
||||
if(b.id != 0 && b.id != 4 && b.id != 5) {
|
||||
b.yPosition = b.yPosition - 2 * 24 + 10;
|
||||
}
|
||||
}
|
||||
|
||||
GuiButton rm = new GuiButton(GuiConstants.REPLAY_MANAGER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 2 * 24, I18n.format("replaymod.gui.replayviewer"));
|
||||
rm.width = rm.width / 2 - 2;
|
||||
//rm.enabled = AuthenticationHandler.isAuthenticated();
|
||||
event.buttonList.add(rm);
|
||||
|
||||
replayCount = ReplayFileIO.getAllReplayFiles().size();
|
||||
|
||||
GuiButton re = new GuiButton(GuiConstants.REPLAY_EDITOR_BUTTON_ID, event.gui.width / 2 + 2, i1 + 2 * 24, I18n.format("replaymod.gui.replayeditor"));
|
||||
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, I18n.format("replaymod.gui.replaycenter"));
|
||||
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, I18n.format("replaymod.gui.settings.title")));
|
||||
}
|
||||
}
|
||||
|
||||
@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 GuiReplayEditor());
|
||||
}
|
||||
} else if(event.gui instanceof GuiOptions && event.button.id == GuiConstants.REPLAY_OPTIONS_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplaySettings(event.gui));
|
||||
}
|
||||
|
||||
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(null);
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
|
||||
ReplayGuiRegistry.show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
177
src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java
Executable file
177
src/main/java/eu/crushedpixel/replaymod/events/handlers/KeyInputHandler.java
Executable file
@@ -0,0 +1,177 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity.MoveDirection;
|
||||
import eu.crushedpixel.replaymod.gui.GuiKeyframeRepository;
|
||||
import eu.crushedpixel.replaymod.gui.GuiMouseInput;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||
import eu.crushedpixel.replaymod.registry.PlayerHandler;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
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;
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeyInputHandler {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private long prevKeysDown = Sys.getTime();
|
||||
|
||||
public void onKeyInput() throws Exception {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
|
||||
if(!Keyboard.isCreated()) Keyboard.create();
|
||||
|
||||
Keyboard.poll();
|
||||
|
||||
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
|
||||
|
||||
boolean speedup = false;
|
||||
|
||||
if(mc.currentScreen == null) {
|
||||
for(KeyBinding kb : keyBindings) {
|
||||
//don't act on Mouse inputs
|
||||
if(kb.getKeyCode() < 0) continue;
|
||||
|
||||
if(!ReplayMod.replaySender.paused() && !kb.isKeyDown()) continue;
|
||||
|
||||
if(ReplayMod.replaySender.paused() && !Keyboard.isKeyDown(kb.getKeyCode()))
|
||||
continue;
|
||||
try {
|
||||
|
||||
if(ReplayHandler.isCamera()) {
|
||||
if(kb.getKeyDescription().equals("key.forward")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.FORWARD);
|
||||
speedup = true;
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals("key.back")) {
|
||||
ReplayHandler.getCameraEntity().setMovement(MoveDirection.BACKWARD);
|
||||
speedup = 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();
|
||||
}
|
||||
}
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null) {
|
||||
if(speedup) {
|
||||
ReplayHandler.getCameraEntity().speedUp();
|
||||
prevKeysDown = Sys.getTime();
|
||||
} else {
|
||||
if(Sys.getTime() - prevKeysDown > 100) {
|
||||
ReplayHandler.getCameraEntity().stopSpeedUp();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void keyInput(InputEvent.KeyInputEvent event) {
|
||||
try {
|
||||
onKeyInput();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings;
|
||||
|
||||
boolean found = false;
|
||||
|
||||
for(KeyBinding kb : keyBindings) {
|
||||
if(!kb.isKeyDown()) continue;
|
||||
|
||||
handleCustomKeybindings(kb, found, -1);
|
||||
found = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void handleCustomKeybindings(KeyBinding kb, boolean found, int keyCode) {
|
||||
//Custom registered handlers
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ADD_MARKER) && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
if(ReplayHandler.isInReplay()) {
|
||||
ReplayHandler.toggleMarker();
|
||||
} else if(ConnectionEventHandler.isRecording()) {
|
||||
ConnectionEventHandler.addMarker();
|
||||
}
|
||||
}
|
||||
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
|
||||
if(kb.getKeyDescription().equals("key.chat") && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
mc.displayGuiScreen(new GuiMouseInput(ReplayMod.overlay));
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_PLAY_PAUSE) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !ReplayHandler.isInPath()) {
|
||||
ReplayMod.overlay.togglePlayPause();
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ROLL_CLOCKWISE) && (kb.isKeyDown() || kb.getKeyCode() == keyCode) && !ReplayHandler.isInPath()) {
|
||||
ReplayHandler.addCameraTilt(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ? 0.2f : 1);
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_ROLL_COUNTERCLOCKWISE) && (kb.isKeyDown() || kb.getKeyCode() == keyCode) && !ReplayHandler.isInPath()) {
|
||||
ReplayHandler.addCameraTilt(Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ? -0.2f : -1);
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_RESET_TILT) && (kb.isKeyDown() || kb.getKeyCode() == keyCode) && !found && !ReplayHandler.isInPath()) {
|
||||
ReplayHandler.setCameraTilt(0);
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !found) {
|
||||
TickAndRenderListener.requestScreenshot();
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_PLAYER_OVERVIEW) && (kb.isPressed() || kb.getKeyCode() == keyCode) && !found) {
|
||||
PlayerHandler.openPlayerOverview();
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_LIGHTING) && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
ReplayMod.replaySettings.setLightingEnabled(!ReplayMod.replaySettings.isLightingEnabled());
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_CLEAR_KEYFRAMES) && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
ReplayHandler.resetKeyframes(false);
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SYNC_TIMELINE) && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
ReplayHandler.syncTimeCursor(Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT));
|
||||
}
|
||||
|
||||
if(kb.getKeyDescription().equals(KeybindRegistry.KEY_KEYFRAME_PRESETS) && (kb.isPressed() || kb.getKeyCode() == keyCode)) {
|
||||
mc.displayGuiScreen(new GuiKeyframeRepository(ReplayHandler.getKeyframeRepository()));
|
||||
}
|
||||
}
|
||||
}
|
||||
252
src/main/java/eu/crushedpixel/replaymod/events/handlers/MinecraftTicker.java
Executable file
252
src/main/java/eu/crushedpixel/replaymod/events/handlers/MinecraftTicker.java
Executable file
@@ -0,0 +1,252 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.crash.CrashReport;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.util.ReportedException;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class MinecraftTicker {
|
||||
|
||||
public static void runMouseKeyboardTick(Minecraft mc) throws IllegalAccessException, IllegalArgumentException,
|
||||
InvocationTargetException, IOException, LWJGLException {
|
||||
ReplayMod.mouseInputHandler.mouseEvent(new MouseEvent());
|
||||
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 = Minecraft.getSystemTime() - mc.systemTime;
|
||||
|
||||
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(mc.leftClickCounter > 0) {
|
||||
mc.leftClickCounter--;
|
||||
}
|
||||
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(mc.debugCrashKeyPressTime > 0L) {
|
||||
if(Minecraft.getSystemTime() - mc.debugCrashKeyPressTime >= 6000L) {
|
||||
throw new ReportedException(new CrashReport("Manually triggered debug crash", new Throwable()));
|
||||
}
|
||||
|
||||
if(!Keyboard.isKeyDown(46) || !Keyboard.isKeyDown(61)) {
|
||||
mc.debugCrashKeyPressTime = -1;
|
||||
}
|
||||
} else if(Keyboard.isKeyDown(46) && Keyboard.isKeyDown(61)) {
|
||||
mc.debugCrashKeyPressTime = Minecraft.getSystemTime();
|
||||
}
|
||||
|
||||
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) {
|
||||
mc.updateDebugProfilerName(0);
|
||||
}
|
||||
|
||||
for(int l = 0; l < 9; ++l) {
|
||||
if(i == 2 + l) {
|
||||
mc.updateDebugProfilerName(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(mc != null)
|
||||
mc.sendClickBlockToController(mc.currentScreen == null && mc.gameSettings.keyBindAttack.isKeyDown() && mc.inGameHasFocus);
|
||||
|
||||
if(mc != null)
|
||||
mc.systemTime = Minecraft.getSystemTime();
|
||||
} catch(Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.entities.CameraEntity;
|
||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraftforge.client.event.MouseEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
public class MouseInputHandler {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private boolean rightDown = false;
|
||||
|
||||
@SubscribeEvent
|
||||
public void mouseEvent(MouseEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(event.dwheel != 0 && mc.currentScreen == null) {
|
||||
boolean increase = event.dwheel > 0;
|
||||
CameraEntity.modifyCameraSpeed(increase);
|
||||
}
|
||||
|
||||
if(Mouse.isButtonDown(1)) {
|
||||
if(!rightDown) {
|
||||
rightDown = true;
|
||||
if(mc.pointedEntity != null && ReplayHandler.isCamera() && mc.currentScreen == null) {
|
||||
ReplayHandler.spectateEntity(mc.pointedEntity);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rightDown = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
450
src/main/java/eu/crushedpixel/replaymod/events/handlers/RecordingHandler.java
Executable file
450
src/main/java/eu/crushedpixel/replaymod/events/handlers/RecordingHandler.java
Executable file
@@ -0,0 +1,450 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
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.*;
|
||||
import net.minecraft.network.play.server.S14PacketEntity.S17PacketEntityLookMove;
|
||||
import net.minecraft.network.play.server.S38PacketPlayerListItem.Action;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
||||
import net.minecraftforge.event.entity.minecart.MinecartInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerSleepInBedEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerUseItemEvent;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecordingHandler {
|
||||
|
||||
public static final int entityID = Integer.MIN_VALUE + 9001;
|
||||
|
||||
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;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerJoin(EntityJoinWorldEvent e) {
|
||||
try {
|
||||
if(e.entity != mc.thePlayer) return;
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
|
||||
EntityPlayer player = (EntityPlayer) e.entity;
|
||||
|
||||
S38PacketPlayerListItem ppli = new S38PacketPlayerListItem();
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeEnumValue(Action.ADD_PLAYER);
|
||||
pbuf.writeVarIntToBuffer(1);
|
||||
pbuf.writeUuid(e.entity.getUniqueID());
|
||||
|
||||
pbuf.writeString(player.getName());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
pbuf.writeVarIntToBuffer(mc.playerController.getCurrentGameType().getID());
|
||||
pbuf.writeVarIntToBuffer(0);
|
||||
|
||||
pbuf.writeBoolean(true);
|
||||
pbuf.writeChatComponent(player.getDisplayName());
|
||||
|
||||
ppli.readPacketData(pbuf);
|
||||
ConnectionEventHandler.insertPacket(ppli);
|
||||
|
||||
ConnectionEventHandler.insertPacket(spawnPlayer(mc.thePlayer));
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private S0CPacketSpawnPlayer spawnPlayer(EntityPlayer player) {
|
||||
try {
|
||||
S0CPacketSpawnPlayer packet = new S0CPacketSpawnPlayer();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
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)));
|
||||
|
||||
ItemStack itemstack = player.inventory.getCurrentItem();
|
||||
pb.writeShort(itemstack == null ? 0 : Item.getIdFromItem(itemstack.getItem()));
|
||||
|
||||
player.getDataWatcher().writeTo(pb);
|
||||
|
||||
packet.readPacketData(pb);
|
||||
|
||||
return packet;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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);
|
||||
|
||||
//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)));
|
||||
|
||||
head.readPacketData(pb1);
|
||||
|
||||
ConnectionEventHandler.insertPacket(head);
|
||||
|
||||
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();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(0);
|
||||
|
||||
pac.readPacketData(pb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
}
|
||||
|
||||
/*
|
||||
//Potion Effect Handling
|
||||
List<Integer> found = new ArrayList<Integer>();
|
||||
for(PotionEffect pe : (Collection<PotionEffect>)e.player.getActivePotionEffects()) {
|
||||
found.add(pe.getPotionID());
|
||||
if(lastEffects.contains(found)) continue;
|
||||
S1DPacketEntityEffect pee = new S1DPacketEntityEffect(entityID, pe);
|
||||
ConnectionEventHandler.insertPacket(pee);
|
||||
}
|
||||
|
||||
for(int id : lastEffects) {
|
||||
if(!found.contains(id)) {
|
||||
S1EPacketRemoveEntityEffect pre = new S1EPacketRemoveEntityEffect(entityID, new PotionEffect(id, 0));
|
||||
ConnectionEventHandler.insertPacket(pre);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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[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);
|
||||
}
|
||||
|
||||
//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();
|
||||
}
|
||||
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(lastRiding);
|
||||
pbuf.writeBoolean(false);
|
||||
|
||||
pea.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
}
|
||||
|
||||
//Sleeping
|
||||
if(!mc.thePlayer.isPlayerSleeping() && wasSleeping) {
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(2);
|
||||
|
||||
pac.readPacketData(pb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
|
||||
wasSleeping = false;
|
||||
}
|
||||
|
||||
} catch(Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPickupItem(ItemPickupEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
ConnectionEventHandler.insertPacket(new S0DPacketCollectItem(event.pickedUp.getEntityId(), entityID));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onHurt(LivingHurtEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(2);
|
||||
|
||||
packet.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
|
||||
//Damage Animation
|
||||
S0BPacketAnimation pac = new S0BPacketAnimation();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(1);
|
||||
|
||||
pac.readPacketData(pb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pac);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDeath(LivingDeathEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entity.getEntityId() != mc.thePlayer.getEntityId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
S19PacketEntityStatus packet = new S19PacketEntityStatus();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeByte(3);
|
||||
|
||||
packet.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onStartEating(PlayerUseItemEvent.Start event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(!event.entityPlayer.isEating()) return;
|
||||
S0BPacketAnimation packet = new S0BPacketAnimation();
|
||||
|
||||
ByteBuf bb = Unpooled.buffer();
|
||||
PacketBuffer pb = new PacketBuffer(bb);
|
||||
|
||||
pb.writeVarIntToBuffer(entityID);
|
||||
pb.writeByte(3);
|
||||
|
||||
packet.readPacketData(pb);
|
||||
|
||||
ConnectionEventHandler.insertPacket(packet);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onSleep(PlayerSleepInBedEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.entityPlayer != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
System.out.println(event.getResult());
|
||||
S0APacketUseBed pub = new S0APacketUseBed();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeVarIntToBuffer(entityID);
|
||||
pbuf.writeBlockPos(event.pos);
|
||||
|
||||
pub.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pub);
|
||||
|
||||
wasSleeping = true;
|
||||
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void enterMinecart(MinecartInteractEvent event) {
|
||||
if(!ConnectionEventHandler.isRecording()) return;
|
||||
try {
|
||||
if(event.player != mc.thePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
S1BPacketEntityAttach pea = new S1BPacketEntityAttach();
|
||||
|
||||
ByteBuf buf = Unpooled.buffer();
|
||||
PacketBuffer pbuf = new PacketBuffer(buf);
|
||||
|
||||
pbuf.writeInt(entityID);
|
||||
pbuf.writeInt(event.minecart.getEntityId());
|
||||
pbuf.writeBoolean(false);
|
||||
|
||||
pea.readPacketData(pbuf);
|
||||
|
||||
ConnectionEventHandler.insertPacket(pea);
|
||||
|
||||
lastRiding = event.minecart.getEntityId();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package eu.crushedpixel.replaymod.events.handlers;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.chat.ChatMessageHandler;
|
||||
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;
|
||||
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 org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
|
||||
public class TickAndRenderListener {
|
||||
|
||||
private static Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static int requestScreenshot = 0;
|
||||
|
||||
//private boolean f1Down = false;
|
||||
|
||||
public static void requestScreenshot() {
|
||||
if(requestScreenshot == 0) requestScreenshot = 1;
|
||||
}
|
||||
|
||||
public static void finishScreenshot() {
|
||||
requestScreenshot = 0;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onRenderWorld(RenderWorldLastEvent event) throws Exception {
|
||||
if(!ReplayHandler.isInReplay()) return; //If not in Replay, cancel
|
||||
if (ReplayProcess.isVideoRecording()) return; // If recording, cancel
|
||||
|
||||
if(requestScreenshot == 1) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayMod.chatMessageHandler.addLocalizedChatMessage("replaymod.chat.savingthumb", ChatMessageHandler.ChatMessageType.INFORMATION);
|
||||
ReplayScreenshot.prepareScreenshot();
|
||||
requestScreenshot = 2;
|
||||
}
|
||||
});
|
||||
} else if(requestScreenshot == 2) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayScreenshot.saveScreenshot();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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()) {
|
||||
mc.isGamePaused = false;
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(TickEvent event) {
|
||||
if(!ReplayHandler.isInReplay() || ReplayProcess.isVideoRecording()) return;
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null)
|
||||
ReplayHandler.getCameraEntity().updateMovement();
|
||||
if(ReplayHandler.isInPath()) {
|
||||
ReplayProcess.unblockAndTick(true);
|
||||
} else onMouseMove(new MouseEvent());
|
||||
|
||||
FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onMouseMove(MouseEvent event) {
|
||||
if(!ReplayHandler.isInReplay()) return;
|
||||
boolean flag = true;
|
||||
|
||||
mc.mcProfiler.startSection("mouse");
|
||||
|
||||
if(flag && Minecraft.isRunningOnMac && mc.inGameHasFocus && !Mouse.isInsideWindow()) {
|
||||
Mouse.setGrabbed(false);
|
||||
Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2);
|
||||
Mouse.setGrabbed(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;
|
||||
|
||||
if(mc.gameSettings.invertMouse) {
|
||||
b0 = -1;
|
||||
}
|
||||
|
||||
if(ReplayHandler.getCameraEntity() != null) {
|
||||
ReplayHandler.getCameraEntity().setAngles(f3, f4 * (float) b0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user