Skip to content

Commit

Permalink
Fix crash in Minecraft Server
Browse files Browse the repository at this point in the history
-Thanks Kynatosh
-Reformatted the file a bit...
  • Loading branch information
Scribble authored and Scribble committed Oct 5, 2021
1 parent f12cfa8 commit da54730
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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.state==SavestateState.WASLOADING) {
if (SavestateHandler.state == SavestateState.WASLOADING) {
SavestateHandler.state = SavestateState.NONE;
SavestateHandler.playerLoadSavestateEventServer();
}
Expand Down Expand Up @@ -77,11 +77,11 @@ public long redirectMathMax(long oneLong, long i) {

@Shadow
private Queue<FutureTask<?>> futureTaskQueue;

@Shadow
private NetworkSystem networkSystem;
private int faketick=0;

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 @@ -93,13 +93,15 @@ public void redirectThreadSleep(long msToTick) {
msToTick = 1L;
}
for (long o = 0; o < msToTick; o++) {
if(TickrateChangerServer.TICKS_PER_SECOND==0) {
currentTime=System.currentTimeMillis();
if (TickrateChangerServer.TICKS_PER_SECOND == 0) {
currentTime = System.currentTimeMillis();
faketick++;
if(faketick>=20) {
faketick=0;
if (faketick >= 20) {
faketick = 0;
networkSystem.networkTick();
runPendingCommands();
if (((MinecraftServer) (Object) this).isDedicatedServer()) {
runPendingCommands();
}
}
}
if (TickrateChangerServer.INTERRUPT) {
Expand All @@ -116,7 +118,7 @@ public void redirectThreadSleep(long msToTick) {
}
}
}

try {
Thread.sleep(1L);
} catch (InterruptedException e) {
Expand All @@ -128,14 +130,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;
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"))
// public void lagServer(CallbackInfo ci) {
// if(SavestateEvents.lagServer) {
Expand All @@ -147,13 +149,13 @@ private void runPendingCommands() {
// }
// }
// }

// @ModifyVariable(method = "run", at = @At(value = "STORE"), index = 5, ordinal = 2)
// public long limitLag(long j) {
// if(j>(500L*(20/TickrateChangerServer.TICKS_PER_SECOND))){
// return 50L;
// }
// return j;
// }

}

0 comments on commit da54730

Please sign in to comment.