Skip to content

Commit

Permalink
Fix dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
Scribble authored Oct 1, 2021
2 parents e0a2ac6 + d1692a6 commit f12cfa8
Show file tree
Hide file tree
Showing 14 changed files with 99 additions and 40 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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'
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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());
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraft.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}

Expand Down Expand Up @@ -73,6 +77,11 @@ public long redirectMathMax(long oneLong, long i) {

@Shadow
private Queue<FutureTask<?>> 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) {
Expand All @@ -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();
Expand All @@ -101,6 +116,7 @@ public void redirectThreadSleep(long msToTick) {
}
}
}

try {
Thread.sleep(1L);
} catch (InterruptedException e) {
Expand All @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 <br>
* Called in {@link SavestatePacketHandler}<br>
* <br>
* 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();
Expand Down Expand Up @@ -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 "";
}

/**
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -246,8 +259,7 @@ public static void loadState() throws LoadstateException, IOException {
}

//Unlock loadstating
isLoading=false;
wasLoading=true;
state=SavestateState.WASLOADING;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ 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()));

} catch (Exception e) {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.scribble.lp.tasmod.savestates.server;

public enum SavestateState {
SAVING,
LOADING,
WASLOADING,
NONE
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,20 @@ public static void pauseUnpauseGame() {
pauseUnpauseClient();
}
}

public static void advanceTick() {
if(Minecraft.getMinecraft().world!=null) {
advanceServerTick();
}else {
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);
Expand All @@ -58,6 +61,7 @@ public static void bypass() {
changeClientTickrate(0);
WASZERO=false;
}

}

public static void advanceClientTick() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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));
}
Expand Down Expand Up @@ -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);
}
}
}
Loading

0 comments on commit f12cfa8

Please sign in to comment.