fixed tasks not executing when warping, fixes #223, fixes #190

This commit is contained in:
gnembon committed 2020-06-17 01:21:42 -03:00
1 parent 17de3ea21e
commit b77268553e
2 files changed
+28 -8

No files matched your search

@@ -39,7 +39,7 @@ public abstract class MinecraftServer_scarpetMixin extends ReentrantThreadExecut
{ {
timeReference = field_4557 = Util.getMeasuringTimeMs(); timeReference = field_4557 = Util.getMeasuringTimeMs();
tick(isAhead); tick(isAhead);
runTask(); while(runTask()) {Thread.yield();}
} }
@Inject(method = "tick", at = @At( @Inject(method = "tick", at = @At(
@@ -4,6 +4,7 @@ import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler; import carpet.utils.CarpetProfiler;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import net.minecraft.server.ServerTask; import net.minecraft.server.ServerTask;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.profiler.DisableableProfiler; import net.minecraft.util.profiler.DisableableProfiler;
import net.minecraft.util.thread.ReentrantThreadExecutor; import net.minecraft.util.thread.ReentrantThreadExecutor;
@@ -50,6 +51,8 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
@Shadow private volatile boolean loading; @Shadow private volatile boolean loading;
@Shadow public abstract Iterable<ServerWorld> getWorlds();
CarpetProfiler.ProfilerToken currentSection; CarpetProfiler.ProfilerToken currentSection;
private float carpetMsptAccum = 0.0f; private float carpetMsptAccum = 0.0f;
@@ -120,16 +123,16 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
this.profiler.startTick(); this.profiler.startTick();
this.profiler.push("tick"); this.profiler.push("tick");
this.tick(TickSpeed.time_warp_start_time != 0 ? ()->!hasRunningTasks() : this::shouldKeepTicking); this.tick(TickSpeed.time_warp_start_time != 0 ? ()->true : this::shouldKeepTicking);
this.profiler.swap("nextTickWait"); this.profiler.swap("nextTickWait");
if (TickSpeed.time_warp_start_time != 0) // clearing all hanging tasks no matter what when warping
{
while(this.runEveryTask()) {Thread.yield();}
}
this.field_19249 = true; this.field_19249 = true;
this.field_19248 = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference); this.field_19248 = Math.max(Util.getMeasuringTimeMs() + /*50L*/ msThisTick, this.timeReference);
if (TickSpeed.time_warp_start_time != 0) // run all tasks (this will not do a lot when warping), but that's fine since we already run them
{ this.method_16208();
runTasks();
runTasks(() -> !hasRunningTasks() );
}
else { this.method_16208(); }
this.profiler.pop(); this.profiler.pop();
this.profiler.endTick(); this.profiler.endTick();
this.loading = true; this.loading = true;
@@ -137,6 +140,23 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantThreadExec
} }
private boolean runEveryTask() {
if (super.runTask()) {
return true;
} else {
if (true) { // unconditionally this time
for(ServerWorld serverlevel : getWorlds()) {
if (serverlevel.getChunkManager().executeQueuedTasks()) {
return true;
}
}
}
return false;
}
}
@Inject(method = "tick", at = @At( @Inject(method = "tick", at = @At(
value = "INVOKE", value = "INVOKE",
target = "Lnet/minecraft/server/PlayerManager;saveAllPlayerData()V", target = "Lnet/minecraft/server/PlayerManager;saveAllPlayerData()V",