diff --git a/src/main/java/de/scribble/lp/tasmod/CommonProxy.java b/src/main/java/de/scribble/lp/tasmod/CommonProxy.java index 94359f3a..b8a52b03 100644 --- a/src/main/java/de/scribble/lp/tasmod/CommonProxy.java +++ b/src/main/java/de/scribble/lp/tasmod/CommonProxy.java @@ -1,9 +1,13 @@ package de.scribble.lp.tasmod; +import de.scribble.lp.tasmod.events.TASmodEvents; +import de.scribble.lp.tasmod.playback.PlaybackPacket; +import de.scribble.lp.tasmod.playback.PlaybackPacketHandler; import de.scribble.lp.tasmod.tickratechanger.TickratePacket; import de.scribble.lp.tasmod.tickratechanger.TickratePacketHandler; import de.scribble.lp.tasmod.ticksync.TickSyncPackage; import de.scribble.lp.tasmod.ticksync.TickSyncPacketHandler; +import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; @@ -18,9 +22,11 @@ public void preInit(FMLPreInitializationEvent ev) { NETWORK.registerMessage(TickratePacketHandler.class, TickratePacket.class, 0, Side.SERVER); NETWORK.registerMessage(TickratePacketHandler.class, TickratePacket.class, 1, Side.CLIENT); NETWORK.registerMessage(TickSyncPacketHandler.class, TickSyncPackage.class, 2, Side.CLIENT); + NETWORK.registerMessage(PlaybackPacketHandler.class, PlaybackPacket.class, 3, Side.CLIENT); } public void init(FMLInitializationEvent ev) { + MinecraftForge.EVENT_BUS.register(new TASmodEvents()); } public void postInit(FMLPostInitializationEvent ev) { diff --git a/src/main/java/de/scribble/lp/tasmod/ModLoader.java b/src/main/java/de/scribble/lp/tasmod/ModLoader.java index 9a8dd9a8..48fb62ef 100644 --- a/src/main/java/de/scribble/lp/tasmod/ModLoader.java +++ b/src/main/java/de/scribble/lp/tasmod/ModLoader.java @@ -3,7 +3,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import de.scribble.lp.tasmod.custom.CustomEntityRenderer; import de.scribble.lp.tasmod.playback.CommandPlay; import de.scribble.lp.tasmod.recording.CommandRecord; import de.scribble.lp.tasmod.tickratechanger.CommandTickrate; @@ -38,8 +37,6 @@ public class ModLoader { public static final Logger logger= LogManager.getFormatterLogger("TASMod"); - public CustomEntityRenderer centityRenderer=new CustomEntityRenderer(); - @EventHandler public void preInit(FMLPreInitializationEvent ev) { proxy.preInit(ev); diff --git a/src/main/java/de/scribble/lp/tasmod/custom/CustomEntityRenderer.java b/src/main/java/de/scribble/lp/tasmod/custom/CustomEntityRenderer.java deleted file mode 100644 index 12c8379c..00000000 --- a/src/main/java/de/scribble/lp/tasmod/custom/CustomEntityRenderer.java +++ /dev/null @@ -1,60 +0,0 @@ -package de.scribble.lp.tasmod.custom; - -import org.lwjgl.input.Mouse; -import org.lwjgl.opengl.Display; - -import de.scribble.lp.tasmod.playback.InputPlayback; -import de.scribble.lp.tasmod.recording.InputRecorder; -import de.scribble.lp.tasmod.virtual.VirtualMouseAndKeyboard; -import net.minecraft.client.Minecraft; - -public class CustomEntityRenderer { - public void runSubtick(float partialTicks, Minecraft mc, float smoothCamYaw, float smoothCamPitch, float smoothCamPartialTicks, float smoothCamFilterX, float smoothCamFilterY) { - boolean flag=Display.isActive(); - if (flag && Minecraft.IS_RUNNING_ON_MAC && mc.inGameHasFocus && !Mouse.isInsideWindow()) - { - Mouse.setGrabbed(false); - Mouse.setCursorPosition(Display.getWidth() / 2, Display.getHeight() / 2 - 20); - Mouse.setGrabbed(true); - } - - if (mc.inGameHasFocus && flag) - { - mc.mouseHelper.mouseXYChange(); - mc.getTutorial().handleMouse(mc.mouseHelper); - float f = mc.gameSettings.mouseSensitivity * 0.6F + 0.2F; - float f1 = f * f * f * 8.0F; - float f2 = (float)mc.mouseHelper.deltaX * f1; - float f3 = (float)mc.mouseHelper.deltaY * f1; - int i = 1; - - if (mc.gameSettings.invertMouse) - { - i = -1; - } - - if (mc.gameSettings.smoothCamera) - { - smoothCamYaw += f2; - smoothCamPitch += f3; - float f4 = partialTicks - smoothCamPartialTicks; - smoothCamPartialTicks = partialTicks; - f2 = smoothCamFilterX * f4; - f3 = smoothCamFilterY * f4; - mc.player.turn(f2, f3 * (float)i); - } - else - { - smoothCamYaw = 0.0F; - smoothCamPitch = 0.0F; - mc.player.turn(f2, f3 * (float)i); - } - InputPlayback.nextPlaybackSubtick(); - VirtualMouseAndKeyboard.fillSubtick(VirtualMouseAndKeyboard.getTimeSinceLastTick(), mc.player.rotationPitch, mc.player.rotationYaw); - InputRecorder.recordSubTick(); - VirtualMouseAndKeyboard.fillSubtickWithPlayback(); - mc.player.rotationPitch=VirtualMouseAndKeyboard.getSubtickPitch(); - mc.player.rotationYaw=VirtualMouseAndKeyboard.getSubtickYaw(); - } - } -} diff --git a/src/main/java/de/scribble/lp/tasmod/events/TASmodEvents.java b/src/main/java/de/scribble/lp/tasmod/events/TASmodEvents.java new file mode 100644 index 00000000..979bec10 --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/events/TASmodEvents.java @@ -0,0 +1,18 @@ +package de.scribble.lp.tasmod.events; + +import de.scribble.lp.tasmod.CommonProxy; +import de.scribble.lp.tasmod.playback.PlaybackPacket; +import de.scribble.lp.tasmod.ticksync.TickSyncPackage; +import de.scribble.lp.tasmod.ticksync.TickSyncServer; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent; + +public class TASmodEvents { + @SubscribeEvent + public void playerLogin(PlayerLoggedInEvent ev) { + TickSyncServer.resetTickCounter(); + CommonProxy.NETWORK.sendToAll(new TickSyncPackage(TickSyncServer.getServertickcounter(), true, TickSyncServer.isEnabled())); + + CommonProxy.NETWORK.sendToAll(new PlaybackPacket()); + } +} diff --git a/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacket.java b/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacket.java new file mode 100644 index 00000000..821a385e --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacket.java @@ -0,0 +1,23 @@ +package de.scribble.lp.tasmod.playback; + +import io.netty.buffer.ByteBuf; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; + +public class PlaybackPacket implements IMessage{ + String filename; + + public PlaybackPacket() { + } + public PlaybackPacket(String filename) { + this.filename=filename; + } + @Override + public void fromBytes(ByteBuf buf) { + } + + @Override + public void toBytes(ByteBuf buf) { + + } + +} diff --git a/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacketHandler.java b/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacketHandler.java new file mode 100644 index 00000000..b4cd8a1f --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacketHandler.java @@ -0,0 +1,25 @@ +package de.scribble.lp.tasmod.playback; + +import java.io.File; + +import net.minecraft.client.Minecraft; +import net.minecraftforge.fml.common.network.simpleimpl.IMessage; +import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import net.minecraftforge.fml.relauncher.Side; + +public class PlaybackPacketHandler implements IMessageHandler{ + + @Override + public IMessage onMessage(PlaybackPacket message, MessageContext ctx) { + if(ctx.side==Side.CLIENT) { + File file = new File(Minecraft.getMinecraft().mcDataDir, "saves" + File.separator + + "tasfiles" + File.separator + "startup.tas"); + if(file.exists()) { + InputPlayback.startPlayback(file, "startup"); + } + } + return null; + } + +}