From 274bc6d9a768819b347e2a3d502bbed1909bfcfc Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 10 Jan 2018 20:42:24 +1100 Subject: [PATCH] Nukkit regen/clear fixes Closes #869 Fixes #868 --- .../optimization/queue/NukkitChunk.java | 26 +++++++++++++++++++ .../optimization/queue/NukkitQueue.java | 12 +++++++++ 2 files changed, 38 insertions(+) diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitChunk.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitChunk.java index 17693793..15dcdd07 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitChunk.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitChunk.java @@ -1,6 +1,7 @@ package com.boydti.fawe.nukkit.optimization.queue; import cn.nukkit.blockentity.BlockEntity; +import cn.nukkit.entity.Entity; import cn.nukkit.level.Level; import cn.nukkit.level.format.generic.BaseFullChunk; import cn.nukkit.nbt.tag.IntTag; @@ -15,6 +16,7 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.LocalWorld; import com.sk89q.worldedit.MutableBlockVector2D; import java.io.IOException; +import java.util.Iterator; import java.util.Map; public class NukkitChunk extends CharFaweChunk { @@ -93,6 +95,30 @@ public class NukkitChunk extends CharFaweChunk { } } } + + Map ents = chunk.getEntities(); + if (!ents.isEmpty()) { + Iterator> iter = ents.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + Entity ent = entry.getValue(); + if (!(ent instanceof cn.nukkit.Player)) { + int x = ent.getFloorX() & 15; + int y = ent.getFloorY(); + int z = ent.getFloorZ() & 15; + char[] idsLayer = this.ids[y >> 4]; + if (idsLayer != null) { + if (idsLayer[FaweCache.CACHE_J[y][z][x]] != 0) { + synchronized (world) { + iter.remove(); + world.removeEntity(ent); + } + } + } + } + } + } + for (int layer = 0; layer < sections.length; layer++) { char[] ids = sections[layer]; if (ids == null) { diff --git a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java index e95aedd7..7c92510a 100644 --- a/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java +++ b/nukkit/src/main/java/com/boydti/fawe/nukkit/optimization/queue/NukkitQueue.java @@ -3,6 +3,7 @@ package com.boydti.fawe.nukkit.optimization.queue; import cn.nukkit.Player; import cn.nukkit.block.Block; import cn.nukkit.blockentity.BlockEntity; +import cn.nukkit.entity.Entity; import cn.nukkit.level.Level; import cn.nukkit.level.Position; import cn.nukkit.level.format.generic.BaseFullChunk; @@ -26,6 +27,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -254,6 +256,16 @@ public class NukkitQueue extends NMSMappedFaweQueue ents = level.getChunkEntities(x, z); + if (!ents.isEmpty()) { + Iterator> iter = ents.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry entry = iter.next(); + Entity entity = entry.getValue(); + iter.remove(); + level.removeEntity(entity); + } + } level.regenerateChunk(x, z); return true; }