Nukkit regen/clear fixes

Closes #869
Fixes #868
This commit is contained in:
Jesse Boyd 2018-01-10 20:42:24 +11:00
parent b36c3dfc90
commit 274bc6d9a7
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 38 additions and 0 deletions

View File

@ -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<BaseFullChunk, NukkitQueue> {
@ -93,6 +95,30 @@ public class NukkitChunk extends CharFaweChunk<BaseFullChunk, NukkitQueue> {
}
}
}
Map<Long, Entity> ents = chunk.getEntities();
if (!ents.isEmpty()) {
Iterator<Map.Entry<Long, Entity>> iter = ents.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Entity> 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) {

View File

@ -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<Level, BaseFullChunk, BaseFu
@Override
public boolean regenerateChunk(Level level, int x, int z, BaseBiome biome, Long seed) {
Map<Long, Entity> ents = level.getChunkEntities(x, z);
if (!ents.isEmpty()) {
Iterator<Map.Entry<Long, Entity>> iter = ents.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry<Long, Entity> entry = iter.next();
Entity entity = entry.getValue();
iter.remove();
level.removeEntity(entity);
}
}
level.regenerateChunk(x, z);
return true;
}