fix: add chunk loc to tile entity location when trimming (#2500)

- fixes #2499
This commit is contained in:
Jordan 2023-12-12 07:00:40 +00:00 committed by GitHub
parent fe626a92e1
commit d4b68b384b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 11 deletions

View File

@ -6,12 +6,11 @@ import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.regions.RegionWrapper;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
public class HeightBoundExtent extends FaweRegionExtent {
@ -50,7 +49,8 @@ public class HeightBoundExtent extends FaweRegionExtent {
@Override
public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
if (trimY(set, min, max, true) | trimNBT(set, this::contains)) {
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
if (trimY(set, min, max, true) | trimNBT(set, this::contains, pos -> this.contains(pos.add(chunkPos)))) {
return set;
}
return null;

View File

@ -155,7 +155,9 @@ public interface IBatchProcessor {
* Utility method to trim entity and blocks with a provided contains function.
*
* @return false if chunk is empty of NBT
* @deprecated tiles are stored in chunk-normalised coordinate space and thus cannot use the same function as entities
*/
@Deprecated(forRemoval = true, since = "TODO")
default boolean trimNBT(IChunkSet set, Function<BlockVector3, Boolean> contains) {
Set<CompoundTag> ents = set.getEntities();
if (!ents.isEmpty()) {
@ -169,6 +171,26 @@ public interface IBatchProcessor {
return !tiles.isEmpty() || !ents.isEmpty();
}
/**
* Utility method to trim entity and blocks with a provided contains function.
*
* @return false if chunk is empty of NBT
* @since TODO
*/
default boolean trimNBT(
IChunkSet set, Function<BlockVector3, Boolean> containsEntity, Function<BlockVector3, Boolean> containsTile
) {
Set<CompoundTag> ents = set.getEntities();
if (!ents.isEmpty()) {
ents.removeIf(ent -> !containsEntity.apply(ent.getEntityPosition().toBlockPoint()));
}
Map<BlockVector3, CompoundTag> tiles = set.getTiles();
if (!tiles.isEmpty()) {
tiles.entrySet().removeIf(blockVector3CompoundTagEntry -> !containsTile.apply(blockVector3CompoundTagEntry.getKey()));
}
return !tiles.isEmpty() || !ents.isEmpty();
}
/**
* Join two processors and return the result.
*/

View File

@ -1,6 +1,7 @@
package com.fastasyncworldedit.core.queue;
import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
import javax.annotation.Nullable;
@ -33,6 +34,16 @@ public interface IChunk extends Trimable, IChunkGet, IChunkSet {
*/
int getZ();
/**
* Return the minimum block coordinate of the chunk
*
* @return BlockVector3 of minimum block coordinate
* @since TODO
*/
default BlockVector3 getChunkBlockCoord() {
return BlockVector3.at(getX() << 4, getMinY(), getZ() << 4);
}
/**
* If the chunk is a delegate, returns its parent's root
*

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.regions;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock;
import com.fastasyncworldedit.core.math.BlockVectorSet;
import com.fastasyncworldedit.core.math.MutableBlockVector2;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.queue.IChunk;
@ -805,7 +804,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return set;
}
trimY(set, minY, maxY, true);
trimNBT(set, this::contains);
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
trimNBT(set, this::contains, pos -> this.contains(pos.add(chunkPos)));
return set;
}
if (tx >= minX && bx <= maxX && tz >= minZ && bz <= maxZ) {
@ -868,8 +868,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
set.setBlocks(layer, arr);
}
trimNBT(set, this::contains);
final BlockVector3 chunkPos = BlockVector3.at(chunk.getX() << 4, 0, chunk.getZ() << 4);
trimNBT(set, this::contains, pos -> this.contains(pos.add(chunkPos)));
return set;
}
return null;
@ -893,7 +893,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
return null;
}
trimY(set, minY, maxY, false);
trimNBT(set, this::contains);
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
trimNBT(set, this::contains, pos -> this.contains(pos.add(chunkPos)));
return set;
}
if (tx >= minX && bx <= maxX && tz >= minZ && bz <= maxZ) {
@ -943,7 +944,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
}
set.setBlocks(layer, arr);
}
trimNBT(set, bv3 -> !this.contains(bv3));
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
trimNBT(set, bv3 -> !this.contains(bv3), bv3 -> !this.contains(bv3.add(chunkPos)));
return set;
}
return set;

View File

@ -425,7 +425,8 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
}
}
if (processExtra) {
trimNBT(set, this::contains);
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
trimNBT(set, this::contains, pos -> this.contains(pos.add(chunkPos)));
}
return set;
} else {
@ -477,7 +478,8 @@ public interface Region extends Iterable<BlockVector3>, Cloneable, IBatchProcess
}
}
if (processExtra) {
trimNBT(set, bv3 -> !this.contains(bv3));
BlockVector3 chunkPos = chunk.getChunkBlockCoord().withY(0);
trimNBT(set, bv3 -> !this.contains(bv3), bv3 -> !this.contains(bv3.add(chunkPos)));
}
return set;
} else {