Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-12-25 02:20:07 +01:00
Region filter
Dieser Commit ist enthalten in:
Ursprung
27ed596027
Commit
7c174beaee
@ -349,11 +349,4 @@ public class BukkitChunkHolder<T extends Future<T>> extends ChunkHolder {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void set(final Filter filter) {
|
|
||||||
// for each block
|
|
||||||
// filter.applyBlock(block)
|
|
||||||
throw new UnsupportedOperationException("Not implemented");
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,6 +2,8 @@ package com.boydti.fawe.beta;
|
|||||||
|
|
||||||
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
|
import com.boydti.fawe.beta.implementation.blocks.CharGetBlocks;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||||
@ -40,7 +42,7 @@ public class CharFilterBlock implements FilterBlock {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void filter(final IGetBlocks iget, final ISetBlocks iset, final int layer, final Filter filter) {
|
public final void filter(final IGetBlocks iget, final ISetBlocks iset, final int layer, final Filter filter, final @Nullable Region region, BlockVector3 min, BlockVector3 max) {
|
||||||
this.layer = layer;
|
this.layer = layer;
|
||||||
final CharGetBlocks get = (CharGetBlocks) iget;
|
final CharGetBlocks get = (CharGetBlocks) iget;
|
||||||
if (!get.hasSection(layer)) return;
|
if (!get.hasSection(layer)) return;
|
||||||
@ -54,7 +56,81 @@ public class CharFilterBlock implements FilterBlock {
|
|||||||
setArr = null;
|
setArr = null;
|
||||||
}
|
}
|
||||||
this.yy = layer << 4;
|
this.yy = layer << 4;
|
||||||
|
if (region == null) {
|
||||||
|
if (min != null && max != null) {
|
||||||
|
iterate(min, max, layer, filter);
|
||||||
|
} else {
|
||||||
|
iterate(filter);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (min != null && max != null) {
|
||||||
|
iterate(region, min, max, layer, filter);
|
||||||
|
} else {
|
||||||
|
iterate(region, filter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void iterate(final Region region, final Filter filter) {
|
||||||
|
for (y = 0, index = 0; y < 16; y++) {
|
||||||
|
int absY = yy + y;
|
||||||
|
for (z = 0; z < 16; z++) {
|
||||||
|
int absZ = zz + z;
|
||||||
|
for (x = 0; x < 16; x++, index++) {
|
||||||
|
int absX = xx + x;
|
||||||
|
if (region.contains(absX, absY, absZ)) {
|
||||||
|
filter.applyBlock(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void iterate(final Region region, BlockVector3 min, BlockVector3 max, int layer, final Filter filter) {
|
||||||
|
int by = Math.max(min.getY(), layer << 4) & 15;
|
||||||
|
int ty = Math.min(max.getY(), 15 + (layer << 4)) & 15;
|
||||||
|
int bx = min.getX();
|
||||||
|
int bz = min.getZ();
|
||||||
|
int tx = max.getX();
|
||||||
|
int tz = max.getZ();
|
||||||
|
for (y = by; y <= ty; y++) {
|
||||||
|
int yIndex = (y << 8);
|
||||||
|
int absY = yy + y;
|
||||||
|
for (z = bz; z <= tz; z++) {
|
||||||
|
int zIndex = yIndex + ((z) << 4);
|
||||||
|
int absZ = zz + z;
|
||||||
|
for (x = bx; x <= tx; x++) {
|
||||||
|
index = zIndex + x;
|
||||||
|
int absX = xx + x;
|
||||||
|
if (region.contains(absX, absY, absZ)) {
|
||||||
|
filter.applyBlock(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void iterate(BlockVector3 min, BlockVector3 max, int layer, final Filter filter) {
|
||||||
|
int by = Math.max(min.getY(), layer << 4) & 15;
|
||||||
|
int ty = Math.min(max.getY(), 15 + (layer << 4)) & 15;
|
||||||
|
int bx = min.getX();
|
||||||
|
int bz = min.getZ();
|
||||||
|
int tx = max.getX();
|
||||||
|
int tz = max.getZ();
|
||||||
|
for (y = by; y <= ty; y++) {
|
||||||
|
int yIndex = (y << 8);
|
||||||
|
for (z = bz; z <= tz; z++) {
|
||||||
|
int zIndex = yIndex + ((z) << 4);
|
||||||
|
for (x = bx; x <= tx; x++) {
|
||||||
|
index = zIndex + x;
|
||||||
|
filter.applyBlock(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final void iterate(final Filter filter) {
|
||||||
for (y = 0, index = 0; y < 16; y++) {
|
for (y = 0, index = 0; y < 16; y++) {
|
||||||
for (z = 0; z < 16; z++) {
|
for (z = 0; z < 16; z++) {
|
||||||
for (x = 0; x < 16; x++, index++) {
|
for (x = 0; x < 16; x++, index++) {
|
||||||
|
@ -16,8 +16,8 @@ public interface Filter {
|
|||||||
* @param cz
|
* @param cz
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
default Filter appliesChunk(final int cx, final int cz) {
|
default boolean appliesChunk(final int cx, final int cz) {
|
||||||
return this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -32,8 +32,8 @@ public interface Filter {
|
|||||||
return chunk;
|
return chunk;
|
||||||
}
|
}
|
||||||
|
|
||||||
default Filter appliesLayer(IChunk chunk, int layer) {
|
default boolean appliesLayer(IChunk chunk, int layer) {
|
||||||
return this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
@ -12,7 +13,7 @@ public interface FilterBlock {
|
|||||||
|
|
||||||
FilterBlock init(int X, int Z, IGetBlocks chunk);
|
FilterBlock init(int X, int Z, IGetBlocks chunk);
|
||||||
|
|
||||||
void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter, @Nullable Region region);
|
void filter(IGetBlocks get, ISetBlocks set, int layer, Filter filter, @Nullable Region region, BlockVector3 min, BlockVector3 max);
|
||||||
|
|
||||||
void setOrdinal(int ordinal);
|
void setOrdinal(int ordinal);
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@ -61,23 +64,25 @@ public interface IChunk<T extends Future<T>> extends Trimable, Callable<T> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filter
|
||||||
|
* @param filter the filter
|
||||||
|
* @param block The filter block
|
||||||
|
* @param region The region allowed to filter (may be null)
|
||||||
|
* @param unitialized a mutable block vector (buffer)
|
||||||
|
* @param unitialized2 a mutable block vector (buffer)
|
||||||
|
*/
|
||||||
|
void filter(Filter filter, FilterBlock block, @Nullable Region region, MutableBlockVector3 unitialized, MutableBlockVector3 unitialized2);
|
||||||
|
|
||||||
/* set - queues a change */
|
/* set - queues a change */
|
||||||
boolean setBiome(int x, int y, int z, BiomeType biome);
|
boolean setBiome(int x, int y, int z, BiomeType biome);
|
||||||
|
|
||||||
boolean setBlock(int x, int y, int z, BlockStateHolder block);
|
boolean setBlock(int x, int y, int z, BlockStateHolder block);
|
||||||
|
|
||||||
/**
|
|
||||||
* Set using the filter
|
|
||||||
* @param filter
|
|
||||||
*/
|
|
||||||
void set(Filter filter);
|
|
||||||
|
|
||||||
/* get - from the world */
|
/* get - from the world */
|
||||||
BiomeType getBiome(int x, int z);
|
BiomeType getBiome(int x, int z);
|
||||||
|
|
||||||
BlockState getBlock(int x, int y, int z);
|
BlockState getBlock(int x, int y, int z);
|
||||||
|
|
||||||
BaseBlock getFullBlock(int x, int y, int z);
|
BaseBlock getFullBlock(int x, int y, int z);
|
||||||
|
|
||||||
void filter(Filter filter, FilterBlock mutable);
|
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
@ -80,8 +83,8 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default void filter(final Filter filter, final FilterBlock mutable) {
|
default void filter(Filter filter, FilterBlock block, @Nullable Region region, MutableBlockVector3 unitialized, MutableBlockVector3 unitialized2) {
|
||||||
getParent().filter(filter, mutable);
|
getParent().filter(filter, block, region, unitialized, unitialized2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -98,9 +101,4 @@ public interface IDelegateChunk<U extends IChunk> extends IChunk {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
default void set(final Filter filter) {
|
|
||||||
getParent().set(filter);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,25 @@
|
|||||||
package com.boydti.fawe.beta;
|
package com.boydti.fawe.beta;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public interface IDelegateFilter extends Filter {
|
public interface IDelegateFilter extends Filter {
|
||||||
Filter getParent();
|
Filter getParent();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Filter appliesChunk(int cx, int cz) {
|
default boolean appliesChunk(int cx, int cz) {
|
||||||
Filter copy = getParent().appliesChunk(cx, cz);
|
return getParent().appliesChunk(cx, cz);
|
||||||
if (copy == null) return null;
|
|
||||||
if (copy != getParent()) {
|
|
||||||
return newInstance(copy);
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default IChunk applyChunk(IChunk chunk) {
|
default IChunk applyChunk(IChunk chunk, @Nullable Region region) {
|
||||||
return getParent().applyChunk(chunk);
|
return getParent().applyChunk(chunk, region);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default Filter appliesLayer(IChunk chunk, int layer) {
|
default boolean appliesLayer(IChunk chunk, int layer) {
|
||||||
Filter copy = getParent().appliesLayer(chunk, layer);
|
return getParent().appliesLayer(chunk, layer);
|
||||||
if (copy == null) return null;
|
|
||||||
if (copy != getParent()) {
|
|
||||||
return newInstance(copy);
|
|
||||||
} else {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,37 +0,0 @@
|
|||||||
package com.boydti.fawe.beta;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.regions.Region;
|
|
||||||
|
|
||||||
public class RegionFilter extends DelegateFilter {
|
|
||||||
private final Region region;
|
|
||||||
|
|
||||||
public RegionFilter(Filter parent, Region region) {
|
|
||||||
super(parent);
|
|
||||||
this.region = region;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Filter appliesChunk(int cx, int cz) {
|
|
||||||
return getParent().appliesChunk(cx, cz);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Filter appliesLayer(IChunk chunk, int layer) {
|
|
||||||
return getParent().appliesLayer(chunk, layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void applyBlock(FilterBlock block) {
|
|
||||||
getParent().applyBlock(block);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finishChunk(IChunk chunk) {
|
|
||||||
getParent().finishChunk(chunk);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Filter newInstance(Filter other) {
|
|
||||||
return new RegionFilter(other, region);
|
|
||||||
}
|
|
||||||
}
|
|
@ -13,6 +13,7 @@ import com.boydti.fawe.util.MemUtil;
|
|||||||
import com.boydti.fawe.util.TaskManager;
|
import com.boydti.fawe.util.TaskManager;
|
||||||
import com.boydti.fawe.wrappers.WorldWrapper;
|
import com.boydti.fawe.wrappers.WorldWrapper;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
@ -155,6 +156,9 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
tasks[i] = forkJoinPoolPrimary.submit(new Runnable() {
|
tasks[i] = forkJoinPoolPrimary.submit(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
MutableBlockVector3 mbv1 = new MutableBlockVector3();
|
||||||
|
MutableBlockVector3 mbv2 = new MutableBlockVector3();
|
||||||
|
|
||||||
final Filter newFilter = filter.fork();
|
final Filter newFilter = filter.fork();
|
||||||
// Create a chunk that we will reuse/reset for each operation
|
// Create a chunk that we will reuse/reset for each operation
|
||||||
final IQueueExtent queue = getQueue(world);
|
final IQueueExtent queue = getQueue(world);
|
||||||
@ -162,7 +166,7 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
FilterBlock block = null;
|
FilterBlock block = null;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
// Get the next chunk pos
|
// Get the next chunk posWeakChunk
|
||||||
final int X, Z;
|
final int X, Z;
|
||||||
synchronized (chunksIter) {
|
synchronized (chunksIter) {
|
||||||
if (!chunksIter.hasNext()) break;
|
if (!chunksIter.hasNext()) break;
|
||||||
@ -177,12 +181,12 @@ public abstract class QueueHandler implements Trimable, Runnable {
|
|||||||
// Initialize
|
// Initialize
|
||||||
chunk.init(queue, X, Z);
|
chunk.init(queue, X, Z);
|
||||||
|
|
||||||
chunk = newFilter.applyChunk(chunk);
|
chunk = newFilter.applyChunk(chunk, region);
|
||||||
|
|
||||||
if (chunk == null) continue;
|
if (chunk == null) continue;
|
||||||
|
|
||||||
if (block == null) block = queue.initFilterBlock();
|
if (block == null) block = queue.initFilterBlock();
|
||||||
chunk.filter(newFilter, block);
|
chunk.filter(newFilter, block, region, mbv1, mbv2);
|
||||||
|
|
||||||
queue.submit(chunk);
|
queue.submit(chunk);
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,14 @@ import com.boydti.fawe.beta.ISetBlocks;
|
|||||||
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
|
import com.boydti.fawe.beta.implementation.SingleThreadQueueExtent;
|
||||||
import com.boydti.fawe.beta.implementation.WorldChunkCache;
|
import com.boydti.fawe.beta.implementation.WorldChunkCache;
|
||||||
import com.boydti.fawe.util.MathMan;
|
import com.boydti.fawe.util.MathMan;
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.biome.BiomeType;
|
import com.sk89q.worldedit.world.biome.BiomeType;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -36,16 +39,45 @@ public abstract class ChunkHolder implements IChunk, Supplier<IGetBlocks> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void filter(final Filter filter, FilterBlock block) {
|
public void filter(final Filter filter, FilterBlock block, @Nullable Region region, final MutableBlockVector3 min, final MutableBlockVector3 max) {
|
||||||
final IGetBlocks get = getOrCreateGet();
|
final IGetBlocks get = getOrCreateGet();
|
||||||
final ISetBlocks set = getOrCreateSet();
|
final ISetBlocks set = getOrCreateSet();
|
||||||
|
try {
|
||||||
|
if (region != null) {
|
||||||
|
switch (region.getChunkBounds(X, Z, min, max)) {
|
||||||
|
case NONE:
|
||||||
|
System.out.println("NONE");
|
||||||
|
return;
|
||||||
|
case FULL:
|
||||||
|
if (min.getY() == 0 && max.getY() == 255) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case PARTIAL:
|
||||||
|
region = null;
|
||||||
|
case CHECKED:
|
||||||
|
default: {
|
||||||
|
int minLayer = min.getY() >> 4;
|
||||||
|
int maxLayer = max.getY() >> 4;
|
||||||
|
System.out.println("Layers " + minLayer + " | " + maxLayer);
|
||||||
|
block = block.init(X, Z, get);
|
||||||
|
for (int layer = minLayer; layer < maxLayer; layer++) {
|
||||||
|
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
|
||||||
|
block.filter(get, set, layer, filter, region, min, max);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
block = block.init(X, Z, get);
|
block = block.init(X, Z, get);
|
||||||
for (int layer = 0; layer < 16; layer++) {
|
for (int layer = 0; layer < 16; layer++) {
|
||||||
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
|
if (!get.hasSection(layer) || !filter.appliesLayer(this, layer)) continue;
|
||||||
block.filter(get, set, layer, filter);
|
block.filter(get, set, layer, filter, region, null, null);
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
filter.finishChunk(this);
|
filter.finishChunk(this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean trim(final boolean aggressive) {
|
public boolean trim(final boolean aggressive) {
|
||||||
|
@ -41,6 +41,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An axis-aligned cuboid. It can be defined using two corners of the cuboid.
|
* An axis-aligned cuboid. It can be defined using two corners of the cuboid.
|
||||||
@ -627,5 +628,36 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion {
|
|||||||
return new CuboidRegion(origin.subtract(size), origin.add(size));
|
return new CuboidRegion(origin.subtract(size), origin.add(size));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
|
||||||
|
int minChunkX = minX >> 4;
|
||||||
|
if (minChunkX <= X) {
|
||||||
|
int maxChunkX = maxX >> 4;
|
||||||
|
if (maxChunkX >= X) {
|
||||||
|
int minChunkZ = minZ >> 4;
|
||||||
|
if (minChunkZ <= X) {
|
||||||
|
int maxChunkZ = maxZ >> 4;
|
||||||
|
if (maxChunkZ >= Z) {
|
||||||
|
int cx1 = X << 4;
|
||||||
|
int cx2 = cx1 + 15;
|
||||||
|
int cz1 = Z << 4;
|
||||||
|
int cz2 = cz1 + 15;
|
||||||
|
|
||||||
|
int bx = Math.max(cx1, minX);
|
||||||
|
int bz = Math.max(cz1, minZ);
|
||||||
|
int tx = Math.min(cx2, maxX);
|
||||||
|
int tz = Math.min(cz2, maxZ);
|
||||||
|
|
||||||
|
min.setComponents(bx & 15, minY, bz & 15);
|
||||||
|
max.setComponents(tx & 15, maxY, tz & 15);
|
||||||
|
if (min.getX() == 0 && min.getZ() == 0 && max.getX() == 15 && max.getZ() == 15) {
|
||||||
|
return FULL;
|
||||||
|
}
|
||||||
|
return PARTIAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
}
|
}
|
@ -21,6 +21,7 @@ package com.sk89q.worldedit.regions;
|
|||||||
|
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
@ -28,6 +29,9 @@ import javax.annotation.Nullable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a physical shape.
|
* Represents a physical shape.
|
||||||
*/
|
*/
|
||||||
@ -178,4 +182,33 @@ public interface Region extends Iterable<BlockVector3>, Cloneable {
|
|||||||
* @return the points.
|
* @return the points.
|
||||||
*/
|
*/
|
||||||
List<BlockVector2> polygonize(int maxPoints);
|
List<BlockVector2> polygonize(int maxPoints);
|
||||||
|
|
||||||
|
default Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
|
||||||
|
BlockVector3 pos1 = getMinimumPoint();
|
||||||
|
BlockVector3 pos2 = getMaximumPoint();
|
||||||
|
int cx1 = X << 4;
|
||||||
|
int cx2 = cx1 + 15;
|
||||||
|
int cz1 = Z << 4;
|
||||||
|
int cz2 = cz1 + 15;
|
||||||
|
|
||||||
|
int bx = Math.max(cx1, pos1.getX());
|
||||||
|
int bz = Math.max(cz1, pos1.getZ());
|
||||||
|
int tx = Math.min(cx2, pos2.getX());
|
||||||
|
int tz = Math.min(cz2, pos2.getZ());
|
||||||
|
|
||||||
|
min.setComponents(bx & 15, pos1.getY(), bz & 15);
|
||||||
|
max.setComponents(tx & 15, pos2.getY(), tz & 15);
|
||||||
|
|
||||||
|
if (bx > cx2 || bz > cz2 || tx < cx1 || tz < cz1) {
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
return CHECKED;
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Contains {
|
||||||
|
FULL,
|
||||||
|
PARTIAL,
|
||||||
|
CHECKED,
|
||||||
|
NONE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,14 @@ package com.sk89q.worldedit.regions;
|
|||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.CHECKED;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.FULL;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.NONE;
|
||||||
|
import static com.sk89q.worldedit.regions.Region.Contains.PARTIAL;
|
||||||
|
|
||||||
import com.google.common.collect.Iterators;
|
import com.google.common.collect.Iterators;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -1,191 +0,0 @@
|
|||||||
/*
|
|
||||||
* WorldEdit, a Minecraft world manipulation toolkit
|
|
||||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
|
||||||
* Copyright (C) WorldEdit team and contributors
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
|
||||||
* under the terms of the GNU Lesser General Public License as published by the
|
|
||||||
* Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
||||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
|
|
||||||
* for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.sk89q.worldedit.regions;
|
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
|
||||||
|
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
|
||||||
import com.sk89q.worldedit.math.transform.Identity;
|
|
||||||
import com.sk89q.worldedit.math.transform.Transform;
|
|
||||||
import com.sk89q.worldedit.world.World;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transforms another region according to a provided vector {@code Transform}.
|
|
||||||
*
|
|
||||||
* @see Transform
|
|
||||||
*/
|
|
||||||
public class TransformRegion extends AbstractRegion {
|
|
||||||
|
|
||||||
private final Region region;
|
|
||||||
private Transform transform = new Identity();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance.
|
|
||||||
*
|
|
||||||
* @param region the region
|
|
||||||
* @param transform the transform
|
|
||||||
*/
|
|
||||||
public TransformRegion(Region region, Transform transform) {
|
|
||||||
this(null, region, transform);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new instance.
|
|
||||||
*
|
|
||||||
* @param world the world, which may be null
|
|
||||||
* @param region the region
|
|
||||||
* @param transform the transform
|
|
||||||
*/
|
|
||||||
public TransformRegion(@Nullable World world, Region region, Transform transform) {
|
|
||||||
super(world);
|
|
||||||
checkNotNull(region);
|
|
||||||
checkNotNull(transform);
|
|
||||||
this.region = region;
|
|
||||||
this.transform = transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the untransformed, base region.
|
|
||||||
*
|
|
||||||
* @return the base region
|
|
||||||
*/
|
|
||||||
public Region getRegion() {
|
|
||||||
return region;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the transform that is applied.
|
|
||||||
*
|
|
||||||
* @return the transform
|
|
||||||
*/
|
|
||||||
public Transform getTransform() {
|
|
||||||
return transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the transform that is applied.
|
|
||||||
*
|
|
||||||
* @param transform the transform
|
|
||||||
*/
|
|
||||||
public void setTransform(Transform transform) {
|
|
||||||
checkNotNull(transform);
|
|
||||||
this.transform = transform;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector3 getMinimumPoint() {
|
|
||||||
return transform.apply(region.getMinimumPoint().toVector3()).toBlockPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector3 getMaximumPoint() {
|
|
||||||
return transform.apply(region.getMaximumPoint().toVector3()).toBlockPoint();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Vector3 getCenter() {
|
|
||||||
return transform.apply(region.getCenter());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getArea() {
|
|
||||||
return region.getArea(); // Cannot transform this
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getWidth() {
|
|
||||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockX() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getHeight() {
|
|
||||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockY() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLength() {
|
|
||||||
return getMaximumPoint().subtract(getMinimumPoint()).getBlockZ() + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void expand(BlockVector3... changes) throws RegionOperationException {
|
|
||||||
throw new RegionOperationException("Can't expand a TransformedRegion");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void contract(BlockVector3... changes) throws RegionOperationException {
|
|
||||||
throw new RegionOperationException("Can't contract a TransformedRegion");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shift(BlockVector3 change) throws RegionOperationException {
|
|
||||||
throw new RegionOperationException("Can't change a TransformedRegion");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean contains(BlockVector3 position) {
|
|
||||||
return region.contains(transform.inverse().apply(position.toVector3()).toBlockPoint());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<BlockVector2> polygonize(int maxPoints) {
|
|
||||||
List<BlockVector2> origPoints = region.polygonize(maxPoints);
|
|
||||||
List<BlockVector2> transformedPoints = new ArrayList<>();
|
|
||||||
for (BlockVector2 vector : origPoints) {
|
|
||||||
transformedPoints.add(transform.apply(vector.toVector3(0)).toVector2().toBlockPoint());
|
|
||||||
}
|
|
||||||
return transformedPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator<BlockVector3> iterator() {
|
|
||||||
final Iterator<BlockVector3> it = region.iterator();
|
|
||||||
|
|
||||||
return new Iterator<BlockVector3>() {
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return it.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public BlockVector3 next() {
|
|
||||||
BlockVector3 next = it.next();
|
|
||||||
if (next != null) {
|
|
||||||
return transform.apply(next.toVector3()).toBlockPoint();
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
it.remove();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -23,6 +23,7 @@ import com.sk89q.worldedit.IncompleteRegionException;
|
|||||||
import com.sk89q.worldedit.LocalSession;
|
import com.sk89q.worldedit.LocalSession;
|
||||||
import com.sk89q.worldedit.math.BlockVector2;
|
import com.sk89q.worldedit.math.BlockVector2;
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
|
import com.sk89q.worldedit.math.MutableBlockVector3;
|
||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
import com.sk89q.worldedit.regions.NullRegion;
|
import com.sk89q.worldedit.regions.NullRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
@ -147,6 +148,11 @@ public class RequestSelection implements Region {
|
|||||||
return getRegion().polygonize(maxPoints);
|
return getRegion().polygonize(maxPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Contains getChunkBounds(int X, int Z, MutableBlockVector3 min, MutableBlockVector3 max) {
|
||||||
|
return getRegion().getChunkBounds(X, Z, min, max);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<BlockVector3> iterator() {
|
public Iterator<BlockVector3> iterator() {
|
||||||
return getRegion().iterator();
|
return getRegion().iterator();
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren