From 511c2791535c883b29052028db00178330651268 Mon Sep 17 00:00:00 2001 From: IronApollo Date: Thu, 7 Feb 2019 09:04:14 -0500 Subject: [PATCH] Fixed issues regarding block transformations and using the BaseBlock to apply a function. --- .../object/extent/BlockTranslateExtent.java | 4 +- .../boydti/fawe/object/extent/NullExtent.java | 80 +++++++++++++++---- .../extent/PositionTransformExtent.java | 28 ++----- .../java/com/sk89q/worldedit/EditSession.java | 4 + .../extent/AbstractDelegateExtent.java | 8 +- .../sk89q/worldedit/extent/NullExtent.java | 5 ++ .../function/block/BlockReplace.java | 9 +-- .../function/visitor/RegionVisitor.java | 2 +- .../worldedit/world/block/BaseBlock.java | 3 +- 9 files changed, 90 insertions(+), 53 deletions(-) diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java index f8789ba7b..b399b95f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java @@ -23,7 +23,7 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { mutable.mutX((location.getX() + dx)); mutable.mutY((location.getY() + dy)); mutable.mutZ((location.getZ() + dz)); @@ -31,7 +31,7 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(int x, int y, int z, T block) throws WorldEditException { mutable.mutX(x + dx); mutable.mutY(y + dy); mutable.mutZ(z + dz); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index cf48c7527..1f851b178 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -41,7 +41,7 @@ public class NullExtent extends FaweRegionExtent { super(new com.sk89q.worldedit.extent.NullExtent(), FaweLimit.MAX); this.reason = BBC.WORLDEDIT_CANCEL_REASON_MANUAL; } - + @Override public ResettableExtent setExtent(Extent extent) { return this; @@ -49,42 +49,74 @@ public class NullExtent extends FaweRegionExtent { @Override public BaseBiome getBiome(final BlockVector2 arg0) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return null; + } } @Override public BlockState getBlock(final BlockVector3 arg0) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return null; + } } @Override public BlockState getLazyBlock(final BlockVector3 arg0) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return null; + } } @Override public boolean setBiome(final BlockVector2 arg0, final BaseBiome arg1) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return false; + } } @Override public boolean setBlock(final BlockVector3 arg0, final BlockStateHolder arg1) throws WorldEditException { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return false; + } } @Override public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return false; + } } @Override public BlockState getLazyBlock(int x, int y, int z) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return null; + } } @Override public Entity createEntity(final Location arg0, final BaseEntity arg1) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return null; + } } @Override @@ -109,12 +141,20 @@ public class NullExtent extends FaweRegionExtent { @Override public boolean contains(int x, int z) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return false; + } } @Override public boolean contains(int x, int y, int z) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return false; + } } @Override @@ -135,17 +175,29 @@ public class NullExtent extends FaweRegionExtent { @Override public int getNearestSurfaceLayer(int x, int z, int y, int minY, int maxY) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return -1; + } } @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return -1; + } } @Override public int getNearestSurfaceTerrainBlock(int x, int z, int y, int minY, int maxY, int failedMin, int failedMax) { - throw new FaweException(reason); + if(reason != null) { + throw new FaweException(reason); + }else { + return -1; + } } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java index a7ced14c0..6c78edc29 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java @@ -43,29 +43,13 @@ public class PositionTransformExtent extends ResettableExtent { mutable.mutY(((pos.getY() - min.getY()))); mutable.mutZ(((pos.getZ() - min.getZ()))); MutableVector tmp = new MutableVector(transform.apply(mutable.toVector3())); - tmp.mutX((tmp.getX() + min.getX())); - tmp.mutY((tmp.getY() + min.getY())); - tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp.toBlockPoint(); - } - - private BlockVector3 getPos(int x, int y, int z) { - if (min == null) { - min = BlockVector3.at(x, y, z); - } - mutable.mutX(((x - min.getX()))); - mutable.mutY(((y - min.getY()))); - mutable.mutZ(((z - min.getZ()))); - MutableVector tmp = new MutableVector(transform.apply(mutable.toVector3())); - tmp.mutX((tmp.getX() + min.getX())); - tmp.mutY((tmp.getY() + min.getY())); - tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp.toBlockPoint(); + BlockVector3 result = min.add(tmp.toBlockPoint()); + return result; } @Override public BlockState getLazyBlock(int x, int y, int z) { - return super.getLazyBlock(getPos(x, y, z)); + return super.getLazyBlock(getPos(BlockVector3.at(x, y, z))); } @Override @@ -87,13 +71,13 @@ public class PositionTransformExtent extends ResettableExtent { } @Override - public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { - return super.setBlock(getPos(x, y, z), block); + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + return super.setBlock(getPos(BlockVector3.at(x, y, z)), block); } @Override - public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + public > boolean setBlock(BlockVector3 location, B block) throws WorldEditException { return super.setBlock(getPos(location), block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java index e2ba544e7..dca81a5cf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -542,6 +542,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return new NullExtent(extent, BBC.WORLDEDIT_CANCEL_REASON_MANUAL); } final Extent toReturn = event.getExtent(); +// if(toReturn instanceof com.sk89q.worldedit.extent.NullExtent) { +// return new NullExtent(toReturn, null); +// return new AbstractDelegateExtent(toReturn); +// }); if (!(toReturn instanceof AbstractDelegateExtent)) { Fawe.debug("Extent " + toReturn + " must be AbstractDelegateExtent"); return extent; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java index 2f6167d74..5229c3ac9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/AbstractDelegateExtent.java @@ -144,15 +144,15 @@ public class AbstractDelegateExtent implements LightingExtent { // mutable.mutZ(z); return setBlock(BlockVector3.at(x, y, z), block); } - - public BlockState getBlock(BlockVector3 position) { - return extent.getBlock(position); - } @Override public > boolean setBlock(BlockVector3 location, T block) throws WorldEditException { return extent.setBlock(location, block); } + + public BlockState getBlock(BlockVector3 position) { + return extent.getBlock(position); + } @Override @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java index cb9f1ea28..074bf9dff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/NullExtent.java @@ -108,6 +108,11 @@ public class NullExtent implements Extent { public > boolean setBlock(BlockVector3 position, B block) throws WorldEditException { return false; } + + @Override + public > boolean setBlock(int x, int y, int z, B block) throws WorldEditException { + return false; + } @Override public boolean setBiome(BlockVector2 position, BaseBiome biome) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java index bb66085d0..b6581203e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockReplace.java @@ -26,7 +26,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; - +import com.sk89q.worldedit.world.block.BaseBlock; import static com.google.common.base.Preconditions.checkNotNull; @@ -52,13 +52,6 @@ public class BlockReplace implements RegionFunction { } @Override -//<<<<<<< HEAD -// public boolean apply(Vector position) throws WorldEditException { -// return pattern.apply(extent, position, position); -//======= -// public boolean apply(BlockVector3 position) throws WorldEditException { -// return extent.setBlock(position, pattern.apply(position)); -//>>>>>>> 399e0ad5... Refactor vector system to be cleaner public boolean apply(BlockVector3 position) throws WorldEditException { return pattern.apply(extent, position, position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index 484e12734..fb3533896 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -86,7 +86,7 @@ public class RegionVisitor implements Operation { @Override public Operation resume(final RunContext run) throws WorldEditException { if (queue != null && Settings.IMP.QUEUE.PRELOAD_CHUNKS > 1) { - /* + /* * The following is done to reduce iteration cost * - Preload chunks just in time * - Only check every 16th block for potential chunk loads diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index e48145ea3..cf9a5d147 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -244,8 +244,7 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { @Override public boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { - // TODO Auto-generated method stub - return false; + return this.toImmutableState().apply(extent, get, set); } @Override