feat: implement removal of entities if they would be in a block after the edit (#2311)

- Includes some refactoring to EditSessionBuilder to prevent doubling-up of processors that are also extents
 - Better ordering of the EditSessionBuilder process/extent code to match where extents actually end up in the stack
 - Fixes #1941
This commit is contained in:
Jordan
2023-06-27 17:37:09 +01:00
committed by GitHub
parent 476ba4ab41
commit 0554b31f11
5 changed files with 115 additions and 52 deletions

View File

@ -622,10 +622,11 @@ public class Settings extends Config {
public boolean PERSISTENT_BRUSHES = true;
@Comment({
"[SAFE] Keep entities that are positioned in non-air blocks when editing an area",
"Might cause client-side FPS lag in some situations"
"[SAFE] Keep entities that are positioned in non-air blocks when editing an area (default: true)",
" - Might cause client-side FPS lag in some situations",
" - Requires fast-placement to be true"
})
public boolean KEEP_ENTITIES_IN_BLOCKS = false;
public boolean KEEP_ENTITIES_IN_BLOCKS = true;
@Comment({
"[SAFE] Attempt to remove entities from the world if they were not present in the expected chunk (default: true)",

View File

@ -0,0 +1,57 @@
package com.fastasyncworldedit.core.extent.processor;
import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunk;
import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes;
import org.jetbrains.annotations.Nullable;
/**
* Processor that removes existing entities that would not be in air after the edit
*
* @since TODO
*/
public class EntityInBlockRemovingProcessor implements IBatchProcessor {
@Override
public IChunkSet processSet(final IChunk chunk, final IChunkGet get, final IChunkSet set) {
for (CompoundTag tag : get.getEntities()) {
// Empty tags for seemingly non-existent entities can exist?
if (tag.getList("Pos").size() == 0) {
continue;
}
BlockVector3 pos = tag.getEntityPosition().toBlockPoint();
int x = pos.getX() & 15;
int y = pos.getY();
int z = pos.getZ() & 15;
if (!set.hasSection(y >> 4)) {
continue;
}
if (set.getBlock(x, y, z).getBlockType() != BlockTypes.__RESERVED__ && !set
.getBlock(x, y, z)
.getBlockType()
.getMaterial()
.isAir()) {
set.removeEntity(tag.getUUID());
}
}
return set;
}
@Nullable
@Override
public Extent construct(final Extent child) {
throw new UnsupportedOperationException("Processing only");
}
@Override
public ProcessorScope getScope() {
// After block removal but before history
return ProcessorScope.CUSTOM;
}
}

View File

@ -7,7 +7,8 @@ package com.fastasyncworldedit.core.extent.processor;
* - CHANGING_BLOCKS (processors that may ADD or CHANGE blocks being set)
* - REMOVING_BLOCKS (processors that may ADD, CHANGE or REMOVE blocks being set)
* - CUSTOM (processors that do not specify a SCOPE)
* - READING_SET_BLOCKS (processors that do not alter blocks at all, and read the blocks that are actually going to set, e.g. history processors)
* - READING_SET_BLOCKS (processors that do not alter blocks at all, and read the blocks that are actually going to set, e.g.
* history processors). There is no guarantee that changes made here will be stored in history.
*/
public enum ProcessorScope {
ADDING_BLOCKS(0),