Skip to content

Commit

Permalink
Fix #2 Start the playback when the world loads
Browse files Browse the repository at this point in the history
-The world will start playing the startup.tas file
  • Loading branch information
Scribble authored and PancakeTAS committed Dec 15, 2020
1 parent 93cc55b commit 3a196b0
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 63 deletions.
6 changes: 6 additions & 0 deletions src/main/java/de/scribble/lp/tasmod/CommonProxy.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/de/scribble/lp/tasmod/ModLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/java/de/scribble/lp/tasmod/events/TASmodEvents.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
23 changes: 23 additions & 0 deletions src/main/java/de/scribble/lp/tasmod/playback/PlaybackPacket.java
Original file line number Diff line number Diff line change
@@ -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) {

}

}
Original file line number Diff line number Diff line change
@@ -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<PlaybackPacket, IMessage>{

@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;
}

}

0 comments on commit 3a196b0

Please sign in to comment.