Skip to content

Commit

Permalink
fix: add chunk loc to tile entity location when trimming
Browse files Browse the repository at this point in the history
 - fixes #2499
  • Loading branch information
dordsor21 committed Nov 26, 2023
1 parent d1798b7 commit 90a2c40
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
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 {

Expand Down Expand Up @@ -50,7 +49,8 @@ public Collection<Region> getRegions() {

@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ default boolean trimY(IChunkSet set, int minY, int maxY, final boolean keepInsid
* 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()) {
Expand All @@ -169,6 +171,26 @@ default boolean trimNBT(IChunkSet set, Function<BlockVector3, Boolean> contains)
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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,6 +34,16 @@ default <V extends IChunk> void init(IQueueExtent<V> extent, int x, int z) {
*/
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
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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;
Expand Down Expand Up @@ -805,7 +804,8 @@ public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
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) {
Expand Down Expand Up @@ -868,8 +868,8 @@ public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
}
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;
Expand All @@ -893,7 +893,8 @@ public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set, boolean
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) {
Expand Down Expand Up @@ -943,7 +944,8 @@ public IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set, boolean
}
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,8 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set) {
}
}
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 {
Expand Down Expand Up @@ -477,7 +478,8 @@ default IChunkSet processSet(IChunk chunk, IChunkGet get, IChunkSet set, boolean
}
}
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 {
Expand Down

0 comments on commit 90a2c40

Please sign in to comment.