diff --git a/libs/replaystudio-0.0.1-SNAPSHOT-all.jar b/libs/replaystudio-0.0.1-SNAPSHOT-all.jar index 447ee212..29847e82 100644 Binary files a/libs/replaystudio-0.0.1-SNAPSHOT-all.jar and b/libs/replaystudio-0.0.1-SNAPSHOT-all.jar differ diff --git a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java index bf162843..8afe70c7 100755 --- a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java +++ b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java @@ -21,6 +21,7 @@ import eu.crushedpixel.replaymod.events.GuiEventHandler; import eu.crushedpixel.replaymod.events.GuiReplayOverlay; import eu.crushedpixel.replaymod.events.KeyInputHandler; import eu.crushedpixel.replaymod.events.RecordingHandler; +import eu.crushedpixel.replaymod.events.TickAndRenderListener; import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler; import eu.crushedpixel.replaymod.recording.ConnectionEventHandler; import eu.crushedpixel.replaymod.registry.KeybindRegistry; @@ -97,6 +98,10 @@ public class ReplayMod FMLCommonHandler.instance().bus().register(overlay); MinecraftForge.EVENT_BUS.register(overlay); + TickAndRenderListener tarl = new TickAndRenderListener(); + FMLCommonHandler.instance().bus().register(tarl); + MinecraftForge.EVENT_BUS.register(tarl); + KeybindRegistry.initialize(); try { diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java index 43bc90a3..5d0778a5 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiEventHandler.java @@ -22,6 +22,7 @@ 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; import eu.crushedpixel.replaymod.gui.GuiReplaySaving; import eu.crushedpixel.replaymod.gui.GuiReplaySettings; @@ -59,7 +60,7 @@ public class GuiEventHandler { @SubscribeEvent public void onGui(GuiOpenEvent event) { - if(VideoWriter.isRecording()) { + if(VideoWriter.isRecording() && !(event.gui instanceof GuiCancelRender)) { event.gui = null; return; } diff --git a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java index 01f613cf..93c8defa 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/GuiReplayOverlay.java @@ -3,36 +3,26 @@ package eu.crushedpixel.replaymod.events; import java.awt.Color; import java.awt.Point; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.util.concurrent.TimeUnit; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiChat; -import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.inventory.GuiInventory; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.client.event.MouseEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; -import net.minecraftforge.client.event.RenderHandEvent; -import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.fml.client.FMLClientHandler; -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; import org.lwjgl.opengl.GL11; +import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.entities.CameraEntity; +import eu.crushedpixel.replaymod.gui.GuiCancelRender; import eu.crushedpixel.replaymod.gui.GuiReplaySpeedSlider; import eu.crushedpixel.replaymod.gui.GuiSpectateSelection; import eu.crushedpixel.replaymod.gui.elements.GuiMouseInput; @@ -40,12 +30,10 @@ import eu.crushedpixel.replaymod.holders.Keyframe; import eu.crushedpixel.replaymod.holders.Position; import eu.crushedpixel.replaymod.holders.PositionKeyframe; import eu.crushedpixel.replaymod.holders.TimeKeyframe; -import eu.crushedpixel.replaymod.reflection.MCPNames; +import eu.crushedpixel.replaymod.recording.ConnectionEventHandler; import eu.crushedpixel.replaymod.registry.ReplayGuiRegistry; import eu.crushedpixel.replaymod.replay.ReplayHandler; -import eu.crushedpixel.replaymod.replay.ReplayProcess; import eu.crushedpixel.replaymod.utils.MouseUtils; -import eu.crushedpixel.replaymod.video.ReplayScreenshot; import eu.crushedpixel.replaymod.video.VideoWriter; public class GuiReplayOverlay extends Gui { @@ -76,102 +64,17 @@ public class GuiReplayOverlay extends Gui { private long lastSystemTime = System.currentTimeMillis(); - private ResourceLocation guiLocation = new ResourceLocation("replaymod", "replay_gui.png"); - private ResourceLocation keyframeLocation = new ResourceLocation("replaymod", "extended_gui.png"); - private ResourceLocation timelineLocation = new ResourceLocation("replaymod", "timeline_icons.png"); + private ResourceLocation replay_gui = new ResourceLocation("replaymod", "replay_gui.png"); + private ResourceLocation extended_gui = new ResourceLocation("replaymod", "extended_gui.png"); + private ResourceLocation timeline_icons = new ResourceLocation("replaymod", "timeline_icons.png"); private GuiReplaySpeedSlider speedSlider; private boolean mouseDown = false; - private static boolean requestScreenshot = false; - - private static Field isGamePaused; - - static { - try { - isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n")); - isGamePaused.setAccessible(true); - } catch(Exception e) { - e.printStackTrace(); - } - } - - //private Field drawBlockOutline; - - public static void requestScreenshot() { - requestScreenshot = true; - } - - public GuiReplayOverlay() { - try { - // drawBlockOutline = EntityRenderer.class.getDeclaredField(MCPNames.field("field_175073_D")); - // drawBlockOutline.setAccessible(true); - // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); - } catch(Exception e) {} - } - - //@SubscribeEvent TODO - public void renderHand(RenderHandEvent event) { - if(ReplayHandler.isInReplay()) { - event.setCanceled(true); - } - } - - @SubscribeEvent - public void tick(TickEvent event) { - if(!ReplayHandler.isInReplay()) return; - if(ReplayHandler.getCameraEntity() != null) - ReplayHandler.getCameraEntity().updateMovement(); - if(!ReplayHandler.isInPath()) onMouseMove(new MouseEvent()); - FMLCommonHandler.instance().bus().post(new InputEvent.KeyInputEvent()); - - } - - private double lastX, lastY, lastZ; - private float lastPitch, lastYaw; - - - @SubscribeEvent - public void onChangeView(MouseEvent event) { - if(ReplayHandler.isInPath()) { - event.setCanceled(true); - } - } - - @SubscribeEvent - public void onRenderWorld(RenderWorldLastEvent event) - throws IllegalAccessException, IllegalArgumentException, - InvocationTargetException, IOException { - if(!ReplayHandler.isInReplay()) return; - if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick(); - 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; - } - if(requestScreenshot) { - requestScreenshot = false; - ReplayScreenshot.saveScreenshot(mc.getFramebuffer()); - } - if(mc.isGamePaused() && ReplayHandler.isInPath()) { - isGamePaused.set(mc, false); - } - } - public void resetUI() throws Exception { if(FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { - mc.displayGuiScreen((GuiScreen)null); + mc.displayGuiScreen(null); } ReplayHandler.setRealTimelineCursor(0); speedSlider = new GuiReplaySpeedSlider(1, sliderX, sliderY, "Speed"); @@ -179,12 +82,22 @@ public class GuiReplayOverlay extends Gui { @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent event) { - if(VideoWriter.isRecording()) { + if(VideoWriter.isRecording() && !(mc.currentScreen instanceof GuiCancelRender)) { event.setCanceled(true); } } - - + + @SubscribeEvent + public void renderRecordingIndicator(RenderGameOverlayEvent.Post event) { + if(!ReplayHandler.isInReplay() && ReplayMod.replaySettings.showRecordingIndicator() && ConnectionEventHandler.isRecording()) { + GlStateManager.resetColor(); + GlStateManager.enableAlpha(); + mc.renderEngine.bindTexture(replay_gui); + this.drawModalRectWithCustomSizedTexture(10, 10, 40, 21, 16, 16, 64, 64); + this.drawString(mc.fontRendererObj, "RECORDING", 30, 18-(mc.fontRendererObj.FONT_HEIGHT/2), Color.WHITE.getRGB()); + } + } + @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event) throws IllegalArgumentException, IllegalAccessException { @@ -192,23 +105,13 @@ public class GuiReplayOverlay extends Gui { return; } - //System.out.println(System.currentTimeMillis()+" | "+MCTimerHandler.getTicks()+" | "+MCTimerHandler.getPartialTicks()); - if(!ReplayGuiRegistry.hidden) ReplayGuiRegistry.hide(); if(FMLClientHandler.instance().isGUIOpen(GuiChat.class) || FMLClientHandler.instance().isGUIOpen(GuiInventory.class)) { mc.displayGuiScreen(new GuiMouseInput()); } - - if(event.type == ElementType.PLAYER_LIST) { - if(event.isCancelable()) { - event.setCanceled(true); - } - return; - } GL11.glEnable(GL11.GL_BLEND); - // drawBlockOutline.set(Minecraft.getMinecraft().entityRenderer, false); if(!ReplayHandler.isInReplay()) { return; @@ -247,7 +150,7 @@ public class GuiReplayOverlay extends Gui { x = 20; } - mc.renderEngine.bindTexture(guiLocation); + mc.renderEngine.bindTexture(replay_gui); GlStateManager.resetColor(); this.drawModalRectWithCustomSizedTexture(ppButtonX, ppButtonY, x, y, 20, 20, 64, 64); @@ -277,7 +180,7 @@ public class GuiReplayOverlay extends Gui { double time = perc*(double)ReplayHandler.getReplayLength(); if(time < ReplayHandler.getReplayTime()) { - mc.displayGuiScreen((GuiScreen)null); + mc.displayGuiScreen(null); } CameraEntity cam = ReplayHandler.getCameraEntity(); @@ -315,7 +218,7 @@ public class GuiReplayOverlay extends Gui { x = 20; } - mc.renderEngine.bindTexture(timelineLocation); + mc.renderEngine.bindTexture(timeline_icons); GlStateManager.resetColor(); this.drawModalRectWithCustomSizedTexture(exportButtonX, exportButtonY, x, y, 20, 20, 64, 64); @@ -342,7 +245,7 @@ public class GuiReplayOverlay extends Gui { y += 20; } - mc.renderEngine.bindTexture(keyframeLocation); + mc.renderEngine.bindTexture(extended_gui); if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof PositionKeyframe)) { @@ -383,7 +286,7 @@ public class GuiReplayOverlay extends Gui { } } - mc.renderEngine.bindTexture(keyframeLocation); + mc.renderEngine.bindTexture(extended_gui); if(hover && Mouse.isButtonDown(0) && isClick() && FMLClientHandler.instance().isGUIOpen(GuiMouseInput.class)) { if(ReplayHandler.getSelected() == null || !(ReplayHandler.getSelected() instanceof TimeKeyframe)) { @@ -443,7 +346,7 @@ public class GuiReplayOverlay extends Gui { int full = maxX-tl_end_width; GlStateManager.resetColor(); - mc.renderEngine.bindTexture(guiLocation); + mc.renderEngine.bindTexture(replay_gui); this.drawModalRectWithCustomSizedTexture(minX, y, tl_begin_x, tl_y, tl_begin_width, 22, 64, 64); for(int i=minX+tl_begin_width; i right_real) break; if(kf.getRealTimestamp() >= left_real) { @@ -758,7 +661,7 @@ public class GuiReplayOverlay extends Gui { dx = 20; } - mc.renderEngine.bindTexture(guiLocation); + mc.renderEngine.bindTexture(replay_gui); GlStateManager.resetColor(); this.drawModalRectWithCustomSizedTexture(r_ppButtonX, r_ppButtonY, dx, dy, 20, 20, 64, 64); @@ -847,39 +750,4 @@ public class GuiReplayOverlay extends Gui { return false; } } - - @SubscribeEvent - public void onMouseMove(MouseEvent event) { - if(!ReplayHandler.isInReplay()) return; - boolean flag = Display.isActive(); - 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) - { - 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); - } - } - } } diff --git a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java index 5236f669..fcc18eac 100755 --- a/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/events/KeyInputHandler.java @@ -1,16 +1,22 @@ 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.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; @@ -26,6 +32,12 @@ public class KeyInputHandler { return; } + if(Keyboard.getEventKeyState() && !Keyboard.isRepeatEvent() && Keyboard.isKeyDown(Keyboard.KEY_ESCAPE) + && ReplayHandler.isInPath() && ReplayProcess.isVideoRecording() + && mc.currentScreen == null) { + mc.displayGuiScreen(new GuiCancelRender()); + } + boolean found = false; KeyBinding[] keyBindings = Minecraft.getMinecraft().gameSettings.keyBindings; @@ -83,7 +95,8 @@ public class KeyInputHandler { //Custom registered handlers if(kb.getKeyDescription().equals(KeybindRegistry.KEY_THUMBNAIL) && kb.isPressed() && !found) { ReplayScreenshot.prepareScreenshot(); - GuiReplayOverlay.requestScreenshot(); + //GuiReplayOverlay.requestScreenshot(); + //TODO: Make this properly work } if(kb.getKeyDescription().equals(KeybindRegistry.KEY_SPECTATE) && kb.isPressed() && !found) { diff --git a/src/main/java/eu/crushedpixel/replaymod/events/TickAndRenderListener.java b/src/main/java/eu/crushedpixel/replaymod/events/TickAndRenderListener.java new file mode 100644 index 00000000..c74a006c --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/events/TickAndRenderListener.java @@ -0,0 +1,115 @@ +package eu.crushedpixel.replaymod.events; + +import java.io.IOException; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; + +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.Display; + +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 eu.crushedpixel.replaymod.reflection.MCPNames; +import eu.crushedpixel.replaymod.replay.ReplayHandler; +import eu.crushedpixel.replaymod.replay.ReplayProcess; +import eu.crushedpixel.replaymod.video.ReplayScreenshot; + +public class TickAndRenderListener { + + private static Minecraft mc = Minecraft.getMinecraft(); + + private double lastX, lastY, lastZ; + private float lastPitch, lastYaw; + + private static Field isGamePaused; + + static { + try { + isGamePaused = Minecraft.class.getDeclaredField(MCPNames.field("field_71445_n")); + isGamePaused.setAccessible(true); + } catch(Exception e) { + e.printStackTrace(); + } + } + + @SubscribeEvent + public void onRenderWorld(RenderWorldLastEvent event) throws + InvocationTargetException, IOException, IllegalAccessException, IllegalArgumentException { + if(!ReplayHandler.isInReplay()) return; + 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; + } + /* + if(requestScreenshot) { + requestScreenshot = false; + ReplayScreenshot.saveScreenshot(mc.getFramebuffer()); + } + */ + if(mc.isGamePaused() && ReplayHandler.isInPath()) { + isGamePaused.set(mc, false); + } + } + + @SubscribeEvent + public void tick(TickEvent event) { + if(!ReplayHandler.isInReplay()) return; + if(ReplayHandler.getCameraEntity() != null) + ReplayHandler.getCameraEntity().updateMovement(); + if(ReplayHandler.isInPath()) ReplayProcess.unblockAndTick(true); + if(!ReplayHandler.isInPath()) 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 (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) + { + 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); + } + } + } +} diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiCancelRender.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiCancelRender.java new file mode 100644 index 00000000..ac2b868f --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiCancelRender.java @@ -0,0 +1,28 @@ +package eu.crushedpixel.replaymod.gui; + +import eu.crushedpixel.replaymod.replay.ReplayProcess; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.GuiYesNo; +import net.minecraft.client.gui.GuiYesNoCallback; + +public class GuiCancelRender extends GuiYesNo { + + private static Minecraft mc = Minecraft.getMinecraft(); + + private static GuiYesNoCallback callback = new GuiYesNoCallback() { + + @Override + public void confirmClicked(boolean result, int id) { + if(result) { + ReplayProcess.stopReplayProcess(false); + } + mc.displayGuiScreen(null); + } + }; + + public GuiCancelRender() { + super(callback, "Cancel Rendering", "Are you sure that you want to cancel the current rendering process?", 0); + } + +} diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java index bcc5a034..b8b21c1f 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiReplaySettings.java @@ -2,21 +2,16 @@ package eu.crushedpixel.replaymod.gui; import java.awt.Color; import java.io.IOException; -import java.util.Map.Entry; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; -import net.minecraft.entity.item.EntityArmorStand; -import net.minecraft.network.play.server.S0EPacketSpawnObject; -import net.minecraft.network.play.server.S0FPacketSpawnMob; -import net.minecraft.network.play.server.S14PacketEntity; -import net.minecraft.network.play.server.S14PacketEntity.S15PacketEntityRelMove; -import net.minecraft.network.play.server.S14PacketEntity.S16PacketEntityLook; import net.minecraftforge.fml.client.FMLClientHandler; import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.settings.ReplaySettings; -import eu.crushedpixel.replaymod.settings.ReplaySettings.Option; +import eu.crushedpixel.replaymod.settings.ReplaySettings.RecordingOptions; +import eu.crushedpixel.replaymod.settings.ReplaySettings.RenderOptions; +import eu.crushedpixel.replaymod.settings.ReplaySettings.ReplayOptions; public class GuiReplaySettings extends GuiScreen { @@ -32,8 +27,11 @@ public class GuiReplaySettings extends GuiScreen { private static final int ENABLE_LIGHTING = 9008; private static final int FRAMERATE_SLIDER_ID = 9009; private static final int RESOURCEPACK_ID = 9010; + private static final int WAITFORCHUNKS_ID = 9011; + private static final int INDICATOR_ID = 9012; - private GuiButton recordServerButton, recordSPButton, sendChatButton, linearButton, lightingButton, resourcePackButton; + private GuiButton recordServerButton, recordSPButton, sendChatButton, linearButton, lightingButton, + resourcePackButton, waitForChunksButton, showIndicatorButton; public GuiReplaySettings(GuiScreen parentGuiScreen) { this.parentGuiScreen = parentGuiScreen; @@ -44,61 +42,74 @@ public class GuiReplaySettings extends GuiScreen { this.buttonList.clear(); this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height - 27, I18n.format("gui.done", new Object[0]))); - Option[] aoptions = Option.values(); - ReplaySettings settings = ReplayMod.replaySettings; - + int k = 0; int i = 0; - for (Option o : aoptions) { - switch(o) { - case lighting: - this.buttonList.add(lightingButton = new GuiButton(ENABLE_LIGHTING, this.width / 2 - 155 + i % 2 * 160, - this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Lighting: "+onOff(settings.isLightingEnabled()))); - break; - case linear: - this.buttonList.add(linearButton = new GuiButton(FORCE_LINEAR, this.width / 2 - 155 + i % 2 * 160, - this.height / 6 + 24 * (i >> 1), 150, 20, "Camera Path: "+linearOnOff(settings.isLinearMovement()))); - break; - case notifications: + for(RecordingOptions o : RecordingOptions.values()) { + if(o == RecordingOptions.notifications) { this.buttonList.add(sendChatButton = new GuiButton(SEND_CHAT, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Notifications: "+onOff(settings.isShowNotifications()))); - break; - case recordServer: + } else if(o == RecordingOptions.recordServer) { this.buttonList.add(recordServerButton = new GuiButton(RECORDSERVER_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Server: " +onOff(settings.isEnableRecordingServer()))); - break; - case recordSingleplayer: + } else if(o == RecordingOptions.recordSingleplayer) { this.buttonList.add(recordSPButton = new GuiButton(RECORDSP_ID, this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), 150, 20, "Record Singleplayer: "+onOff(settings.isEnableRecordingSingleplayer()))); - break; - case useResources: - this.buttonList.add(resourcePackButton = new GuiButton(RESOURCEPACK_ID, this.width / 2 - 155 + i % 2 * 160, - this.height / 6 + 24 * (i >> 1), 150, 20, "Server Resource Packs: "+onOff(settings.getUseResourcePacks()))); - break; - case videoFramerate: - this.buttonList.add(new GuiVideoFramerateSlider(FRAMERATE_SLIDER_ID, - this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), settings.getVideoFramerate(), "Video Framerate")); - break; - case videoQuality: - this.buttonList.add(new GuiVideoQualitySlider(QUALITY_SLIDER_ID, - this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), (float)settings.getVideoQuality(), "Video Quality")); - break; - default: - break; + } else if(o == RecordingOptions.indicator) { + this.buttonList.add(showIndicatorButton = new GuiButton(INDICATOR_ID, this.width / 2 - 155 + i % 2 * 160, + this.height / 6 + 24 * (i >> 1), 150, 20, "Show Recording Indicator: "+onOff(settings.showRecordingIndicator()))); } ++i; ++k; } - + + if (i % 2 == 1) { ++i; } + + for(ReplayOptions o : ReplayOptions.values()) { + if(o == ReplayOptions.lighting) { + this.buttonList.add(lightingButton = new GuiButton(ENABLE_LIGHTING, this.width / 2 - 155 + i % 2 * 160, + this.height / 6 + 24 * (i >> 1), 150, 20, "Enable Lighting: "+onOff(settings.isLightingEnabled()))); + } else if(o == ReplayOptions.linear) { + this.buttonList.add(linearButton = new GuiButton(FORCE_LINEAR, this.width / 2 - 155 + i % 2 * 160, + this.height / 6 + 24 * (i >> 1), 150, 20, "Camera Path: "+linearOnOff(settings.isLinearMovement()))); + } else if(o == ReplayOptions.useResources) { + this.buttonList.add(resourcePackButton = new GuiButton(RESOURCEPACK_ID, this.width / 2 - 155 + i % 2 * 160, + this.height / 6 + 24 * (i >> 1), 150, 20, "Server Resource Packs: "+onOff(settings.getUseResourcePacks()))); + } + + ++i; + ++k; + } + + if (i % 2 == 1) + { + ++i; + } + + for(RenderOptions o : RenderOptions.values()) { + if(o == RenderOptions.videoFramerate) { + this.buttonList.add(new GuiVideoFramerateSlider(FRAMERATE_SLIDER_ID, + this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), settings.getVideoFramerate(), "Video Framerate")); + } else if(o == RenderOptions.videoQuality) { + this.buttonList.add(new GuiVideoQualitySlider(QUALITY_SLIDER_ID, + this.width / 2 - 155 + i % 2 * 160, this.height / 6 + 24 * (i >> 1), (float)settings.getVideoQuality(), "Video Quality")); + } else if(o == RenderOptions.waitForChunks) { + this.buttonList.add(resourcePackButton = new GuiButton(WAITFORCHUNKS_ID, this.width / 2 - 155 + i % 2 * 160, + this.height / 6 + 24 * (i >> 1), 150, 20, "Force Render Chunks: "+onOff(settings.getWaitForChunks()))); + } + + ++i; + ++k; + } } private String onOff(boolean on) { @@ -163,6 +174,18 @@ public class GuiReplaySettings extends GuiScreen { resourcePackButton.displayString = "Server Resource Packs: "+onOff(enabled); ReplayMod.replaySettings.setUseResourcePacks(enabled); break; + case WAITFORCHUNKS_ID: + enabled = ReplayMod.replaySettings.getWaitForChunks(); + enabled = !enabled; + resourcePackButton.displayString = "Force Render Chunks: "+onOff(enabled); + ReplayMod.replaySettings.setWaitForChunks(enabled); + break; + case INDICATOR_ID: + enabled = ReplayMod.replaySettings.showRecordingIndicator(); + enabled = !enabled; + showIndicatorButton.displayString = "Show Recording Indicator: "+onOff(enabled); + ReplayMod.replaySettings.setEnableIndicator(enabled); + break; } } } diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java index 4ccc171a..7255df85 100755 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplayProcess.java @@ -1,12 +1,17 @@ package eu.crushedpixel.replaymod.replay; import java.awt.image.BufferedImage; +import java.lang.reflect.Field; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.renderer.ChunkRenderContainer; +import net.minecraft.client.renderer.RenderGlobal; +import net.minecraft.client.renderer.chunk.RenderChunk; import eu.crushedpixel.replaymod.ReplayMod; import eu.crushedpixel.replaymod.chat.ChatMessageRequests; import eu.crushedpixel.replaymod.chat.ChatMessageRequests.ChatMessageType; +import eu.crushedpixel.replaymod.gui.GuiCancelRender; import eu.crushedpixel.replaymod.holders.Keyframe; import eu.crushedpixel.replaymod.holders.Position; import eu.crushedpixel.replaymod.holders.PositionKeyframe; @@ -14,6 +19,7 @@ import eu.crushedpixel.replaymod.holders.TimeKeyframe; import eu.crushedpixel.replaymod.interpolation.LinearPoint; import eu.crushedpixel.replaymod.interpolation.LinearTimestamp; import eu.crushedpixel.replaymod.interpolation.SplinePoint; +import eu.crushedpixel.replaymod.reflection.MCPNames; import eu.crushedpixel.replaymod.timer.EnchantmentTimer; import eu.crushedpixel.replaymod.timer.MCTimerHandler; import eu.crushedpixel.replaymod.video.ScreenCapture; @@ -36,6 +42,8 @@ public class ReplayProcess { private static LinearPoint motionLinear = null; private static LinearTimestamp timeLinear = null; + private static double lastSpeed = 1f; + private static double previousReplaySpeed = 0; private static boolean calculated = false; @@ -64,11 +72,12 @@ public class ReplayProcess { } blocked = deepBlock = false; - + startRealTime = System.currentTimeMillis(); lastRealTime = startRealTime; lastRealReplayTime = 0; lastTimestamp = -1; + lastSpeed = 1f; linear = ReplayMod.replaySettings.isLinearMovement(); ReplayHandler.sortKeyframes(); ReplayHandler.setInPath(true); @@ -80,15 +89,17 @@ public class ReplayProcess { if(tf != null) { int ts = tf.getTimestamp(); if(ts < ReplayHandler.getReplayTime()) { - mc.displayGuiScreen((GuiScreen)null); + mc.displayGuiScreen(null); } ReplayHandler.setReplayTime(ts); } ChatMessageRequests.addChatMessage("Replay started!", ChatMessageType.INFORMATION); + mc.renderGlobal.loadRenderers(); + if(isVideoRecording()) { - MCTimerHandler.setTimerSpeed(1); + MCTimerHandler.setTimerSpeed(1f); MCTimerHandler.setPassiveTimer(); } } @@ -96,11 +107,16 @@ public class ReplayProcess { public static void stopReplayProcess(boolean finished) { if(!ReplayHandler.isInPath()) return; if(finished) ChatMessageRequests.addChatMessage("Replay finished!", ChatMessageType.INFORMATION); - else ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION); + else { + ChatMessageRequests.addChatMessage("Replay stopped!", ChatMessageType.INFORMATION); + if(isVideoRecording()) { + VideoWriter.abortRecording(); + } + } ReplayHandler.setInPath(false); MCTimerHandler.setActiveTimer(); ReplayHandler.setSpeed(previousReplaySpeed); - ReplayHandler.setSpeed(0); + //ReplayHandler.setSpeed(0); } private static boolean blocked = false; @@ -108,22 +124,35 @@ public class ReplayProcess { private static boolean requestFinish = false; - public static void unblockAndTick() { + public static void unblockAndTick(boolean justCheck) { if(!deepBlock) blocked = false; if(!blocked || !isVideoRecording()) - ReplayProcess.tickReplay(); + ReplayProcess.tickReplay(justCheck); } - public static void tickReplay() { - pathTick(isVideoRecording()); + public static void tickReplay(boolean justCheck) { + pathTick(isVideoRecording(), justCheck); } - private static void pathTick(boolean recording) { + private static void pathTick(boolean recording, boolean justCheck) { if(ReplayHandler.isHurrying()) { lastRealTime = System.currentTimeMillis(); return; } + if(recording && ((ReplayMod.replaySettings.getWaitForChunks() && RenderChunk.renderChunksUpdated != 0) || mc.currentScreen instanceof GuiCancelRender)) { + MCTimerHandler.setTimerSpeed(0f); + MCTimerHandler.setPartialTicks(0f); + MCTimerHandler.setRenderPartialTicks(0f); + MCTimerHandler.setTicks(0); + return; + } else if (recording && ReplayMod.replaySettings.getWaitForChunks()) { + MCTimerHandler.setTimerSpeed((float)lastSpeed); + } + + + if(justCheck) return; + if(recording) { if(blocked) return; @@ -277,7 +306,10 @@ public class ReplayProcess { ReplayHandler.getCameraEntity().movePath(pos); } - ReplayHandler.setSpeed(curSpeed); + if(curSpeed > 0) { + ReplayHandler.setSpeed(curSpeed); + lastSpeed = curSpeed; + } if(recording) { MCTimerHandler.updateTimer((1f/ReplayMod.replaySettings.getVideoFramerate())); diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java index 8433041a..e0ddf4de 100755 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java @@ -147,7 +147,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { } public void jumpToTime(int millis) { - setReplaySpeed(replaySpeed); + if(!(ReplayHandler.isInPath() && ReplayProcess.isVideoRecording())) setReplaySpeed(replaySpeed); if((millis < currentTimeStamp && !isHurrying())) { if(ReplayHandler.isInPath()) { @@ -494,7 +494,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { if(p == null) return; //If hurrying, ignore some packets, unless during Replay Path and *not* in initial hurry - if(hurryToTimestamp && (!ReplayHandler.isInPath() || (desiredTimeStamp-currentTimeStamp > 1000))) { + if(hurryToTimestamp && (!ReplayHandler.isInPath() || (desiredTimeStamp-currentTimeStamp > 1000))) { if(p instanceof S45PacketTitle || p instanceof S2APacketParticles) return; } diff --git a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java index ca22102a..c8ce52af 100755 --- a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java +++ b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java @@ -1,6 +1,9 @@ package eu.crushedpixel.replaymod.settings; import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; import net.minecraft.client.Minecraft; import net.minecraft.client.settings.GameSettings.Options; @@ -13,21 +16,61 @@ import eu.crushedpixel.replaymod.replay.ReplayHandler; public class ReplaySettings { - public enum Option { - recordServer(true), recordSingleplayer(true), notifications(true), linear(false), - lighting(false), useResources(true), videoQuality(0.5f), videoFramerate(30); - + public static interface ValueEnum { + public Object getValue(); + public void setValue(Object value); + } + + public enum RecordingOptions implements ValueEnum { + recordServer(true), recordSingleplayer(true), notifications(true), indicator(true); + private Object value; - + public Object getValue() { return value; } - + public void setValue(Object value) { this.value = value; } - - Option(Object value) { + + RecordingOptions(Object value) { + this.value = value; + } + } + + public enum ReplayOptions implements ValueEnum { + linear(false), lighting(false), useResources(true); + + private Object value; + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + ReplayOptions(Object value) { + this.value = value; + } + } + + public enum RenderOptions implements ValueEnum { + videoQuality(0.5f), videoFramerate(30), waitForChunks(true); + + private Object value; + + public Object getValue() { + return value; + } + + public void setValue(Object value) { + this.value = value; + } + + RenderOptions(Object value) { this.value = value; } } @@ -43,74 +86,105 @@ public class ReplaySettings { e.printStackTrace(); } } - + + public List getValueEnums() { + List enums = new ArrayList(); + enums.addAll(Arrays.asList(ReplayOptions.values())); + enums.addAll(Arrays.asList(RenderOptions.values())); + return enums; + } + public void readValues() { Configuration config = ReplayMod.config; - - for(Option o : Option.values()) { - Property p = getConfigSetting(config, o); + + for(RecordingOptions o : RecordingOptions.values()) { + Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "recording"); o.setValue(getValueObject(p)); } + for(ReplayOptions o : ReplayOptions.values()) { + Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "replay"); + o.setValue(getValueObject(p)); + } + + for(RenderOptions o : RenderOptions.values()) { + Property p = getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "render"); + o.setValue(getValueObject(p)); + } + config.save(); } - + public int getVideoFramerate() { - return (Integer)Option.videoFramerate.getValue(); + return (Integer)RenderOptions.videoFramerate.getValue(); } public void setVideoFramerate(int framerate) { - Option.videoFramerate.setValue(Math.min(120, Math.max(10, framerate))); + RenderOptions.videoFramerate.setValue(Math.min(120, Math.max(10, framerate))); rewriteSettings(); } public double getVideoQuality() { - return (Double)Option.videoQuality.getValue(); + return (Double)RenderOptions.videoQuality.getValue(); + } + public void setEnableIndicator(boolean enable) { + RecordingOptions.indicator.setValue(enable); + rewriteSettings(); + } + public boolean showRecordingIndicator() { + return (Boolean)RecordingOptions.indicator.getValue(); } public void setVideoQuality(double videoQuality) { - Option.videoQuality.setValue(Math.min(0.9f, Math.max(0.1f, videoQuality))); + RenderOptions.videoQuality.setValue(Math.min(0.9f, Math.max(0.1f, videoQuality))); rewriteSettings(); } public boolean isEnableRecordingServer() { - return (Boolean)Option.recordServer.getValue(); + return (Boolean)RecordingOptions.recordServer.getValue(); } public void setEnableRecordingServer(boolean enableRecordingServer) { - Option.recordServer.setValue(enableRecordingServer); + RecordingOptions.recordServer.setValue(enableRecordingServer); rewriteSettings(); } public boolean isEnableRecordingSingleplayer() { - return (Boolean)Option.recordSingleplayer.getValue(); + return (Boolean)RecordingOptions.recordSingleplayer.getValue(); } public void setEnableRecordingSingleplayer(boolean enableRecordingSingleplayer) { - Option.recordSingleplayer.setValue(enableRecordingSingleplayer); + RecordingOptions.recordSingleplayer.setValue(enableRecordingSingleplayer); rewriteSettings(); } public boolean isShowNotifications() { - return (Boolean)Option.notifications.getValue(); + return (Boolean)RecordingOptions.notifications.getValue(); } public void setShowNotifications(boolean showNotifications) { - Option.notifications.setValue(showNotifications); + RecordingOptions.notifications.setValue(showNotifications); rewriteSettings(); } public boolean isLinearMovement() { - return (Boolean)Option.linear.getValue(); + return (Boolean)ReplayOptions.linear.getValue(); } public void setLinearMovement(boolean linear) { - Option.linear.setValue(linear); + ReplayOptions.linear.setValue(linear); rewriteSettings(); } public boolean isLightingEnabled() { - return (Boolean)Option.lighting.getValue(); + return (Boolean)ReplayOptions.lighting.getValue(); } public void setUseResourcePacks(boolean use) { - Option.useResources.setValue(use); + ReplayOptions.useResources.setValue(use); rewriteSettings(); } public boolean getUseResourcePacks() { - return (Boolean)Option.useResources.getValue(); + return (Boolean)ReplayOptions.useResources.getValue(); } - + public void setWaitForChunks(boolean wait) { + RenderOptions.waitForChunks.setValue(wait); + rewriteSettings(); + } + public boolean getWaitForChunks() { + return (Boolean)RenderOptions.waitForChunks.getValue(); + } + //TODO: FIX public void setLightingEnabled(boolean enabled) { - Option.lighting.setValue(enabled); + ReplayOptions.lighting.setValue(enabled); if(enabled) { Minecraft.getMinecraft().gameSettings.setOptionFloatValue(Options.GAMMA, 1000); } else { @@ -130,34 +204,39 @@ public class ReplaySettings { rewriteSettings(); } - + public void rewriteSettings() { ReplayMod.instance.config.load(); - ReplayMod.instance.config.removeCategory(ReplayMod.instance.config.getCategory("settings")); - - for(Option o : Option.values()) { - getConfigSetting(ReplayMod.instance.config, o); + + for(String cat : ReplayMod.instance.config.getCategoryNames()) { + ReplayMod.instance.config.removeCategory(ReplayMod.instance.config.getCategory(cat)); } - + + for(ReplayOptions o : ReplayOptions.values()) { + getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "replay"); + } + + for(RenderOptions o : RenderOptions.values()) { + getConfigSetting(ReplayMod.instance.config, o.name(), o.getValue(), "render"); + } + ReplayMod.instance.config.save(); } - - private Property getConfigSetting(Configuration config, Option o) { - Object value = o.getValue(); + + private Property getConfigSetting(Configuration config, String name, Object value, String category) { if(value instanceof Integer) { - return config.get("settings", o.name(), (Integer)o.getValue()); + return config.get(category, name, (Integer)value); } else if(value instanceof Boolean) { - return config.get("settings", o.name(), (Boolean)o.getValue()); + return config.get(category, name, (Boolean)value); } else if(value instanceof Double) { - return config.get("settings", o.name(), (Double)o.getValue()); + return config.get(category, name, (Double)value); } else if(value instanceof Float) { - return config.get("settings", o.name(), (double)(Float)o.getValue()); + return config.get(category, name, (double)(Float)value); } else if(value instanceof String) { - return config.get("settings", o.name(), (String)o.getValue()); + return config.get(category, name, (String)value); } return null; } - private Object getValueObject(Property p) { if(p.isIntValue()) { return p.getInt(); diff --git a/src/main/java/eu/crushedpixel/replaymod/timer/MCTimerHandler.java b/src/main/java/eu/crushedpixel/replaymod/timer/MCTimerHandler.java index 5b7bdb47..d0034284 100755 --- a/src/main/java/eu/crushedpixel/replaymod/timer/MCTimerHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/timer/MCTimerHandler.java @@ -6,6 +6,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.util.MathHelper; import net.minecraft.util.Timer; import eu.crushedpixel.replaymod.reflection.MCPNames; +import eu.crushedpixel.replaymod.replay.ReplayHandler; import eu.crushedpixel.replaymod.video.ReplayTimer; public class MCTimerHandler { diff --git a/src/main/java/eu/crushedpixel/replaymod/video/ReplayScreenshot.java b/src/main/java/eu/crushedpixel/replaymod/video/ReplayScreenshot.java index f3e1e22d..da87b0c3 100755 --- a/src/main/java/eu/crushedpixel/replaymod/video/ReplayScreenshot.java +++ b/src/main/java/eu/crushedpixel/replaymod/video/ReplayScreenshot.java @@ -43,7 +43,6 @@ public class ReplayScreenshot { private static GuiScreen beforeScreen; public static void prepareScreenshot() { - System.out.println("thumbnail preparing"); before = mc.gameSettings.hideGUI; beforeSpeed = ReplayHandler.getSpeed(); beforeScreen = mc.currentScreen; @@ -56,7 +55,6 @@ public class ReplayScreenshot { if(locked) return; locked = true; - System.out.println("thumbnail started"); try { GuiReplaySaving.replaySaving = true; @@ -78,7 +76,6 @@ public class ReplayScreenshot { @Override public void run() { try { - System.out.println("thumbnail saving started"); float aspect = 1280f/720f; Rectangle rect; diff --git a/src/main/java/eu/crushedpixel/replaymod/video/VideoWriter.java b/src/main/java/eu/crushedpixel/replaymod/video/VideoWriter.java index 9a37ec59..58700b4f 100755 --- a/src/main/java/eu/crushedpixel/replaymod/video/VideoWriter.java +++ b/src/main/java/eu/crushedpixel/replaymod/video/VideoWriter.java @@ -27,8 +27,10 @@ public class VideoWriter { private static final String VIDEO_EXTENSION = ".avi"; private static MovieWriter out; + private static File file; private static boolean isRecording = false; private static boolean requestFinish = false; + private static boolean abort = false; private static Buffer buf; private static int track; @@ -52,7 +54,7 @@ public class VideoWriter { String fileName = sdf.format(Calendar.getInstance().getTime()); - File file = new File(folder, fileName+VIDEO_EXTENSION); + file = new File(folder, fileName+VIDEO_EXTENSION); file.createNewFile(); out = Registry.getInstance().getWriter(file); @@ -79,15 +81,20 @@ public class VideoWriter { @Override public void run() { while(true) { - if(toWrite.isEmpty()) { + if(toWrite.isEmpty() || abort) { if(requestFinish) { requestFinish = false; isRecording = false; try { out.close(); + if(abort) { + file.delete(); + } } catch (IOException e) { e.printStackTrace(); } + abort = false; + toWrite = new LinkedBlockingQueue(); return; } try { @@ -132,4 +139,9 @@ public class VideoWriter { e.printStackTrace(); } } + + public static void abortRecording() { + requestFinish = true; + abort = true; + } } diff --git a/src/main/resources/assets/replaymod/replay_gui.png b/src/main/resources/assets/replaymod/replay_gui.png index a97fb3d8..051f365f 100755 Binary files a/src/main/resources/assets/replaymod/replay_gui.png and b/src/main/resources/assets/replaymod/replay_gui.png differ