From 64da82c9857d86ebac292ba730f9c43582bd3ea8 Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 1 Jun 2024 12:10:11 +0100 Subject: [PATCH] Better chest handling --- ...erweightFaweMutableBlockPlaceContext.java} | 17 +++--- .../PaperweightPlacementStateProcessor.java | 6 +- ...erweightFaweMutableBlockPlaceContext.java} | 24 ++++---- .../PaperweightPlacementStateProcessor.java | 14 +++-- ...erweightFaweMutableBlockPlaceContext.java} | 17 +++--- .../PaperweightPlacementStateProcessor.java | 6 +- ...erweightFaweMutableBlockPlaceContext.java} | 17 +++--- .../PaperweightPlacementStateProcessor.java | 6 +- .../processor/PlacementStateProcessor.java | 57 +++++++++++++++++-- .../function/mask/BlockCategoryMask.java | 10 ++++ .../sk89q/worldedit/math/BlockVector3.java | 4 ++ .../sk89q/worldedit/util/SideEffectSet.java | 14 ++--- 12 files changed, 127 insertions(+), 65 deletions(-) rename worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/{FaweMutableBlockPlaceContext.java => PaperweightFaweMutableBlockPlaceContext.java} (86%) rename worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/{FaweMutableBlockPlaceContext.java => PaperweightFaweMutableBlockPlaceContext.java} (84%) rename worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/{FaweMutableBlockPlaceContext.java => PaperweightFaweMutableBlockPlaceContext.java} (86%) rename worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/{FaweMutableBlockPlaceContext.java => PaperweightFaweMutableBlockPlaceContext.java} (86%) diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/FaweMutableBlockPlaceContext.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweMutableBlockPlaceContext.java similarity index 86% rename from worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/FaweMutableBlockPlaceContext.java rename to worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweMutableBlockPlaceContext.java index a05be1dbe..7573ac125 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/FaweMutableBlockPlaceContext.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightFaweMutableBlockPlaceContext.java @@ -14,20 +14,21 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FaweMutableBlockPlaceContext extends BlockPlaceContext { +public class PaperweightFaweMutableBlockPlaceContext extends BlockPlaceContext { - private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult(new Vec3( - Integer.MAX_VALUE, - Integer.MAX_VALUE, - Integer.MAX_VALUE - ), Direction.NORTH, BlockPos.ZERO, false); + private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult( + new Vec3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + Direction.NORTH, + new BlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + false + ); private final ServerLevel level; private BlockHitResult hitResult = null; private Direction direction = null; private BlockPos relativePos; @SuppressWarnings("DataFlowIssue") - public FaweMutableBlockPlaceContext(ServerLevel level) { + public PaperweightFaweMutableBlockPlaceContext(ServerLevel level) { super( level, null, @@ -40,7 +41,7 @@ public class FaweMutableBlockPlaceContext extends BlockPlaceContext { this.replaceClicked = false; } - public FaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { + public PaperweightFaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { this.hitResult = hitResult; this.direction = direction; this.relativePos = hitResult.getBlockPos().relative(hitResult.getDirection()); diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java index fc83d6327..bc09a61a1 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightPlacementStateProcessor.java @@ -24,13 +24,13 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin .getInstance() .getBukkitImplAdapter()); - private final FaweMutableBlockPlaceContext mutableBlockPlaceContext; + private final PaperweightFaweMutableBlockPlaceContext mutableBlockPlaceContext; private final PaperweightLevelProxy proxyLevel; public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { super(extent, mask, region); this.proxyLevel = PaperweightLevelProxy.getInstance(this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } private PaperweightPlacementStateProcessor( @@ -43,7 +43,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); this.proxyLevel = PaperweightLevelProxy.getInstance(this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @Override diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/FaweMutableBlockPlaceContext.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweMutableBlockPlaceContext.java similarity index 84% rename from worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/FaweMutableBlockPlaceContext.java rename to worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweMutableBlockPlaceContext.java index 13034892c..a2e8e1ed6 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/FaweMutableBlockPlaceContext.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightFaweMutableBlockPlaceContext.java @@ -14,33 +14,29 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FaweMutableBlockPlaceContext extends BlockPlaceContext { +public class PaperweightFaweMutableBlockPlaceContext extends BlockPlaceContext { - private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult(new Vec3( - Integer.MAX_VALUE, - Integer.MAX_VALUE, - Integer.MAX_VALUE - ), Direction.NORTH, BlockPos.ZERO, false); + private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult( + new Vec3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + Direction.NORTH, + new BlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + false + ); private final ServerLevel level; private BlockHitResult hitResult = null; private Direction direction = null; private BlockPos relativePos; @SuppressWarnings("DataFlowIssue") - public FaweMutableBlockPlaceContext(ServerLevel level) { - super( - level, - null, - null, - null, - DEFAULT_BLOCK_HIT + public PaperweightFaweMutableBlockPlaceContext(ServerLevel level) { + super(level, null, null, null, DEFAULT_BLOCK_HIT ); this.level = level; this.replaceClicked = false; } - public FaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { + public PaperweightFaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { this.hitResult = hitResult; this.direction = direction; this.relativePos = hitResult.getBlockPos().relative(hitResult.getDirection()); diff --git a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java index 74c9c80f1..f0c2d7223 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_20_4/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R3/PaperweightPlacementStateProcessor.java @@ -24,13 +24,13 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin .getInstance() .getBukkitImplAdapter()); - private final FaweMutableBlockPlaceContext mutableBlockPlaceContext; + private final PaperweightFaweMutableBlockPlaceContext mutableBlockPlaceContext; private final PaperweightLevelProxy proxyLevel; public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { super(extent, mask, region); this.proxyLevel = PaperweightLevelProxy.getInstance(this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } private PaperweightPlacementStateProcessor( @@ -43,12 +43,18 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); this.proxyLevel = PaperweightLevelProxy.getInstance(this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @Override protected char getStateAtFor( - int x, int y, int z, BlockState state, Vector3 clickPos, Direction clickedFaceDirection, BlockVector3 clickedBlock + int x, + int y, + int z, + BlockState state, + Vector3 clickPos, + Direction clickedFaceDirection, + BlockVector3 clickedBlock ) { Block block = ((PaperweightBlockMaterial) state.getMaterial()).getBlock(); Vec3 pos = new Vec3(clickPos.x(), clickPos.y(), clickPos.z()); diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/FaweMutableBlockPlaceContext.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweMutableBlockPlaceContext.java similarity index 86% rename from worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/FaweMutableBlockPlaceContext.java rename to worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweMutableBlockPlaceContext.java index b4d4802dc..51318e771 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/FaweMutableBlockPlaceContext.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightFaweMutableBlockPlaceContext.java @@ -14,20 +14,21 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FaweMutableBlockPlaceContext extends BlockPlaceContext { +public class PaperweightFaweMutableBlockPlaceContext extends BlockPlaceContext { - private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult(new Vec3( - Integer.MAX_VALUE, - Integer.MAX_VALUE, - Integer.MAX_VALUE - ), Direction.NORTH, BlockPos.ZERO, false); + private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult( + new Vec3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + Direction.NORTH, + new BlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + false + ); private final ServerLevel level; private BlockHitResult hitResult = null; private Direction direction = null; private BlockPos relativePos; @SuppressWarnings("DataFlowIssue") - public FaweMutableBlockPlaceContext(ServerLevel level) { + public PaperweightFaweMutableBlockPlaceContext(ServerLevel level) { super( level, null, @@ -40,7 +41,7 @@ public class FaweMutableBlockPlaceContext extends BlockPlaceContext { this.replaceClicked = false; } - public FaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { + public PaperweightFaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { this.hitResult = hitResult; this.direction = direction; this.relativePos = hitResult.getBlockPos().relative(hitResult.getDirection()); diff --git a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlacementStateProcessor.java index 0bee6e5f7..cf52c30cf 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_20_5/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R4/PaperweightPlacementStateProcessor.java @@ -31,7 +31,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor .getInstance() .getBukkitImplAdapter()); private final PaperweightLevelProxy proxyLevel; - private final FaweMutableBlockPlaceContext mutableBlockPlaceContext; + private final PaperweightFaweMutableBlockPlaceContext mutableBlockPlaceContext; public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { super(extent, mask, region); @@ -47,7 +47,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor bukkitWorld = (BukkitWorld) world; } this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } private PaperweightPlacementStateProcessor( @@ -61,7 +61,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); this.proxyLevel = PaperweightLevelProxy.getInstance(serverLevel, this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @Override diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/FaweMutableBlockPlaceContext.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweMutableBlockPlaceContext.java similarity index 86% rename from worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/FaweMutableBlockPlaceContext.java rename to worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweMutableBlockPlaceContext.java index d5db5e210..a69fcdca3 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/FaweMutableBlockPlaceContext.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightFaweMutableBlockPlaceContext.java @@ -14,20 +14,21 @@ import net.minecraft.world.phys.Vec3; import javax.annotation.Nonnull; import javax.annotation.Nullable; -public class FaweMutableBlockPlaceContext extends BlockPlaceContext { +public class PaperweightFaweMutableBlockPlaceContext extends BlockPlaceContext { - private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult(new Vec3( - Integer.MAX_VALUE, - Integer.MAX_VALUE, - Integer.MAX_VALUE - ), Direction.NORTH, BlockPos.ZERO, false); + private static final BlockHitResult DEFAULT_BLOCK_HIT = new BlockHitResult( + new Vec3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + Direction.NORTH, + new BlockPos(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE), + false + ); private final ServerLevel level; private BlockHitResult hitResult = null; private Direction direction = null; private BlockPos relativePos; @SuppressWarnings("DataFlowIssue") - public FaweMutableBlockPlaceContext(ServerLevel level) { + public PaperweightFaweMutableBlockPlaceContext(ServerLevel level) { super( level, null, @@ -40,7 +41,7 @@ public class FaweMutableBlockPlaceContext extends BlockPlaceContext { this.replaceClicked = false; } - public FaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { + public PaperweightFaweMutableBlockPlaceContext withSetting(BlockHitResult hitResult, Direction direction) { this.hitResult = hitResult; this.direction = direction; this.relativePos = hitResult.getBlockPos().relative(hitResult.getDirection()); diff --git a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlacementStateProcessor.java b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlacementStateProcessor.java index fea47e54b..a17c7ebd8 100644 --- a/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlacementStateProcessor.java +++ b/worldedit-bukkit/adapters/adapter-1_21/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_21_R1/PaperweightPlacementStateProcessor.java @@ -30,7 +30,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin .getInstance() .getBukkitImplAdapter()); - private final FaweMutableBlockPlaceContext mutableBlockPlaceContext; + private final PaperweightFaweMutableBlockPlaceContext mutableBlockPlaceContext; private final PaperweightLevelProxy proxyLevel; public PaperweightPlacementStateProcessor(Extent extent, BlockTypeMask mask, Region region) { @@ -47,7 +47,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor bukkitWorld = (BukkitWorld) world; } this.proxyLevel = PaperweightLevelProxy.getInstance(((CraftWorld) bukkitWorld.getWorld()).getHandle(), this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } private PaperweightPlacementStateProcessor( @@ -61,7 +61,7 @@ public class PaperweightPlacementStateProcessor extends PlacementStateProcessor ) { super(extent, mask, crossChunkSecondPasses, threadProcessors, region, finished); this.proxyLevel = PaperweightLevelProxy.getInstance(serverLevel, this); - this.mutableBlockPlaceContext = new FaweMutableBlockPlaceContext(proxyLevel); + this.mutableBlockPlaceContext = new PaperweightFaweMutableBlockPlaceContext(proxyLevel); } @Override diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java index 3175cd656..aa05dc52f 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/extent/processor/PlacementStateProcessor.java @@ -1,5 +1,7 @@ package com.fastasyncworldedit.core.extent.processor; +import com.fastasyncworldedit.core.configuration.Caption; +import com.fastasyncworldedit.core.extent.NullExtent; import com.fastasyncworldedit.core.extent.filter.block.FilterBlock; import com.fastasyncworldedit.core.function.mask.AdjacentAny2DMask; import com.fastasyncworldedit.core.math.BlockVector3ChunkMap; @@ -9,11 +11,12 @@ 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.fastasyncworldedit.core.registry.state.PropertyKey; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.function.mask.BlockCategoryMask; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; @@ -48,6 +51,7 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp private static volatile boolean SETUP = false; private static BlockTypeMask DEFAULT_MASK = null; + private static BlockTypeMask IN_FIRST_PASS = null; private static BlockTypeMask REQUIRES_SECOND_PASS = null; private static AdjacentAny2DMask ADJACENT_STAIR_MASK = null; @@ -59,6 +63,7 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp protected final AtomicBoolean finished; private final MutableVector3 clickPos = new MutableVector3(); private final MutableBlockVector3 clickedBlock = new MutableBlockVector3(); + private final MutableBlockVector3 placedBlock = new MutableBlockVector3(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); private IChunkGet processChunkGet = null; private IChunkSet processChunkSet = null; @@ -109,7 +114,19 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp } private static void setup() { - REQUIRES_SECOND_PASS = new BlockTypeMask(new NullExtent()); + NullExtent nullExtent = new NullExtent( + com.sk89q.worldedit.extent.NullExtent.INSTANCE, + Caption.of("PlacementStateProcessor fell through to null extent") + ); + + IN_FIRST_PASS = new BlockTypeMask(nullExtent); + IN_FIRST_PASS.add( + BlockTypes.CHEST, + BlockTypes.TRAPPED_CHEST + ); + IN_FIRST_PASS.add(BlockCategories.STAIRS.getAll()); + + REQUIRES_SECOND_PASS = new BlockTypeMask(nullExtent); REQUIRES_SECOND_PASS.add( BlockTypes.IRON_BARS, BlockTypes.GLASS_PANE, @@ -164,8 +181,8 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp DEFAULT_MASK.add(category.getAll()); } } - BlockTypeMask stairs = new BlockTypeMask(new NullExtent(), BlockCategories.STAIRS.getAll()); - ADJACENT_STAIR_MASK = new AdjacentAny2DMask(stairs, false); + + ADJACENT_STAIR_MASK = new AdjacentAny2DMask(new BlockCategoryMask(nullExtent, BlockCategories.STAIRS), false); SETUP = true; } @@ -225,13 +242,14 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp int blockX = processChunkX + x; char ordinal = set[index]; BlockState state = BlockTypesCache.states[ordinal]; - if (firstPass && !BlockCategories.STAIRS.contains(state)) { + if (firstPass && !IN_FIRST_PASS.test(state)) { continue; } if (!mask.test(state)) { continue; } - if (!firstPass && REQUIRES_SECOND_PASS.test(state)) { + boolean atEdge = x == 0 || x == 15 || z == 0 || z == 15; + if (!firstPass && atEdge && REQUIRES_SECOND_PASS.test(state)) { postCompleteSecondPasses.put(new SecondPass( blockX, blockY, @@ -241,6 +259,11 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp set[index] = BlockTypesCache.ReservedIDs.__RESERVED__; continue; } + if (state.getBlockType().equals(BlockTypes.CHEST) || state.getBlockType().equals(BlockTypes.TRAPPED_CHEST)) { + placedBlock.setComponents(blockX, blockY, blockZ); + } else { + placedBlock.setComponents(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE); + } char newOrdinal = getBlockOrdinal(blockX, blockY, blockZ, state); if (newOrdinal == ordinal) { continue; @@ -313,6 +336,28 @@ public abstract class PlacementStateProcessor extends AbstractDelegateExtent imp if (ordinal == BlockTypesCache.ReservedIDs.__RESERVED__) { return processChunkGet.getBlock(x & 15, y, z & 15); } + BlockState state = BlockTypesCache.states[ordinal]; + // "Hack" for stairs as internal server methods will only accept "single" chests for joining + if (state.getBlockType().equals(BlockTypes.CHEST) || state.getBlockType().equals(BlockTypes.TRAPPED_CHEST)) { + String shape = state.getState(PropertyKey.TYPE).toString(); + if (shape.equals("right")) { + Direction facing = state.getState(PropertyKey.FACING); + Direction left = facing.getLeft(); + int testX = x + left.getBlockX(); + int testZ = z + left.getBlockZ(); + if (placedBlock.isAt(testX, y, testZ)) { + return state.with(PropertyKey.TYPE, "single"); + } + } else if(shape.equals("left")) { + Direction facing = state.getState(PropertyKey.FACING); + Direction right = facing.getRight(); + int testX = x + right.getBlockX(); + int testZ = z + right.getBlockZ(); + if (placedBlock.isAt(testX, y, testZ)) { + return state.with(PropertyKey.TYPE, "single"); + } + } + } return BlockTypesCache.states[ordinal]; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java index a1b869efb..bb89b0a08 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockCategoryMask.java @@ -22,6 +22,7 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategory; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import javax.annotation.Nullable; @@ -54,6 +55,15 @@ public class BlockCategoryMask extends AbstractExtentMask { public boolean test(Extent extent, BlockVector3 vector) { return category.contains(extent.getBlock(vector)); } + + /** + * Test a specific block against this category mask + * + * @since TODO + */ + public > boolean test(B blockStateHolder) { + return category.contains(blockStateHolder); + } //FAWE end @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java index 017ec7ca0..1917e68b2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -127,6 +127,10 @@ public abstract class BlockVector3 { } //FAWE start + public boolean isAt(int x, int y, int z) { + return x() == x && y() == y && z() == z; + } + public MutableBlockVector3 setComponents(double x, double y, double z) { return new MutableBlockVector3((int) x, (int) y, (int) z); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/SideEffectSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/SideEffectSet.java index 2aa3bcea5..8e7a707bc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/SideEffectSet.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/SideEffectSet.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.util; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.Maps; import java.util.Arrays; @@ -31,7 +30,12 @@ import java.util.stream.Collectors; public class SideEffectSet { - private static final SideEffectSet DEFAULT = new SideEffectSet(); + //FAWE start - assign value map + private static final SideEffectSet DEFAULT = new SideEffectSet( + Arrays.stream(SideEffect.values()) + .filter(SideEffect::isExposed) + .collect(Collectors.toMap(Function.identity(), SideEffect::getDefaultValue))); + //FAWE end private static final SideEffectSet NONE = new SideEffectSet( Arrays.stream(SideEffect.values()) .filter(SideEffect::isExposed) @@ -42,12 +46,6 @@ public class SideEffectSet { private final Set appliedSideEffects; private final boolean appliesAny; - //FAWE start - private SideEffectSet() { - this(ImmutableMap.of()); - } - //FAWE end - public SideEffectSet(Map sideEffects) { this.sideEffects = Maps.immutableEnumMap(sideEffects);