yeet most of tick
This commit is contained in:
1 parent
2c01a98216
commit
1a7e8b6875
30 files changed
+156
-1420
No files matched your search
@@ -0,0 +1,29 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(targets = "net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity")
|
||||
public class BoundTickingBlockEntity_profilerMixin<T extends BlockEntity>
|
||||
{
|
||||
@Shadow @Final private T blockEntity;
|
||||
CarpetProfiler.ProfilerToken entitySection;
|
||||
|
||||
@Inject(method = "tick()V", at = @At("HEAD"))
|
||||
private void startTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
entitySection = CarpetProfiler.start_block_entity_section(blockEntity.getLevel(), blockEntity, CarpetProfiler.TYPE.TILEENTITY);
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||
private void endTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
CarpetProfiler.end_current_entity_section(entitySection);
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityTicker;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(targets = "net.minecraft.world.level.chunk.LevelChunk$BoundTickingBlockEntity")
|
||||
public class BoundTickingBlockEntity_tickMixin<T extends BlockEntity>
|
||||
{
|
||||
@Shadow @Final private T blockEntity;
|
||||
CarpetProfiler.ProfilerToken entitySection;
|
||||
|
||||
|
||||
@Inject(method = "tick()V", at = @At("HEAD"))
|
||||
private void startTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
entitySection = CarpetProfiler.start_block_entity_section(blockEntity.getLevel(), blockEntity, CarpetProfiler.TYPE.TILEENTITY);
|
||||
}
|
||||
|
||||
@Redirect(method = "tick()V", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/level/block/entity/BlockEntityTicker;tick(Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/block/entity/BlockEntity;)V"
|
||||
))
|
||||
private void checkProcessBEs(BlockEntityTicker<T> blockEntityTicker, Level world, BlockPos pos, BlockState state, T blockEntity)
|
||||
{
|
||||
TickRateManager tickRateManager = ((LevelInterface)world).tickRateManager();
|
||||
if (tickRateManager.runsNormally())
|
||||
{
|
||||
blockEntityTicker.tick(world, pos, state, blockEntity);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tick()V", at = @At("RETURN"))
|
||||
private void endTileEntitySection(CallbackInfo ci)
|
||||
{
|
||||
CarpetProfiler.end_current_entity_section(entitySection);
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@ import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@Mixin(ChunkMap.class)
|
||||
public class ChunkMap_tickMixin
|
||||
public class ChunkMap_profilerMixin
|
||||
{
|
||||
@Shadow @Final ServerLevel level;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
@@ -1,7 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.world.level.redstone.NeighborUpdater;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
@@ -54,12 +53,6 @@ public abstract class Level_tickMixin implements LevelInterface
|
||||
@Inject(method = "guardEntityTick", at = @At("HEAD"), cancellable = true)
|
||||
private void startEntity(Consumer<Entity> consumer_1, Entity e, CallbackInfo ci)
|
||||
{
|
||||
TickRateManager trm = tickRateManager();
|
||||
if (!trm.shouldEntityTick(e))
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
|
||||
entitySection = CarpetProfiler.start_entity_section((Level) (Object) this, e, CarpetProfiler.TYPE.ENTITY);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(LivingEntity.class)
|
||||
public class LivingEntity_tickSpeedMixin
|
||||
{
|
||||
@Inject(method = "pushEntities", at = @At("HEAD"), cancellable = true)
|
||||
private void onPushEntities(CallbackInfo ci)
|
||||
{
|
||||
if ((LivingEntity)(Object)this instanceof ServerPlayer) {
|
||||
var server = (MinecraftServerInterface)((LivingEntity)(Object)this).level().getServer();
|
||||
if(server.getTickRateManager().gameIsPaused()) {
|
||||
ci.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.LevelInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import carpet.fakes.MinecraftInterface;
|
||||
import carpet.network.CarpetClient;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
@@ -13,10 +11,8 @@ import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MinecraftMixin implements MinecraftInterface
|
||||
public class MinecraftMixin
|
||||
{
|
||||
@Shadow public ClientLevel level;
|
||||
|
||||
@@ -29,19 +25,10 @@ public class MinecraftMixin implements MinecraftInterface
|
||||
@Inject(at = @At("HEAD"), method = "tick")
|
||||
private void onClientTick(CallbackInfo info) {
|
||||
if (this.level != null) {
|
||||
getTickRateManager().ifPresent(TickRateManager::tick);
|
||||
boolean runsNormally = ((LevelInterface)this.level).tickRateManager().runsNormally();
|
||||
// hope server doesn't need to tick - should be handled by the server on its own
|
||||
if (!getTickRateManager().map(TickRateManager::runsNormally).orElse(true))
|
||||
if (!runsNormally)
|
||||
CarpetClient.shapes.renewShapes();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TickRateManager> getTickRateManager()
|
||||
{
|
||||
if (this.level != null) {
|
||||
return Optional.of(((LevelInterface)this.level).tickRateManager());
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
@@ -2,72 +2,27 @@ package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
import carpet.patches.CopyProfilerResult;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.TickTask;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.profiling.EmptyProfileResults;
|
||||
import net.minecraft.util.profiling.ProfileResults;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.util.thread.ReentrantBlockableEventLoop;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
import org.slf4j.Logger;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
|
||||
@Mixin(value = MinecraftServer.class, priority = Integer.MAX_VALUE - 10)
|
||||
public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableEventLoop<TickTask> implements MinecraftServerInterface
|
||||
{
|
||||
@Shadow private volatile boolean running;
|
||||
|
||||
@Shadow private long nextTickTime;
|
||||
|
||||
@Shadow @Final private static Logger LOGGER;
|
||||
|
||||
@Shadow private ProfilerFiller profiler;
|
||||
|
||||
public MinecraftServer_tickspeedMixin(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Shadow protected abstract void tickServer(BooleanSupplier booleanSupplier_1);
|
||||
|
||||
@Shadow protected abstract boolean haveTime();
|
||||
|
||||
@Shadow private long delayedTasksMaxNextTickTime;
|
||||
|
||||
@Shadow private volatile boolean isReady;
|
||||
|
||||
@Shadow private long lastOverloadWarning;
|
||||
|
||||
@Shadow private boolean mayHaveDelayedTasks;
|
||||
|
||||
@Shadow public abstract Iterable<ServerLevel> getAllLevels();
|
||||
|
||||
@Shadow private int tickCount;
|
||||
|
||||
@Shadow protected abstract void waitUntilNextTick();
|
||||
|
||||
@Shadow protected abstract void startMetricsRecordingTick();
|
||||
|
||||
@Shadow protected abstract void endMetricsRecordingTick();
|
||||
|
||||
@Shadow private boolean debugCommandProfilerDelayStart;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
private float carpetMsptAccum = 0.0f;
|
||||
|
||||
private ServerTickRateManager serverTickRateManager;
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
@@ -82,131 +37,20 @@ public abstract class MinecraftServer_tickspeedMixin extends ReentrantBlockableE
|
||||
return serverTickRateManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* To ensure compatibility with other mods we should allow milliseconds
|
||||
*/
|
||||
|
||||
// Cancel a while statement
|
||||
@Redirect(method = "runServer", at = @At(value = "FIELD", target = "Lnet/minecraft/server/MinecraftServer;running:Z"))
|
||||
private boolean cancelRunLoop(MinecraftServer server)
|
||||
{
|
||||
return false;
|
||||
} // target run()
|
||||
|
||||
// Replaced the above cancelled while statement with this one
|
||||
// could possibly just inject that mspt selection at the beginning of the loop, but then adding all mspt's to
|
||||
// replace 50L will be a hassle
|
||||
@Inject(method = "runServer", at = @At(value = "INVOKE", shift = At.Shift.AFTER,
|
||||
target = "Lnet/minecraft/server/MinecraftServer;buildServerStatus()Lnet/minecraft/network/protocol/status/ServerStatus;"))
|
||||
target = "Lnet/minecraft/server/MinecraftServer;startMetricsRecordingTick()V"))
|
||||
private void modifiedRunLoop(CallbackInfo ci)
|
||||
{
|
||||
while (this.running)
|
||||
if (CarpetProfiler.tick_health_requested != 0L)
|
||||
{
|
||||
//long long_1 = Util.getMeasuringTimeMs() - this.timeReference;
|
||||
//CM deciding on tick speed
|
||||
if (CarpetProfiler.tick_health_requested != 0L)
|
||||
{
|
||||
CarpetProfiler.start_tick_profiling();
|
||||
}
|
||||
long msThisTick = 0L;
|
||||
long long_1 = 0L;
|
||||
float mspt = serverTickRateManager.mspt();
|
||||
if (serverTickRateManager.isInWarpSpeed() && serverTickRateManager.continueWarp())
|
||||
{
|
||||
//making sure server won't flop after the warp or if the warp is interrupted
|
||||
this.nextTickTime = this.lastOverloadWarning = Util.getMillis();
|
||||
carpetMsptAccum = mspt;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Math.abs(carpetMsptAccum - mspt) > 1.0f)
|
||||
{
|
||||
// Tickrate changed. Ensure that we use the correct value.
|
||||
carpetMsptAccum = mspt;
|
||||
}
|
||||
|
||||
msThisTick = (long)carpetMsptAccum; // regular tick
|
||||
carpetMsptAccum += mspt - msThisTick;
|
||||
|
||||
long_1 = Util.getMillis() - this.nextTickTime;
|
||||
}
|
||||
//end tick deciding
|
||||
//smoothed out delay to include mcpt component. With 50L gives defaults.
|
||||
if (long_1 > /*2000L*/1000L+20*mspt && this.nextTickTime - this.lastOverloadWarning >= /*15000L*/10000L+100*mspt)
|
||||
{
|
||||
long long_2 = (long)(long_1 / mspt);//50L;
|
||||
LOGGER.warn("Can't keep up! Is the server overloaded? Running {}ms or {} ticks behind", long_1, long_2);
|
||||
this.nextTickTime += (long)(long_2 * mspt);//50L;
|
||||
this.lastOverloadWarning = this.nextTickTime;
|
||||
}
|
||||
|
||||
if (this.debugCommandProfilerDelayStart) {
|
||||
this.debugCommandProfilerDelayStart = false;
|
||||
this.profilerTimings = Pair.of(Util.getNanos(), tickCount);
|
||||
//this.field_33978 = new MinecraftServer.class_6414(Util.getMeasuringTimeNano(), this.ticks);
|
||||
}
|
||||
this.nextTickTime += msThisTick;//50L;
|
||||
//TickDurationMonitor tickDurationMonitor = TickDurationMonitor.create("Server");
|
||||
//this.startMonitor(tickDurationMonitor);
|
||||
this.startMetricsRecordingTick();
|
||||
this.profiler.push("tick");
|
||||
this.tickServer(serverTickRateManager.isInWarpSpeed() ? ()->true : this::haveTime);
|
||||
this.profiler.popPush("nextTickWait");
|
||||
if (serverTickRateManager.isInWarpSpeed()) // clearing all hanging tasks no matter what when warping
|
||||
{
|
||||
while(this.runEveryTask()) {Thread.yield();}
|
||||
}
|
||||
this.mayHaveDelayedTasks = true;
|
||||
this.delayedTasksMaxNextTickTime = Math.max(Util.getMillis() + /*50L*/ msThisTick, this.nextTickTime);
|
||||
// run all tasks (this will not do a lot when warping), but that's fine since we already run them
|
||||
this.waitUntilNextTick();
|
||||
this.profiler.pop();
|
||||
this.endMetricsRecordingTick();
|
||||
this.isReady = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// just because profilerTimings class is public
|
||||
Pair<Long,Integer> profilerTimings = null;
|
||||
/// overworld around profiler timings
|
||||
@Inject(method = "isTimeProfilerRunning", at = @At("HEAD"), cancellable = true)
|
||||
public void isCMDebugRunning(CallbackInfoReturnable<Boolean> cir)
|
||||
{
|
||||
cir.setReturnValue(debugCommandProfilerDelayStart || profilerTimings != null);
|
||||
}
|
||||
@Inject(method = "stopTimeProfiler", at = @At("HEAD"), cancellable = true)
|
||||
public void stopCMDebug(CallbackInfoReturnable<ProfileResults> cir)
|
||||
{
|
||||
if (this.profilerTimings == null) {
|
||||
cir.setReturnValue(EmptyProfileResults.EMPTY);
|
||||
} else {
|
||||
ProfileResults profileResult = new CopyProfilerResult(
|
||||
profilerTimings.getRight(), profilerTimings.getLeft(),
|
||||
this.tickCount, Util.getNanos()
|
||||
);
|
||||
this.profilerTimings = null;
|
||||
cir.setReturnValue(profileResult);
|
||||
CarpetProfiler.start_tick_profiling();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private boolean runEveryTask() {
|
||||
if (super.pollTask()) {
|
||||
return true;
|
||||
} else {
|
||||
if (true) { // unconditionally this time
|
||||
for(ServerLevel serverlevel : getAllLevels()) {
|
||||
if (serverlevel.getChunkSource().pollTask()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickServer", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/MinecraftServer;saveEverything(ZZZ)Z", // save
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
||||
@Mixin(ServerChunkCache.class)
|
||||
public abstract class ServerChunkCache_profilerMixin
|
||||
{
|
||||
|
||||
@Shadow @Final ServerLevel level;
|
||||
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("HEAD"))
|
||||
private void startSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "FIELD",
|
||||
target = "net/minecraft/server/level/ServerChunkCache.level:Lnet/minecraft/server/level/ServerLevel;",
|
||||
ordinal = 10
|
||||
))
|
||||
private void skipChunkTicking(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/level/ServerLevel.tickChunk(Lnet/minecraft/world/level/chunk/LevelChunk;I)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void resumeSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("RETURN"))
|
||||
private void stopSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
//@Redirect(method = "tick", at = @At(
|
||||
// value = "INVOKE",
|
||||
// target = "Lnet/minecraft/server/level/DistanceManager;purgeStaleTickets()V"
|
||||
//))
|
||||
//private void pauseTicketSystem(DistanceManager distanceManager)
|
||||
//{
|
||||
// pausing expiry of tickets
|
||||
// that will prevent also chunks from unloading, so require a deep frozen state
|
||||
//ServerTickRateManager trm = ((MinecraftServerInterface) level.getServer()).getTickRateManager();
|
||||
//if (!trm.runsNormally() && trm.deeplyFrozen()) return;
|
||||
//distanceManager.purgeStaleTickets();
|
||||
//}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import carpet.helpers.ServerTickRateManager;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.server.level.DistanceManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import net.minecraft.server.level.ChunkHolder;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerChunkCache;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
@Mixin(ServerChunkCache.class)
|
||||
public abstract class ServerChunkCache_tickMixin
|
||||
{
|
||||
|
||||
@Shadow @Final ServerLevel level;
|
||||
|
||||
@Shadow @Final
|
||||
public ChunkMap chunkMap;
|
||||
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("HEAD"))
|
||||
private void startSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "FIELD",
|
||||
target = "net/minecraft/server/level/ServerChunkCache.level:Lnet/minecraft/server/level/ServerLevel;",
|
||||
ordinal = 10
|
||||
))
|
||||
private void skipChunkTicking(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "net/minecraft/server/level/ServerLevel.tickChunk(Lnet/minecraft/world/level/chunk/LevelChunk;I)V",
|
||||
shift = At.Shift.AFTER
|
||||
))
|
||||
private void resumeSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(level, "Spawning", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tickChunks", at = @At("RETURN"))
|
||||
private void stopSpawningSection(CallbackInfo ci)
|
||||
{
|
||||
if (currentSection != null)
|
||||
{
|
||||
CarpetProfiler.end_current_section(currentSection);
|
||||
}
|
||||
}
|
||||
|
||||
//// Tick freeze
|
||||
@Redirect(method = "tickChunks", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;isDebug()Z"
|
||||
))
|
||||
private boolean skipChunkTicking(ServerLevel serverWorld)
|
||||
{
|
||||
boolean debug = serverWorld.isDebug();
|
||||
if (!((MinecraftServerInterface)serverWorld.getServer()).getTickRateManager().runsNormally())
|
||||
{
|
||||
// simplified chunk tick iteration assuming world is frozen otherwise as suggested by Hadron67
|
||||
// to be kept in sync with the original injection source
|
||||
if (!debug){
|
||||
List<ChunkHolder> holders = Lists.newArrayList(((ThreadedAnvilChunkStorageInterface)chunkMap).getChunksCM());
|
||||
Collections.shuffle(holders);
|
||||
for (ChunkHolder holder: holders){
|
||||
Optional<LevelChunk> optional = holder.getTickingChunkFuture().getNow(ChunkHolder.UNLOADED_LEVEL_CHUNK).left();
|
||||
if (optional.isPresent()){
|
||||
holder.broadcastChanges(optional.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return debug;
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/DistanceManager;purgeStaleTickets()V"
|
||||
))
|
||||
private void pauseTicketSystem(DistanceManager distanceManager)
|
||||
{
|
||||
// pausing expiry of tickets
|
||||
// that will prevent also chunks from unloading, so require a deep frozen state
|
||||
ServerTickRateManager trm = ((MinecraftServerInterface) level.getServer()).getTickRateManager();
|
||||
if (!trm.runsNormally() && trm.deeplyFrozen()) return;
|
||||
distanceManager.purgeStaleTickets();
|
||||
}
|
||||
|
||||
}
|
||||
+2
-14
@@ -1,33 +1,21 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.ServerFunctionManager;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerFunctionManager.class)
|
||||
public class ServerFunctionManager_tickMixin
|
||||
public class ServerFunctionManager_profilerMixin
|
||||
{
|
||||
@Shadow @Final MinecraftServer server;
|
||||
CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tick", at = @At("HEAD"), cancellable = true)
|
||||
private void beforeDatapacks(CallbackInfo ci)
|
||||
{
|
||||
if (! ((MinecraftServerInterface)server).getTickRateManager().runsNormally())
|
||||
{
|
||||
ci.cancel();
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
currentSection = CarpetProfiler.start_section(null, "Datapacks", CarpetProfiler.TYPE.GENERAL);
|
||||
}
|
||||
|
||||
@Inject(method = "tick", at = @At("RETURN"))
|
||||
@@ -1,59 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftServerInterface;
|
||||
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(ServerGamePacketListenerImpl.class)
|
||||
public class ServerGamePacketListenerImpl_tickMixin
|
||||
{
|
||||
@Shadow public ServerPlayer player;
|
||||
|
||||
@Shadow private double firstGoodX;
|
||||
|
||||
@Shadow private double firstGoodY;
|
||||
|
||||
@Shadow private double firstGoodZ;
|
||||
|
||||
@Inject(method = "handlePlayerInput", at = @At(value = "RETURN"))
|
||||
private void checkMoves(ServerboundPlayerInputPacket p, CallbackInfo ci)
|
||||
{
|
||||
if (p.getXxa() != 0.0F || p.getZza() != 0.0F || p.isJumping() || p.isShiftKeyDown())
|
||||
{
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().resetPlayerActivity();
|
||||
}
|
||||
}
|
||||
|
||||
// to skip reposition adjustment check
|
||||
private static long lastMovedTick = 0L;
|
||||
private static double lastMoved = 0.0D;
|
||||
|
||||
@Inject(method = "handleMovePlayer", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerPlayer;isSleeping()Z",
|
||||
shift = At.Shift.BEFORE
|
||||
))
|
||||
private void checkMove(ServerboundMovePlayerPacket p, CallbackInfo ci)
|
||||
{
|
||||
double movedBy = player.position().distanceToSqr(firstGoodX, firstGoodY, firstGoodZ);
|
||||
if (movedBy == 0.0D) return;
|
||||
// corrective tick
|
||||
if (movedBy < 0.0009 && lastMoved > 0.0009 && Math.abs(player.getServer().getTickCount()-lastMovedTick-20)<2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (movedBy > 0.0D)
|
||||
{
|
||||
lastMoved = movedBy;
|
||||
lastMovedTick = player.getServer().getTickCount();
|
||||
((MinecraftServerInterface)player.getServer()).getTickRateManager().resetPlayerActivity();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,10 +7,8 @@ import carpet.utils.CarpetProfiler;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.BooleanSupplier;
|
||||
@@ -18,9 +16,7 @@ import java.util.function.Supplier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.profiling.ProfilerFiller;
|
||||
import net.minecraft.world.entity.raid.Raids;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.border.WorldBorder;
|
||||
import net.minecraft.world.level.dimension.DimensionType;
|
||||
import net.minecraft.world.level.storage.WritableLevelData;
|
||||
|
||||
@@ -38,10 +34,6 @@ public abstract class ServerLevel_tickMixin extends Level implements LevelInterf
|
||||
return ((MinecraftServerInterface)getServer()).getTickRateManager();
|
||||
}
|
||||
|
||||
@Shadow protected abstract void runBlockEvents();
|
||||
|
||||
@Shadow protected abstract void tickTime();
|
||||
|
||||
private CarpetProfiler.ProfilerToken currentSection;
|
||||
|
||||
@Inject(method = "tick", at = @At(
|
||||
@@ -159,57 +151,4 @@ public abstract class ServerLevel_tickMixin extends Level implements LevelInterf
|
||||
}
|
||||
}
|
||||
|
||||
//// freeze
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/level/border/WorldBorder;tick()V"
|
||||
))
|
||||
private void tickWorldBorder(WorldBorder worldBorder)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) worldBorder.tick();
|
||||
}
|
||||
|
||||
@Inject(method = "advanceWeatherCycle", cancellable = true, at = @At("HEAD"))
|
||||
private void tickWeather(CallbackInfo ci)
|
||||
{
|
||||
if (!tickRateManager().runsNormally()) ci.cancel();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;tickTime()V"
|
||||
))
|
||||
private void tickTimeConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) tickTime();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;isDebug()Z"
|
||||
))
|
||||
private boolean tickPendingBlocks(ServerLevel serverWorld)
|
||||
{
|
||||
if (!tickRateManager().runsNormally()) return true;
|
||||
return serverWorld.isDebug(); // isDebug()
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/world/entity/raid/Raids;tick()V"
|
||||
))
|
||||
private void tickConditionally(Raids raidManager)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) raidManager.tick();
|
||||
}
|
||||
|
||||
@Redirect(method = "tick", at = @At(
|
||||
value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/level/ServerLevel;runBlockEvents()V"
|
||||
))
|
||||
private void tickConditionally(ServerLevel serverWorld)
|
||||
{
|
||||
if (tickRateManager().runsNormally()) runBlockEvents();
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.MinecraftInterface;
|
||||
import carpet.helpers.TickRateManager;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.Timer;
|
||||
import carpet.CarpetSettings;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(Timer.class)
|
||||
public class Timer_tickSpeedMixin {
|
||||
@Redirect(method = "advanceTime", at = @At(
|
||||
value = "FIELD",
|
||||
target = "Lnet/minecraft/client/Timer;msPerTick:F"
|
||||
))
|
||||
private float adjustTickSpeed(Timer counter) {
|
||||
if (CarpetSettings.smoothClientAnimations)
|
||||
{
|
||||
Optional<TickRateManager> trm = ((MinecraftInterface)Minecraft.getInstance()).getTickRateManager();
|
||||
if (trm.isPresent() && trm.get().runsNormally())
|
||||
{
|
||||
return Math.max(50.0f, trm.get().mspt());
|
||||
}
|
||||
}
|
||||
return 50f;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(WorldBorder.class)
|
||||
public class WorldBorder_tickMixin
|
||||
public class WorldBorder_syncedWorldBorderMixin
|
||||
{
|
||||
@Shadow private WorldBorder.BorderExtent extent;
|
||||
|
||||
Reference in new issue
Block a user