Fixes chunk iterate

This commit is contained in:
Sotr
2018-06-11 20:59:26 +08:00
parent 41d97284be
commit 6855fbe294
2 changed files with 23 additions and 2 deletions

View File

@@ -7,11 +7,17 @@ import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap;
import net.minecraft.server.Chunk; import net.minecraft.server.Chunk;
import net.minecraft.server.ChunkProviderServer; import net.minecraft.server.ChunkProviderServer;
import net.minecraft.server.Enchantment;
import net.minecraft.server.EntityTypes;
import net.minecraft.server.IChunkLoader; import net.minecraft.server.IChunkLoader;
import net.minecraft.server.MobEffectList;
import net.minecraft.server.PotionRegistry;
import net.minecraft.server.WorldServer; import net.minecraft.server.WorldServer;
@Mixin(value = ChunkProviderServer.class, remap = false) @Mixin(value = ChunkProviderServer.class, remap = false)
@@ -45,7 +51,7 @@ public abstract class MixinChunkProviderServer {
long unloadAfter = world.paperConfig.delayChunkUnloadsBy; long unloadAfter = world.paperConfig.delayChunkUnloadsBy;
int targetSize = Math.min(pendingUnloadChunks - 100, (int) (pendingUnloadChunks * UNLOAD_QUEUE_RESIZE_FACTOR)); // Paper - Make more aggressive int targetSize = Math.min(pendingUnloadChunks - 100, (int) (pendingUnloadChunks * UNLOAD_QUEUE_RESIZE_FACTOR)); // Paper - Make more aggressive
for (int i = 0; i < chunks.size() && pendingUnloadChunks > targetSize; i++) { // CraftBukkit removes unload logic to its method, we must check index for (int i = 0; i < chunks.size() && pendingUnloadChunks > targetSize; i++) {
Chunk chunk = it.next(); Chunk chunk = it.next();
if (chunk != null && chunk.isUnloading()) { if (chunk != null && chunk.isUnloading()) {
@@ -58,10 +64,11 @@ public abstract class MixinChunkProviderServer {
} }
// If a plugin cancelled it, we shouldn't trying unload it for a while // If a plugin cancelled it, we shouldn't trying unload it for a while
chunk.setShouldUnload(false); // Paper chunk.setShouldUnload(false); // Paper
if (!unloadChunk(chunk, true)) continue; // Event cancelled if (!unloadChunk(chunk, true)) continue; // Event cancelled
pendingUnloadChunks--; pendingUnloadChunks--;
it.remove();
if (activityAccountant.activityTimeIsExhausted()) break; if (activityAccountant.activityTimeIsExhausted()) break;
} }
@@ -72,6 +79,14 @@ public abstract class MixinChunkProviderServer {
return false; return false;
} }
@Redirect(method = "unloadChunk", at = @At(
value = "INVOKE",
target = "it/unimi/dsi/fastutil/longs/Long2ObjectOpenHashMap.remove(J)Lnet/minecraft/server/Chunk;"
))
private Chunk remove(Long2ObjectOpenHashMap<Chunk> chunks, Object chunkHash) {
return null;
}
@Overwrite @Overwrite
public String getName() { public String getName() {
return "ServerChunkCache: " + chunks.size(); // Akarin - remove unload queue return "ServerChunkCache: " + chunks.size(); // Akarin - remove unload queue

View File

@@ -18,6 +18,12 @@ import com.google.common.collect.Lists; // CraftBukkit
import org.bukkit.Server; // CraftBukkit import org.bukkit.Server; // CraftBukkit
import org.bukkit.craftbukkit.util.CraftMagicNumbers; // Paper import org.bukkit.craftbukkit.util.CraftMagicNumbers; // Paper
/**
* <b>Akarin Changes Note</b><br>
* <br>
* 1) Expose private members<br>
* @author cakoyo
*/
public class Chunk { public class Chunk {
private static final Logger e = LogManager.getLogger(); private static final Logger e = LogManager.getLogger();