always flush chunk updates when tick freezes (#422)

This commit is contained in:
hadroncfy authored and GitHub committed 2020-08-20 22:57:10 -03:00
1 parent 68f545df4f
commit 2788770109
3 files changed
+41 -2

No files matched your search

@@ -3,6 +3,7 @@ package carpet.fakes;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import net.minecraft.server.world.ChunkHolder;
import net.minecraft.util.math.ChunkPos; import net.minecraft.util.math.ChunkPos;
public interface ThreadedAnvilChunkStorageInterface public interface ThreadedAnvilChunkStorageInterface
@@ -12,4 +13,6 @@ public interface ThreadedAnvilChunkStorageInterface
void relightChunk(ChunkPos pos); void relightChunk(ChunkPos pos);
void releaseRelightTicket(ChunkPos pos); void releaseRelightTicket(ChunkPos pos);
Iterable<ChunkHolder> getChunks();
} }
@@ -1,9 +1,14 @@
package carpet.mixins; package carpet.mixins;
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
import carpet.helpers.TickSpeed; import carpet.helpers.TickSpeed;
import carpet.utils.CarpetProfiler; import carpet.utils.CarpetProfiler;
import net.minecraft.server.world.ChunkHolder;
import net.minecraft.server.world.ServerChunkManager; import net.minecraft.server.world.ServerChunkManager;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
import net.minecraft.world.chunk.WorldChunk;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@@ -12,14 +17,24 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.BooleanSupplier; import java.util.function.BooleanSupplier;
import com.google.common.collect.Lists;
@Mixin(ServerChunkManager.class) @Mixin(ServerChunkManager.class)
public abstract class ServerChunkManager_tickMixin public abstract class ServerChunkManager_tickMixin
{ {
@Shadow @Final private ServerWorld world; @Shadow @Final private ServerWorld world;
@Shadow @Final
public ThreadedAnvilChunkStorage threadedAnvilChunkStorage;
CarpetProfiler.ProfilerToken currentSection; CarpetProfiler.ProfilerToken currentSection;
@Inject(method = "tickChunks", at = @At("HEAD")) @Inject(method = "tickChunks", at = @At("HEAD"))
@@ -44,8 +59,21 @@ public abstract class ServerChunkManager_tickMixin
)) ))
private boolean skipChunkTicking(ServerWorld serverWorld) private boolean skipChunkTicking(ServerWorld serverWorld)
{ {
if (!TickSpeed.process_entities) return true; boolean debug = serverWorld.isDebugWorld();
return serverWorld.isDebugWorld(); if (!TickSpeed.process_entities) {
if (!debug){
List<ChunkHolder> holders = Lists.newArrayList(((ThreadedAnvilChunkStorageInterface)threadedAnvilChunkStorage).getChunks());
Collections.shuffle(holders);
for (ChunkHolder holder: holders){
Optional<WorldChunk> optional = holder.getTickingFuture().getNow(ChunkHolder.UNLOADED_WORLD_CHUNK).left();
if (optional.isPresent()){
holder.flushUpdates(optional.get());
}
}
}
return true;
}
return debug;
} }
} }
@@ -95,6 +95,9 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
@Shadow @Shadow
protected abstract CompletableFuture<Either<List<Chunk>, Unloaded>> getRegion (final ChunkPos centerChunk, final int margin, final IntFunction<ChunkStatus> distanceToStatus); protected abstract CompletableFuture<Either<List<Chunk>, Unloaded>> getRegion (final ChunkPos centerChunk, final int margin, final IntFunction<ChunkStatus> distanceToStatus);
@Shadow
protected abstract Iterable<ChunkHolder> entryIterator();
//in method_20617 //in method_20617
//method_19534(Lnet/minecraft/server/world/ChunkHolder;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture; //method_19534(Lnet/minecraft/server/world/ChunkHolder;Lnet/minecraft/world/chunk/Chunk;)Ljava/util/concurrent/CompletableFuture;
// incmopatibility with optifine makes this mixin fail. // incmopatibility with optifine makes this mixin fail.
@@ -426,4 +429,9 @@ public abstract class ThreadedAnvilChunkStorage_scarpetChunkCreationMixin implem
return report; return report;
} }
@Override
public Iterable<ChunkHolder> getChunks() {
return entryIterator();
}
} }