gracefully handle error in EntityInBlockRemovingProcessor

-  ensures edit continues on chunk correctly
This commit is contained in:
dordsor21 2023-07-15 12:27:33 +01:00
parent 1745c50878
commit 8da530ee80
No known key found for this signature in database
GPG Key ID: 1E53E88969FFCF0B

View File

@ -6,8 +6,10 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
/** /**
@ -17,27 +19,33 @@ import org.jetbrains.annotations.Nullable;
*/ */
public class EntityInBlockRemovingProcessor implements IBatchProcessor { public class EntityInBlockRemovingProcessor implements IBatchProcessor {
private static final Logger LOGGER = LogManagerCompat.getLogger();
@Override @Override
public IChunkSet processSet(final IChunk chunk, final IChunkGet get, final IChunkSet set) { public IChunkSet processSet(final IChunk chunk, final IChunkGet get, final IChunkSet set) {
for (CompoundTag tag : get.getEntities()) { try {
// Empty tags for seemingly non-existent entities can exist? for (CompoundTag tag : get.getEntities()) {
if (tag.getList("Pos").size() == 0) { // Empty tags for seemingly non-existent entities can exist?
continue; if (tag.getList("Pos").size() == 0) {
} continue;
BlockVector3 pos = tag.getEntityPosition().toBlockPoint(); }
int x = pos.getX() & 15; BlockVector3 pos = tag.getEntityPosition().toBlockPoint();
int y = pos.getY(); int x = pos.getX() & 15;
int z = pos.getZ() & 15; int y = pos.getY();
if (!set.hasSection(y >> 4)) { int z = pos.getZ() & 15;
continue; if (!set.hasSection(y >> 4)) {
} continue;
if (set.getBlock(x, y, z).getBlockType() != BlockTypes.__RESERVED__ && !set }
.getBlock(x, y, z) if (set.getBlock(x, y, z).getBlockType() != BlockTypes.__RESERVED__ && !set
.getBlockType() .getBlock(x, y, z)
.getMaterial() .getBlockType()
.isAir()) { .getMaterial()
set.removeEntity(tag.getUUID()); .isAir()) {
set.removeEntity(tag.getUUID());
}
} }
} catch (Exception e) {
LOGGER.warn("Could not remove entities in blocks in chunk {},{}", chunk.getX(), chunk.getZ(), e);
} }
return set; return set;
} }