diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 9b81ad74..1860807d 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -19,9 +19,9 @@ jobs: - name: Prepare folders run: mkdir -p gradle/wrapper - name: Download gradle properties - run: wget -P gradle/wrapper https://mgnet.work/.web_ram/gradle-wrapper.properties + run: wget -P gradle/wrapper https://data.mgnet.work/tasmod/gradle-wrapper.properties - name: Obtain gradle - run: wget -P gradle/wrapper https://mgnet.work/.web_ram/gradle-wrapper.jar + run: wget -P gradle/wrapper https://data.mgnet.work/tasmod/gradle-wrapper.jar - name: Build TASmod with Gradle run: java -cp gradle/wrapper/gradle-wrapper.jar org.gradle.wrapper.GradleWrapperMain shadowJar --no-daemon - run: find . -type f ! -name "*forge.jar" -delete diff --git a/build.gradle b/build.gradle index 16dc2d6f..5ce7d23b 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ apply plugin: 'org.spongepowered.mixin' //Only edit below this line, the above code adds and enables the necessary things for Forge to be setup. -version = "Alpha6" +version = "Alpha7-WIP" group = "de.scribble.lp.tastools" // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = "TASmod-1.12.2" @@ -47,7 +47,7 @@ minecraft { } repositories { mavenCentral() - maven { url = "https://mgnet.work/repo" } + maven { url = "https://maven.mgnet.work" } maven { name = 'sponge' url = 'https://repo.spongepowered.org/maven' @@ -68,6 +68,7 @@ dependencies { compile 'org.msgpack:msgpack-core:0.8.16' compile 'org.msgpack:jackson-dataformat-msgpack:0.8.16' compile files('libs/KillTheRNG-1.12.2-1.0-deobf.jar') + //compile files('libs/BigArrayList-1.3.jar') compile 'com.dselent:bigarraylist:1.0' // real examples //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env diff --git a/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java b/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java index ca7af098..9a14c621 100644 --- a/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java +++ b/src/main/java/de/scribble/lp/tasmod/events/PlayerJoinLeaveEvents.java @@ -24,6 +24,7 @@ public static void firePlayerJoinedServerSide(EntityPlayerMP player) { TASmod.logger.info("Firing login events for {} on the SERVER", player.getName()); TickSyncServer.joinServer(player); TASmod.containerStateServer.joinServer(player); + TickrateChangerServer.joinServer(player); } /** @@ -32,8 +33,7 @@ public static void firePlayerJoinedServerSide(EntityPlayerMP player) { * @param player The player that left the server */ public static void firePlayerLeaveServerSide(EntityPlayerMP player) { - TASmod.logger.info("Firing logout events for {} on the SERVER", player.getName()); - TickrateChangerServer.leaveServer(player); +// TASmod.logger.info("Firing logout events for {} on the SERVER", player.getName()); } /** diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java b/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java index 179808b1..c87d4b7f 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java +++ b/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java @@ -35,6 +35,8 @@ public abstract class MixinMinecraft { @Shadow private GuiScreen currentScreen; +// private int faketick=0; + @Inject(method = "runGameLoop", at = @At(value = "HEAD")) public void injectRunGameLoop(CallbackInfo ci) { // TASmod @@ -44,6 +46,15 @@ public void injectRunGameLoop(CallbackInfo ci) { if(((Minecraft) (Object) this).player!=null) { ClientProxy.hud.tick(); } + + //Fake tickrate loop when you are in tickrate 0 +// if(TickrateChangerClient.TICKS_PER_SECOND==0) { +// faketick++; +// if(faketick>=Minecraft.getDebugFPS()/3) { //Not yet used but maybe in the future +// faketick=0; +// } +// } + while (Keyboard.next()) { ClientProxy.virtual.updateNextKeyboard(Keyboard.getEventKey(), Keyboard.getEventKeyState(), Keyboard.getEventCharacter()); } diff --git a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java b/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java index 80531b7e..9a54bd17 100644 --- a/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java +++ b/src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java @@ -13,10 +13,14 @@ import de.scribble.lp.tasmod.CommonProxy; import de.scribble.lp.tasmod.TASmod; import de.scribble.lp.tasmod.savestates.server.SavestateHandler; +import de.scribble.lp.tasmod.savestates.server.SavestateState; import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer; import de.scribble.lp.tasmod.ticksync.TickSyncPackage; import de.scribble.lp.tasmod.ticksync.TickSyncServer; +import net.minecraft.network.NetworkSystem; import net.minecraft.server.MinecraftServer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; @Mixin(MinecraftServer.class) public abstract class MixinMinecraftServer { @@ -33,8 +37,8 @@ public long modifyMSPT(long fiftyLong) { @Redirect(method = "run", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;tick()V", ordinal = 1)) public void redirectTick(MinecraftServer server) { this.tick(); - if (SavestateHandler.wasLoading) { - SavestateHandler.wasLoading = false; + if (SavestateHandler.state==SavestateState.WASLOADING) { + SavestateHandler.state = SavestateState.NONE; SavestateHandler.playerLoadSavestateEventServer(); } @@ -73,6 +77,11 @@ public long redirectMathMax(long oneLong, long i) { @Shadow private Queue> futureTaskQueue; + + @Shadow + private NetworkSystem networkSystem; + + private int faketick=0; @Redirect(method = "run", at = @At(value = "INVOKE", target = "Ljava/lang/Thread;sleep(J)V")) public void redirectThreadSleep(long msToTick) { @@ -86,6 +95,12 @@ public void redirectThreadSleep(long msToTick) { for (long o = 0; o < msToTick; o++) { if(TickrateChangerServer.TICKS_PER_SECOND==0) { currentTime=System.currentTimeMillis(); + faketick++; + if(faketick>=20) { + faketick=0; + networkSystem.networkTick(); + runPendingCommands(); + } } if (TickrateChangerServer.INTERRUPT) { currentTime = System.currentTimeMillis(); @@ -101,6 +116,7 @@ public void redirectThreadSleep(long msToTick) { } } } + try { Thread.sleep(1L); } catch (InterruptedException e) { @@ -110,6 +126,14 @@ public void redirectThreadSleep(long msToTick) { } } + @SideOnly(Side.SERVER) + private void runPendingCommands() { + if((MinecraftServer)(Object)this instanceof net.minecraft.server.dedicated.DedicatedServer) { + net.minecraft.server.dedicated.DedicatedServer server=(net.minecraft.server.dedicated.DedicatedServer)(MinecraftServer)(Object)this; + server.executePendingCommands(); + } + } + // ===================================================================================================================================== // @Inject(method = "tick", at = @At("HEAD")) diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacketHandler.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacketHandler.java index e7de5a1e..daed6f0c 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacketHandler.java +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/LoadstatePacketHandler.java @@ -30,7 +30,7 @@ public IMessage onMessage(LoadstatePacket message, MessageContext ctx) { player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to load a savestate: "+e.getCause().toString())); e.printStackTrace(); } finally { - SavestateHandler.isLoading=false; + SavestateHandler.state=SavestateState.NONE; } }); }else { diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java index 9abe5c4e..306392fe 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java @@ -1,6 +1,7 @@ package de.scribble.lp.tasmod.savestates.server; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import org.apache.commons.io.FileUtils; @@ -39,28 +40,26 @@ public class SavestateHandler { private static MinecraftServer server=TASmod.getServerInstance(); private static File savestateDirectory; - public static boolean isSaving=false; - - public static boolean isLoading=false; - public static boolean wasLoading=false; + public static SavestateState state=SavestateState.NONE; /** * Creates a copy of the currently played world and saves it in .minecraft/saves/savestates/worldname
* Called in {@link SavestatePacketHandler}
*
* Side: Server + * @param savestateIndex The index where the mod will save the savestate -1 if it should load the latest * @throws SavestateException * @throws IOException */ - public static void saveState() throws SavestateException, IOException { - if(isSaving) { + public static void saveState(int savestateIndex) throws SavestateException, IOException { + if(state==SavestateState.SAVING) { throw new SavestateException("A savestating operation is already being carried out"); } - if(isLoading) { + if(state==SavestateState.LOADING) { throw new SavestateException("A loadstate operation is being carried out"); } //Lock savestating and loadstating - isSaving=true; + state=SavestateState.SAVING; //Create a directory just in case createSavestateDirectory(); @@ -107,7 +106,21 @@ public static void saveState() throws SavestateException, IOException { CommonProxy.NETWORK.sendToAll(new SavestatePacket()); //Unlock savestating - isSaving=false; + state=SavestateState.NONE; + } + + private static String nextSaveName(String worldname, int index) { + File[] listofFiles=savestateDirectory.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return pathname.getName().startsWith(worldname); + } + + }); + if(index<0) { + } + return ""; } /** @@ -117,14 +130,13 @@ public static void saveState() throws SavestateException, IOException { * @return targetsavefolder The file where the savestate should be copied to * @throws SavestateException if the found savestates count is greater or equal than 300 */ + @Deprecated private static File getNextSaveFolderLocation(String worldname) throws SavestateException { int i = 1; int limit=300; File targetsavefolder=null; - isSaving=true; while (i <= limit) { if (i >= limit) { - isSaving = false; throw new SavestateException("Savestatecount is greater or equal than "+limit); } targetsavefolder = new File(savestateDirectory,worldname + "-Savestate" + Integer.toString(i)+File.separator); @@ -143,6 +155,7 @@ private static File getNextSaveFolderLocation(String worldname) throws Savestate * @param worldname the name of the world currently on the server * @return The correct name of the next savestate */ + @Deprecated private static String nameWhenSaving(String worldname) { int i = 1; int limit=300; @@ -171,14 +184,14 @@ private static String nameWhenSaving(String worldname) { * @throws IOException */ public static void loadState() throws LoadstateException, IOException { - if(isSaving) { + if(state==SavestateState.SAVING) { throw new LoadstateException("A savestating operation is already being carried out"); } - if(isLoading) { + if(state==SavestateState.LOADING) { throw new LoadstateException("A loadstate operation is being carried out"); } //Lock savestating and loadstating - isLoading=true; + state=SavestateState.LOADING; //Create a directory just in case createSavestateDirectory(); @@ -246,8 +259,7 @@ public static void loadState() throws LoadstateException, IOException { } //Unlock loadstating - isLoading=false; - wasLoading=true; + state=SavestateState.WASLOADING; } /** diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java index 399319ba..f63bcd87 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java @@ -30,7 +30,7 @@ public IMessage onMessage(SavestatePacket message, MessageContext ctx) { return; } try { - SavestateHandler.saveState(); + SavestateHandler.saveState(-1); } catch (SavestateException e) { player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getMessage())); @@ -38,7 +38,7 @@ public IMessage onMessage(SavestatePacket message, MessageContext ctx) { e.printStackTrace(); player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getCause().toString())); } finally { - SavestateHandler.isSaving=false; + SavestateHandler.state=SavestateState.NONE; } }); }else { diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java new file mode 100644 index 00000000..15f3f0fe --- /dev/null +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateState.java @@ -0,0 +1,8 @@ +package de.scribble.lp.tasmod.savestates.server; + +public enum SavestateState { + SAVING, + LOADING, + WASLOADING, + NONE +} diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java index 08184455..eb0f98ab 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java +++ b/src/main/java/de/scribble/lp/tasmod/tickratechanger/CommandTickrate.java @@ -8,6 +8,7 @@ import net.minecraft.command.CommandException; import net.minecraft.command.ICommandSender; import net.minecraft.server.MinecraftServer; +import net.minecraft.util.text.TextComponentString; public class CommandTickrate extends CommandBase{ @Override @@ -27,6 +28,10 @@ public String getUsage(ICommandSender sender) { @Override public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException { + if(args.length==0) { + sender.sendMessage(new TextComponentString("Current tickrate: "+ TickrateChangerServer.TICKS_PER_SECOND)); + return; + } float tickrate= Float.parseFloat(args[0]); TickrateChangerServer.changeServerTickrate(tickrate); TickrateChangerServer.changeClientTickrate(tickrate); diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java index 28cc2118..cd4ab332 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java +++ b/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerClient.java @@ -35,6 +35,7 @@ public static void pauseUnpauseGame() { pauseUnpauseClient(); } } + public static void advanceTick() { if(Minecraft.getMinecraft().world!=null) { advanceServerTick(); @@ -42,10 +43,12 @@ public static void advanceTick() { advanceClientTick(); } } + /** * Bypasses the tick system */ public static void bypass() { + //Stopping any playback or recording if you are in tickrate 0 and the GuiControls if(Minecraft.getMinecraft().currentScreen instanceof GuiControls) { if(TICKS_PER_SECOND==0&&WASZERO==false) { changeClientTickrate(20); @@ -58,6 +61,7 @@ public static void bypass() { changeClientTickrate(0); WASZERO=false; } + } public static void advanceClientTick() { diff --git a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java b/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java index 74b15c83..a15eb751 100644 --- a/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java +++ b/src/main/java/de/scribble/lp/tasmod/tickratechanger/TickrateChangerServer.java @@ -1,8 +1,8 @@ package de.scribble.lp.tasmod.tickratechanger; import de.scribble.lp.tasmod.CommonProxy; +import de.scribble.lp.tasmod.TASmod; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.server.MinecraftServer; public class TickrateChangerServer { public static float TICKS_PER_SECOND=20F; @@ -13,11 +13,6 @@ public class TickrateChangerServer { public static int cooldownKeyPause; public static int cooldownKeyAdvance; - private static MinecraftServer serverInstance; - - public TickrateChangerServer(MinecraftServer server) { - serverInstance=server; - } public static void changeClientTickrate(float tickrate) { CommonProxy.NETWORK.sendToAll(new TickratePacket(false, tickrate, false)); } @@ -54,13 +49,13 @@ public static void advanceTick() { } /** - * Fired when a player left the server + * Fired when a player joined the server * @param player */ - public static void leaveServer(EntityPlayerMP player) { - //TODO Test this in multiplayer - if (TickrateChangerServer.TICKS_PER_SECOND == 0) { - TickrateChangerServer.changeServerTickrate(20F); + public static void joinServer(EntityPlayerMP player) { + if(TASmod.getServerInstance().isDedicatedServer()) { + TASmod.logger.info("Sending the current tickrate ({}) to {}", TICKS_PER_SECOND, player.getName()); + CommonProxy.NETWORK.sendTo(new TickratePacket(false, TICKS_PER_SECOND, false), player); } } } diff --git a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java b/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java index ee7b7d1f..bedd0129 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java +++ b/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java @@ -11,7 +11,6 @@ import com.dselent.bigarraylist.BigArrayList; -import de.scribble.lp.tasmod.commands.savetas.FileThread; import de.scribble.lp.tasmod.inputcontainer.InputContainer; import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; import de.scribble.lp.tasmod.monitoring.DesyncMonitoring; diff --git a/src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java b/src/main/java/de/scribble/lp/tasmod/util/FileThread.java similarity index 95% rename from src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java rename to src/main/java/de/scribble/lp/tasmod/util/FileThread.java index df3c0eba..1f3e80a7 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java +++ b/src/main/java/de/scribble/lp/tasmod/util/FileThread.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.commands.savetas; +package de.scribble.lp.tasmod.util; import java.io.File; import java.io.FileNotFoundException;