From 399e0ad5fa7637d5d3ccce7ead1ad409e85c7dd2 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 14 Oct 2018 03:40:53 -0700 Subject: [PATCH] Refactor vector system to be cleaner - Move Vector, etc. into `.math` package - Drop many methods that will be auto-promoted anyways, eg. with `divide(int)` and `divide(double)` the first is now gone. - Take Block vectors into their own class hierarchy - Make it clear throughout the API what takes blockvectors - many more improvements --- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 40 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 16 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 47 +- .../EditSessionBlockChangeDelegate.java | 10 +- .../bukkit/adapter/BukkitImplAdapter.java | 4 +- .../main/java/com/sk89q/jnbt/NBTUtils.java | 6 +- .../java/com/sk89q/util/yaml/YAMLNode.java | 40 +- .../java/com/sk89q/worldedit/BlockVector.java | 97 -- .../com/sk89q/worldedit/BlockVector2D.java | 93 -- .../java/com/sk89q/worldedit/EditSession.java | 270 +++--- .../com/sk89q/worldedit/LocalSession.java | 9 +- .../com/sk89q/worldedit/PlayerDirection.java | 27 +- .../main/java/com/sk89q/worldedit/Vector.java | 846 ------------------ .../java/com/sk89q/worldedit/Vector2D.java | 691 -------------- .../java/com/sk89q/worldedit/WorldEdit.java | 5 +- .../worldedit/command/BiomeCommands.java | 16 +- .../worldedit/command/BrushCommands.java | 4 +- .../worldedit/command/ChunkCommands.java | 14 +- .../worldedit/command/ClipboardCommands.java | 18 +- .../command/FlattenedClipboardTransform.java | 39 +- .../worldedit/command/GenerationCommands.java | 67 +- .../worldedit/command/RegionCommands.java | 41 +- .../worldedit/command/SelectionCommands.java | 98 +- .../worldedit/command/UtilityCommands.java | 16 +- .../command/argument/ItemUseParser.java | 4 +- .../command/composition/DeformCommand.java | 2 +- .../worldedit/command/tool/AreaPickaxe.java | 8 +- .../command/tool/BlockDataCyler.java | 6 +- .../worldedit/command/tool/BlockReplacer.java | 6 +- .../worldedit/command/tool/BrushTool.java | 2 +- .../worldedit/command/tool/DistanceWand.java | 11 +- .../command/tool/FloatingTreeRemover.java | 34 +- .../worldedit/command/tool/FloodFillTool.java | 25 +- .../command/tool/LongRangeBuildTool.java | 15 +- .../worldedit/command/tool/QueryTool.java | 6 +- .../command/tool/RecursivePickaxe.java | 26 +- .../worldedit/command/tool/SinglePickaxe.java | 6 +- .../worldedit/command/tool/TreePlanter.java | 2 +- .../worldedit/command/tool/brush/Brush.java | 4 +- .../command/tool/brush/ButcherBrush.java | 4 +- .../command/tool/brush/ClipboardBrush.java | 6 +- .../command/tool/brush/CylinderBrush.java | 4 +- .../command/tool/brush/GravityBrush.java | 8 +- .../tool/brush/HollowCylinderBrush.java | 4 +- .../command/tool/brush/HollowSphereBrush.java | 4 +- .../tool/brush/OperationFactoryBrush.java | 4 +- .../command/tool/brush/SmoothBrush.java | 12 +- .../command/tool/brush/SphereBrush.java | 4 +- .../com/sk89q/worldedit/entity/Player.java | 11 +- .../event/extent/EditSessionEvent.java | 4 +- .../extension/factory/DefaultBlockParser.java | 4 +- .../extension/factory/DefaultMaskParser.java | 7 +- .../platform/AbstractPlayerActor.java | 45 +- .../extension/platform/PlatformManager.java | 15 +- .../extension/platform/PlayerProxy.java | 7 +- .../extent/AbstractDelegateExtent.java | 20 +- .../worldedit/extent/ChangeSetExtent.java | 8 +- .../com/sk89q/worldedit/extent/Extent.java | 6 +- .../sk89q/worldedit/extent/InputExtent.java | 12 +- .../sk89q/worldedit/extent/MaskingExtent.java | 4 +- .../sk89q/worldedit/extent/NullExtent.java | 26 +- .../sk89q/worldedit/extent/OutputExtent.java | 8 +- .../extent/buffer/ForgetfulExtentBuffer.java | 46 +- .../extent/cache/LastAccessExtentCache.java | 17 +- .../extent/clipboard/BlockArrayClipboard.java | 38 +- .../worldedit/extent/clipboard/Clipboard.java | 8 +- .../clipboard/io/MCEditSchematicReader.java | 21 +- .../clipboard/io/SpongeSchematicReader.java | 19 +- .../clipboard/io/SpongeSchematicWriter.java | 13 +- .../extent/inventory/BlockBagExtent.java | 4 +- .../extent/reorder/ChunkBatchingExtent.java | 17 +- .../extent/reorder/MultiStageReorder.java | 27 +- .../transform/BlockTransformExtent.java | 21 +- .../extent/validation/BlockChangeLimiter.java | 4 +- .../validation/DataValidatorExtent.java | 4 +- .../extent/world/BlockQuirkExtent.java | 4 +- .../extent/world/ChunkLoadingExtent.java | 4 +- .../extent/world/FastModeExtent.java | 10 +- .../extent/world/SurvivalModeExtent.java | 4 +- .../function/CombinedRegionFunction.java | 4 +- .../function/FlatRegionFunction.java | 4 +- .../function/FlatRegionMaskingFilter.java | 6 +- .../worldedit/function/GroundFunction.java | 6 +- .../worldedit/function/LayerFunction.java | 6 +- .../worldedit/function/RegionFunction.java | 4 +- .../function/RegionMaskingFilter.java | 6 +- .../function/biome/BiomeReplace.java | 4 +- .../block/BlockDistributionCounter.java | 4 +- .../function/block/BlockReplace.java | 4 +- .../worldedit/function/block/Counter.java | 11 +- .../function/block/ExtentBlockCopy.java | 19 +- .../worldedit/function/block/Naturalizer.java | 6 +- .../function/entity/ExtentEntityCopy.java | 23 +- .../worldedit/function/factory/Deform.java | 34 +- .../function/generator/FloraGenerator.java | 4 +- .../function/generator/ForestGenerator.java | 4 +- .../generator/GardenPatchGenerator.java | 12 +- .../worldedit/function/mask/BiomeMask2D.java | 4 +- .../function/mask/BlockCategoryMask.java | 4 +- .../worldedit/function/mask/BlockMask.java | 4 +- .../function/mask/BlockTypeMask.java | 4 +- .../function/mask/BoundedHeightMask.java | 4 +- .../function/mask/ExistingBlockMask.java | 4 +- .../function/mask/ExpressionMask.java | 6 +- .../function/mask/ExpressionMask2D.java | 4 +- .../sk89q/worldedit/function/mask/Mask.java | 4 +- .../sk89q/worldedit/function/mask/Mask2D.java | 4 +- .../function/mask/MaskIntersection.java | 4 +- .../function/mask/MaskIntersection2D.java | 4 +- .../worldedit/function/mask/MaskUnion.java | 4 +- .../worldedit/function/mask/MaskUnion2D.java | 4 +- .../sk89q/worldedit/function/mask/Masks.java | 20 +- .../worldedit/function/mask/NoiseFilter.java | 6 +- .../function/mask/NoiseFilter2D.java | 6 +- .../worldedit/function/mask/OffsetMask.java | 14 +- .../worldedit/function/mask/OffsetMask2D.java | 12 +- .../worldedit/function/mask/RegionMask.java | 4 +- .../function/mask/SolidBlockMask.java | 4 +- .../function/operation/ForwardExtentCopy.java | 15 +- .../function/pattern/BlockPattern.java | 4 +- .../function/pattern/ClipboardPattern.java | 8 +- .../worldedit/function/pattern/Pattern.java | 4 +- .../function/pattern/RandomPattern.java | 4 +- .../pattern/RepeatingExtentPattern.java | 18 +- .../function/util/FlatRegionOffset.java | 12 +- .../worldedit/function/util/RegionOffset.java | 12 +- .../function/visitor/BreadthFirstSearch.java | 55 +- .../function/visitor/DownwardVisitor.java | 16 +- .../function/visitor/FlatRegionVisitor.java | 4 +- .../function/visitor/LayerVisitor.java | 10 +- .../function/visitor/NonRisingVisitor.java | 14 +- .../function/visitor/RecursiveVisitor.java | 4 +- .../function/visitor/RegionVisitor.java | 4 +- .../worldedit/history/change/BlockChange.java | 8 +- .../changeset/BlockOptimizedHistory.java | 7 +- .../internal/annotation/Direction.java | 4 +- .../command/CommandLoggingHandler.java | 6 +- .../internal/command/WorldEditBinding.java | 8 +- .../internal/cui/SelectionCylinderEvent.java | 10 +- .../cui/SelectionEllipsoidPointEvent.java | 6 +- .../internal/cui/SelectionPoint2DEvent.java | 24 +- .../internal/cui/SelectionPointEvent.java | 6 +- .../internal/cui/ServerCUIHandler.java | 4 +- .../expression/runtime/Functions.java | 8 +- .../sk89q/worldedit/math/BlockVector2.java | 529 +++++++++++ .../sk89q/worldedit/math/BlockVector3.java | 613 +++++++++++++ .../com/sk89q/worldedit/math/Vector2.java | 471 ++++++++++ .../com/sk89q/worldedit/math/Vector3.java | 596 ++++++++++++ .../worldedit/math/convolution/HeightMap.java | 16 +- .../sk89q/worldedit/math/geom/Polygons.java | 14 +- .../math/interpolation/Interpolation.java | 6 +- .../KochanekBartelsInterpolation.java | 56 +- .../interpolation/LinearInterpolation.java | 18 +- .../worldedit/math/interpolation/Node.java | 12 +- .../ReparametrisingInterpolation.java | 6 +- .../math/noise/JLibNoiseGenerator.java | 9 +- .../worldedit/math/noise/NoiseGenerator.java | 8 +- .../worldedit/math/noise/RandomNoise.java | 8 +- .../math/transform/AffineTransform.java | 15 +- .../math/transform/CombinedTransform.java | 4 +- .../worldedit/math/transform/Identity.java | 4 +- .../worldedit/math/transform/Transform.java | 6 +- .../worldedit/regions/AbstractRegion.java | 83 +- .../regions/ConvexPolyhedralRegion.java | 80 +- .../sk89q/worldedit/regions/CuboidRegion.java | 197 ++-- .../worldedit/regions/CylinderRegion.java | 94 +- .../worldedit/regions/EllipsoidRegion.java | 77 +- .../sk89q/worldedit/regions/FlatRegion.java | 4 +- .../sk89q/worldedit/regions/NullRegion.java | 44 +- .../worldedit/regions/Polygonal2DRegion.java | 89 +- .../com/sk89q/worldedit/regions/Region.java | 29 +- .../worldedit/regions/RegionIntersection.java | 25 +- .../worldedit/regions/RegionSelector.java | 13 +- .../worldedit/regions/TransformRegion.java | 48 +- .../regions/factory/CuboidRegionFactory.java | 4 +- .../factory/CylinderRegionFactory.java | 8 +- .../regions/factory/RegionFactory.java | 4 +- .../regions/factory/SphereRegionFactory.java | 7 +- .../iterator/FlatRegion3DIterator.java | 16 +- .../regions/iterator/FlatRegionIterator.java | 24 +- .../regions/iterator/RegionIterator.java | 15 +- .../worldedit/regions/polyhedron/Edge.java | 12 +- .../regions/polyhedron/Triangle.java | 16 +- .../ConvexPolyhedralRegionSelector.java | 35 +- .../selector/CuboidRegionSelector.java | 41 +- .../selector/CylinderRegionSelector.java | 55 +- .../selector/EllipsoidRegionSelector.java | 48 +- .../ExtendingCuboidRegionSelector.java | 33 +- .../selector/Polygonal2DRegionSelector.java | 39 +- .../selector/SphereRegionSelector.java | 19 +- .../regions/shape/ArbitraryBiomeShape.java | 10 +- .../regions/shape/ArbitraryShape.java | 4 +- .../worldedit/regions/shape/RegionShape.java | 4 +- .../shape/WorldEditExpressionEnvironment.java | 20 +- .../sk89q/worldedit/session/PasteBuilder.java | 6 +- .../session/request/RequestSelection.java | 29 +- .../com/sk89q/worldedit/util/Direction.java | 60 +- .../sk89q/worldedit/util/LocatedBlock.java | 8 +- .../com/sk89q/worldedit/util/Location.java | 83 +- .../com/sk89q/worldedit/util/TargetBlock.java | 27 +- .../sk89q/worldedit/util/TreeGenerator.java | 24 +- .../util/collection/LocatedBlockList.java | 4 +- .../sk89q/worldedit/util/gson/GsonUtil.java | 4 +- .../worldedit/util/gson/VectorAdapter.java | 8 +- .../sk89q/worldedit/world/AbstractWorld.java | 35 +- .../com/sk89q/worldedit/world/NullWorld.java | 25 +- .../java/com/sk89q/worldedit/world/World.java | 37 +- .../worldedit/world/chunk/AnvilChunk.java | 29 +- .../worldedit/world/chunk/AnvilChunk13.java | 19 +- .../sk89q/worldedit/world/chunk/Chunk.java | 4 +- .../sk89q/worldedit/world/chunk/OldChunk.java | 21 +- .../world/registry/BundledBlockData.java | 4 +- .../world/registry/BundledItemData.java | 4 +- .../world/registry/LegacyMapper.java | 4 +- .../world/snapshot/SnapshotRestore.java | 34 +- .../worldedit/world/storage/ChunkStore.java | 16 +- .../world/storage/LegacyChunkStore.java | 9 +- .../world/storage/McRegionChunkStore.java | 9 +- .../world/storage/McRegionReader.java | 4 +- .../world/storage/MissingChunkException.java | 8 +- .../java/com/sk89q/worldedit/VectorTest.java | 152 ---- .../sk89q/worldedit/util/LocationTest.java | 22 +- .../sk89q/worldedit/forge/ForgeAdapter.java | 15 +- .../sk89q/worldedit/forge/ForgeEntity.java | 4 +- .../sk89q/worldedit/forge/ForgePlayer.java | 15 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 51 +- .../worldedit/forge/TileEntityUtils.java | 11 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 8 +- .../sk89q/worldedit/sponge/SpongeWorld.java | 24 +- .../sponge/adapter/SpongeImplAdapter.java | 5 +- 230 files changed, 4216 insertions(+), 3913 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java delete mode 100644 worldedit-core/src/test/java/com/sk89q/worldedit/VectorTest.java diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java index 2f30ed2e9..ddb2c2e26 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitAdapter.java @@ -23,13 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.base.Function; import com.sk89q.worldedit.NotABlockException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -42,6 +43,7 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.data.BlockData; @@ -159,7 +161,7 @@ public class BukkitAdapter { */ public static Location adapt(org.bukkit.Location location) { checkNotNull(location); - Vector position = asVector(location); + Vector3 position = asVector(location); return new com.sk89q.worldedit.util.Location( adapt(location.getWorld()), position, @@ -175,7 +177,7 @@ public class BukkitAdapter { */ public static org.bukkit.Location adapt(Location location) { checkNotNull(location); - Vector position = location.toVector(); + Vector3 position = location.toVector(); return new org.bukkit.Location( adapt((World) location.getExtent()), position.getX(), position.getY(), position.getZ(), @@ -190,7 +192,22 @@ public class BukkitAdapter { * @param position the WorldEdit position * @return a Bukkit location */ - public static org.bukkit.Location adapt(org.bukkit.World world, Vector position) { + public static org.bukkit.Location adapt(org.bukkit.World world, Vector3 position) { + checkNotNull(world); + checkNotNull(position); + return new org.bukkit.Location( + world, + position.getX(), position.getY(), position.getZ()); + } + + /** + * Create a Bukkit location from a WorldEdit position with a Bukkit world. + * + * @param world the Bukkit world + * @param position the WorldEdit position + * @return a Bukkit location + */ + public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) { checkNotNull(world); checkNotNull(position); return new org.bukkit.Location( @@ -221,9 +238,20 @@ public class BukkitAdapter { * @param location The Bukkit location * @return a WorldEdit vector */ - public static Vector asVector(org.bukkit.Location location) { + public static Vector3 asVector(org.bukkit.Location location) { checkNotNull(location); - return new Vector(location.getX(), location.getY(), location.getZ()); + return new Vector3(location.getX(), location.getY(), location.getZ()); + } + + /** + * Create a WorldEdit BlockVector from a Bukkit location. + * + * @param location The Bukkit location + * @return a WorldEdit vector + */ + public static BlockVector3 asBlockVector(org.bukkit.Location location) { + checkNotNull(location); + return new BlockVector3(location.getX(), location.getY(), location.getZ()); } /** diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 46a0564a6..d5db5ca53 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -20,22 +20,24 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItemStack; +import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; + import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -115,7 +117,7 @@ public class BukkitPlayer extends AbstractPlayerActor { } @Override - public void setPosition(Vector pos, float pitch, float yaw) { + public void setPosition(Vector3 pos, float pitch, float yaw) { player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ(), yaw, pitch)); } @@ -173,7 +175,7 @@ public class BukkitPlayer extends AbstractPlayerActor { return; } - setPosition(new Vector(x + 0.5, y, z + 0.5)); + setPosition(new Vector3(x + 0.5, y, z + 0.5)); player.setFlying(true); } @@ -185,7 +187,7 @@ public class BukkitPlayer extends AbstractPlayerActor { @Override public com.sk89q.worldedit.util.Location getLocation() { Location nativeLocation = player.getLocation(); - Vector position = BukkitAdapter.asVector(nativeLocation); + Vector3 position = BukkitAdapter.asVector(nativeLocation); return new com.sk89q.worldedit.util.Location( getWorld(), position, @@ -243,7 +245,7 @@ public class BukkitPlayer extends AbstractPlayerActor { } @Override - public void sendFakeBlock(Vector pos, BlockStateHolder block) { + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ()); if (block == null) { player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java index d8956542d..ad1cb83c2 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java @@ -21,16 +21,16 @@ package com.sk89q.worldedit.bukkit; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.history.change.BlockChange; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.AbstractWorld; @@ -39,6 +39,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; + import org.bukkit.Effect; import org.bukkit.TreeType; import org.bukkit.World; @@ -90,7 +91,7 @@ public class BukkitWorld extends AbstractWorld { List ents = world.getEntities(); List entities = new ArrayList<>(); for (Entity ent : ents) { - if (region.contains(BukkitAdapter.asVector(ent.getLocation()))) { + if (region.contains(BukkitAdapter.asBlockVector(ent.getLocation()))) { entities.add(BukkitAdapter.adapt(ent)); } } @@ -159,7 +160,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public int getBlockLightLevel(Vector pt) { + public int getBlockLightLevel(BlockVector3 pt) { return getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).getLightLevel(); } @@ -167,14 +168,14 @@ public class BukkitWorld extends AbstractWorld { public boolean regenerate(Region region, EditSession editSession) { BlockStateHolder[] history = new BlockStateHolder[16 * 16 * (getMaxY() + 1)]; - for (Vector2D chunk : region.getChunks()) { - Vector min = new Vector(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); + for (BlockVector2 chunk : region.getChunks()) { + BlockVector3 min = new BlockVector3(chunk.getBlockX() * 16, 0, chunk.getBlockZ() * 16); // First save all the blocks inside for (int x = 0; x < 16; ++x) { for (int y = 0; y < (getMaxY() + 1); ++y) { for (int z = 0; z < 16; ++z) { - Vector pt = min.add(x, y, z); + BlockVector3 pt = min.add(x, y, z); int index = y * 16 * 16 + z * 16 + x; history[index] = editSession.getFullBlock(pt); } @@ -191,14 +192,14 @@ public class BukkitWorld extends AbstractWorld { for (int x = 0; x < 16; ++x) { for (int y = 0; y < (getMaxY() + 1); ++y) { for (int z = 0; z < 16; ++z) { - Vector pt = min.add(x, y, z); + BlockVector3 pt = min.add(x, y, z); int index = y * 16 * 16 + z * 16 + x; // We have to restore the block if it was outside if (!region.contains(pt)) { editSession.smartSetBlock(pt, history[index]); } else { // Otherwise fool with history - editSession.getChangeSet().add(new BlockChange(pt.toBlockVector(), history[index], editSession.getFullBlock(pt))); + editSession.getChangeSet().add(new BlockChange(pt, history[index], editSession.getFullBlock(pt))); } } } @@ -237,7 +238,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public boolean clearContainerBlockContents(Vector pt) { + public boolean clearContainerBlockContents(BlockVector3 pt) { Block block = getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); if (block == null) { return false; @@ -291,7 +292,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector pt) { + public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 pt) { World world = getWorld(); TreeType bukkitType = toBukkitTreeType(type); return type != null && world.generateTree(BukkitAdapter.adapt(world, pt), bukkitType, @@ -299,13 +300,13 @@ public class BukkitWorld extends AbstractWorld { } @Override - public void dropItem(Vector pt, BaseItemStack item) { + public void dropItem(Vector3 pt, BaseItemStack item) { World world = getWorld(); world.dropItemNaturally(BukkitAdapter.adapt(world, pt), BukkitAdapter.adapt(item)); } @Override - public void checkLoadedChunk(Vector pt) { + public void checkLoadedChunk(BlockVector3 pt) { World world = getWorld(); if (!world.isChunkLoaded(pt.getBlockX() >> 4, pt.getBlockZ() >> 4)) { @@ -337,15 +338,15 @@ public class BukkitWorld extends AbstractWorld { } @Override - public void fixAfterFastMode(Iterable chunks) { + public void fixAfterFastMode(Iterable chunks) { World world = getWorld(); - for (BlockVector2D chunkPos : chunks) { + for (BlockVector2 chunkPos : chunks) { world.refreshChunk(chunkPos.getBlockX(), chunkPos.getBlockZ()); } } @Override - public boolean playEffect(Vector position, int type, int data) { + public boolean playEffect(Vector3 position, int type, int data) { World world = getWorld(); final Effect effect = effects.get(type); @@ -404,18 +405,18 @@ public class BukkitWorld extends AbstractWorld { } @Override - public void simulateBlockMine(Vector pt) { + public void simulateBlockMine(BlockVector3 pt) { getWorld().getBlockAt(pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()).breakNaturally(); } @Override - public com.sk89q.worldedit.world.block.BlockState getBlock(Vector position) { + public com.sk89q.worldedit.world.block.BlockState getBlock(BlockVector3 position) { Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ()); return BukkitAdapter.adapt(bukkitBlock.getBlockData()); } @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { @@ -438,7 +439,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); @@ -448,7 +449,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { int id = adapter.getBiomeId(getWorld().getBiome(position.getBlockX(), position.getBlockZ())); @@ -459,7 +460,7 @@ public class BukkitWorld extends AbstractWorld { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { Biome bukkitBiome = adapter.getBiome(biome.getId()); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java index 97fa2b170..35b3afe50 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.bukkit; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.world.block.BlockTypes; +import com.sk89q.worldedit.math.BlockVector3; + import org.bukkit.BlockChangeDelegate; import org.bukkit.block.data.BlockData; @@ -40,7 +40,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public boolean setBlockData(int x, int y, int z, BlockData blockData) { try { - editSession.setBlock(new Vector(x, y, z), BukkitAdapter.adapt(blockData)); + editSession.setBlock(new BlockVector3(x, y, z), BukkitAdapter.adapt(blockData)); } catch (MaxChangedBlocksException e) { return false; } @@ -49,7 +49,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public BlockData getBlockData(int x, int y, int z) { - return BukkitAdapter.adapt(editSession.getBlock(new Vector(x, y, z))); + return BukkitAdapter.adapt(editSession.getBlock(new BlockVector3(x, y, z))); } @Override @@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate { @Override public boolean isEmpty(int x, int y, int z) { - return editSession.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isAir(); + return editSession.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isAir(); } } diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java index e08f9daf5..393877581 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/BukkitImplAdapter.java @@ -20,9 +20,9 @@ package com.sk89q.worldedit.bukkit.adapter; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -112,7 +112,7 @@ public interface BukkitImplAdapter { * @param pos The position * @param nbtData The NBT Data */ - void sendFakeNBT(Player player, Vector pos, CompoundTag nbtData); + void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData); /** * Make the client think it has operator status. diff --git a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java index e44262911..d0fdaae58 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java @@ -21,7 +21,7 @@ package com.sk89q.jnbt; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.storage.InvalidFormatException; import java.util.Map; @@ -167,9 +167,9 @@ public final class NBTUtils { * @param listTag the list tag * @return a vector */ - public static Vector toVector(ListTag listTag) { + public static Vector3 toVector(ListTag listTag) { checkNotNull(listTag); - return new Vector(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2)); + return new Vector3(listTag.asDouble(0), listTag.asDouble(1), listTag.asDouble(2)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java index d0e5fc0c7..158b72074 100644 --- a/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java +++ b/worldedit-core/src/main/java/com/sk89q/util/yaml/YAMLNode.java @@ -19,9 +19,9 @@ package com.sk89q.util.yaml; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import java.util.ArrayList; import java.util.LinkedHashMap; @@ -111,9 +111,9 @@ public class YAMLNode { * @return the new object */ private Object prepareSerialization(Object value) { - if (value instanceof Vector) { + if (value instanceof Vector3) { Map out = new LinkedHashMap<>(); - Vector vec = (Vector) value; + Vector3 vec = (Vector3) value; out.put("x", vec.getX()); out.put("y", vec.getY()); out.put("z", vec.getZ()); @@ -201,7 +201,7 @@ public class YAMLNode { * @param path path to node (dot notation) * @return string or default */ - public Vector getVector(String path) { + public Vector3 getVector(String path) { YAMLNode o = getNode(path); if (o == null) { return null; @@ -215,7 +215,7 @@ public class YAMLNode { return null; } - return new Vector(x, y, z); + return new Vector3(x, y, z); } /** @@ -226,7 +226,7 @@ public class YAMLNode { * @param path path to node (dot notation) * @return string or default */ - public Vector2D getVector2d(String path) { + public Vector2 getVector2(String path) { YAMLNode o = getNode(path); if (o == null) { return null; @@ -239,7 +239,7 @@ public class YAMLNode { return null; } - return new Vector2D(x, z); + return new Vector2(x, z); } /** @@ -251,8 +251,8 @@ public class YAMLNode { * @param def default value * @return string or default */ - public Vector getVector(String path, Vector def) { - Vector v = getVector(path); + public Vector3 getVector(String path, Vector3 def) { + Vector3 v = getVector(path); if (v == null) { if (writeDefaults) setProperty(path, def); return def; @@ -558,9 +558,9 @@ public class YAMLNode { * @param def default value or null for an empty list as default * @return list of integers */ - public List getVectorList(String path, List def) { + public List getVectorList(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -571,7 +571,7 @@ public class YAMLNode { continue; } - list.add(new Vector(x, y, z)); + list.add(new Vector3(x, y, z)); } return list; @@ -588,10 +588,10 @@ public class YAMLNode { * @param def default value or null for an empty list as default * @return list of integers */ - public List getVector2dList(String path, List def) { + public List getVector2List(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -601,7 +601,7 @@ public class YAMLNode { continue; } - list.add(new Vector2D(x, z)); + list.add(new Vector2(x, z)); } return list; @@ -618,10 +618,10 @@ public class YAMLNode { * @param def default value or null for an empty list as default * @return list of integers */ - public List getBlockVector2dList(String path, List def) { + public List getBlockVector2List(String path, List def) { List raw = getNodeList(path, null); - List list = new ArrayList<>(); + List list = new ArrayList<>(); for (YAMLNode o : raw) { Double x = o.getDouble("x"); @@ -631,7 +631,7 @@ public class YAMLNode { continue; } - list.add(new BlockVector2D(x, z)); + list.add(new BlockVector2(x, z)); } return list; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java deleted file mode 100644 index c444d80d1..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * 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 . - */ - -package com.sk89q.worldedit; - -/** - * Extension of {@code Vector} that that compares with other instances - * using integer components. - */ -public class BlockVector extends Vector { - - public static final BlockVector ZERO = new BlockVector(0, 0, 0); - public static final BlockVector UNIT_X = new BlockVector(1, 0, 0); - public static final BlockVector UNIT_Y = new BlockVector(0, 1, 0); - public static final BlockVector UNIT_Z = new BlockVector(0, 0, 1); - public static final BlockVector ONE = new BlockVector(1, 1, 1); - - /** - * Construct an instance as a copy of another instance. - * - * @param position the other position - */ - public BlockVector(Vector position) { - super(position); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public BlockVector(int x, int y, int z) { - super(x, y, z); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public BlockVector(float x, float y, float z) { - super(x, y, z); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public BlockVector(double x, double y, double z) { - super(x, y, z); - } - - @Override - public int hashCode() { - return ((int) x ^ ((int) z << 12)) ^ ((int) y << 24); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector)) { - return false; - } - Vector other = (Vector) obj; - return (int) other.getX() == (int) this.x && (int) other.getY() == (int) this.y - && (int) other.getZ() == (int) this.z; - - } - - @Override - public BlockVector toBlockVector() { - return this; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java deleted file mode 100644 index 07d54430b..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector2D.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * 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 . - */ - -package com.sk89q.worldedit; - -/** - * Extension of {@code Vector2D} that that compares with other instances - * using integer components. - */ -public class BlockVector2D extends Vector2D { - - public static final BlockVector2D ZERO = new BlockVector2D(0, 0); - public static final BlockVector2D UNIT_X = new BlockVector2D(1, 0); - public static final BlockVector2D UNIT_Z = new BlockVector2D(0, 1); - public static final BlockVector2D ONE = new BlockVector2D(1, 1); - - /** - * Construct an instance from another instance. - * - * @param position the position to copy - */ - public BlockVector2D(Vector2D position) { - super(position); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public BlockVector2D(int x, int z) { - super(x, z); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public BlockVector2D(float x, float z) { - super(x, z); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public BlockVector2D(double x, double z) { - super(x, z); - } - - @Override - public int hashCode() { - return ((int) x << 16) ^ (int) z; - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector2D)) { - return false; - } - - Vector2D other = (Vector2D) obj; - return (int) other.x == (int) this.x && (int) other.z == (int) this.z; - - } - - @Override - public BlockVector2D toBlockVector2D() { - return this; - } - -} 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 bc98a20e3..2e896a221 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -25,8 +25,6 @@ import static com.sk89q.worldedit.regions.Regions.asFlatRegion; import static com.sk89q.worldedit.regions.Regions.maximumBlockY; import static com.sk89q.worldedit.regions.Regions.minimumBlockY; -import com.sk89q.worldedit.function.block.BlockDistributionCounter; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.event.extent.EditSessionEvent; @@ -48,6 +46,7 @@ import com.sk89q.worldedit.extent.world.FastModeExtent; import com.sk89q.worldedit.extent.world.SurvivalModeExtent; import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.RegionMaskingFilter; +import com.sk89q.worldedit.function.block.BlockDistributionCounter; import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.block.Counter; import com.sk89q.worldedit.function.block.Naturalizer; @@ -81,7 +80,11 @@ import com.sk89q.worldedit.history.changeset.ChangeSet; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.runtime.RValue; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MathUtils; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Interpolation; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.Node; @@ -113,8 +116,6 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.registry.LegacyMapper; import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.LinkedList; import java.util.List; @@ -139,7 +140,7 @@ public class EditSession implements Extent, AutoCloseable { private static final Logger log = Logger.getLogger(EditSession.class.getCanonicalName()); /** - * Used by {@link #setBlock(Vector, BlockStateHolder, Stage)} to + * Used by {@link EditSession#setBlock(BlockVector3, BlockStateHolder, Stage)} to * determine which {@link Extent}s should be bypassed. */ public enum Stage { @@ -451,22 +452,22 @@ public class EditSession implements Extent, AutoCloseable { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return bypassNone.getBiome(position); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return bypassNone.setBiome(position, biome); } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return world.getBlock(position); } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { return world.getFullBlock(position); } @@ -481,7 +482,7 @@ public class EditSession implements Extent, AutoCloseable { */ public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { for (int y = maxY; y >= minY; --y) { - Vector pt = new Vector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); BlockState block = getBlock(pt); if (block.getBlockType().getMaterial().isMovementBlocker()) { return y; @@ -500,7 +501,7 @@ public class EditSession implements Extent, AutoCloseable { * @return whether the block changed * @throws WorldEditException thrown on a set error */ - public boolean setBlock(Vector position, BlockStateHolder block, Stage stage) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, Stage stage) throws WorldEditException { switch (stage) { case BEFORE_HISTORY: return bypassNone.setBlock(position, block); @@ -520,7 +521,7 @@ public class EditSession implements Extent, AutoCloseable { * @param block the block * @return whether the block changed */ - public boolean rawSetBlock(Vector position, BlockStateHolder block) { + public boolean rawSetBlock(BlockVector3 position, BlockStateHolder block) { try { return setBlock(position, block, Stage.BEFORE_CHANGE); } catch (WorldEditException e) { @@ -535,7 +536,7 @@ public class EditSession implements Extent, AutoCloseable { * @param block the block * @return whether the block changed */ - public boolean smartSetBlock(Vector position, BlockStateHolder block) { + public boolean smartSetBlock(BlockVector3 position, BlockStateHolder block) { try { return setBlock(position, block, Stage.BEFORE_REORDER); } catch (WorldEditException e) { @@ -544,7 +545,7 @@ public class EditSession implements Extent, AutoCloseable { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws MaxChangedBlocksException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException { try { return setBlock(position, block, Stage.BEFORE_HISTORY); } catch (MaxChangedBlocksException e) { @@ -562,7 +563,7 @@ public class EditSession implements Extent, AutoCloseable { * @return Whether the block changed -- not entirely dependable * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public boolean setBlock(Vector position, Pattern pattern) throws MaxChangedBlocksException { + public boolean setBlock(BlockVector3 position, Pattern pattern) throws MaxChangedBlocksException { return setBlock(position, pattern.apply(position)); } @@ -575,9 +576,9 @@ public class EditSession implements Extent, AutoCloseable { * @return the number of changed blocks * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - private int setBlocks(Set vset, Pattern pattern) throws MaxChangedBlocksException { + private int setBlocks(Set vset, Pattern pattern) throws MaxChangedBlocksException { int affected = 0; - for (Vector v : vset) { + for (BlockVector3 v : vset) { affected += setBlock(v, pattern) ? 1 : 0; } return affected; @@ -623,12 +624,12 @@ public class EditSession implements Extent, AutoCloseable { } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return getWorld().getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return getWorld().getMaximumPoint(); } @@ -690,7 +691,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fillXZ(Vector origin, BlockStateHolder block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { + public int fillXZ(BlockVector3 origin, BlockStateHolder block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { return fillXZ(origin, new BlockPattern(block), radius, depth, recursive); } @@ -705,14 +706,14 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fillXZ(Vector origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { + public int fillXZ(BlockVector3 origin, Pattern pattern, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { checkNotNull(origin); checkNotNull(pattern); checkArgument(radius >= 0, "radius >= 0"); checkArgument(depth >= 1, "depth >= 1"); MaskIntersection mask = new MaskIntersection( - new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), + new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), new BoundedHeightMask( Math.max(origin.getBlockY() - depth + 1, 0), Math.min(getWorld().getMaxY(), origin.getBlockY())), @@ -747,7 +748,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int removeAbove(Vector position, int apothem, int height) throws MaxChangedBlocksException { + public int removeAbove(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(height >= 1, "height >= 1"); @@ -769,7 +770,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int removeBelow(Vector position, int apothem, int height) throws MaxChangedBlocksException { + public int removeBelow(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(height >= 1, "height >= 1"); @@ -791,12 +792,12 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int removeNear(Vector position, BlockType blockType, int apothem) throws MaxChangedBlocksException { + public int removeNear(BlockVector3 position, BlockType blockType, int apothem) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); Mask mask = new BlockTypeMask(this, blockType); - Vector adjustment = new Vector(1, 1, 1).multiply(apothem - 1); + BlockVector3 adjustment = BlockVector3.ONE.multiply(apothem - 1); Region region = new CuboidRegion( getWorld(), // Causes clamping of Y range position.add(adjustment.multiply(-1)), @@ -900,11 +901,11 @@ public class EditSession implements Extent, AutoCloseable { checkNotNull(region); checkNotNull(pattern); - Vector center = region.getCenter(); + Vector3 center = region.getCenter(); Region centerRegion = new CuboidRegion( getWorld(), // Causes clamping of Y range - new Vector(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())), - new Vector(MathUtils.roundHalfUp(center.getX()), + new BlockVector3(((int) center.getX()), ((int) center.getY()), ((int) center.getZ())), + new BlockVector3(MathUtils.roundHalfUp(center.getX()), center.getY(), MathUtils.roundHalfUp(center.getZ()))); return setBlocks(centerRegion, pattern); } @@ -1054,7 +1055,7 @@ public class EditSession implements Extent, AutoCloseable { checkNotNull(pattern); BlockReplace replace = new BlockReplace(this, pattern); - RegionOffset offset = new RegionOffset(new Vector(0, 1, 0), replace); + RegionOffset offset = new RegionOffset(new BlockVector3(0, 1, 0), replace); GroundFunction ground = new GroundFunction(new ExistingBlockMask(this), offset); LayerVisitor visitor = new LayerVisitor(asFlatRegion(region), minimumBlockY(region), maximumBlockY(region), ground); Operations.completeLegacy(visitor); @@ -1089,13 +1090,13 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int stackCuboidRegion(Region region, Vector dir, int count, boolean copyAir) throws MaxChangedBlocksException { + public int stackCuboidRegion(Region region, BlockVector3 dir, int count, boolean copyAir) throws MaxChangedBlocksException { checkNotNull(region); checkNotNull(dir); checkArgument(count >= 1, "count >= 1 required"); - Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); - Vector to = region.getMinimumPoint(); + BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); + BlockVector3 to = region.getMinimumPoint(); ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to); copy.setRepetitions(count); copy.setTransform(new AffineTransform().translate(dir.multiply(size))); @@ -1117,12 +1118,12 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks moved * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int moveRegion(Region region, Vector dir, int distance, boolean copyAir, BlockStateHolder replacement) throws MaxChangedBlocksException { + public int moveRegion(Region region, BlockVector3 dir, int distance, boolean copyAir, BlockStateHolder replacement) throws MaxChangedBlocksException { checkNotNull(region); checkNotNull(dir); checkArgument(distance >= 1, "distance >= 1 required"); - Vector to = region.getMinimumPoint(); + BlockVector3 to = region.getMinimumPoint(); // Remove the original blocks com.sk89q.worldedit.function.pattern.Pattern pattern = replacement != null ? @@ -1161,7 +1162,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks moved * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int moveCuboidRegion(Region region, Vector dir, int distance, boolean copyAir, BlockStateHolder replacement) throws MaxChangedBlocksException { + public int moveCuboidRegion(Region region, BlockVector3 dir, int distance, boolean copyAir, BlockStateHolder replacement) throws MaxChangedBlocksException { return moveRegion(region, dir, distance, copyAir, replacement); } @@ -1173,20 +1174,20 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drainArea(Vector origin, double radius) throws MaxChangedBlocksException { + public int drainArea(BlockVector3 origin, double radius) throws MaxChangedBlocksException { checkNotNull(origin); checkArgument(radius >= 0, "radius >= 0 required"); MaskIntersection mask = new MaskIntersection( new BoundedHeightMask(0, getWorld().getMaxY()), - new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), + new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), getWorld().createLiquidMask()); BlockReplace replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState())); RecursiveVisitor visitor = new RecursiveVisitor(mask, replace); // Around the origin in a 3x3 block - for (BlockVector position : CuboidRegion.fromCenter(origin, 1)) { + for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { if (mask.test(position)) { visitor.visit(position); } @@ -1206,7 +1207,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fixLiquid(Vector origin, double radius, BlockType fluid) throws MaxChangedBlocksException { + public int fixLiquid(BlockVector3 origin, double radius, BlockType fluid) throws MaxChangedBlocksException { checkNotNull(origin); checkArgument(radius >= 0, "radius >= 0 required"); @@ -1219,7 +1220,7 @@ public class EditSession implements Extent, AutoCloseable { // There are boundaries that the routine needs to stay in MaskIntersection mask = new MaskIntersection( new BoundedHeightMask(0, Math.min(origin.getBlockY(), getWorld().getMaxY())), - new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), + new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), blockMask ); @@ -1227,7 +1228,7 @@ public class EditSession implements Extent, AutoCloseable { NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block - for (BlockVector position : CuboidRegion.fromCenter(origin, 1)) { + for (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { if (liquidMask.test(position)) { visitor.visit(position); } @@ -1249,7 +1250,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCylinder(Vector pos, Pattern block, double radius, int height, boolean filled) throws MaxChangedBlocksException { + public int makeCylinder(BlockVector3 pos, Pattern block, double radius, int height, boolean filled) throws MaxChangedBlocksException { return makeCylinder(pos, block, radius, radius, height, filled); } @@ -1265,7 +1266,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCylinder(Vector pos, Pattern block, double radiusX, double radiusZ, int height, boolean filled) throws MaxChangedBlocksException { + public int makeCylinder(BlockVector3 pos, Pattern block, double radiusX, double radiusZ, int height, boolean filled) throws MaxChangedBlocksException { int affected = 0; radiusX += 0.5; @@ -1279,7 +1280,7 @@ public class EditSession implements Extent, AutoCloseable { } if (pos.getBlockY() < 0) { - pos = pos.setY(0); + pos = pos.withY(0); } else if (pos.getBlockY() + height - 1 > world.getMaxY()) { height = world.getMaxY() - pos.getBlockY() + 1; } @@ -1343,7 +1344,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeSphere(Vector pos, Pattern block, double radius, boolean filled) throws MaxChangedBlocksException { + public int makeSphere(BlockVector3 pos, Pattern block, double radius, boolean filled) throws MaxChangedBlocksException { return makeSphere(pos, block, radius, radius, radius, filled); } @@ -1359,7 +1360,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeSphere(Vector pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException { + public int makeSphere(BlockVector3 pos, Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled) throws MaxChangedBlocksException { int affected = 0; radiusX += 0.5; @@ -1445,7 +1446,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePyramid(Vector position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException { + public int makePyramid(BlockVector3 position, Pattern block, int size, boolean filled) throws MaxChangedBlocksException { int affected = 0; int height = size; @@ -1485,7 +1486,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int thaw(Vector position, double radius) + public int thaw(BlockVector3 position, double radius) throws MaxChangedBlocksException { int affected = 0; double radiusSq = radius * radius; @@ -1500,12 +1501,12 @@ public class EditSession implements Extent, AutoCloseable { int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { - if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) { + if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { continue; } for (int y = world.getMaxY(); y >= 1; --y) { - Vector pt = new Vector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); BlockType id = getBlock(pt).getBlockType(); if (id == BlockTypes.ICE) { @@ -1536,7 +1537,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int simulateSnow(Vector position, double radius) throws MaxChangedBlocksException { + public int simulateSnow(BlockVector3 position, double radius) throws MaxChangedBlocksException { int affected = 0; double radiusSq = radius * radius; @@ -1550,12 +1551,12 @@ public class EditSession implements Extent, AutoCloseable { int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { - if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) { + if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { continue; } for (int y = world.getMaxY(); y >= 1; --y) { - Vector pt = new Vector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); BlockType id = getBlock(pt).getBlockType(); if (id.getMaterial().isAir()) { @@ -1604,7 +1605,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int green(Vector position, double radius, boolean onlyNormalDirt) + public int green(BlockVector3 position, double radius, boolean onlyNormalDirt) throws MaxChangedBlocksException { int affected = 0; final double radiusSq = radius * radius; @@ -1618,12 +1619,12 @@ public class EditSession implements Extent, AutoCloseable { final int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { - if ((new Vector(x, oy, z)).distanceSq(position) > radiusSq) { + if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { continue; } for (int y = world.getMaxY(); y >= 1; --y) { - final Vector pt = new Vector(x, y, z); + final BlockVector3 pt = new BlockVector3(x, y, z); final BlockState block = getBlock(pt); if (block.getBlockType() == BlockTypes.DIRT || @@ -1652,7 +1653,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of patches created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePumpkinPatches(Vector position, int apothem) throws MaxChangedBlocksException { + public int makePumpkinPatches(BlockVector3 position, int apothem) throws MaxChangedBlocksException { // We want to generate pumpkins GardenPatchGenerator generator = new GardenPatchGenerator(this); generator.setPlant(GardenPatchGenerator.getPumpkinPattern()); @@ -1681,7 +1682,7 @@ public class EditSession implements Extent, AutoCloseable { * @return number of trees created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeForest(Vector basePosition, int size, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException { + public int makeForest(BlockVector3 basePosition, int size, double density, TreeGenerator.TreeType treeType) throws MaxChangedBlocksException { int affected = 0; for (int x = basePosition.getBlockX() - size; x <= basePosition.getBlockX() @@ -1689,7 +1690,7 @@ public class EditSession implements Extent, AutoCloseable { for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ() + size; ++z) { // Don't want to be in the ground - if (!getBlock(new Vector(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) { + if (!getBlock(new BlockVector3(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) { continue; } // The gods don't want a tree here @@ -1699,13 +1700,13 @@ public class EditSession implements Extent, AutoCloseable { for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) { // Check if we hit the ground - BlockType t = getBlock(new Vector(x, y, z)).getBlockType(); + BlockType t = getBlock(new BlockVector3(x, y, z)).getBlockType(); if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { - treeType.generate(this, new Vector(x, y + 1, z)); + treeType.generate(this, new BlockVector3(x, y + 1, z)); ++affected; break; } else if (t == BlockTypes.SNOW) { - setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState()); + setBlock(new BlockVector3(x, y, z), BlockTypes.AIR.getDefaultState()); } else if (!t.getMaterial().isAir()) { // Trees won't grow on this! break; } @@ -1729,7 +1730,7 @@ public class EditSession implements Extent, AutoCloseable { return count.getDistribution(); } - public int makeShape(final Region region, final Vector zero, final Vector unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException { + public int makeShape(final Region region, final Vector3 zero, final Vector3 unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException { final Expression expression = Expression.compile(expressionString, "x", "y", "z", "type", "data"); expression.optimize(); @@ -1742,9 +1743,9 @@ public class EditSession implements Extent, AutoCloseable { final ArbitraryShape shape = new ArbitraryShape(region) { @Override protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) { - final Vector current = new Vector(x, y, z); + final Vector3 current = new Vector3(x, y, z); environment.setCurrentBlock(current); - final Vector scaled = current.subtract(zero).divide(unit); + final Vector3 scaled = current.subtract(zero).divide(unit); try { if (expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ(), defaultMaterial.getBlockType().getLegacyId(), 0) <= 0) { @@ -1763,7 +1764,7 @@ public class EditSession implements Extent, AutoCloseable { return shape.generate(this, pattern, hollow); } - public int deformRegion(final Region region, final Vector zero, final Vector unit, final String expressionString) throws ExpressionException, MaxChangedBlocksException { + public int deformRegion(final Region region, final Vector3 zero, final Vector3 unit, final String expressionString) throws ExpressionException, MaxChangedBlocksException { final Expression expression = Expression.compile(expressionString, "x", "y", "z"); expression.optimize(); @@ -1774,16 +1775,16 @@ public class EditSession implements Extent, AutoCloseable { final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero); expression.setEnvironment(environment); - final DoubleArrayList queue = new DoubleArrayList<>(false); + final DoubleArrayList queue = new DoubleArrayList<>(false); - for (BlockVector position : region) { + for (BlockVector3 position : region) { // offset, scale - final Vector scaled = position.subtract(zero).divide(unit); + final Vector3 scaled = position.toVector3().subtract(zero).divide(unit); // transform expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ()); - final BlockVector sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue()); + final BlockVector3 sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue()); // read block from world final BaseBlock material = world.getFullBlock(sourcePosition); @@ -1793,8 +1794,8 @@ public class EditSession implements Extent, AutoCloseable { } int affected = 0; - for (Map.Entry entry : queue) { - BlockVector position = entry.getKey(); + for (Map.Entry entry : queue) { + BlockVector3 position = entry.getKey(); BaseBlock material = entry.getValue(); // set at new position @@ -1819,10 +1820,10 @@ public class EditSession implements Extent, AutoCloseable { public int hollowOutRegion(Region region, int thickness, Pattern pattern) throws MaxChangedBlocksException { int affected = 0; - final Set outside = new HashSet<>(); + final Set outside = new HashSet<>(); - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final BlockVector3 min = region.getMinimumPoint(); + final BlockVector3 max = region.getMaximumPoint(); final int minX = min.getBlockX(); final int minY = min.getBlockY(); @@ -1833,30 +1834,30 @@ public class EditSession implements Extent, AutoCloseable { for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { - recurseHollow(region, new BlockVector(x, y, minZ), outside); - recurseHollow(region, new BlockVector(x, y, maxZ), outside); + recurseHollow(region, new BlockVector3(x, y, minZ), outside); + recurseHollow(region, new BlockVector3(x, y, maxZ), outside); } } for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { - recurseHollow(region, new BlockVector(minX, y, z), outside); - recurseHollow(region, new BlockVector(maxX, y, z), outside); + recurseHollow(region, new BlockVector3(minX, y, z), outside); + recurseHollow(region, new BlockVector3(maxX, y, z), outside); } } for (int z = minZ; z <= maxZ; ++z) { for (int x = minX; x <= maxX; ++x) { - recurseHollow(region, new BlockVector(x, minY, z), outside); - recurseHollow(region, new BlockVector(x, maxY, z), outside); + recurseHollow(region, new BlockVector3(x, minY, z), outside); + recurseHollow(region, new BlockVector3(x, maxY, z), outside); } } for (int i = 1; i < thickness; ++i) { - final Set newOutside = new HashSet<>(); - outer: for (BlockVector position : region) { - for (Vector recurseDirection: recurseDirections) { - BlockVector neighbor = position.add(recurseDirection).toBlockVector(); + final Set newOutside = new HashSet<>(); + outer: for (BlockVector3 position : region) { + for (BlockVector3 recurseDirection : recurseDirections) { + BlockVector3 neighbor = position.add(recurseDirection); if (outside.contains(neighbor)) { newOutside.add(position); @@ -1868,9 +1869,9 @@ public class EditSession implements Extent, AutoCloseable { outside.addAll(newOutside); } - outer: for (BlockVector position : region) { - for (Vector recurseDirection: recurseDirections) { - BlockVector neighbor = position.add(recurseDirection).toBlockVector(); + outer: for (BlockVector3 position : region) { + for (BlockVector3 recurseDirection : recurseDirections) { + BlockVector3 neighbor = position.add(recurseDirection); if (outside.contains(neighbor)) { continue outer; @@ -1897,10 +1898,10 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drawLine(Pattern pattern, Vector pos1, Vector pos2, double radius, boolean filled) + public int drawLine(Pattern pattern, BlockVector3 pos1, BlockVector3 pos2, double radius, boolean filled) throws MaxChangedBlocksException { - Set vset = new HashSet<>(); + Set vset = new HashSet<>(); boolean notdrawn = true; int x1 = pos1.getBlockX(), y1 = pos1.getBlockY(), z1 = pos1.getBlockZ(); @@ -1909,7 +1910,7 @@ public class EditSession implements Extent, AutoCloseable { int dx = Math.abs(x2 - x1), dy = Math.abs(y2 - y1), dz = Math.abs(z2 - z1); if (dx + dy + dz == 0) { - vset.add(new Vector(tipx, tipy, tipz)); + vset.add(new BlockVector3(tipx, tipy, tipz)); notdrawn = false; } @@ -1919,7 +1920,7 @@ public class EditSession implements Extent, AutoCloseable { tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dx) * (y2 - y1 > 0 ? 1 : -1)); tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dx) * (z2 - z1 > 0 ? 1 : -1)); - vset.add(new Vector(tipx, tipy, tipz)); + vset.add(new BlockVector3(tipx, tipy, tipz)); } notdrawn = false; } @@ -1930,7 +1931,7 @@ public class EditSession implements Extent, AutoCloseable { tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dy) * (x2 - x1 > 0 ? 1 : -1)); tipz = (int) Math.round(z1 + domstep * ((double) dz) / ((double) dy) * (z2 - z1 > 0 ? 1 : -1)); - vset.add(new Vector(tipx, tipy, tipz)); + vset.add(new BlockVector3(tipx, tipy, tipz)); } notdrawn = false; } @@ -1941,7 +1942,7 @@ public class EditSession implements Extent, AutoCloseable { tipy = (int) Math.round(y1 + domstep * ((double) dy) / ((double) dz) * (y2-y1>0 ? 1 : -1)); tipx = (int) Math.round(x1 + domstep * ((double) dx) / ((double) dz) * (x2-x1>0 ? 1 : -1)); - vset.add(new Vector(tipx, tipy, tipz)); + vset.add(new BlockVector3(tipx, tipy, tipz)); } notdrawn = false; } @@ -1968,16 +1969,16 @@ public class EditSession implements Extent, AutoCloseable { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drawSpline(Pattern pattern, List nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) + public int drawSpline(Pattern pattern, List nodevectors, double tension, double bias, double continuity, double quality, double radius, boolean filled) throws MaxChangedBlocksException { - Set vset = new HashSet<>(); + Set vset = new HashSet<>(); List nodes = new ArrayList<>(nodevectors.size()); Interpolation interpol = new KochanekBartelsInterpolation(); - for (Vector nodevector : nodevectors) { - Node n = new Node(nodevector); + for (BlockVector3 nodevector : nodevectors) { + Node n = new Node(nodevector.toVector3()); n.setTension(tension); n.setBias(bias); n.setContinuity(continuity); @@ -1987,12 +1988,9 @@ public class EditSession implements Extent, AutoCloseable { interpol.setNodes(nodes); double splinelength = interpol.arcLength(0, 1); for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { - Vector tipv = interpol.getPosition(loop); - int tipx = (int) Math.round(tipv.getX()); - int tipy = (int) Math.round(tipv.getY()); - int tipz = (int) Math.round(tipv.getZ()); + Vector3 tipv = interpol.getPosition(loop); - vset.add(new Vector(tipx, tipy, tipz)); + vset.add(tipv.toBlockPoint()); } vset = getBallooned(vset, radius); @@ -2010,18 +2008,18 @@ public class EditSession implements Extent, AutoCloseable { return Math.sqrt(sum); } - private static Set getBallooned(Set vset, double radius) { - Set returnset = new HashSet<>(); + private static Set getBallooned(Set vset, double radius) { + Set returnset = new HashSet<>(); int ceilrad = (int) Math.ceil(radius); - for (Vector v : vset) { + for (BlockVector3 v : vset) { int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); for (int loopx = tipx - ceilrad; loopx <= tipx + ceilrad; loopx++) { for (int loopy = tipy - ceilrad; loopy <= tipy + ceilrad; loopy++) { for (int loopz = tipz - ceilrad; loopz <= tipz + ceilrad; loopz++) { if (hypot(loopx - tipx, loopy - tipy, loopz - tipz) <= radius) { - returnset.add(new Vector(loopx, loopy, loopz)); + returnset.add(new BlockVector3(loopx, loopy, loopz)); } } } @@ -2030,28 +2028,28 @@ public class EditSession implements Extent, AutoCloseable { return returnset; } - private static Set getHollowed(Set vset) { - Set returnset = new HashSet<>(); - for (Vector v : vset) { + private static Set getHollowed(Set vset) { + Set returnset = new HashSet<>(); + for (BlockVector3 v : vset) { double x = v.getX(), y = v.getY(), z = v.getZ(); - if (!(vset.contains(new Vector(x + 1, y, z)) && - vset.contains(new Vector(x - 1, y, z)) && - vset.contains(new Vector(x, y + 1, z)) && - vset.contains(new Vector(x, y - 1, z)) && - vset.contains(new Vector(x, y, z + 1)) && - vset.contains(new Vector(x, y, z - 1)))) { + if (!(vset.contains(new BlockVector3(x + 1, y, z)) && + vset.contains(new BlockVector3(x - 1, y, z)) && + vset.contains(new BlockVector3(x, y + 1, z)) && + vset.contains(new BlockVector3(x, y - 1, z)) && + vset.contains(new BlockVector3(x, y, z + 1)) && + vset.contains(new BlockVector3(x, y, z - 1)))) { returnset.add(v); } } return returnset; } - private void recurseHollow(Region region, BlockVector origin, Set outside) { - final LinkedList queue = new LinkedList<>(); + private void recurseHollow(Region region, BlockVector3 origin, Set outside) { + final LinkedList queue = new LinkedList<>(); queue.addLast(origin); while (!queue.isEmpty()) { - final BlockVector current = queue.removeFirst(); + final BlockVector3 current = queue.removeFirst(); final BlockState block = getBlock(current); if (block.getBlockType().getMaterial().isMovementBlocker()) { continue; @@ -2065,15 +2063,15 @@ public class EditSession implements Extent, AutoCloseable { continue; } - for (Vector recurseDirection: recurseDirections) { - queue.addLast(current.add(recurseDirection).toBlockVector()); + for (BlockVector3 recurseDirection : recurseDirections) { + queue.addLast(current.add(recurseDirection)); } - } // while + } } - public int makeBiomeShape(final Region region, final Vector zero, final Vector unit, final BaseBiome biomeType, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException { - final Vector2D zero2D = zero.toVector2D(); - final Vector2D unit2D = unit.toVector2D(); + public int makeBiomeShape(final Region region, final Vector3 zero, final Vector3 unit, final BaseBiome biomeType, final String expressionString, final boolean hollow) throws ExpressionException, MaxChangedBlocksException { + final Vector2 zero2D = zero.toVector2(); + final Vector2 unit2D = unit.toVector2(); final Expression expression = Expression.compile(expressionString, "x", "z"); expression.optimize(); @@ -2085,9 +2083,9 @@ public class EditSession implements Extent, AutoCloseable { final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) { @Override protected BaseBiome getBiome(int x, int z, BaseBiome defaultBiomeType) { - final Vector2D current = new Vector2D(x, z); - environment.setCurrentBlock(current.toVector(0)); - final Vector2D scaled = current.subtract(zero2D).divide(unit2D); + final Vector2 current = new Vector2(x, z); + environment.setCurrentBlock(current.toVector3(0)); + final Vector2 scaled = current.subtract(zero2D).divide(unit2D); try { if (expression.evaluate(scaled.getX(), scaled.getZ()) <= 0) { @@ -2106,13 +2104,13 @@ public class EditSession implements Extent, AutoCloseable { return shape.generate(this, biomeType, hollow); } - private static final Vector[] recurseDirections = { - Direction.NORTH.toVector(), - Direction.EAST.toVector(), - Direction.SOUTH.toVector(), - Direction.WEST.toVector(), - Direction.UP.toVector(), - Direction.DOWN.toVector(), + private static final BlockVector3[] recurseDirections = { + Direction.NORTH.toBlockVector(), + Direction.EAST.toBlockVector(), + Direction.SOUTH.toBlockVector(), + Direction.WEST.toBlockVector(), + Direction.UP.toBlockVector(), + Direction.DOWN.toBlockVector(), }; private static double lengthSq(double x, double y, double z) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java index d30e4ec6f..567488fbe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -40,6 +40,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionShapeEvent; import com.sk89q.worldedit.internal.cui.ServerCUIHandler; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; @@ -91,7 +92,7 @@ public class LocalSession { private transient boolean fastMode = false; private transient Mask mask; private transient TimeZone timezone = TimeZone.getDefault(); - private transient Vector cuiTemporaryBlock; + private transient BlockVector3 cuiTemporaryBlock; // Saved properties private String lastScript; @@ -450,10 +451,10 @@ public class LocalSession { * @return the position to use * @throws IncompleteRegionException thrown if a region is not fully selected */ - public Vector getPlacementPosition(Player player) throws IncompleteRegionException { + public BlockVector3 getPlacementPosition(Player player) throws IncompleteRegionException { checkNotNull(player); if (!placeAtPos1) { - return player.getBlockIn().toVector(); + return player.getBlockIn().toVector().toBlockPoint(); } return selector.getPrimaryPosition(); @@ -661,7 +662,7 @@ public class LocalSession { if (block != null) { // If it's null, we don't need to do anything. The old was already removed. Map tags = block.getNbtData().getValue(); - cuiTemporaryBlock = new Vector( + cuiTemporaryBlock = new BlockVector3( ((IntTag) tags.get("x")).getValue(), ((IntTag) tags.get("y")).getValue(), ((IntTag) tags.get("z")).getValue() diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java index 2a82fea88..39a7c0409 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/PlayerDirection.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Direction; /** @@ -28,26 +29,26 @@ import com.sk89q.worldedit.util.Direction; */ public enum PlayerDirection { - NORTH(new Vector(0, 0, -1), true), - NORTH_EAST((new Vector(1, 0, -1)).normalize(), false), - EAST(new Vector(1, 0, 0), true), - SOUTH_EAST((new Vector(1, 0, 1)).normalize(), false), - SOUTH(new Vector(0, 0, 1), true), - SOUTH_WEST((new Vector(-1, 0, 1)).normalize(), false), - WEST(new Vector(-1, 0, 0), true), - NORTH_WEST((new Vector(-1, 0, -1)).normalize(), false), - UP(new Vector(0, 1, 0), true), - DOWN(new Vector(0, -1, 0), true); + NORTH(new Vector3(0, 0, -1), true), + NORTH_EAST((new Vector3(1, 0, -1)).normalize(), false), + EAST(new Vector3(1, 0, 0), true), + SOUTH_EAST((new Vector3(1, 0, 1)).normalize(), false), + SOUTH(new Vector3(0, 0, 1), true), + SOUTH_WEST((new Vector3(-1, 0, 1)).normalize(), false), + WEST(new Vector3(-1, 0, 0), true), + NORTH_WEST((new Vector3(-1, 0, -1)).normalize(), false), + UP(new Vector3(0, 1, 0), true), + DOWN(new Vector3(0, -1, 0), true); - private final Vector dir; + private final Vector3 dir; private final boolean isOrthogonal; - PlayerDirection(Vector vec, boolean isOrthogonal) { + PlayerDirection(Vector3 vec, boolean isOrthogonal) { this.dir = vec; this.isOrthogonal = isOrthogonal; } - public Vector vector() { + public Vector3 vector() { return dir; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java deleted file mode 100644 index a47210ce6..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java +++ /dev/null @@ -1,846 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * 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 . - */ - -package com.sk89q.worldedit; - -import com.sk89q.worldedit.math.transform.AffineTransform; - -import javax.annotation.Nullable; - -/** - * An immutable 3-dimensional vector. - */ -public class Vector implements Comparable { - - public static final Vector ZERO = new Vector(0, 0, 0); - public static final Vector UNIT_X = new Vector(1, 0, 0); - public static final Vector UNIT_Y = new Vector(0, 1, 0); - public static final Vector UNIT_Z = new Vector(0, 0, 1); - public static final Vector ONE = new Vector(1, 1, 1); - - protected final double x, y, z; - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public Vector(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public Vector(int x, int y, int z) { - this.x = (double) x; - this.y = (double) y; - this.z = (double) z; - } - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - */ - public Vector(float x, float y, float z) { - this.x = (double) x; - this.y = (double) y; - this.z = (double) z; - } - - /** - * Copy another vector. - * - * @param other another vector to make a copy of - */ - public Vector(Vector other) { - this.x = other.x; - this.y = other.y; - this.z = other.z; - } - - /** - * Construct a new instance with X, Y, and Z coordinates set to 0. - * - *

One can also refer to a static {@link #ZERO}.

- */ - public Vector() { - this.x = 0; - this.y = 0; - this.z = 0; - } - - /** - * Get the X coordinate. - * - * @return the x coordinate - */ - public double getX() { - return x; - } - - /** - * Get the X coordinate rounded. - * - * @return the x coordinate - */ - public int getBlockX() { - return (int) Math.round(x); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector setX(double x) { - return new Vector(x, y, z); - } - - /** - * Set the X coordinate. - * - * @param x the X coordinate - * @return new vector - */ - public Vector setX(int x) { - return new Vector(x, y, z); - } - - /** - * Get the Y coordinate. - * - * @return the y coordinate - */ - public double getY() { - return y; - } - - /** - * Get the Y coordinate rounded. - * - * @return the y coordinate - */ - public int getBlockY() { - return (int) Math.round(y); - } - - /** - * Set the Y coordinate. - * - * @param y the new Y - * @return a new vector - */ - public Vector setY(double y) { - return new Vector(x, y, z); - } - - /** - * Set the Y coordinate. - * - * @param y the new Y - * @return a new vector - */ - public Vector setY(int y) { - return new Vector(x, y, z); - } - - /** - * Get the Z coordinate. - * - * @return the z coordinate - */ - public double getZ() { - return z; - } - - /** - * Get the Z coordinate rounded. - * - * @return the z coordinate - */ - public int getBlockZ() { - return (int) Math.round(z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector setZ(double z) { - return new Vector(x, y, z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector setZ(int z) { - return new Vector(x, y, z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param other the other vector - * @return a new vector - */ - public Vector add(Vector other) { - return new Vector(x + other.x, y + other.y, z + other.z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param x the value to add - * @param y the value to add - * @param z the value to add - * @return a new vector - */ - public Vector add(double x, double y, double z) { - return new Vector(this.x + x, this.y + y, this.z + z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param x the value to add - * @param y the value to add - * @param z the value to add - * @return a new vector - */ - public Vector add(int x, int y, int z) { - return new Vector(this.x + x, this.y + y, this.z + z); - } - - /** - * Add a list of vectors to this vector and return the - * result as a new vector. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector add(Vector... others) { - double newX = x, newY = y, newZ = z; - - for (Vector other : others) { - newX += other.x; - newY += other.y; - newZ += other.z; - } - - return new Vector(newX, newY, newZ); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param other the other vector - * @return a new vector - */ - public Vector subtract(Vector other) { - return new Vector(x - other.x, y - other.y, z - other.z); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param x the value to subtract - * @param y the value to subtract - * @param z the value to subtract - * @return a new vector - */ - public Vector subtract(double x, double y, double z) { - return new Vector(this.x - x, this.y - y, this.z - z); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param x the value to subtract - * @param y the value to subtract - * @param z the value to subtract - * @return a new vector - */ - public Vector subtract(int x, int y, int z) { - return new Vector(this.x - x, this.y - y, this.z - z); - } - - /** - * Subtract a list of vectors from this vector and return the result - * as a new vector. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector subtract(Vector... others) { - double newX = x, newY = y, newZ = z; - - for (Vector other : others) { - newX -= other.x; - newY -= other.y; - newZ -= other.z; - } - - return new Vector(newX, newY, newZ); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param other the other vector - * @return a new vector - */ - public Vector multiply(Vector other) { - return new Vector(x * other.x, y * other.y, z * other.z); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param x the value to multiply - * @param y the value to multiply - * @param z the value to multiply - * @return a new vector - */ - public Vector multiply(double x, double y, double z) { - return new Vector(this.x * x, this.y * y, this.z * z); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param x the value to multiply - * @param y the value to multiply - * @param z the value to multiply - * @return a new vector - */ - public Vector multiply(int x, int y, int z) { - return new Vector(this.x * x, this.y * y, this.z * z); - } - - /** - * Multiply this vector by zero or more vectors on each component. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector multiply(Vector... others) { - double newX = x, newY = y, newZ = z; - - for (Vector other : others) { - newX *= other.x; - newY *= other.y; - newZ *= other.z; - } - - return new Vector(newX, newY, newZ); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector multiply(double n) { - return new Vector(this.x * n, this.y * n, this.z * n); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector multiply(float n) { - return new Vector(this.x * n, this.y * n, this.z * n); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector multiply(int n) { - return new Vector(this.x * n, this.y * n, this.z * n); - } - - /** - * Divide this vector by another vector on each component. - * - * @param other the other vector - * @return a new vector - */ - public Vector divide(Vector other) { - return new Vector(x / other.x, y / other.y, z / other.z); - } - - /** - * Divide this vector by another vector on each component. - * - * @param x the value to divide by - * @param y the value to divide by - * @param z the value to divide by - * @return a new vector - */ - public Vector divide(double x, double y, double z) { - return new Vector(this.x / x, this.y / y, this.z / z); - } - - /** - * Divide this vector by another vector on each component. - * - * @param x the value to divide by - * @param y the value to divide by - * @param z the value to divide by - * @return a new vector - */ - public Vector divide(int x, int y, int z) { - return new Vector(this.x / x, this.y / y, this.z / z); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector divide(int n) { - return new Vector(x / n, y / n, z / n); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector divide(double n) { - return new Vector(x / n, y / n, z / n); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector divide(float n) { - return new Vector(x / n, y / n, z / n); - } - - /** - * Get the length of the vector. - * - * @return length - */ - public double length() { - return Math.sqrt(x * x + y * y + z * z); - } - - /** - * Get the length, squared, of the vector. - * - * @return length, squared - */ - public double lengthSq() { - return x * x + y * y + z * z; - } - - /** - * Get the distance between this vector and another vector. - * - * @param other the other vector - * @return distance - */ - public double distance(Vector other) { - return Math.sqrt(Math.pow(other.x - x, 2) + - Math.pow(other.y - y, 2) + - Math.pow(other.z - z, 2)); - } - - /** - * Get the distance between this vector and another vector, squared. - * - * @param other the other vector - * @return distance - */ - public double distanceSq(Vector other) { - return Math.pow(other.x - x, 2) + - Math.pow(other.y - y, 2) + - Math.pow(other.z - z, 2); - } - - /** - * Get the normalized vector, which is the vector divided by its - * length, as a new vector. - * - * @return a new vector - */ - public Vector normalize() { - return divide(length()); - } - - /** - * Gets the dot product of this and another vector. - * - * @param other the other vector - * @return the dot product of this and the other vector - */ - public double dot(Vector other) { - return x * other.x + y * other.y + z * other.z; - } - - /** - * Gets the cross product of this and another vector. - * - * @param other the other vector - * @return the cross product of this and the other vector - */ - public Vector cross(Vector other) { - return new Vector( - y * other.z - z * other.y, - z * other.x - x * other.z, - x * other.y - y * other.x - ); - } - - /** - * Checks to see if a vector is contained with another. - * - * @param min the minimum point (X, Y, and Z are the lowest) - * @param max the maximum point (X, Y, and Z are the lowest) - * @return true if the vector is contained - */ - public boolean containedWithin(Vector min, Vector max) { - return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z; - } - - /** - * Checks to see if a vector is contained with another, comparing - * using discrete comparisons, inclusively. - * - * @param min the minimum point (X, Y, and Z are the lowest) - * @param max the maximum point (X, Y, and Z are the lowest) - * @return true if the vector is contained - */ - public boolean containedWithinBlock(Vector min, Vector max) { - return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX() - && getBlockY() >= min.getBlockY() && getBlockY() <= max.getBlockY() - && getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockZ(); - } - - /** - * Clamp the Y component. - * - * @param min the minimum value - * @param max the maximum value - * @return a new vector - */ - public Vector clampY(int min, int max) { - return new Vector(x, Math.max(min, Math.min(max, y)), z); - } - - /** - * Floors the values of all components. - * - * @return a new vector - */ - public Vector floor() { - return new Vector(Math.floor(x), Math.floor(y), Math.floor(z)); - } - - /** - * Rounds all components up. - * - * @return a new vector - */ - public Vector ceil() { - return new Vector(Math.ceil(x), Math.ceil(y), Math.ceil(z)); - } - - /** - * Rounds all components to the closest integer. - * - *

Components < 0.5 are rounded down, otherwise up.

- * - * @return a new vector - */ - public Vector round() { - return new Vector(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5)); - } - - /** - * Returns a vector with the absolute values of the components of - * this vector. - * - * @return a new vector - */ - public Vector positive() { - return new Vector(Math.abs(x), Math.abs(y), Math.abs(z)); - } - - /** - * Perform a 2D transformation on this vector and return a new one. - * - * @param angle in degrees - * @param aboutX about which x coordinate to rotate - * @param aboutZ about which z coordinate to rotate - * @param translateX what to add after rotation - * @param translateZ what to add after rotation - * @return a new vector - * @see AffineTransform another method to transform vectors - */ - public Vector transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { - angle = Math.toRadians(angle); - double x = this.x - aboutX; - double z = this.z - aboutZ; - double x2 = x * Math.cos(angle) - z * Math.sin(angle); - double z2 = x * Math.sin(angle) + z * Math.cos(angle); - - return new Vector( - x2 + aboutX + translateX, - y, - z2 + aboutZ + translateZ - ); - } - - /** - * Returns whether this vector is collinear with another vector. - * - * @param other the other vector - * @return true if collinear - */ - public boolean isCollinearWith(Vector other) { - if (x == 0 && y == 0 && z == 0) { - // this is a zero vector - return true; - } - - final double otherX = other.x; - final double otherY = other.y; - final double otherZ = other.z; - - if (otherX == 0 && otherY == 0 && otherZ == 0) { - // other is a zero vector - return true; - } - - if ((x == 0) != (otherX == 0)) return false; - if ((y == 0) != (otherY == 0)) return false; - if ((z == 0) != (otherZ == 0)) return false; - - final double quotientX = otherX / x; - if (!Double.isNaN(quotientX)) { - return other.equals(multiply(quotientX)); - } - - final double quotientY = otherY / y; - if (!Double.isNaN(quotientY)) { - return other.equals(multiply(quotientY)); - } - - final double quotientZ = otherZ / z; - if (!Double.isNaN(quotientZ)) { - return other.equals(multiply(quotientZ)); - } - - throw new RuntimeException("This should not happen"); - } - - /** - * Get this vector's pitch as used within the game. - * - * @return pitch in radians - */ - public float toPitch() { - double x = getX(); - double z = getZ(); - - if (x == 0 && z == 0) { - return getY() > 0 ? -90 : 90; - } else { - double x2 = x * x; - double z2 = z * z; - double xz = Math.sqrt(x2 + z2); - return (float) Math.toDegrees(Math.atan(-getY() / xz)); - } - } - - /** - * Get this vector's yaw as used within the game. - * - * @return yaw in radians - */ - public float toYaw() { - double x = getX(); - double z = getZ(); - - double t = Math.atan2(-x, z); - double _2pi = 2 * Math.PI; - - return (float) Math.toDegrees(((t + _2pi) % _2pi)); - } - - /** - * Create a new {@code BlockVector} using the given components. - * - * @param x the X coordinate - * @param y the Y coordinate - * @param z the Z coordinate - * @return a new {@code BlockVector} - */ - public static BlockVector toBlockPoint(double x, double y, double z) { - return new BlockVector( - Math.floor(x), - Math.floor(y), - Math.floor(z) - ); - } - - /** - * Create a new {@code BlockVector} from this vector. - * - * @return a new {@code BlockVector} - */ - public BlockVector toBlockPoint() { - return new BlockVector( - Math.floor(x), - Math.floor(y), - Math.floor(z) - ); - } - - /** - * Create a new {@code BlockVector} from this vector. - * - * @return a new {@code BlockVector} - */ - public BlockVector toBlockVector() { - return toBlockPoint(); -// return new BlockVector(this); TODO Look into this further. - } - - /** - * Creates a 2D vector by dropping the Y component from this vector. - * - * @return a new {@code Vector2D} - */ - public Vector2D toVector2D() { - return new Vector2D(x, z); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector)) { - return false; - } - - Vector other = (Vector) obj; - return other.x == this.x && other.y == this.y && other.z == this.z; - } - - @Override - public int compareTo(@Nullable Vector other) { - if (other == null) { - throw new IllegalArgumentException("null not supported"); - } - if (y != other.y) return Double.compare(y, other.y); - if (z != other.z) return Double.compare(z, other.z); - if (x != other.x) return Double.compare(x, other.x); - return 0; - } - - @Override - public int hashCode() { - return ((int) x ^ ((int) z << 12)) ^ ((int) y << 24); - } - - @Override - public String toString() { - return "(" + x + ", " + y + ", " + z + ")"; - } - - /** - * Gets the minimum components of two vectors. - * - * @param v1 the first vector - * @param v2 the second vector - * @return minimum - */ - public static Vector getMinimum(Vector v1, Vector v2) { - return new Vector( - Math.min(v1.x, v2.x), - Math.min(v1.y, v2.y), - Math.min(v1.z, v2.z) - ); - } - - /** - * Gets the maximum components of two vectors. - * - * @param v1 the first vector - * @param v2 the second vector - * @return maximum - */ - public static Vector getMaximum(Vector v1, Vector v2) { - return new Vector( - Math.max(v1.x, v2.x), - Math.max(v1.y, v2.y), - Math.max(v1.z, v2.z) - ); - } - - /** - * Gets the midpoint of two vectors. - * - * @param v1 the first vector - * @param v2 the second vector - * @return maximum - */ - public static Vector getMidpoint(Vector v1, Vector v2) { - return new Vector( - (v1.x + v2.x) / 2, - (v1.y + v2.y) / 2, - (v1.z + v2.z) / 2 - ); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java deleted file mode 100644 index c4ecc15f7..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java +++ /dev/null @@ -1,691 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * 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 . - */ - -package com.sk89q.worldedit; - -import com.google.common.collect.ComparisonChain; -import com.sk89q.worldedit.math.transform.AffineTransform; - -import java.util.Comparator; - -/** - * An immutable 2-dimensional vector. - */ -public class Vector2D { - - /** - * A comparator for Vector2Ds that orders the vectors by rows, with x as the - * column and z as the row. - * - * For example, if x is the horizontal axis and z is the vertical axis, it - * sorts like so: - * - *
-     * 0123
-     * 4567
-     * 90ab
-     * cdef
-     * 
- */ - public static final Comparator COMPARING_GRID_ARRANGEMENT = (a, b) -> { - return ComparisonChain.start() - .compare(a.getBlockZ(), b.getBlockZ()) - .compare(a.getBlockX(), b.getBlockX()) - .result(); - }; - - public static final Vector2D ZERO = new Vector2D(0, 0); - public static final Vector2D UNIT_X = new Vector2D(1, 0); - public static final Vector2D UNIT_Z = new Vector2D(0, 1); - public static final Vector2D ONE = new Vector2D(1, 1); - - protected final double x, z; - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public Vector2D(double x, double z) { - this.x = x; - this.z = z; - } - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public Vector2D(int x, int z) { - this.x = (double) x; - this.z = (double) z; - } - - /** - * Construct an instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public Vector2D(float x, float z) { - this.x = (double) x; - this.z = (double) z; - } - - /** - * Copy another vector. - * - * @param other the other vector - */ - public Vector2D(Vector2D other) { - this.x = other.x; - this.z = other.z; - } - - /** - * Construct a new instance with X and Z coordinates set to 0. - * - *

One can also refer to a static {@link #ZERO}.

- */ - public Vector2D() { - this.x = 0; - this.z = 0; - } - - /** - * Get the X coordinate. - * - * @return the x coordinate - */ - public double getX() { - return x; - } - - /** - * Get the X coordinate rounded. - * - * @return the x coordinate - */ - public int getBlockX() { - return (int) Math.round(x); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector2D setX(double x) { - return new Vector2D(x, z); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector2D setX(int x) { - return new Vector2D(x, z); - } - - /** - * Get the Z coordinate. - * - * @return the z coordinate - */ - public double getZ() { - return z; - } - - /** - * Get the Z coordinate rounded. - * - * @return the z coordinate - */ - public int getBlockZ() { - return (int) Math.round(z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector2D setZ(double z) { - return new Vector2D(x, z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector2D setZ(int z) { - return new Vector2D(x, z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param other the other vector - * @return a new vector - */ - public Vector2D add(Vector2D other) { - return new Vector2D(x + other.x, z + other.z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param x the value to add - * @param z the value to add - * @return a new vector - */ - public Vector2D add(double x, double z) { - return new Vector2D(this.x + x, this.z + z); - } - - /** - * Add another vector to this vector and return the result as a new vector. - * - * @param x the value to add - * @param z the value to add - * @return a new vector - */ - public Vector2D add(int x, int z) { - return new Vector2D(this.x + x, this.z + z); - } - - /** - * Add a list of vectors to this vector and return the - * result as a new vector. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector2D add(Vector2D... others) { - double newX = x, newZ = z; - - for (Vector2D other : others) { - newX += other.x; - newZ += other.z; - } - - return new Vector2D(newX, newZ); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param other the other vector - * @return a new vector - */ - public Vector2D subtract(Vector2D other) { - return new Vector2D(x - other.x, z - other.z); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param x the value to subtract - * @param z the value to subtract - * @return a new vector - */ - public Vector2D subtract(double x, double z) { - return new Vector2D(this.x - x, this.z - z); - } - - /** - * Subtract another vector from this vector and return the result - * as a new vector. - * - * @param x the value to subtract - * @param z the value to subtract - * @return a new vector - */ - public Vector2D subtract(int x, int z) { - return new Vector2D(this.x - x, this.z - z); - } - - /** - * Subtract a list of vectors from this vector and return the result - * as a new vector. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector2D subtract(Vector2D... others) { - double newX = x, newZ = z; - - for (Vector2D other : others) { - newX -= other.x; - newZ -= other.z; - } - - return new Vector2D(newX, newZ); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param other the other vector - * @return a new vector - */ - public Vector2D multiply(Vector2D other) { - return new Vector2D(x * other.x, z * other.z); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param x the value to multiply - * @param z the value to multiply - * @return a new vector - */ - public Vector2D multiply(double x, double z) { - return new Vector2D(this.x * x, this.z * z); - } - - /** - * Multiply this vector by another vector on each component. - * - * @param x the value to multiply - * @param z the value to multiply - * @return a new vector - */ - public Vector2D multiply(int x, int z) { - return new Vector2D(this.x * x, this.z * z); - } - - /** - * Multiply this vector by zero or more vectors on each component. - * - * @param others an array of vectors - * @return a new vector - */ - public Vector2D multiply(Vector2D... others) { - double newX = x, newZ = z; - - for (Vector2D other : others) { - newX *= other.x; - newZ *= other.z; - } - - return new Vector2D(newX, newZ); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector2D multiply(double n) { - return new Vector2D(this.x * n, this.z * n); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector2D multiply(float n) { - return new Vector2D(this.x * n, this.z * n); - } - - /** - * Perform scalar multiplication and return a new vector. - * - * @param n the value to multiply - * @return a new vector - */ - public Vector2D multiply(int n) { - return new Vector2D(this.x * n, this.z * n); - } - - /** - * Divide this vector by another vector on each component. - * - * @param other the other vector - * @return a new vector - */ - public Vector2D divide(Vector2D other) { - return new Vector2D(x / other.x, z / other.z); - } - - /** - * Divide this vector by another vector on each component. - * - * @param x the value to divide by - * @param z the value to divide by - * @return a new vector - */ - public Vector2D divide(double x, double z) { - return new Vector2D(this.x / x, this.z / z); - } - - /** - * Divide this vector by another vector on each component. - * - * @param x the value to divide by - * @param z the value to divide by - * @return a new vector - */ - public Vector2D divide(int x, int z) { - return new Vector2D(this.x / x, this.z / z); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector2D divide(int n) { - return new Vector2D(x / n, z / n); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector2D divide(double n) { - return new Vector2D(x / n, z / n); - } - - /** - * Perform scalar division and return a new vector. - * - * @param n the value to divide by - * @return a new vector - */ - public Vector2D divide(float n) { - return new Vector2D(x / n, z / n); - } - - /** - * Get the length of the vector. - * - * @return length - */ - public double length() { - return Math.sqrt(x * x + z * z); - } - - /** - * Get the length, squared, of the vector. - * - * @return length, squared - */ - public double lengthSq() { - return x * x + z * z; - } - - /** - * Get the distance between this vector and another vector. - * - * @param other the other vector - * @return distance - */ - public double distance(Vector2D other) { - return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.z - z, 2)); - } - - /** - * Get the distance between this vector and another vector, squared. - * - * @param other the other vector - * @return distance - */ - public double distanceSq(Vector2D other) { - return Math.pow(other.x - x, 2) + - Math.pow(other.z - z, 2); - } - - /** - * Get the normalized vector, which is the vector divided by its - * length, as a new vector. - * - * @return a new vector - */ - public Vector2D normalize() { - return divide(length()); - } - - /** - * Gets the dot product of this and another vector. - * - * @param other the other vector - * @return the dot product of this and the other vector - */ - public double dot(Vector2D other) { - return x * other.x + z * other.z; - } - - /** - * Checks to see if a vector is contained with another. - * - * @param min the minimum point (X, Y, and Z are the lowest) - * @param max the maximum point (X, Y, and Z are the lowest) - * @return true if the vector is contained - */ - public boolean containedWithin(Vector2D min, Vector2D max) { - return x >= min.x && x <= max.x - && z >= min.z && z <= max.z; - } - - /** - * Checks to see if a vector is contained with another. - * - * @param min the minimum point (X, Y, and Z are the lowest) - * @param max the maximum point (X, Y, and Z are the lowest) - * @return true if the vector is contained - */ - public boolean containedWithinBlock(Vector2D min, Vector2D max) { - return getBlockX() >= min.getBlockX() && getBlockX() <= max.getBlockX() - && getBlockZ() >= min.getBlockZ() && getBlockZ() <= max.getBlockZ(); - } - - /** - * Floors the values of all components. - * - * @return a new vector - */ - public Vector2D floor() { - return new Vector2D(Math.floor(x), Math.floor(z)); - } - - /** - * Rounds all components up. - * - * @return a new vector - */ - public Vector2D ceil() { - return new Vector2D(Math.ceil(x), Math.ceil(z)); - } - - /** - * Rounds all components to the closest integer. - * - *

Components < 0.5 are rounded down, otherwise up.

- * - * @return a new vector - */ - public Vector2D round() { - return new Vector2D(Math.floor(x + 0.5), Math.floor(z + 0.5)); - } - - /** - * Returns a vector with the absolute values of the components of - * this vector. - * - * @return a new vector - */ - public Vector2D positive() { - return new Vector2D(Math.abs(x), Math.abs(z)); - } - - /** - * Perform a 2D transformation on this vector and return a new one. - * - * @param angle in degrees - * @param aboutX about which x coordinate to rotate - * @param aboutZ about which z coordinate to rotate - * @param translateX what to add after rotation - * @param translateZ what to add after rotation - * @return a new vector - * @see AffineTransform another method to transform vectors - */ - public Vector2D transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { - angle = Math.toRadians(angle); - double x = this.x - aboutX; - double z = this.z - aboutZ; - double x2 = x * Math.cos(angle) - z * Math.sin(angle); - double z2 = x * Math.sin(angle) + z * Math.cos(angle); - return new Vector2D( - x2 + aboutX + translateX, - z2 + aboutZ + translateZ - ); - } - - /** - * Returns whether this vector is collinear with another vector. - * - * @param other the other vector - * @return true if collinear - */ - public boolean isCollinearWith(Vector2D other) { - if (x == 0 && z == 0) { - // this is a zero vector - return true; - } - - final double otherX = other.x; - final double otherZ = other.z; - - if (otherX == 0 && otherZ == 0) { - // other is a zero vector - return true; - } - - if ((x == 0) != (otherX == 0)) return false; - if ((z == 0) != (otherZ == 0)) return false; - - final double quotientX = otherX / x; - if (!Double.isNaN(quotientX)) { - return other.equals(multiply(quotientX)); - } - - final double quotientZ = otherZ / z; - if (!Double.isNaN(quotientZ)) { - return other.equals(multiply(quotientZ)); - } - - throw new RuntimeException("This should not happen"); - } - - /** - * Create a new {@code BlockVector2D} from this vector. - * - * @return a new {@code BlockVector2D} - */ - public BlockVector2D toBlockVector2D() { - return new BlockVector2D(this); - } - - /** - * Creates a 3D vector by adding a zero Y component to this vector. - * - * @return a new vector - */ - public Vector toVector() { - return new Vector(x, 0, z); - } - - /** - * Creates a 3D vector by adding the specified Y component to this vector. - * - * @param y the Y component - * @return a new vector - */ - public Vector toVector(double y) { - return new Vector(x, y, z); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector2D)) { - return false; - } - - Vector2D other = (Vector2D) obj; - return other.x == this.x && other.z == this.z; - - } - - @Override - public int hashCode() { - return ((int) x << 16) ^ (int) z; - } - - @Override - public String toString() { - return "(" + x + ", " + z + ")"; - } - - /** - * Gets the minimum components of two vectors. - * - * @param v1 the first vector - * @param v2 the second vector - * @return minimum - */ - public static Vector2D getMinimum(Vector2D v1, Vector2D v2) { - return new Vector2D( - Math.min(v1.x, v2.x), - Math.min(v1.z, v2.z) - ); - } - - /** - * Gets the maximum components of two vectors. - * - * @param v1 the first vector - * @param v2 the second vector - * @return maximum - */ - public static Vector2D getMaximum(Vector2D v1, Vector2D v2) { - return new Vector2D( - Math.max(v1.x, v2.x), - Math.max(v1.z, v2.z) - ); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index cc2f9a440..2f9232062 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -40,6 +40,7 @@ import com.sk89q.worldedit.extension.platform.PlatformManager; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.scripting.CraftScriptContext; import com.sk89q.worldedit.scripting.CraftScriptEngine; import com.sk89q.worldedit.scripting.RhinoCraftScriptEngine; @@ -370,7 +371,7 @@ public class WorldEdit { * @return a direction vector * @throws UnknownDirectionException thrown if the direction is not known */ - public Vector getDirection(Player player, String dirStr) throws UnknownDirectionException { + public BlockVector3 getDirection(Player player, String dirStr) throws UnknownDirectionException { dirStr = dirStr.toLowerCase(); final PlayerDirection dir = getPlayerDirection(player, dirStr); @@ -382,7 +383,7 @@ public class WorldEdit { case NORTH: case UP: case DOWN: - return dir.vector(); + return dir.vector().toBlockPoint(); default: throw new UnknownDirectionException(dir.name()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java index 70deb8133..8d94ae739 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BiomeCommands.java @@ -28,8 +28,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; @@ -41,6 +39,8 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.FlatRegionVisitor; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.FlatRegion; import com.sk89q.worldedit.regions.Region; @@ -139,12 +139,12 @@ public class BiomeCommands { return; } - BaseBiome biome = player.getWorld().getBiome(blockPosition.toVector().toVector2D()); + BaseBiome biome = player.getWorld().getBiome(blockPosition.toVector().toBlockPoint().toBlockVector2()); biomes.add(biome); qualifier = "at line of sight point"; } else if (args.hasFlag('p')) { - BaseBiome biome = player.getWorld().getBiome(player.getLocation().toVector().toVector2D()); + BaseBiome biome = player.getWorld().getBiome(player.getLocation().toVector().toBlockPoint().toBlockVector2()); biomes.add(biome); qualifier = "at your position"; @@ -153,12 +153,12 @@ public class BiomeCommands { Region region = session.getSelection(world); if (region instanceof FlatRegion) { - for (Vector2D pt : ((FlatRegion) region).asFlatRegion()) { + for (BlockVector2 pt : ((FlatRegion) region).asFlatRegion()) { biomes.add(world.getBiome(pt)); } } else { - for (Vector pt : region) { - biomes.add(world.getBiome(pt.toVector2D())); + for (BlockVector3 pt : region) { + biomes.add(world.getBiome(pt.toBlockVector2())); } } @@ -195,7 +195,7 @@ public class BiomeCommands { Mask2D mask2d = mask != null ? mask.toMask2D() : null; if (atPosition) { - region = new CuboidRegion(player.getLocation().toVector(), player.getLocation().toVector()); + region = new CuboidRegion(player.getLocation().toVector().toBlockPoint(), player.getLocation().toVector().toBlockPoint()); } else { region = session.getSelection(world); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java index 126653046..2ce7a07ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/BrushCommands.java @@ -27,7 +27,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.BrushTool; @@ -45,6 +44,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.command.binding.Switch; @@ -143,7 +143,7 @@ public class BrushCommands { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); - Vector size = clipboard.getDimensions(); + BlockVector3 size = clipboard.getDimensions(); worldEdit.checkMaxBrushRadius(size.getBlockX()); worldEdit.checkMaxBrushRadius(size.getBlockY()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index ae96027b0..d213184f3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -29,10 +29,10 @@ import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.MathUtils; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.storage.LegacyChunkStore; @@ -76,7 +76,7 @@ public class ChunkCommands { player.print("Chunk: " + chunkX + ", " + chunkZ); player.print("Old format: " + folder1 + "/" + folder2 + "/" + filename); player.print("McRegion: region/" + McRegionChunkStore.getFilename( - new Vector2D(chunkX, chunkZ))); + new BlockVector2(chunkX, chunkZ))); } @Command( @@ -88,9 +88,9 @@ public class ChunkCommands { ) @CommandPermissions("worldedit.listchunks") public void listChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - Set chunks = session.getSelection(player.getWorld()).getChunks(); + Set chunks = session.getSelection(player.getWorld()).getChunks(); - for (Vector2D chunk : chunks) { + for (BlockVector2 chunk : chunks) { player.print(LegacyChunkStore.getFilename(chunk)); } } @@ -108,7 +108,7 @@ public class ChunkCommands { player.print("Note that this command does not yet support the mcregion format."); LocalConfiguration config = worldEdit.getConfiguration(); - Set chunks = session.getSelection(player.getWorld()).getChunks(); + Set chunks = session.getSelection(player.getWorld()).getChunks(); FileOutputStream out = null; if (config.shellSaveType == null) { @@ -125,7 +125,7 @@ public class ChunkCommands { writer.write("ECHO.\r\n"); writer.write("PAUSE\r\n"); - for (Vector2D chunk : chunks) { + for (BlockVector2 chunk : chunks) { String filename = LegacyChunkStore.getFilename(chunk); writer.write("ECHO " + filename + "\r\n"); writer.write("DEL \"world/" + filename + "\"\r\n"); @@ -156,7 +156,7 @@ public class ChunkCommands { writer.write("echo\n"); writer.write("read -p \"Press any key to continue...\"\n"); - for (Vector2D chunk : chunks) { + for (BlockVector2 chunk : chunks) { String filename = LegacyChunkStore.getFilename(chunk); writer.write("echo " + filename + "\n"); writer.write("rm \"world/" + filename + "\"\n"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java index 181f648d7..51c8c3602 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ClipboardCommands.java @@ -28,7 +28,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; @@ -42,6 +41,8 @@ import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Selection; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -154,7 +155,7 @@ public class ClipboardCommands { Clipboard clipboard = holder.getClipboard(); Region region = clipboard.getRegion(); - Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); + BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); Operation operation = holder .createPaste(editSession) .to(to) @@ -163,10 +164,10 @@ public class ClipboardCommands { Operations.completeLegacy(operation); if (selectPasted) { - Vector clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); - Vector realTo = to.add(holder.getTransform().apply(clipboardOffset)); - Vector max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()))); - RegionSelector selector = new CuboidRegionSelector(player.getWorld(), realTo, max); + BlockVector3 clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); + Vector3 realTo = to.toVector3().add(holder.getTransform().apply(clipboardOffset.toVector3())); + Vector3 max = realTo.add(holder.getTransform().apply(region.getMaximumPoint().subtract(region.getMinimumPoint()).toVector3())); + RegionSelector selector = new CuboidRegionSelector(player.getWorld(), realTo.toBlockPoint(), max.toBlockPoint()); session.setRegionSelector(player.getWorld(), selector); selector.learnChanges(); selector.explainRegionAdjust(player, session); @@ -211,11 +212,10 @@ public class ClipboardCommands { ) @CommandPermissions("worldedit.clipboard.flip") public void flip(Player player, LocalSession session, EditSession editSession, - @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException { + @Optional(Direction.AIM) @Direction BlockVector3 direction) throws WorldEditException { ClipboardHolder holder = session.getClipboard(); - Clipboard clipboard = holder.getClipboard(); AffineTransform transform = new AffineTransform(); - transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1)); + transform = transform.scale(direction.abs().multiply(-2).add(1, 1, 1).toVector3()); holder.setTransform(holder.getTransform().combine(transform)); player.print("The clipboard copy has been flipped."); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java index b15d444d9..204f062ec 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/FlattenedClipboardTransform.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.command; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.CombinedTransform; import com.sk89q.worldedit.math.transform.Transform; @@ -66,8 +66,8 @@ class FlattenedClipboardTransform { */ public Region getTransformedRegion() { Region region = original.getRegion(); - Vector minimum = region.getMinimumPoint(); - Vector maximum = region.getMaximumPoint(); + Vector3 minimum = region.getMinimumPoint().toVector3(); + Vector3 maximum = region.getMaximumPoint().toVector3(); Transform transformAround = new CombinedTransform( @@ -75,39 +75,34 @@ class FlattenedClipboardTransform { transform, new AffineTransform().translate(original.getOrigin())); - Vector[] corners = new Vector[] { + Vector3[] corners = new Vector3[] { minimum, maximum, - minimum.setX(maximum.getX()), - minimum.setY(maximum.getY()), - minimum.setZ(maximum.getZ()), - maximum.setX(minimum.getX()), - maximum.setY(minimum.getY()), - maximum.setZ(minimum.getZ()) }; + minimum.withX(maximum.getX()), + minimum.withY(maximum.getY()), + minimum.withZ(maximum.getZ()), + maximum.withX(minimum.getX()), + maximum.withY(minimum.getY()), + maximum.withZ(minimum.getZ()) }; for (int i = 0; i < corners.length; i++) { corners[i] = transformAround.apply(corners[i]); } - Vector newMinimum = corners[0]; - Vector newMaximum = corners[0]; + Vector3 newMinimum = corners[0]; + Vector3 newMaximum = corners[0]; for (int i = 1; i < corners.length; i++) { - newMinimum = Vector.getMinimum(newMinimum, corners[i]); - newMaximum = Vector.getMaximum(newMaximum, corners[i]); + newMinimum = newMinimum.getMinimum(corners[i]); + newMaximum = newMaximum.getMaximum(corners[i]); } // After transformation, the points may not really sit on a block, // so we should expand the region for edge cases - newMinimum = newMinimum.setX(Math.floor(newMinimum.getX())); - newMinimum = newMinimum.setY(Math.floor(newMinimum.getY())); - newMinimum = newMinimum.setZ(Math.floor(newMinimum.getZ())); + newMinimum = newMinimum.floor(); + newMaximum = newMaximum.ceil(); - newMaximum = newMaximum.setX(Math.ceil(newMaximum.getX())); - newMaximum = newMaximum.setY(Math.ceil(newMaximum.getY())); - newMaximum = newMaximum.setZ(Math.ceil(newMaximum.getZ())); - - return new CuboidRegion(newMinimum, newMaximum); + return new CuboidRegion(newMinimum.toBlockPoint(), newMaximum.toBlockPoint()); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java index 381de7a8a..5e0a6139c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GenerationCommands.java @@ -29,13 +29,14 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator.TreeType; import com.sk89q.worldedit.util.command.binding.Range; @@ -116,7 +117,7 @@ public class GenerationCommands { worldEdit.checkMaxRadius(radiusZ); worldEdit.checkMaxRadius(height); - Vector pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(player); int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow); player.print(affected + " block(s) have been created."); } @@ -177,9 +178,9 @@ public class GenerationCommands { worldEdit.checkMaxRadius(radiusY); worldEdit.checkMaxRadius(radiusZ); - Vector pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(player); if (raised) { - pos = pos.add(0, radiusY, 0); + pos = pos.add(0, (int) radiusY, 0); } int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow); @@ -240,7 +241,7 @@ public class GenerationCommands { @CommandPermissions("worldedit.generation.pyramid") @Logging(PLACEMENT) public void pyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow) throws WorldEditException { - Vector pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(player); worldEdit.checkMaxRadius(size); int affected = editSession.makePyramid(pos, pattern, size, !hollow); player.findFreePosition(); @@ -277,31 +278,31 @@ public class GenerationCommands { @Switch('o') boolean offset, @Switch('c') boolean offsetCenter) throws WorldEditException { - final Vector zero; - Vector unit; + final Vector3 zero; + Vector3 unit; if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; + zero = Vector3.ZERO; + unit = Vector3.ONE; } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; + zero = session.getPlacementPosition(player).toVector3(); + unit = Vector3.ONE; } else if (offsetCenter) { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); zero = max.add(min).multiply(0.5); - unit = Vector.ONE; + unit = Vector3.ONE; } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); zero = max.add(min).multiply(0.5); unit = max.subtract(zero); - if (unit.getX() == 0) unit = unit.setX(1.0); - if (unit.getY() == 0) unit = unit.setY(1.0); - if (unit.getZ() == 0) unit = unit.setZ(1.0); + if (unit.getX() == 0) unit = unit.withX(1.0); + if (unit.getY() == 0) unit = unit.withY(1.0); + if (unit.getZ() == 0) unit = unit.withZ(1.0); } try { @@ -342,31 +343,31 @@ public class GenerationCommands { @Switch('r') boolean useRawCoords, @Switch('o') boolean offset, @Switch('c') boolean offsetCenter) throws WorldEditException { - final Vector zero; - Vector unit; + final Vector3 zero; + Vector3 unit; if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; + zero = Vector3.ZERO; + unit = Vector3.ONE; } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; + zero = session.getPlacementPosition(player).toVector3(); + unit = Vector3.ONE; } else if (offsetCenter) { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); zero = max.add(min).multiply(0.5); - unit = Vector.ONE; + unit = Vector3.ONE; } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); zero = max.add(min).multiply(0.5); unit = max.subtract(zero); - if (unit.getX() == 0) unit = unit.setX(1.0); - if (unit.getY() == 0) unit = unit.setY(1.0); - if (unit.getZ() == 0) unit = unit.setZ(1.0); + if (unit.getX() == 0) unit = unit.withX(1.0); + if (unit.getY() == 0) unit = unit.withY(1.0); + if (unit.getZ() == 0) unit = unit.withZ(1.0); } try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java index 3b7efa781..9eb113c09 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/RegionCommands.java @@ -32,7 +32,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; @@ -48,6 +47,8 @@ import com.sk89q.worldedit.function.visitor.LayerVisitor; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.convolution.GaussianKernel; import com.sk89q.worldedit.math.convolution.HeightMap; import com.sk89q.worldedit.math.convolution.HeightMapFilter; @@ -110,8 +111,8 @@ public class RegionCommands { } CuboidRegion cuboidregion = (CuboidRegion) region; - Vector pos1 = cuboidregion.getPos1(); - Vector pos2 = cuboidregion.getPos2(); + BlockVector3 pos1 = cuboidregion.getPos1(); + BlockVector3 pos2 = cuboidregion.getPos2(); int blocksChanged = editSession.drawLine(pattern, pos1, pos2, thickness, !shell); player.print(blocksChanged + " block(s) have been changed."); @@ -143,7 +144,7 @@ public class RegionCommands { } ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region; - List vectors = new ArrayList<>(cpregion.getVertices()); + List vectors = new ArrayList<>(cpregion.getVertices()); int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell); @@ -274,7 +275,7 @@ public class RegionCommands { public void move(Player player, EditSession editSession, LocalSession session, @Selection Region region, @Optional("1") @Range(min = 1) int count, - @Optional(Direction.AIM) @Direction Vector direction, + @Optional(Direction.AIM) @Direction BlockVector3 direction, @Optional("air") BlockStateHolder replace, @Switch('s') boolean moveSelection) throws WorldEditException { @@ -312,16 +313,16 @@ public class RegionCommands { public void stack(Player player, EditSession editSession, LocalSession session, @Selection Region region, @Optional("1") @Range(min = 1) int count, - @Optional(Direction.AIM) @Direction Vector direction, + @Optional(Direction.AIM) @Direction BlockVector3 direction, @Switch('s') boolean moveSelection, @Switch('a') boolean ignoreAirBlocks) throws WorldEditException { int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks); if (moveSelection) { try { - final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()); + final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()); - final Vector shiftVector = direction.multiply(count * (Math.abs(direction.dot(size)) + 1)); + final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint(); region.shift(shiftVector); session.getRegionSelector(player.getWorld()).learnChanges(); @@ -378,25 +379,25 @@ public class RegionCommands { @Text String expression, @Switch('r') boolean useRawCoords, @Switch('o') boolean offset) throws WorldEditException { - final Vector zero; - Vector unit; + final Vector3 zero; + Vector3 unit; if (useRawCoords) { - zero = Vector.ZERO; - unit = Vector.ONE; + zero = Vector3.ZERO; + unit = Vector3.ONE; } else if (offset) { - zero = session.getPlacementPosition(player); - unit = Vector.ONE; + zero = session.getPlacementPosition(player).toVector3(); + unit = Vector3.ONE; } else { - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); - zero = max.add(min).multiply(0.5); + zero = max.add(min).divide(2); unit = max.subtract(zero); - if (unit.getX() == 0) unit = unit.setX(1.0); - if (unit.getY() == 0) unit = unit.setY(1.0); - if (unit.getZ() == 0) unit = unit.setZ(1.0); + if (unit.getX() == 0) unit = unit.withX(1.0); + if (unit.getY() == 0) unit = unit.withY(1.0); + if (unit.getZ() == 0) unit = unit.withZ(1.0); } try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index 5f4fca09c..d5c8aaa75 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -29,8 +29,6 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; @@ -38,6 +36,8 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionSelector; @@ -58,7 +58,6 @@ import com.sk89q.worldedit.util.formatting.StyledFragment; import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; -import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -103,13 +102,13 @@ public class SelectionCommands { pos = player.getBlockIn(); } - if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector(), ActorSelectorLimits.forActor(player))) { + if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainPrimarySelection(player, session, pos.toVector()); + .explainPrimarySelection(player, session, pos.toVector().toBlockPoint()); } @Command( @@ -138,13 +137,13 @@ public class SelectionCommands { pos = player.getBlockIn(); } - if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector(), ActorSelectorLimits.forActor(player))) { + if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainSecondarySelection(player, session, pos.toVector()); + .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); } @Command( @@ -160,13 +159,13 @@ public class SelectionCommands { Location pos = player.getBlockTrace(300); if (pos != null) { - if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector(), ActorSelectorLimits.forActor(player))) { + if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainPrimarySelection(player, session, pos.toVector()); + .explainPrimarySelection(player, session, pos.toVector().toBlockPoint()); } else { player.printError("No block in sight!"); } @@ -185,13 +184,13 @@ public class SelectionCommands { Location pos = player.getBlockTrace(300); if (pos != null) { - if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector(), ActorSelectorLimits.forActor(player))) { + if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainSecondarySelection(player, session, pos.toVector()); + .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); } else { player.printError("No block in sight!"); } @@ -216,23 +215,23 @@ public class SelectionCommands { @Logging(POSITION) @CommandPermissions("worldedit.selection.chunk") public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - final Vector min; - final Vector max; + final BlockVector3 min; + final BlockVector3 max; final World world = player.getWorld(); if (args.hasFlag('s')) { Region region = session.getSelection(world); - final Vector2D min2D = ChunkStore.toChunk(region.getMinimumPoint()); - final Vector2D max2D = ChunkStore.toChunk(region.getMaximumPoint()); + final BlockVector2 min2D = ChunkStore.toChunk(region.getMinimumPoint()); + final BlockVector2 max2D = ChunkStore.toChunk(region.getMaximumPoint()); - min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16); - max = new Vector(max2D.getBlockX() * 16 + 15, world.getMaxY(), max2D.getBlockZ() * 16 + 15); + min = new BlockVector3(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16); + max = new BlockVector3(max2D.getBlockX() * 16 + 15, world.getMaxY(), max2D.getBlockZ() * 16 + 15); player.print("Chunks selected: (" + min2D.getBlockX() + ", " + min2D.getBlockZ() + ") - (" + max2D.getBlockX() + ", " + max2D.getBlockZ() + ")"); } else { - final Vector2D min2D; + final BlockVector2 min2D; if (args.argsLength() == 1) { // coords specified String[] coords = args.getString(0).split(","); @@ -241,14 +240,14 @@ public class SelectionCommands { } int x = Integer.parseInt(coords[0]); int z = Integer.parseInt(coords[1]); - Vector2D pos = new Vector2D(x, z); - min2D = (args.hasFlag('c')) ? pos : ChunkStore.toChunk(pos.toVector()); + BlockVector2 pos = new BlockVector2(x, z); + min2D = (args.hasFlag('c')) ? pos : ChunkStore.toChunk(pos.toBlockVector3()); } else { // use player loc - min2D = ChunkStore.toChunk(player.getBlockIn().toVector()); + min2D = ChunkStore.toChunk(player.getBlockIn().toVector().toBlockPoint()); } - min = new Vector(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16); + min = new BlockVector3(min2D.getBlockX() * 16, 0, min2D.getBlockZ() * 16); max = min.add(15, world.getMaxY(), 15); player.print("Chunk selected: " @@ -321,8 +320,8 @@ public class SelectionCommands { try { int oldSize = region.getArea(); region.expand( - new Vector(0, (player.getWorld().getMaxY() + 1), 0), - new Vector(0, -(player.getWorld().getMaxY() + 1), 0)); + new BlockVector3(0, (player.getWorld().getMaxY() + 1), 0), + new BlockVector3(0, -(player.getWorld().getMaxY() + 1), 0)); session.getRegionSelector(player.getWorld()).learnChanges(); int newSize = region.getArea(); session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); @@ -335,7 +334,7 @@ public class SelectionCommands { return; } - List dirs = new ArrayList<>(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); int reverseChange = 0; @@ -380,11 +379,11 @@ public class SelectionCommands { int oldSize = region.getArea(); if (reverseChange == 0) { - for (Vector dir : dirs) { + for (BlockVector3 dir : dirs) { region.expand(dir.multiply(change)); } } else { - for (Vector dir : dirs) { + for (BlockVector3 dir : dirs) { region.expand(dir.multiply(change), dir.multiply(-reverseChange)); } } @@ -408,7 +407,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.contract") public void contract(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - List dirs = new ArrayList<>(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); int reverseChange = 0; @@ -452,11 +451,11 @@ public class SelectionCommands { Region region = session.getSelection(player.getWorld()); int oldSize = region.getArea(); if (reverseChange == 0) { - for (Vector dir : dirs) { + for (BlockVector3 dir : dirs) { region.contract(dir.multiply(change)); } } else { - for (Vector dir : dirs) { + for (BlockVector3 dir : dirs) { region.contract(dir.multiply(change), dir.multiply(-reverseChange)); } } @@ -483,7 +482,7 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.shift") public void shift(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - List dirs = new ArrayList<>(); + List dirs = new ArrayList<>(); int change = args.getInteger(0); if (args.argsLength() == 2) { if (args.getString(1).contains(",")) { @@ -500,7 +499,7 @@ public class SelectionCommands { try { Region region = session.getSelection(player.getWorld()); - for (Vector dir : dirs) { + for (BlockVector3 dir : dirs) { region.shift(dir.multiply(change)); } @@ -560,23 +559,23 @@ public class SelectionCommands { player.print("Region inset."); } - private Vector[] getChangesForEachDir(CommandContext args) { - List changes = new ArrayList<>(6); + private BlockVector3[] getChangesForEachDir(CommandContext args) { + List changes = new ArrayList<>(6); int change = args.getInteger(0); if (!args.hasFlag('h')) { - changes.add((new Vector(0, 1, 0)).multiply(change)); - changes.add((new Vector(0, -1, 0)).multiply(change)); + changes.add((new BlockVector3(0, 1, 0)).multiply(change)); + changes.add((new BlockVector3(0, -1, 0)).multiply(change)); } if (!args.hasFlag('v')) { - changes.add((new Vector(1, 0, 0)).multiply(change)); - changes.add((new Vector(-1, 0, 0)).multiply(change)); - changes.add((new Vector(0, 0, 1)).multiply(change)); - changes.add((new Vector(0, 0, -1)).multiply(change)); + changes.add((new BlockVector3(1, 0, 0)).multiply(change)); + changes.add((new BlockVector3(-1, 0, 0)).multiply(change)); + changes.add((new BlockVector3(0, 0, 1)).multiply(change)); + changes.add((new BlockVector3(0, 0, -1)).multiply(change)); } - return changes.toArray(new Vector[0]); + return changes.toArray(new BlockVector3[0]); } @Command( @@ -589,34 +588,33 @@ public class SelectionCommands { ) @CommandPermissions("worldedit.selection.size") public void size(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - if (args.hasFlag('c')) { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); Region region = clipboard.getRegion(); - Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()); - Vector origin = clipboard.getOrigin(); + BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()); + BlockVector3 origin = clipboard.getOrigin(); player.print("Cuboid dimensions (max - min): " + size); player.print("Offset: " + origin); - player.print("Cuboid distance: " + size.distance(Vector.ONE)); + player.print("Cuboid distance: " + size.distance(BlockVector3.ONE)); player.print("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ())); return; } - + Region region = session.getSelection(player.getWorld()); - Vector size = region.getMaximumPoint() + BlockVector3 size = region.getMaximumPoint() .subtract(region.getMinimumPoint()) .add(1, 1, 1); - + player.print("Type: " + session.getRegionSelector(player.getWorld()) .getTypeName()); - + for (String line : session.getRegionSelector(player.getWorld()) .getInformationLines()) { player.print(line); } - + player.print("Size: " + size); player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint())); player.print("# of blocks: " + region.getArea()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 96e3e9875..c87da1110 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -30,7 +30,6 @@ import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.util.CreatureButcher; @@ -49,6 +48,7 @@ import com.sk89q.worldedit.function.visitor.EntityVisitor; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; @@ -103,7 +103,7 @@ public class UtilityCommands { we.checkMaxRadius(radius); int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : 1; - Vector pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(player); int affected = editSession.fillXZ(pos, pattern, radius, depth, false); player.print(affected + " block(s) have been created."); } @@ -129,7 +129,7 @@ public class UtilityCommands { we.checkMaxRadius(radius); int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : Integer.MAX_VALUE; - Vector pos = session.getPlacementPosition(player); + BlockVector3 pos = session.getPlacementPosition(player); int affected = 0; if (pattern instanceof BlockPattern) { affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, true); @@ -290,9 +290,9 @@ public class UtilityCommands { to = we.getPatternFactory().parseFromInput(args.getString(2), context); } - Vector base = session.getPlacementPosition(player); - Vector min = base.subtract(size, size, size); - Vector max = base.add(size, size, size); + BlockVector3 base = session.getPlacementPosition(player); + BlockVector3 min = base.subtract(size, size, size); + BlockVector3 max = base.add(size, size, size); Region region = new CuboidRegion(player.getWorld(), min, max); if (to instanceof BlockPattern) { @@ -432,7 +432,7 @@ public class UtilityCommands { if (player != null) { session = we.getSessionManager().get(player); - Vector center = session.getPlacementPosition(player); + BlockVector3 center = session.getPlacementPosition(player); editSession = session.createEditSession(player); List entities; if (radius >= 0) { @@ -492,7 +492,7 @@ public class UtilityCommands { if (player != null) { session = we.getSessionManager().get(player); - Vector center = session.getPlacementPosition(player); + BlockVector3 center = session.getPlacementPosition(player); editSession = session.createEditSession(player); List entities; if (radius >= 0) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java index 2ce222c5b..816516978 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/argument/ItemUseParser.java @@ -22,12 +22,12 @@ package com.sk89q.worldedit.command.argument; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.command.argument.CommandArgs; import com.sk89q.worldedit.util.command.composition.SimpleCommand; @@ -82,7 +82,7 @@ public class ItemUseParser extends SimpleCommand> { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return world.useItem(position, item, Direction.UP); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java index 3bcb8a063..cae499dce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/composition/DeformCommand.java @@ -60,7 +60,7 @@ public class DeformCommand extends SimpleCommand Player player = (Player) locals.get(Actor.class); LocalSession session = WorldEdit.getInstance().getSessionManager().get(locals.get(Actor.class)); try { - deform.setOffset(session.getPlacementPosition(player)); + deform.setOffset(session.getPlacementPosition(player).toVector3()); } catch (IncompleteRegionException e) { throw new WrappedCommandException(e); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java index 1af33599c..58405c6b5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java @@ -23,10 +23,10 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -52,7 +52,7 @@ public class AreaPickaxe implements BlockTool { int ox = clicked.getBlockX(); int oy = clicked.getBlockY(); int oz = clicked.getBlockZ(); - BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType(); + BlockType initialType = clicked.getExtent().getBlock(clicked.toVector().toBlockPoint()).getBlockType(); if (initialType.getMaterial().isAir()) { return true; @@ -69,12 +69,12 @@ public class AreaPickaxe implements BlockTool { for (int x = ox - range; x <= ox + range; ++x) { for (int y = oy - range; y <= oy + range; ++y) { for (int z = oz - range; z <= oz + range; ++z) { - Vector pos = new Vector(x, y, z); + BlockVector3 pos = new BlockVector3(x, y, z); if (editSession.getBlock(pos).getBlockType() != initialType) { continue; } - ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().distanceSq(pos)); + ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().toBlockPoint().distanceSq(pos)); editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java index 474c689b3..2cc5e6e87 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockDataCyler.java @@ -27,6 +27,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; @@ -54,7 +55,8 @@ public class BlockDataCyler implements DoubleActionBlockTool { World world = (World) clicked.getExtent(); - BlockState block = world.getBlock(clicked.toVector()); + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + BlockState block = world.getBlock(blockPoint); if (!config.allowedDataCycleBlocks.isEmpty() && !player.hasPermission("worldedit.override.data-cycler") @@ -83,7 +85,7 @@ public class BlockDataCyler implements DoubleActionBlockTool { editSession.disableBuffering(); try { - editSession.setBlock(clicked.toVector(), newBlock); + editSession.setBlock(blockPoint, newBlock); player.print("Value of " + currentProperty.getName() + " is now " + currentProperty.getValues().get(index).toString()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java index 38619396b..4b5ecd79e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BlockReplacer.java @@ -23,13 +23,13 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -55,7 +55,7 @@ public class BlockReplacer implements DoubleActionBlockTool { try (EditSession editSession = session.createEditSession(player)) { try { editSession.disableBuffering(); - Vector position = clicked.toVector(); + BlockVector3 position = clicked.toVector().toBlockPoint(); editSession.setBlock(position, pattern.apply(position)); } catch (MaxChangedBlocksException ignored) { } finally { @@ -73,7 +73,7 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { - BlockStateHolder targetBlock = player.getWorld().getBlock(clicked.toVector()); + BlockStateHolder targetBlock = player.getWorld().getBlock(clicked.toVector().toBlockPoint()); if (targetBlock != null) { pattern = new BlockPattern(targetBlock); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java index 55d2947f7..403361f02 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/BrushTool.java @@ -189,7 +189,7 @@ public class BrushTool implements TraceTool { } try { - brush.build(editSession, target.toVector(), material, size); + brush.build(editSession, target.toVector().toBlockPoint(), material, size); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java index 7488c14ad..5fa95d04b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/DistanceWand.java @@ -25,6 +25,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.Location; @@ -49,8 +50,9 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool { if (target == null) return true; RegionSelector selector = session.getRegionSelector(player.getWorld()); - if (selector.selectPrimary(target.toVector(), ActorSelectorLimits.forActor(player))) { - selector.explainPrimarySelection(player, session, target.toVector()); + BlockVector3 blockPoint = target.toVector().toBlockPoint(); + if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainPrimarySelection(player, session, blockPoint); } return true; @@ -66,8 +68,9 @@ public class DistanceWand extends BrushTool implements DoubleActionTraceTool { if (target == null) return true; RegionSelector selector = session.getRegionSelector(player.getWorld()); - if (selector.selectSecondary(target.toVector(), ActorSelectorLimits.forActor(player))) { - selector.explainSecondarySelection(player, session, target.toVector()); + BlockVector3 blockPoint = target.toVector().toBlockPoint(); + if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainSecondarySelection(player, session, blockPoint); } return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java index 5c457f13b..b60ab4dc1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java @@ -23,10 +23,10 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; @@ -69,7 +69,7 @@ public class FloatingTreeRemover implements BlockTool { Player player, LocalSession session, Location clicked) { final World world = (World) clicked.getExtent(); - final BlockState state = world.getBlock(clicked.toVector()); + final BlockState state = world.getBlock(clicked.toVector().toBlockPoint()); if (!isTreeBlock(state.getBlockType())) { player.printError("That's not a tree."); @@ -78,13 +78,13 @@ public class FloatingTreeRemover implements BlockTool { try (EditSession editSession = session.createEditSession(player)) { try { - final Set blockSet = bfs(world, clicked.toVector()); + final Set blockSet = bfs(world, clicked.toVector().toBlockPoint()); if (blockSet == null) { player.printError("That's not a floating tree."); return true; } - for (Vector blockVector : blockSet) { + for (BlockVector3 blockVector : blockSet) { final BlockState otherState = editSession.getBlock(blockVector); if (isTreeBlock(otherState.getBlockType())) { editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); @@ -100,13 +100,13 @@ public class FloatingTreeRemover implements BlockTool { return true; } - private Vector[] recurseDirections = { - Direction.NORTH.toVector(), - Direction.EAST.toVector(), - Direction.SOUTH.toVector(), - Direction.WEST.toVector(), - Direction.UP.toVector(), - Direction.DOWN.toVector(), + private BlockVector3[] recurseDirections = { + Direction.NORTH.toBlockVector(), + Direction.EAST.toBlockVector(), + Direction.SOUTH.toBlockVector(), + Direction.WEST.toBlockVector(), + Direction.UP.toBlockVector(), + Direction.DOWN.toBlockVector(), }; /** @@ -116,17 +116,17 @@ public class FloatingTreeRemover implements BlockTool { * @param origin any point contained in the floating tree * @return a set containing all blocks in the tree/shroom or null if this is not a floating tree/shroom. */ - private Set bfs(World world, Vector origin) throws MaxChangedBlocksException { - final Set visited = new HashSet<>(); - final LinkedList queue = new LinkedList<>(); + private Set bfs(World world, BlockVector3 origin) throws MaxChangedBlocksException { + final Set visited = new HashSet<>(); + final LinkedList queue = new LinkedList<>(); queue.addLast(origin); visited.add(origin); while (!queue.isEmpty()) { - final Vector current = queue.removeFirst(); - for (Vector recurseDirection : recurseDirections) { - final Vector next = current.add(recurseDirection); + final BlockVector3 current = queue.removeFirst(); + for (BlockVector3 recurseDirection : recurseDirections) { + final BlockVector3 next = current.add(recurseDirection); if (origin.distanceSq(next) > rangeSq) { // Maximum range exceeded => stop walking continue; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java index 16030d299..2206b8f94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java @@ -19,16 +19,15 @@ package com.sk89q.worldedit.command.tool; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; @@ -59,7 +58,8 @@ public class FloodFillTool implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { World world = (World) clicked.getExtent(); - BlockType initialType = world.getBlock(clicked.toVector()).getBlockType(); + BlockVector3 origin = clicked.toVector().toBlockPoint(); + BlockType initialType = world.getBlock(origin).getBlockType(); if (initialType.getMaterial().isAir()) { return true; @@ -71,8 +71,7 @@ public class FloodFillTool implements BlockTool { try (EditSession editSession = session.createEditSession(player)) { try { - recurse(editSession, clicked.toVector().toBlockVector(), - clicked.toVector(), range, initialType, new HashSet<>()); + recurse(editSession, origin, origin, range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { @@ -83,8 +82,8 @@ public class FloodFillTool implements BlockTool { return true; } - private void recurse(EditSession editSession, BlockVector pos, Vector origin, int size, BlockType initialType, - Set visited) throws MaxChangedBlocksException { + private void recurse(EditSession editSession, BlockVector3 pos, BlockVector3 origin, int size, BlockType initialType, + Set visited) throws MaxChangedBlocksException { if (origin.distance(pos) > size || visited.contains(pos)) { return; @@ -98,17 +97,17 @@ public class FloodFillTool implements BlockTool { return; } - recurse(editSession, pos.add(1, 0, 0).toBlockVector(), + recurse(editSession, pos.add(1, 0, 0), origin, size, initialType, visited); - recurse(editSession, pos.add(-1, 0, 0).toBlockVector(), + recurse(editSession, pos.add(-1, 0, 0), origin, size, initialType, visited); - recurse(editSession, pos.add(0, 0, 1).toBlockVector(), + recurse(editSession, pos.add(0, 0, 1), origin, size, initialType, visited); - recurse(editSession, pos.add(0, 0, -1).toBlockVector(), + recurse(editSession, pos.add(0, 0, -1), origin, size, initialType, visited); - recurse(editSession, pos.add(0, 1, 0).toBlockVector(), + recurse(editSession, pos.add(0, 1, 0), origin, size, initialType, visited); - recurse(editSession, pos.add(0, -1, 0).toBlockVector(), + recurse(editSession, pos.add(0, -1, 0), origin, size, initialType, visited); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java index 3d056de68..046a53749 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java @@ -27,6 +27,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -55,11 +56,12 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo if (pos == null) return false; try (EditSession eS = session.createEditSession(player)) { eS.disableBuffering(); - BlockStateHolder applied = secondary.apply(pos.toVector()); + BlockVector3 blockPoint = pos.toVector().toBlockPoint(); + BlockStateHolder applied = secondary.apply(blockPoint); if (applied.getBlockType().getMaterial().isAir()) { - eS.setBlock(pos.toVector(), secondary); + eS.setBlock(blockPoint, secondary); } else { - eS.setBlock(pos.getDirection(), secondary); + eS.setBlock(pos.getDirection().toBlockPoint(), secondary); } return true; } catch (MaxChangedBlocksException e) { @@ -75,11 +77,12 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo if (pos == null) return false; try (EditSession eS = session.createEditSession(player)) { eS.disableBuffering(); - BlockStateHolder applied = primary.apply(pos.toVector()); + BlockVector3 blockPoint = pos.toVector().toBlockPoint(); + BlockStateHolder applied = primary.apply(blockPoint); if (applied.getBlockType().getMaterial().isAir()) { - eS.setBlock(pos.toVector(), primary); + eS.setBlock(blockPoint, primary); } else { - eS.setBlock(pos.getDirection(), primary); + eS.setBlock(pos.getDirection().toBlockPoint(), primary); } return true; } catch (MaxChangedBlocksException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 1ad0441a4..59e21bfde 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.blocks.MobSpawnerBlock; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -44,13 +45,14 @@ public class QueryTool implements BlockTool { World world = (World) clicked.getExtent(); EditSession editSession = session.createEditSession(player); - BlockStateHolder block = editSession.getFullBlock(clicked.toVector()); + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + BlockStateHolder block = editSession.getFullBlock(blockPoint); player.print("\u00A79@" + clicked.toVector() + ": " + "\u00A7e" + block.getBlockType().getName() + "\u00A77" + " (" + block.toString() + ") " + "\u00A7f" - + " (" + world.getBlockLightLevel(clicked.toVector()) + "/" + world.getBlockLightLevel(clicked.toVector().add(0, 1, 0)) + ")"); + + " (" + world.getBlockLightLevel(blockPoint) + "/" + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")"); if (block instanceof MobSpawnerBlock) { player.printRaw("\u00A7e" + "Mob Type: " diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java index afeb4728d..e49a17374 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java @@ -19,15 +19,14 @@ package com.sk89q.worldedit.command.tool; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -56,7 +55,8 @@ public class RecursivePickaxe implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); - BlockType initialType = world.getBlock(clicked.toVector()).getBlockType(); + BlockVector3 origin = clicked.toVector().toBlockPoint(); + BlockType initialType = world.getBlock(origin).getBlockType(); if (initialType.getMaterial().isAir()) { return true; @@ -70,8 +70,8 @@ public class RecursivePickaxe implements BlockTool { editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); try { - recurse(server, editSession, world, clicked.toVector().toBlockVector(), - clicked.toVector(), range, initialType, new HashSet<>()); + recurse(server, editSession, world, clicked.toVector().toBlockPoint(), + clicked.toVector().toBlockPoint(), range, initialType, new HashSet<>()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { @@ -82,8 +82,8 @@ public class RecursivePickaxe implements BlockTool { return true; } - private static void recurse(Platform server, EditSession editSession, World world, BlockVector pos, - Vector origin, double size, BlockType initialType, Set visited) throws MaxChangedBlocksException { + private static void recurse(Platform server, EditSession editSession, World world, BlockVector3 pos, + BlockVector3 origin, double size, BlockType initialType, Set visited) throws MaxChangedBlocksException { final double distanceSq = origin.distanceSq(pos); if (distanceSq > size*size || visited.contains(pos)) { @@ -100,17 +100,17 @@ public class RecursivePickaxe implements BlockTool { editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); - recurse(server, editSession, world, pos.add(1, 0, 0).toBlockVector(), + recurse(server, editSession, world, pos.add(1, 0, 0), origin, size, initialType, visited); - recurse(server, editSession, world, pos.add(-1, 0, 0).toBlockVector(), + recurse(server, editSession, world, pos.add(-1, 0, 0), origin, size, initialType, visited); - recurse(server, editSession, world, pos.add(0, 0, 1).toBlockVector(), + recurse(server, editSession, world, pos.add(0, 0, 1), origin, size, initialType, visited); - recurse(server, editSession, world, pos.add(0, 0, -1).toBlockVector(), + recurse(server, editSession, world, pos.add(0, 0, -1), origin, size, initialType, visited); - recurse(server, editSession, world, pos.add(0, 1, 0).toBlockVector(), + recurse(server, editSession, world, pos.add(0, 1, 0), origin, size, initialType, visited); - recurse(server, editSession, world, pos.add(0, -1, 0).toBlockVector(), + recurse(server, editSession, world, pos.add(0, -1, 0), origin, size, initialType, visited); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java index fbf1874ce..8ba789626 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/SinglePickaxe.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -43,7 +44,8 @@ public class SinglePickaxe implements BlockTool { @Override public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { World world = (World) clicked.getExtent(); - final BlockType blockType = world.getBlock(clicked.toVector()).getBlockType(); + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + final BlockType blockType = world.getBlock(blockPoint).getBlockType(); if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; @@ -51,7 +53,7 @@ public class SinglePickaxe implements BlockTool { try (EditSession editSession = session.createEditSession(player)) { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); - editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState()); + editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java index 27c1df2e9..8c353ed74 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/TreePlanter.java @@ -53,7 +53,7 @@ public class TreePlanter implements BlockTool { boolean successful = false; for (int i = 0; i < 10; i++) { - if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0))) { + if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0).toBlockPoint())) { successful = true; break; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/Brush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/Brush.java index 0caf07dbe..c066c7d10 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/Brush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/Brush.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; /** * A brush is a long-range build tool. @@ -38,6 +38,6 @@ public interface Brush { * @param size the size of the brush * @throws MaxChangedBlocksException */ - void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException; + void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java index 175cc32ae..f715c424f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ButcherBrush.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.EntityVisitor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CylinderRegion; import java.util.List; @@ -40,7 +40,7 @@ public class ButcherBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { CylinderRegion region = CylinderRegion.createRadius(editSession, position, size); List entities = editSession.getEntities(region); Operations.completeLegacy(new EntityVisitor(entities.iterator(), flags.createFunction())); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java index 184480787..d6abe3cc9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/ClipboardBrush.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; @@ -42,10 +42,10 @@ public class ClipboardBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { Clipboard clipboard = holder.getClipboard(); Region region = clipboard.getRegion(); - Vector centerOffset = region.getCenter().subtract(clipboard.getOrigin()); + BlockVector3 centerOffset = region.getCenter().toBlockPoint().subtract(clipboard.getOrigin()); Operation operation = holder .createPaste(editSession) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java index 10db344ca..12a663ed3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/CylinderBrush.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; public class CylinderBrush implements Brush { @@ -35,7 +35,7 @@ public class CylinderBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java index 8eaf1fbce..5ae29bec7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -39,21 +39,21 @@ public class GravityBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { final double startY = fullHeight ? editSession.getWorld().getMaxY() : position.getBlockY() + size; for (double x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { for (double z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { double y = startY; final List blockTypes = new ArrayList<>(); for (; y > position.getBlockY() - size; --y) { - final Vector pt = new Vector(x, y, z); + final BlockVector3 pt = new BlockVector3(x, y, z); final BlockStateHolder block = editSession.getBlock(pt); if (!block.getBlockType().getMaterial().isAir()) { blockTypes.add(block); editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); } } - Vector pt = new Vector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); Collections.reverse(blockTypes); for (int i = 0; i < blockTypes.size();) { if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java index 3f9eb06c7..dbf959e1b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowCylinderBrush.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; public class HollowCylinderBrush implements Brush { @@ -35,7 +35,7 @@ public class HollowCylinderBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java index 7980ec744..0e89b3c16 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/HollowSphereBrush.java @@ -21,15 +21,15 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; public class HollowSphereBrush implements Brush { @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java index f9a679d62..6a323f14b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/OperationFactoryBrush.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.Contextual; import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.factory.RegionFactory; public class OperationFactoryBrush implements Brush { @@ -40,7 +40,7 @@ public class OperationFactoryBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { EditContext context = new EditContext(); context.setDestination(editSession); context.setRegion(regionFactory.createCenteredAt(position, size)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java index df76950d4..d46b1ec3a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SmoothBrush.java @@ -21,8 +21,9 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.convolution.GaussianKernel; import com.sk89q.worldedit.math.convolution.HeightMap; import com.sk89q.worldedit.math.convolution.HeightMapFilter; @@ -39,10 +40,11 @@ public class SmoothBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { - Location min = new Location(editSession.getWorld(), position.subtract(size, size, size)); - Vector max = position.add(size, size + 10, size); - Region region = new CuboidRegion(editSession.getWorld(), min.toVector(), max); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { + Vector3 posDouble = position.toVector3(); + Location min = new Location(editSession.getWorld(), posDouble.subtract(size, size, size)); + BlockVector3 max = posDouble.add(size, size + 10, size).toBlockPoint(); + Region region = new CuboidRegion(editSession.getWorld(), min.toVector().toBlockPoint(), max); HeightMap heightMap = new HeightMap(editSession, region); HeightMapFilter filter = new HeightMapFilter(new GaussianKernel(5, 1.0)); heightMap.applyFilter(filter, iterations); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java index ba4b3eaf2..d8028f2ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/SphereBrush.java @@ -21,15 +21,15 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; public class SphereBrush implements Brush { @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java index ac2fc81ed..4b8b4483f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/entity/Player.java @@ -20,15 +20,16 @@ package com.sk89q.worldedit.entity; import com.sk89q.worldedit.PlayerDirection; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.inventory.BlockBag; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; @@ -256,14 +257,14 @@ public interface Player extends Entity, Actor { * @param pitch the pitch (up/down) of the player's view in degrees * @param yaw the yaw (left/right) of the player's view in degrees */ - void setPosition(Vector pos, float pitch, float yaw); + void setPosition(Vector3 pos, float pitch, float yaw); /** * Move the player. * * @param pos where to move them */ - void setPosition(Vector pos); + void setPosition(Vector3 pos); /** * Sends a fake block to the client. @@ -275,5 +276,5 @@ public interface Player extends Entity, Actor { * @param pos The position of the block * @param block The block to send, null to reset */ - void sendFakeBlock(Vector pos, @Nullable BlockStateHolder block); + void sendFakeBlock(BlockVector3 pos, @Nullable BlockStateHolder block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java index d1bf6a238..a84ffc152 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/event/extent/EditSessionEvent.java @@ -23,10 +23,10 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.EditSession.Stage; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.event.Event; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -53,7 +53,7 @@ import javax.annotation.Nullable; * is set to {@link Stage#BEFORE_HISTORY}, then you can drop (or log) changes * before the change has reached the history, reordering, and actual change * extents, but that means that any changes made with - * {@link EditSession#rawSetBlock(Vector, BlockStateHolder)} will skip your + * {@link EditSession#rawSetBlock(BlockVector3, BlockStateHolder)} will skip your * custom {@link Extent} because that method bypasses history (and reorder). * It is thus recommended that loggers intercept at {@link Stage#BEFORE_CHANGE} * and block interceptors intercept at BOTH {@link Stage#BEFORE_CHANGE} and diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java index 510656828..d75b9c739 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultBlockParser.java @@ -19,7 +19,6 @@ package com.sk89q.worldedit.extension.factory; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.WorldEdit; @@ -37,6 +36,7 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.registry.InputParser; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.world.World; @@ -245,7 +245,7 @@ class DefaultBlockParser extends InputParser { } else if ("pos1".equalsIgnoreCase(typeString)) { // Get the block type from the "primary position" final World world = context.requireWorld(); - final BlockVector primaryPosition; + final BlockVector3 primaryPosition; try { primaryPosition = context.requireSession().getRegionSelector(world).getPrimaryPosition(); } catch (IncompleteRegionException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java index 981e60800..5f9c9b806 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/DefaultMaskParser.java @@ -20,7 +20,6 @@ package com.sk89q.worldedit.extension.factory; import com.sk89q.worldedit.IncompleteRegionException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.NoMatchException; @@ -42,6 +41,8 @@ import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.registry.InputParser; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.noise.RandomNoise; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.session.request.Request; @@ -134,7 +135,7 @@ class DefaultMaskParser extends InputParser { } else { submask = new ExistingBlockMask(extent); } - OffsetMask offsetMask = new OffsetMask(submask, new Vector(0, firstChar == '>' ? -1 : 1, 0)); + OffsetMask offsetMask = new OffsetMask(submask, new BlockVector3(0, firstChar == '>' ? -1 : 1, 0)); return new MaskIntersection(offsetMask, Masks.negate(submask)); case '$': @@ -161,7 +162,7 @@ class DefaultMaskParser extends InputParser { try { Expression exp = Expression.compile(component.substring(1), "x", "y", "z"); WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment( - Request.request().getEditSession(), Vector.ONE, Vector.ZERO); + Request.request().getEditSession(), Vector3.ONE, Vector3.ZERO); exp.setEnvironment(env); return new ExpressionMask(exp); } catch (ExpressionException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java index d08b2bf18..fabfe0662 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java @@ -21,16 +21,17 @@ package com.sk89q.worldedit.extension.platform; import com.sk89q.worldedit.NotABlockException; import com.sk89q.worldedit.PlayerDirection; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TargetBlock; import com.sk89q.worldedit.util.auth.AuthorizationException; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -105,7 +106,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { byte free = 0; while (y <= world.getMaximumPoint().getBlockY() + 2) { - if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { ++free; } else { free = 0; @@ -113,7 +114,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (free == 2) { if (y - 1 != origY) { - setPosition(new Vector(x + 0.5, y - 2 + 1, z + 0.5)); + setPosition(new Vector3(x + 0.5, y - 2 + 1, z + 0.5)); } return; @@ -131,10 +132,10 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { int z = searchPos.getBlockZ(); while (y >= 0) { - final Vector pos = new Vector(x, y, z); + final BlockVector3 pos = new BlockVector3(x, y, z); final BlockState id = world.getBlock(pos); if (id.getBlockType().getMaterial().isMovementBlocker()) { - setPosition(new Vector(x + 0.5, y + 1, z + 0.5)); + setPosition(new Vector3(x + 0.5, y + 1, z + 0.5)); return; } @@ -159,7 +160,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { byte spots = 0; while (y <= world.getMaximumPoint().getY() + 2) { - if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { ++free; } else { free = 0; @@ -168,7 +169,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (free == 2) { ++spots; if (spots == 2) { - final Vector platform = new Vector(x, y - 2, z); + final BlockVector3 platform = new BlockVector3(x, y - 2, z); final BlockStateHolder block = world.getBlock(platform); final com.sk89q.worldedit.world.block.BlockType type = block.getBlockType(); @@ -177,7 +178,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { return false; } - setPosition(platform.add(0.5, 1, 0.5)); + setPosition(platform.toVector3().add(0.5, 1, 0.5)); return true; } } @@ -199,7 +200,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { byte free = 0; while (y >= 1) { - if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { ++free; } else { free = 0; @@ -210,14 +211,14 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { // lightly and also check to see if there's something to // stand upon while (y >= 0) { - final Vector platform = new Vector(x, y, z); + final BlockVector3 platform = new BlockVector3(x, y, z); final BlockStateHolder block = world.getBlock(platform); final BlockType type = block.getBlockType(); // Don't want to end up in lava if (!type.getMaterial().isAir() && type != BlockTypes.LAVA) { // Found a block! - setPosition(platform.add(0.5, 1, 0.5)); + setPosition(platform.toVector3().add(0.5, 1, 0.5)); return true; } @@ -248,13 +249,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { Extent world = getLocation().getExtent(); // No free space above - if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isAir()) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isAir()) { return false; } while (y <= world.getMaximumPoint().getY()) { // Found a ceiling! - if (world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + if (world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { int platformY = Math.max(initialY, y - 3 - clearance); floatAt(x, platformY + 1, z, alwaysGlass); return true; @@ -282,7 +283,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { final Extent world = getLocation().getExtent(); while (y <= world.getMaximumPoint().getY() + 2) { - if (world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + if (world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { break; // Hit something } else if (y > maxY + 1) { break; @@ -300,24 +301,24 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { try { - Vector spot = new Vector(x, y - 1, z); + BlockVector3 spot = new BlockVector3(x, y - 1, z); if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); } } catch (WorldEditException e) { e.printStackTrace(); } - setPosition(new Vector(x + 0.5, y, z + 0.5)); + setPosition(new Vector3(x + 0.5, y, z + 0.5)); } @Override public Location getBlockIn() { - return getLocation().setPosition(getLocation().toVector().toBlockVector()); + return getLocation().setPosition(getLocation().toVector().floor()); } @Override public Location getBlockOn() { - return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().toBlockVector()); + return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor()); } @Override @@ -392,7 +393,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { boolean inFree = false; while ((block = hitBlox.getNextBlock()) != null) { - boolean free = !world.getBlock(block.toVector()).getBlockType().getMaterial().isMovementBlocker(); + boolean free = !world.getBlock(block.toVector().toBlockPoint()).getBlockType().getMaterial().isMovementBlocker(); if (firstBlock) { firstBlock = false; @@ -426,7 +427,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { } @Override - public void setPosition(Vector pos) { + public void setPosition(Vector3 pos) { setPosition(pos, getLocation().getPitch(), getLocation().getYaw()); } @@ -499,7 +500,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { } @Override - public void sendFakeBlock(Vector pos, BlockStateHolder block) { + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java index 95c202455..6ff415d4b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformManager.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.tool.BlockTool; import com.sk89q.worldedit.command.tool.DoubleActionBlockTool; @@ -38,6 +37,8 @@ import com.sk89q.worldedit.event.platform.PlatformInitializeEvent; import com.sk89q.worldedit.event.platform.PlatformReadyEvent; import com.sk89q.worldedit.event.platform.PlayerInputEvent; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -302,7 +303,7 @@ public class PlatformManager { Actor actor = createProxyActor(event.getCause()); Location location = event.getLocation(); - Vector vector = location.toVector(); + Vector3 vector = location.toVector(); // At this time, only handle interaction from players if (actor instanceof Player) { @@ -321,8 +322,9 @@ public class PlatformManager { RegionSelector selector = session.getRegionSelector(player.getWorld()); - if (selector.selectPrimary(location.toVector(), ActorSelectorLimits.forActor(player))) { - selector.explainPrimarySelection(actor, session, vector); + BlockVector3 blockPoint = vector.toBlockPoint(); + if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainPrimarySelection(actor, session, blockPoint); } event.setCancelled(true); @@ -356,8 +358,9 @@ public class PlatformManager { } RegionSelector selector = session.getRegionSelector(player.getWorld()); - if (selector.selectSecondary(vector, ActorSelectorLimits.forActor(player))) { - selector.explainSecondarySelection(actor, session, vector); + BlockVector3 blockPoint = vector.toBlockPoint(); + if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainSecondarySelection(actor, session, blockPoint); } event.setCancelled(true); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index adb5e2e83..be748c2c7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -21,12 +21,13 @@ package com.sk89q.worldedit.extension.platform; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -92,7 +93,7 @@ class PlayerProxy extends AbstractPlayerActor { } @Override - public void setPosition(Vector pos, float pitch, float yaw) { + public void setPosition(Vector3 pos, float pitch, float yaw) { basePlayer.setPosition(pos, pitch, yaw); } @@ -158,7 +159,7 @@ class PlayerProxy extends AbstractPlayerActor { } @Override - public void sendFakeBlock(Vector pos, BlockStateHolder block) { + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { basePlayer.sendFakeBlock(pos, block); } } 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 a93c9b93d..94c346ff6 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 @@ -21,17 +21,17 @@ package com.sk89q.worldedit.extent; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -66,17 +66,17 @@ public abstract class AbstractDelegateExtent implements Extent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return extent.getBlock(position); } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { return extent.getFullBlock(position); } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return extent.setBlock(location, block); } @@ -97,22 +97,22 @@ public abstract class AbstractDelegateExtent implements Extent { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return extent.getBiome(position); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return extent.setBiome(position, biome); } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return extent.getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return extent.getMaximumPoint(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java index e4f6ba48d..15ccf544b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/ChangeSetExtent.java @@ -21,17 +21,17 @@ package com.sk89q.worldedit.extent; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.history.change.BlockChange; import com.sk89q.worldedit.history.change.EntityCreate; import com.sk89q.worldedit.history.change.EntityRemove; import com.sk89q.worldedit.history.changeset.ChangeSet; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; @@ -59,9 +59,9 @@ public class ChangeSetExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { BaseBlock previous = getFullBlock(location); - changeSet.add(new BlockChange(location.toBlockVector(), previous, block)); + changeSet.add(new BlockChange(location, previous, block)); return super.setBlock(location, block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java index 5ed584351..e76170f95 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/Extent.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; @@ -46,7 +46,7 @@ public interface Extent extends InputExtent, OutputExtent { * * @return the minimum point */ - Vector getMinimumPoint(); + BlockVector3 getMinimumPoint(); /** * Get the maximum point in the extent. @@ -56,7 +56,7 @@ public interface Extent extends InputExtent, OutputExtent { * * @return the maximum point */ - Vector getMaximumPoint(); + BlockVector3 getMaximumPoint(); /** * Get a list of all entities within the given region. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/InputExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/InputExtent.java index 61ea293c8..8b0fd2d48 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/InputExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/InputExtent.java @@ -19,11 +19,11 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; /** @@ -45,7 +45,7 @@ public interface InputExtent { * @param position position of the block * @return the block */ - BlockState getBlock(Vector position); + BlockState getBlock(BlockVector3 position); /** * Get a immutable snapshot of the block at the given location. @@ -53,7 +53,7 @@ public interface InputExtent { * @param position position of the block * @return the block */ - BaseBlock getFullBlock(Vector position); + BaseBlock getFullBlock(BlockVector3 position); /** * Get the biome at the given location. @@ -64,6 +64,6 @@ public interface InputExtent { * @param position the (x, z) location to check the biome at * @return the biome at the location */ - BaseBiome getBiome(Vector2D position); + BaseBiome getBiome(BlockVector2 position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java index cbd21675c..6f27d0dae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/MaskingExtent.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.extent; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -65,7 +65,7 @@ public class MaskingExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return mask.test(location) && super.setBlock(location, block); } 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 93ffb6e94..832ecd489 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 @@ -19,16 +19,16 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -44,16 +44,14 @@ import javax.annotation.Nullable; */ public class NullExtent implements Extent { - private final Vector nullPoint = new Vector(0, 0, 0); - @Override - public Vector getMinimumPoint() { - return nullPoint; + public BlockVector3 getMinimumPoint() { + return BlockVector3.ZERO; } @Override - public Vector getMaximumPoint() { - return nullPoint; + public BlockVector3 getMaximumPoint() { + return BlockVector3.ZERO; } @Override @@ -73,28 +71,28 @@ public class NullExtent implements Extent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { return getBlock(position).toBaseBlock(); } @Nullable @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return null; } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return false; } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java index 36747fd97..002ed755b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/OutputExtent.java @@ -19,10 +19,10 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -50,7 +50,7 @@ public interface OutputExtent { * @return true if the block was successfully set (return value may not be accurate) * @throws WorldEditException thrown on an error */ - boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException; + boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException; /** * Set the biome. @@ -59,7 +59,7 @@ public interface OutputExtent { * @param biome the biome to set to * @return true if the biome was successfully set (return value may not be accurate) */ - boolean setBiome(Vector2D position, BaseBiome biome); + boolean setBiome(BlockVector2 position, BaseBiome biome); /** * Return an {@link Operation} that should be called to tie up loose ends diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java index 3905f4ccb..ebb5afea5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/buffer/ForgetfulExtentBuffer.java @@ -21,14 +21,14 @@ package com.sk89q.worldedit.extent.buffer; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; @@ -44,19 +44,19 @@ import java.util.Map; * actual application of the changes. * *

This buffer will not attempt to return results from the buffer when - * accessor methods (such as {@link #getBlock(Vector)}) are called.

+ * accessor methods (such as {@link #getBlock(BlockVector3)}) are called.

*/ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pattern { - private final Map buffer = new LinkedHashMap<>(); + private final Map buffer = new LinkedHashMap<>(); private final Mask mask; - private Vector min = null; - private Vector max = null; + private BlockVector3 min = null; + private BlockVector3 max = null; /** * Create a new extent buffer that will buffer every change. * - * @param delegate the delegate extent for {@link Extent#getBlock(Vector)}, etc. calls + * @param delegate the delegate extent for {@link Extent#getBlock(BlockVector3)}, etc. calls */ public ForgetfulExtentBuffer(Extent delegate) { this(delegate, Masks.alwaysTrue()); @@ -66,7 +66,7 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat * Create a new extent buffer that will buffer changes that meet the criteria * of the given mask. * - * @param delegate the delegate extent for {@link Extent#getBlock(Vector)}, etc. calls + * @param delegate the delegate extent for {@link Extent#getBlock(BlockVector3)}, etc. calls * @param mask the mask */ public ForgetfulExtentBuffer(Extent delegate, Mask mask) { @@ -77,22 +77,22 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { // Update minimum if (min == null) { min = location; } else { - min = Vector.getMinimum(min, location); + min = min.getMinimum(location); } // Update maximum if (max == null) { max = location; } else { - max = Vector.getMaximum(max, location); + max = max.getMaximum(location); } - BlockVector blockVector = location.toBlockVector(); + BlockVector3 blockVector = location; if (mask.test(blockVector)) { buffer.put(blockVector, block); return true; @@ -102,8 +102,8 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat } @Override - public BlockStateHolder apply(Vector pos) { - BlockStateHolder block = buffer.get(pos.toBlockVector()); + public BlockStateHolder apply(BlockVector3 pos) { + BlockStateHolder block = buffer.get(pos); if (block != null) { return block; } else { @@ -119,32 +119,32 @@ public class ForgetfulExtentBuffer extends AbstractDelegateExtent implements Pat public Region asRegion() { return new AbstractRegion(null) { @Override - public Vector getMinimumPoint() { - return min != null ? min : new Vector(); + public BlockVector3 getMinimumPoint() { + return min != null ? min : BlockVector3.ZERO; } @Override - public Vector getMaximumPoint() { - return max != null ? max : new Vector(); + public BlockVector3 getMaximumPoint() { + return max != null ? max : BlockVector3.ZERO; } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { throw new UnsupportedOperationException("Cannot change the size of this region"); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { throw new UnsupportedOperationException("Cannot change the size of this region"); } @Override - public boolean contains(Vector position) { - return buffer.containsKey(position.toBlockVector()); + public boolean contains(BlockVector3 position) { + return buffer.containsKey(position); } @Override - public Iterator iterator() { + public Iterator iterator() { return buffer.keySet().iterator(); } }; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/cache/LastAccessExtentCache.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/cache/LastAccessExtentCache.java index b4c4e267a..4fdb6e430 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/cache/LastAccessExtentCache.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/cache/LastAccessExtentCache.java @@ -19,15 +19,15 @@ package com.sk89q.worldedit.extent.cache; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.block.BlockState; /** * Returns the same cached {@link BlockState} for repeated calls to - * {@link #getBlock(Vector)} with the same position. + * {@link #getBlock(BlockVector3)} with the same position. */ public class LastAccessExtentCache extends AbstractDelegateExtent { @@ -43,23 +43,22 @@ public class LastAccessExtentCache extends AbstractDelegateExtent { } @Override - public BlockState getBlock(Vector position) { - BlockVector blockVector = position.toBlockVector(); + public BlockState getBlock(BlockVector3 position) { CachedBlock lastBlock = this.lastBlock; - if (lastBlock != null && lastBlock.position.equals(blockVector)) { + if (lastBlock != null && lastBlock.position.equals(position)) { return lastBlock.block; } else { BlockState block = super.getBlock(position); - this.lastBlock = new CachedBlock(blockVector, block); + this.lastBlock = new CachedBlock(position, block); return block; } } private static class CachedBlock { - private final BlockVector position; + private final BlockVector3 position; private final BlockState block; - private CachedBlock(BlockVector position, BlockState block) { + private CachedBlock(BlockVector3 position, BlockState block) { this.position = position; this.block = block; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java index cd817f9bf..32e4a17d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/BlockArrayClipboard.java @@ -21,16 +21,16 @@ package com.sk89q.worldedit.extent.clipboard; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -48,7 +48,7 @@ import javax.annotation.Nullable; public class BlockArrayClipboard implements Clipboard { private final Region region; - private Vector origin; + private BlockVector3 origin; private final BlockStateHolder[][][] blocks; private final List entities = new ArrayList<>(); @@ -64,7 +64,7 @@ public class BlockArrayClipboard implements Clipboard { this.region = region.clone(); this.origin = region.getMinimumPoint(); - Vector dimensions = getDimensions(); + BlockVector3 dimensions = getDimensions(); blocks = new BlockStateHolder[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()]; } @@ -74,27 +74,27 @@ public class BlockArrayClipboard implements Clipboard { } @Override - public Vector getOrigin() { + public BlockVector3 getOrigin() { return origin; } @Override - public void setOrigin(Vector origin) { + public void setOrigin(BlockVector3 origin) { this.origin = origin; } @Override - public Vector getDimensions() { + public BlockVector3 getDimensions() { return region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return region.getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return region.getMaximumPoint(); } @@ -102,7 +102,7 @@ public class BlockArrayClipboard implements Clipboard { public List getEntities(Region region) { List filtered = new ArrayList<>(); for (Entity entity : entities) { - if (region.contains(entity.getLocation().toVector())) { + if (region.contains(entity.getLocation().toVector().toBlockPoint())) { filtered.add(entity); } } @@ -123,9 +123,9 @@ public class BlockArrayClipboard implements Clipboard { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { if (region.contains(position)) { - Vector v = position.subtract(region.getMinimumPoint()); + BlockVector3 v = position.subtract(region.getMinimumPoint()); BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()]; if (block != null) { return block.toImmutableState(); @@ -136,9 +136,9 @@ public class BlockArrayClipboard implements Clipboard { } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { if (region.contains(position)) { - Vector v = position.subtract(region.getMinimumPoint()); + BlockVector3 v = position.subtract(region.getMinimumPoint()); BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()]; if (block != null) { return block.toBaseBlock(); @@ -149,9 +149,9 @@ public class BlockArrayClipboard implements Clipboard { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { if (region.contains(position)) { - Vector v = position.subtract(region.getMinimumPoint()); + BlockVector3 v = position.subtract(region.getMinimumPoint()); blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block; return true; } else { @@ -160,12 +160,12 @@ public class BlockArrayClipboard implements Clipboard { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return new BaseBiome(0); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java index fa7ff1929..e0022d480 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/Clipboard.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.extent.clipboard; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; /** @@ -42,20 +42,20 @@ public interface Clipboard extends Extent { * * @return the dimensions */ - Vector getDimensions(); + BlockVector3 getDimensions(); /** * Get the origin point from which the copy was made from. * * @return the origin */ - Vector getOrigin(); + BlockVector3 getOrigin(); /** * Set the origin point from which the copy was made from. * * @param origin the origin */ - void setOrigin(Vector origin); + void setOrigin(BlockVector3 origin); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java index f3e653827..f278595a0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java @@ -30,14 +30,13 @@ import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler; import com.sk89q.worldedit.extent.clipboard.io.legacycompat.SignCompatibilityHandler; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; @@ -105,7 +104,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { // Metadata // ==================================================================== - Vector origin; + BlockVector3 origin; Region region; // Get information @@ -117,18 +116,18 @@ public class MCEditSchematicReader extends NBTSchematicReader { int originX = requireTag(schematic, "WEOriginX", IntTag.class).getValue(); int originY = requireTag(schematic, "WEOriginY", IntTag.class).getValue(); int originZ = requireTag(schematic, "WEOriginZ", IntTag.class).getValue(); - Vector min = new Vector(originX, originY, originZ); + BlockVector3 min = new BlockVector3(originX, originY, originZ); int offsetX = requireTag(schematic, "WEOffsetX", IntTag.class).getValue(); int offsetY = requireTag(schematic, "WEOffsetY", IntTag.class).getValue(); int offsetZ = requireTag(schematic, "WEOffsetZ", IntTag.class).getValue(); - Vector offset = new Vector(offsetX, offsetY, offsetZ); + BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ); origin = min.subtract(offset); - region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE)); + region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); } catch (IOException ignored) { - origin = new Vector(0, 0, 0); - region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); + origin = BlockVector3.ZERO; + region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); } // ==================================================================== @@ -162,7 +161,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { // Need to pull out tile entities List tileEntities = requireTag(schematic, "TileEntities", ListTag.class).getValue(); - Map> tileEntitiesMap = new HashMap<>(); + Map> tileEntitiesMap = new HashMap<>(); for (Tag tag : tileEntities) { if (!(tag instanceof CompoundTag)) continue; @@ -206,7 +205,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { } } - BlockVector vec = new BlockVector(x, y, z); + BlockVector3 vec = new BlockVector3(x, y, z); tileEntitiesMap.put(vec, values); } @@ -220,7 +219,7 @@ public class MCEditSchematicReader extends NBTSchematicReader { for (int y = 0; y < height; ++y) { for (int z = 0; z < length; ++z) { int index = y * width * length + z * width + x; - BlockVector pt = new BlockVector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]); try { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java index e1541bc63..b9c582bad 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicReader.java @@ -31,8 +31,6 @@ import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.input.InputParseException; @@ -40,6 +38,7 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.legacycompat.NBTCompatibilityHandler; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockState; @@ -96,7 +95,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { } private Clipboard readVersion1(Map schematic) throws IOException { - Vector origin; + BlockVector3 origin; Region region; Map metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue(); @@ -110,19 +109,19 @@ public class SpongeSchematicReader extends NBTSchematicReader { throw new IOException("Invalid offset specified in schematic."); } - Vector min = new Vector(offsetParts[0], offsetParts[1], offsetParts[2]); + BlockVector3 min = new BlockVector3(offsetParts[0], offsetParts[1], offsetParts[2]); if (metadata.containsKey("WEOffsetX")) { // We appear to have WorldEdit Metadata int offsetX = requireTag(metadata, "WEOffsetX", IntTag.class).getValue(); int offsetY = requireTag(metadata, "WEOffsetY", IntTag.class).getValue(); int offsetZ = requireTag(metadata, "WEOffsetZ", IntTag.class).getValue(); - Vector offset = new Vector(offsetX, offsetY, offsetZ); + BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ); origin = min.subtract(offset); - region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE)); + region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); } else { origin = min; - region = new CuboidRegion(origin, origin.add(width, height, length).subtract(Vector.ONE)); + region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); } int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue(); @@ -151,7 +150,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); - Map> tileEntitiesMap = new HashMap<>(); + Map> tileEntitiesMap = new HashMap<>(); try { List> tileEntityTags = requireTag(schematic, "TileEntities", ListTag.class).getValue().stream() .map(tag -> (CompoundTag) tag) @@ -160,7 +159,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { for (Map tileEntity : tileEntityTags) { int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue(); - tileEntitiesMap.put(new BlockVector(pos[0], pos[1], pos[2]).toBlockVector(), tileEntity); + tileEntitiesMap.put(new BlockVector3(pos[0], pos[1], pos[2]), tileEntity); } } catch (Exception e) { throw new IOException("Failed to load Tile Entities: " + e.getMessage()); @@ -193,7 +192,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { int z = (index % (width * length)) / width; int x = (index % (width * length)) % width; BlockState state = palette.get(value); - BlockVector pt = new BlockVector(x, y, z); + BlockVector3 pt = new BlockVector3(x, y, z); try { if (tileEntitiesMap.containsKey(pt)) { Map values = Maps.newHashMap(tileEntitiesMap.get(pt)); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java index 8ed384e5e..629eb22ba 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/SpongeSchematicWriter.java @@ -30,11 +30,10 @@ import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; +import com.sk89q.worldedit.world.block.BaseBlock; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -76,9 +75,9 @@ public class SpongeSchematicWriter implements ClipboardWriter { */ private Map write1(Clipboard clipboard) throws IOException { Region region = clipboard.getRegion(); - Vector origin = clipboard.getOrigin(); - Vector min = region.getMinimumPoint(); - Vector offset = min.subtract(origin); + BlockVector3 origin = clipboard.getOrigin(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 offset = min.subtract(origin); int width = region.getWidth(); int height = region.getHeight(); int length = region.getLength(); @@ -127,7 +126,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { int z0 = min.getBlockZ() + z; for (int x = 0; x < width; x++) { int x0 = min.getBlockX() + x; - BlockVector point = new BlockVector(x0, y0, z0); + BlockVector3 point = new BlockVector3(x0, y0, z0); BaseBlock block = clipboard.getFullBlock(point); if (block.getNbtData() != null) { Map values = new HashMap<>(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java index 95af3d0c8..21b790ee9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java @@ -19,10 +19,10 @@ package com.sk89q.worldedit.extent.inventory; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -82,7 +82,7 @@ public class BlockBagExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { if (blockBag != null) { BlockState existing = getExtent().getBlock(position); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java index b819bcac4..92a3b6188 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java @@ -19,15 +19,14 @@ package com.sk89q.worldedit.extent.reorder; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.function.operation.SetLocatedBlocks; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.collection.LocatedBlockList; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -49,11 +48,11 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent { * Comparator optimized for sorting chunks by the region file they reside * in. This allows for file caches to be used while loading the chunk. */ - private static final Comparator REGION_OPTIMIZED_SORT = - Comparator.comparing(vec -> vec.divide(32).floor(), Vector2D.COMPARING_GRID_ARRANGEMENT) - .thenComparing(Vector2D.COMPARING_GRID_ARRANGEMENT); + private static final Comparator REGION_OPTIMIZED_SORT = + Comparator.comparing((BlockVector2 vec) -> vec.divide(32), BlockVector2.COMPARING_GRID_ARRANGEMENT) + .thenComparing(BlockVector2.COMPARING_GRID_ARRANGEMENT); - private final SortedMap batches = new TreeMap<>(REGION_OPTIMIZED_SORT); + private final SortedMap batches = new TreeMap<>(REGION_OPTIMIZED_SORT); private boolean enabled; public ChunkBatchingExtent(Extent extent) { @@ -74,11 +73,11 @@ public class ChunkBatchingExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (!enabled) { return getExtent().setBlock(location, block); } - BlockVector2D chunkPos = new BlockVector2D(location.getBlockX() >> 4, location.getBlockZ() >> 4); + BlockVector2 chunkPos = new BlockVector2(location.getBlockX() >> 4, location.getBlockZ() >> 4); batches.computeIfAbsent(chunkPos, k -> new LocatedBlockList()).add(location, block); return true; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java index 3ef74dd7a..44eea7d45 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/MultiStageReorder.java @@ -20,8 +20,6 @@ package com.sk89q.worldedit.extent.reorder; import com.google.common.collect.Iterables; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.Blocks; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -30,6 +28,7 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.function.operation.SetLocatedBlocks; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.LocatedBlock; import com.sk89q.worldedit.util.collection.LocatedBlockList; @@ -95,7 +94,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { BlockState existing = getBlock(location); if (!enabled) { @@ -104,18 +103,18 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder if (Blocks.shouldPlaceLast(block.getBlockType())) { // Place torches, etc. last - stage2.add(location.toBlockVector(), block); + stage2.add(location, block); return !existing.equalsFuzzy(block); } else if (Blocks.shouldPlaceFinal(block.getBlockType())) { // Place signs, reed, etc even later - stage3.add(location.toBlockVector(), block); + stage3.add(location, block); return !existing.equalsFuzzy(block); } else if (Blocks.shouldPlaceLast(existing.getBlockType())) { // Destroy torches, etc. first super.setBlock(location, BlockTypes.AIR.getDefaultState()); return super.setBlock(location, block); } else { - stage1.add(location.toBlockVector(), block); + stage1.add(location, block); return !existing.equalsFuzzy(block); } } @@ -135,21 +134,21 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder public Operation resume(RunContext run) throws WorldEditException { Extent extent = getExtent(); - final Set blocks = new HashSet<>(); - final Map blockTypes = new HashMap<>(); + final Set blocks = new HashSet<>(); + final Map blockTypes = new HashMap<>(); for (LocatedBlock entry : stage3) { - final BlockVector pt = entry.getLocation().toBlockVector(); + final BlockVector3 pt = entry.getLocation(); blocks.add(pt); blockTypes.put(pt, entry.getBlock()); } while (!blocks.isEmpty()) { - BlockVector current = blocks.iterator().next(); + BlockVector3 current = blocks.iterator().next(); if (!blocks.contains(current)) { continue; } - final Deque walked = new LinkedList<>(); + final Deque walked = new LinkedList<>(); while (true) { walked.addFirst(current); @@ -162,13 +161,13 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder Property halfProperty = blockStateHolder.getBlockType().getProperty("half"); if (blockStateHolder.getState(halfProperty).equals("lower")) { // Deal with lower door halves being attached to the floor AND the upper half - BlockVector upperBlock = current.add(0, 1, 0).toBlockVector(); + BlockVector3 upperBlock = current.add(0, 1, 0); if (blocks.contains(upperBlock) && !walked.contains(upperBlock)) { walked.addFirst(upperBlock); } } } else if (BlockCategories.RAILS.contains(blockStateHolder.getBlockType())) { - BlockVector lowerBlock = current.add(0, -1, 0).toBlockVector(); + BlockVector3 lowerBlock = current.add(0, -1, 0); if (blocks.contains(lowerBlock) && !walked.contains(lowerBlock)) { walked.addFirst(lowerBlock); } @@ -192,7 +191,7 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } } - for (BlockVector pt : walked) { + for (BlockVector3 pt : walked) { extent.setBlock(pt, blockTypes.get(pt)); blocks.remove(pt); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java index 6c1c93302..b0ecc66ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/transform/BlockTransformExtent.java @@ -22,16 +22,17 @@ package com.sk89q.worldedit.extent.transform; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Sets; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.registry.state.BooleanProperty; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Direction; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -84,17 +85,17 @@ public class BlockTransformExtent extends AbstractDelegateExtent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return transformBlock(super.getBlock(position), false); } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { return transformBlock(super.getFullBlock(position), false); } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return super.setBlock(location, transformBlock(block, true)); } @@ -132,7 +133,7 @@ public class BlockTransformExtent extends AbstractDelegateExtent { if (property instanceof DirectionalProperty) { Direction value = (Direction) block.getState(property); if (value != null) { - Vector newValue = getNewStateValue((DirectionalProperty) property, transform, value.toVector()); + Vector3 newValue = getNewStateValue((DirectionalProperty) property, transform, value.toVector()); if (newValue != null) { changedBlock = (T) changedBlock.with(property, Direction.findClosest(newValue, Direction.Flag.ALL)); } @@ -171,9 +172,9 @@ public class BlockTransformExtent extends AbstractDelegateExtent { * @return a new state or null if none could be found */ @Nullable - private static Vector getNewStateValue(DirectionalProperty state, Transform transform, Vector oldDirection) { - Vector newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector.ZERO)).normalize(); - Vector newValue = null; + private static Vector3 getNewStateValue(DirectionalProperty state, Transform transform, Vector3 oldDirection) { + Vector3 newDirection = transform.apply(oldDirection).subtract(transform.apply(Vector3.ZERO)).normalize(); + Vector3 newValue = null; double closest = -2; boolean found = false; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/BlockChangeLimiter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/BlockChangeLimiter.java index a25477235..48267a7be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/BlockChangeLimiter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/BlockChangeLimiter.java @@ -22,10 +22,10 @@ package com.sk89q.worldedit.extent.validation; import static com.google.common.base.Preconditions.checkArgument; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -77,7 +77,7 @@ public class BlockChangeLimiter extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (limit >= 0) { if (count >= limit) { throw new MaxChangedBlocksException(limit); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java index ffb2b175a..64d27cd97 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/validation/DataValidatorExtent.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.extent.validation; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -49,7 +49,7 @@ public class DataValidatorExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { final int y = location.getBlockY(); final BlockType type = block.getBlockType(); if (y < 0 || y > world.getMaxY()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java index 25591defb..85ba63585 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/BlockQuirkExtent.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.extent.world; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -51,7 +51,7 @@ public class BlockQuirkExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { BlockType existing = getExtent().getBlock(position).getBlockType(); if (existing.getMaterial().hasContainer()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/ChunkLoadingExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/ChunkLoadingExtent.java index 845276a58..c20177927 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/ChunkLoadingExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/ChunkLoadingExtent.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.extent.world; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -61,7 +61,7 @@ public class ChunkLoadingExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { world.checkLoadedChunk(location); return super.setBlock(location, block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java index 9ad839a32..7914762b5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/FastModeExtent.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.extent.world; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -40,7 +40,7 @@ import java.util.Set; public class FastModeExtent extends AbstractDelegateExtent { private final World world; - private final Set dirtyChunks = new HashSet<>(); + private final Set dirtyChunks = new HashSet<>(); private boolean enabled = true; /** @@ -84,9 +84,9 @@ public class FastModeExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (enabled) { - dirtyChunks.add(new BlockVector2D(location.getBlockX() >> 4, location.getBlockZ() >> 4)); + dirtyChunks.add(new BlockVector2(location.getBlockX() >> 4, location.getBlockZ() >> 4)); return world.setBlock(location, block, false); } else { return world.setBlock(location, block, true); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java index 52fe0af5e..efb5a208f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.extent.world; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -79,7 +79,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (toolUse && block.getBlockType().getMaterial().isAir()) { world.simulateBlockMine(location); return true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java index ba853eba9..b5dd22af2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/CombinedRegionFunction.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.math.BlockVector3; import java.util.ArrayList; import java.util.Arrays; @@ -81,7 +81,7 @@ public class CombinedRegionFunction implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { boolean ret = false; for (RegionFunction function : functions) { if (function.apply(position)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionFunction.java index 41144fc8f..fa8e0f9da 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionFunction.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.function; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.FlatRegion; /** @@ -36,6 +36,6 @@ public interface FlatRegionFunction { * @return true if something was changed * @throws WorldEditException thrown on an error */ - boolean apply(Vector2D position) throws WorldEditException; + boolean apply(BlockVector2 position) throws WorldEditException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java index ff287632c..961a5721d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/FlatRegionMaskingFilter.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector2; /** - * Passes calls to {@link #apply(com.sk89q.worldedit.Vector2D)} to the + * Passes calls to {@link #apply(BlockVector2)} to the * delegate {@link com.sk89q.worldedit.function.FlatRegionFunction} if they * match the given mask. */ @@ -50,7 +50,7 @@ public class FlatRegionMaskingFilter implements FlatRegionFunction { } @Override - public boolean apply(Vector2D position) throws WorldEditException { + public boolean apply(BlockVector2 position) throws WorldEditException { return mask.test(position) && function.apply(position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/GroundFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/GroundFunction.java index 2b14b57b2..d3162ff13 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/GroundFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/GroundFunction.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; /** * Applies a {@link RegionFunction} to the first ground block. @@ -76,12 +76,12 @@ public class GroundFunction implements LayerFunction { } @Override - public boolean isGround(Vector position) { + public boolean isGround(BlockVector3 position) { return mask.test(position); } @Override - public boolean apply(Vector position, int depth) throws WorldEditException { + public boolean apply(BlockVector3 position, int depth) throws WorldEditException { if (depth == 0) { if (function.apply(position)) { affected++; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/LayerFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/LayerFunction.java index bd9acb7cb..8d82f016f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/LayerFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/LayerFunction.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.function; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.visitor.LayerVisitor; +import com.sk89q.worldedit.math.BlockVector3; /** * A function that takes a position and a depth. @@ -35,7 +35,7 @@ public interface LayerFunction { * @param position return whether the given block is the ground * @return true if the search should stop */ - boolean isGround(Vector position); + boolean isGround(BlockVector3 position); /** * Apply the function to the given position. @@ -48,5 +48,5 @@ public interface LayerFunction { * @return true whether this method should be called for further layers * @throws WorldEditException thrown on an error */ - boolean apply(Vector position, int depth) throws WorldEditException; + boolean apply(BlockVector3 position, int depth) throws WorldEditException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java index 91276d237..332565e35 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionFunction.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.function; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.math.BlockVector3; /** * Performs a function on points in a region. @@ -34,6 +34,6 @@ public interface RegionFunction { * @return true if something was changed * @throws WorldEditException thrown on an error */ - boolean apply(Vector position) throws WorldEditException; + boolean apply(BlockVector3 position) throws WorldEditException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java index 673d411d2..cea580d8b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/RegionMaskingFilter.java @@ -21,12 +21,12 @@ package com.sk89q.worldedit.function; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; /** - * Passes calls to {@link #apply(com.sk89q.worldedit.Vector)} to the + * Passes calls to {@link #apply(BlockVector3)} to the * delegate {@link com.sk89q.worldedit.function.RegionFunction} if they * match the given mask. */ @@ -49,7 +49,7 @@ public class RegionMaskingFilter implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return mask.test(position) && function.apply(position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java index ac5fdf98d..444f0e4e1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/biome/BiomeReplace.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.function.biome; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.FlatRegionFunction; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.biome.BaseBiome; /** @@ -49,7 +49,7 @@ public class BiomeReplace implements FlatRegionFunction { } @Override - public boolean apply(Vector2D position) throws WorldEditException { + public boolean apply(BlockVector2 position) throws WorldEditException { return extent.setBiome(position, biome); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java index 8d282e9c3..258e02871 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java @@ -19,10 +19,10 @@ package com.sk89q.worldedit.function.block; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -47,7 +47,7 @@ public class BlockDistributionCounter implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { BlockStateHolder blk = extent.getBlock(position); if (fuzzy) { blk = ((BlockState) blk).toFuzzy(); 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 0013ade94..fbc0c9acf 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 @@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.block; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; 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; /** * Replaces blocks with a given pattern. @@ -49,7 +49,7 @@ public class BlockReplace implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return extent.setBlock(position, pattern.apply(position)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Counter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Counter.java index 8c5cd8001..06b5284bd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Counter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Counter.java @@ -19,17 +19,18 @@ package com.sk89q.worldedit.function.block; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; /** - * Keeps a count of the number of times that {@link #apply(Vector)} is called. + * Keeps a count of the number of times that {@link #apply(BlockVector3)} is + * called. */ - public class Counter implements RegionFunction { +public class Counter implements RegionFunction { private int count; - + /** * Returns the number of blocks that have been counted. * @@ -40,7 +41,7 @@ import com.sk89q.worldedit.function.RegionFunction; } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { count++; return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java index 223b419b3..1e5c62873 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/ExtentBlockCopy.java @@ -23,15 +23,16 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTagBuilder; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.internal.helper.MCDirections; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction.Flag; +import com.sk89q.worldedit.world.block.BaseBlock; /** * Copies blocks from one extent to another. @@ -40,8 +41,8 @@ public class ExtentBlockCopy implements RegionFunction { private final Extent source; private final Extent destination; - private final Vector from; - private final Vector to; + private final BlockVector3 from; + private final BlockVector3 to; private final Transform transform; /** @@ -53,7 +54,7 @@ public class ExtentBlockCopy implements RegionFunction { * @param to the destination offset * @param transform a transform to apply to positions (after source offset, before destination offset) */ - public ExtentBlockCopy(Extent source, Vector from, Extent destination, Vector to, Transform transform) { + public ExtentBlockCopy(Extent source, BlockVector3 from, Extent destination, BlockVector3 to, Transform transform) { checkNotNull(source); checkNotNull(from); checkNotNull(destination); @@ -67,10 +68,10 @@ public class ExtentBlockCopy implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { BaseBlock block = source.getFullBlock(position); - Vector orig = position.subtract(from); - Vector transformed = transform.apply(orig); + BlockVector3 orig = position.subtract(from); + BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint(); // Apply transformations to NBT data if necessary block = transformNbtData(block); @@ -96,7 +97,7 @@ public class ExtentBlockCopy implements RegionFunction { Direction direction = MCDirections.fromRotation(rot); if (direction != null) { - Vector vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector.ZERO)).normalize(); + Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize(); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL); if (newDirection != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java index ba2cf9a3d..c4c72951e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/Naturalizer.java @@ -22,11 +22,11 @@ package com.sk89q.worldedit.function.block; import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.LayerFunction; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; /** @@ -61,12 +61,12 @@ public class Naturalizer implements LayerFunction { } @Override - public boolean isGround(Vector position) { + public boolean isGround(BlockVector3 position) { return mask.test(position); } @Override - public boolean apply(Vector position, int depth) throws WorldEditException { + public boolean apply(BlockVector3 position, int depth) throws WorldEditException { if (mask.test(position)) { affected++; switch (depth) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java index e157de444..af33fecbf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/entity/ExtentEntityCopy.java @@ -23,13 +23,14 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTagBuilder; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.EntityFunction; import com.sk89q.worldedit.internal.helper.MCDirections; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.Direction.Flag; @@ -42,8 +43,8 @@ import com.sk89q.worldedit.util.Location; public class ExtentEntityCopy implements EntityFunction { private final Extent destination; - private final Vector from; - private final Vector to; + private final Vector3 from; + private final Vector3 to; private final Transform transform; private boolean removing; @@ -55,7 +56,7 @@ public class ExtentEntityCopy implements EntityFunction { * @param to the destination position * @param transform the transformation to apply to both position and orientation */ - public ExtentEntityCopy(Vector from, Extent destination, Vector to, Transform transform) { + public ExtentEntityCopy(Vector3 from, Extent destination, Vector3 to, Transform transform) { checkNotNull(from); checkNotNull(destination); checkNotNull(to); @@ -91,13 +92,13 @@ public class ExtentEntityCopy implements EntityFunction { Location newLocation; Location location = entity.getLocation(); - Vector pivot = from.round().add(0.5, 0.5, 0.5); - Vector newPosition = transform.apply(location.toVector().subtract(pivot)); - Vector newDirection; + Vector3 pivot = from.round().add(0.5, 0.5, 0.5); + Vector3 newPosition = transform.apply(location.toVector().subtract(pivot)); + Vector3 newDirection; newDirection = transform.isIdentity() ? entity.getLocation().getDirection() - : transform.apply(location.getDirection()).subtract(transform.apply(Vector.ZERO)).normalize(); + : transform.apply(location.getDirection()).subtract(transform.apply(Vector3.ZERO)).normalize(); newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); // Some entities store their position data in NBT @@ -134,8 +135,8 @@ public class ExtentEntityCopy implements EntityFunction { boolean hasFacing = tag.containsKey("Facing"); if (hasTilePosition) { - Vector tilePosition = new Vector(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); - Vector newTilePosition = transform.apply(tilePosition.subtract(from)).add(to); + Vector3 tilePosition = new Vector3(tag.asInt("TileX"), tag.asInt("TileY"), tag.asInt("TileZ")); + BlockVector3 newTilePosition = transform.apply(tilePosition.subtract(from)).add(to).toBlockPoint(); CompoundTagBuilder builder = tag.createBuilder() .putInt("TileX", newTilePosition.getBlockX()) @@ -155,7 +156,7 @@ public class ExtentEntityCopy implements EntityFunction { Direction direction = MCDirections.fromHanging(d); if (direction != null) { - Vector vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector.ZERO)).normalize(); + Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize(); Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL); if (newDirection != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index d80ad4570..ac52933be 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; @@ -32,6 +31,7 @@ import com.sk89q.worldedit.function.EditContext; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; import com.sk89q.worldedit.internal.expression.ExpressionException; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; @@ -43,7 +43,7 @@ public class Deform implements Contextual { private Region region; private String expression; private Mode mode = Mode.UNIT_CUBE; - private Vector offset = new Vector(); + private Vector3 offset = Vector3.ZERO; public Deform(String expression) { this(new NullExtent(), new NullRegion(), expression); @@ -104,11 +104,11 @@ public class Deform implements Contextual { this.mode = mode; } - public Vector getOffset() { + public Vector3 getOffset() { return offset; } - public void setOffset(Vector offset) { + public void setOffset(Vector3 offset) { checkNotNull(offset, "offset"); this.offset = offset; } @@ -120,31 +120,31 @@ public class Deform implements Contextual { @Override public Operation createFromContext(final EditContext context) { - final Vector zero; - Vector unit; + final Vector3 zero; + Vector3 unit; Region region = firstNonNull(context.getRegion(), this.region); switch (mode) { case UNIT_CUBE: - final Vector min = region.getMinimumPoint(); - final Vector max = region.getMaximumPoint(); + final Vector3 min = region.getMinimumPoint().toVector3(); + final Vector3 max = region.getMaximumPoint().toVector3(); zero = max.add(min).multiply(0.5); unit = max.subtract(zero); - if (unit.getX() == 0) unit = unit.setX(1.0); - if (unit.getY() == 0) unit = unit.setY(1.0); - if (unit.getZ() == 0) unit = unit.setZ(1.0); + if (unit.getX() == 0) unit = unit.withX(1.0); + if (unit.getY() == 0) unit = unit.withY(1.0); + if (unit.getZ() == 0) unit = unit.withZ(1.0); break; case RAW_COORD: - zero = Vector.ZERO; - unit = Vector.ONE; + zero = Vector3.ZERO; + unit = Vector3.ONE; break; case OFFSET: default: zero = offset; - unit = Vector.ONE; + unit = Vector3.ONE; } return new DeformOperation(context.getDestination(), region, zero, unit, expression); @@ -153,11 +153,11 @@ public class Deform implements Contextual { private static final class DeformOperation implements Operation { private final Extent destination; private final Region region; - private final Vector zero; - private final Vector unit; + private final Vector3 zero; + private final Vector3 unit; private final String expression; - private DeformOperation(Extent destination, Region region, Vector zero, Vector unit, String expression) { + private DeformOperation(Extent destination, Region region, Vector3 zero, Vector3 unit, String expression) { this.destination = destination; this.region = region; this.zero = zero; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java index 3f6265de7..506dc218f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/FloraGenerator.java @@ -20,12 +20,12 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -103,7 +103,7 @@ public class FloraGenerator implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { BlockStateHolder block = editSession.getBlock(position); if (block.getBlockType() == BlockTypes.GRASS_BLOCK) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java index bf37a4d9c..3e63aa83a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/ForestGenerator.java @@ -20,9 +20,9 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -49,7 +49,7 @@ public class ForestGenerator implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { BlockStateHolder block = editSession.getBlock(position); BlockType t = block.getBlockType(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java index 48f85b841..a8d154955 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -84,12 +84,12 @@ public class GardenPatchGenerator implements RegionFunction { * @param basePos the base position * @param pos the vine position */ - private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException { + private void placeVine(BlockVector3 basePos, BlockVector3 pos) throws MaxChangedBlocksException { if (pos.distance(basePos) > 4) return; if (!editSession.getBlock(pos).getBlockType().getMaterial().isAir()) return; for (int i = -1; i > -3; --i) { - Vector testPos = pos.add(0, i, 0); + BlockVector3 testPos = pos.add(0, i, 0); if (editSession.getBlock(testPos).getBlockType().getMaterial().isAir()) { pos = testPos; } else { @@ -102,7 +102,7 @@ public class GardenPatchGenerator implements RegionFunction { int t = random.nextInt(4); int h = random.nextInt(3) - 1; - Vector p; + BlockVector3 p; BlockState log = BlockTypes.OAK_LOG.getDefaultState(); @@ -158,7 +158,7 @@ public class GardenPatchGenerator implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { if (!editSession.getBlock(position).getBlockType().getMaterial().isAir()) { position = position.add(0, 1, 0); } @@ -198,7 +198,7 @@ public class GardenPatchGenerator implements RegionFunction { * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { + private static boolean setBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java index d7bf33c8a..9b04d871d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BiomeMask2D.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.biome.BaseBiome; import java.util.Arrays; @@ -90,7 +90,7 @@ public class BiomeMask2D extends AbstractMask2D { } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { BaseBiome biome = extent.getBiome(vector); return biomes.contains(biome); } 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 fae7888a0..625d8b781 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 @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockCategory; import javax.annotation.Nullable; @@ -41,7 +41,7 @@ public class BlockCategoryMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return category.contains(getExtent().getBlock(vector)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java index d200f3f30..839f377ef 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockMask.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.Arrays; @@ -94,7 +94,7 @@ public class BlockMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { BlockStateHolder block = getExtent().getBlock(vector); for (BlockStateHolder testBlock : blocks) { if (testBlock.equalsFuzzy(block)) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java index 0e2ab590e..d388fef67 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BlockTypeMask.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import java.util.Arrays; @@ -94,7 +94,7 @@ public class BlockTypeMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return blocks.contains(getExtent().getBlock(vector).getBlockType()); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java index 3622926e3..2f72d5a1d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/BoundedHeightMask.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -47,7 +47,7 @@ public class BoundedHeightMask extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return vector.getY() >= minY && vector.getY() <= maxY; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java index 911b4ce69..ac4d24452 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -40,7 +40,7 @@ public class ExistingBlockMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java index d662e0fa3..9f597e267 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import javax.annotation.Nullable; @@ -61,10 +61,10 @@ public class ExpressionMask extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { try { if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) { - ((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector); + ((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3()); } return expression.evaluate(vector.getX(), vector.getY(), vector.getZ()) > 0; } catch (EvaluationException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java index 2b4031ca8..ffc6c9a94 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExpressionMask2D.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.ExpressionException; import com.sk89q.worldedit.internal.expression.runtime.EvaluationException; +import com.sk89q.worldedit.math.BlockVector2; public class ExpressionMask2D extends AbstractMask2D { @@ -52,7 +52,7 @@ public class ExpressionMask2D extends AbstractMask2D { } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { try { return expression.evaluate(vector.getX(), 0, vector.getZ()) > 0; } catch (EvaluationException e) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java index 96b4af82b..16a9a7c70 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -34,7 +34,7 @@ public interface Mask { * @param vector the vector to test * @return true if the criteria is met */ - boolean test(Vector vector); + boolean test(BlockVector3 vector); /** * Get the 2D version of this mask if one exists. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java index ad48dcb5e..3e48a0e9a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Mask2D.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; /** * Tests whether a given vector meets a criteria. @@ -32,6 +32,6 @@ public interface Mask2D { * @param vector the vector to test * @return true if the criteria is met */ - boolean test(Vector2D vector); + boolean test(BlockVector2 vector); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java index 5968b3b6c..bd7d49ad0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import java.util.ArrayList; import java.util.Arrays; @@ -89,7 +89,7 @@ public class MaskIntersection extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (masks.isEmpty()) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java index 07e43be38..eec35eab9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskIntersection2D.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import java.util.Arrays; import java.util.Collection; @@ -83,7 +83,7 @@ public class MaskIntersection2D implements Mask2D { } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { if (masks.isEmpty()) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java index a54794255..3a301a874 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import java.util.ArrayList; import java.util.Collection; @@ -53,7 +53,7 @@ public class MaskUnion extends MaskIntersection { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Collection masks = getMasks(); for (Mask mask : masks) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java index 099dc9a05..678fcbdd4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/MaskUnion2D.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import java.util.Collection; @@ -47,7 +47,7 @@ public class MaskUnion2D extends MaskIntersection2D { } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { Collection masks = getMasks(); for (Mask2D mask : masks) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java index 007520485..f2375de83 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/Masks.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -71,7 +71,7 @@ public final class Masks { checkNotNull(mask); return new AbstractMask() { @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return !mask.test(vector); } @@ -104,7 +104,7 @@ public final class Masks { checkNotNull(mask); return new AbstractMask2D() { @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { return !mask.test(vector); } }; @@ -119,8 +119,8 @@ public final class Masks { public static Mask asMask(final Mask2D mask) { return new AbstractMask() { @Override - public boolean test(Vector vector) { - return mask.test(vector.toVector2D()); + public boolean test(BlockVector3 vector) { + return mask.test(vector.toBlockVector2()); } @Nullable @@ -133,12 +133,12 @@ public final class Masks { private static class AlwaysTrue implements Mask, Mask2D { @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return true; } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { return true; } @@ -151,12 +151,12 @@ public final class Masks { private static class AlwaysFalse implements Mask, Mask2D { @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return false; } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java index 04c793bde..ee9b6e44d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter.java @@ -22,7 +22,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.noise.NoiseGenerator; import javax.annotation.Nullable; @@ -85,8 +85,8 @@ public class NoiseFilter extends AbstractMask { } @Override - public boolean test(Vector vector) { - return noiseGenerator.noise(vector) <= density; + public boolean test(BlockVector3 vector) { + return noiseGenerator.noise(vector.toVector3()) <= density; } @Nullable diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java index fdcbcd59b..a64889f54 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/NoiseFilter2D.java @@ -22,7 +22,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.noise.NoiseGenerator; /** @@ -83,8 +83,8 @@ public class NoiseFilter2D extends AbstractMask2D { } @Override - public boolean test(Vector2D pos) { - return noiseGenerator.noise(pos) <= density; + public boolean test(BlockVector2 pos) { + return noiseGenerator.noise(pos.toVector2()) <= density; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java index d8d3d455f..e5df3b153 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -32,7 +32,7 @@ import javax.annotation.Nullable; public class OffsetMask extends AbstractMask { private Mask mask; - private Vector offset; + private BlockVector3 offset; /** * Create a new instance. @@ -40,7 +40,7 @@ public class OffsetMask extends AbstractMask { * @param mask the mask * @param offset the offset */ - public OffsetMask(Mask mask, Vector offset) { + public OffsetMask(Mask mask, BlockVector3 offset) { checkNotNull(mask); checkNotNull(offset); this.mask = mask; @@ -71,7 +71,7 @@ public class OffsetMask extends AbstractMask { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -80,13 +80,13 @@ public class OffsetMask extends AbstractMask { * * @param offset the offset */ - public void setOffset(Vector offset) { + public void setOffset(BlockVector3 offset) { checkNotNull(offset); this.offset = offset; } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return getMask().test(vector.add(offset)); } @@ -95,7 +95,7 @@ public class OffsetMask extends AbstractMask { public Mask2D toMask2D() { Mask2D childMask = getMask().toMask2D(); if (childMask != null) { - return new OffsetMask2D(childMask, getOffset().toVector2D()); + return new OffsetMask2D(childMask, getOffset().toBlockVector2()); } else { return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java index 74daead9d..94b595fdf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/OffsetMask2D.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; /** * Checks whether another mask tests true for a position that is offset @@ -30,7 +30,7 @@ import com.sk89q.worldedit.Vector2D; public class OffsetMask2D extends AbstractMask2D { private Mask2D mask; - private Vector2D offset; + private BlockVector2 offset; /** * Create a new instance. @@ -38,7 +38,7 @@ public class OffsetMask2D extends AbstractMask2D { * @param mask the mask * @param offset the offset */ - public OffsetMask2D(Mask2D mask, Vector2D offset) { + public OffsetMask2D(Mask2D mask, BlockVector2 offset) { checkNotNull(mask); checkNotNull(offset); this.mask = mask; @@ -69,7 +69,7 @@ public class OffsetMask2D extends AbstractMask2D { * * @return the offset */ - public Vector2D getOffset() { + public BlockVector2 getOffset() { return offset; } @@ -78,13 +78,13 @@ public class OffsetMask2D extends AbstractMask2D { * * @param offset the offset */ - public void setOffset(Vector2D offset) { + public void setOffset(BlockVector2 offset) { checkNotNull(offset); this.offset = offset; } @Override - public boolean test(Vector2D vector) { + public boolean test(BlockVector2 vector) { return getMask().test(vector.add(offset)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java index 7d2d78dfc..28df2c206 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/RegionMask.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.mask; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import javax.annotation.Nullable; @@ -62,7 +62,7 @@ public class RegionMask extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return region.contains(vector); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java index 917c22f36..b8ea48288 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/SolidBlockMask.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.function.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import javax.annotation.Nullable; @@ -32,7 +32,7 @@ public class SolidBlockMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); BlockState block = extent.getBlock(vector); return block.getBlockType().getMaterial().isMovementBlocker(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index 3a9a38d4e..77037c7df 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -23,7 +23,6 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Lists; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityProperties; @@ -37,6 +36,8 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.visitor.EntityVisitor; import com.sk89q.worldedit.function.visitor.RegionVisitor; +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.regions.Region; @@ -55,8 +56,8 @@ public class ForwardExtentCopy implements Operation { private final Extent source; private final Extent destination; private final Region region; - private final Vector from; - private final Vector to; + private final BlockVector3 from; + private final BlockVector3 to; private int repetitions = 1; private Mask sourceMask = Masks.alwaysTrue(); private boolean removingEntities; @@ -75,9 +76,9 @@ public class ForwardExtentCopy implements Operation { * @param region the region to copy * @param destination the destination extent * @param to the destination position - * @see #ForwardExtentCopy(Extent, Region, Vector, Extent, Vector) the main constructor + * @see #ForwardExtentCopy(Extent, Region, BlockVector3, Extent, BlockVector3) the main constructor */ - public ForwardExtentCopy(Extent source, Region region, Extent destination, Vector to) { + public ForwardExtentCopy(Extent source, Region region, Extent destination, BlockVector3 to) { this(source, region, region.getMinimumPoint(), destination, to); } @@ -90,7 +91,7 @@ public class ForwardExtentCopy implements Operation { * @param destination the destination extent * @param to the destination position */ - public ForwardExtentCopy(Extent source, Region region, Vector from, Extent destination, Vector to) { + public ForwardExtentCopy(Extent source, Region region, BlockVector3 from, Extent destination, BlockVector3 to) { checkNotNull(source); checkNotNull(region); checkNotNull(from); @@ -255,7 +256,7 @@ public class ForwardExtentCopy implements Operation { lastVisitor = blockVisitor; if (copyingEntities) { - ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform); + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); entityCopy.setRemoving(removingEntities); List entities = Lists.newArrayList(source.getEntities(region)); entities.removeIf(entity -> { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java index c45b90986..2a0edba8c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/BlockPattern.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.pattern; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -61,7 +61,7 @@ public class BlockPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { return block; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java index 6f08d5b34..7159d13e2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/ClipboardPattern.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.pattern; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -31,7 +31,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class ClipboardPattern extends AbstractPattern { private final Clipboard clipboard; - private final Vector size; + private final BlockVector3 size; /** * Create a new clipboard pattern. @@ -45,12 +45,12 @@ public class ClipboardPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { int xp = Math.abs(position.getBlockX()) % size.getBlockX(); int yp = Math.abs(position.getBlockY()) % size.getBlockY(); int zp = Math.abs(position.getBlockZ()) % size.getBlockZ(); - return clipboard.getFullBlock(clipboard.getMinimumPoint().add(new Vector(xp, yp, zp))); + return clipboard.getFullBlock(clipboard.getMinimumPoint().add(xp, yp, zp)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java index 5b73f720b..75c5cf20b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/Pattern.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.function.pattern; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -33,6 +33,6 @@ public interface Pattern { * @param position the position * @return a block */ - BlockStateHolder apply(Vector position); + BlockStateHolder apply(BlockVector3 position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java index c28c147f9..acdcdd662 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RandomPattern.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.function.pattern; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.ArrayList; @@ -53,7 +53,7 @@ public class RandomPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { double r = random.nextDouble(); double offset = 0; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java index 659fef612..54434f1b0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/pattern/RepeatingExtentPattern.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.function.pattern; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -31,7 +31,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class RepeatingExtentPattern extends AbstractPattern { private Extent extent; - private Vector offset; + private BlockVector3 offset; /** * Create a new instance. @@ -39,7 +39,7 @@ public class RepeatingExtentPattern extends AbstractPattern { * @param extent the extent * @param offset the offset */ - public RepeatingExtentPattern(Extent extent, Vector offset) { + public RepeatingExtentPattern(Extent extent, BlockVector3 offset) { setExtent(extent); setOffset(offset); } @@ -68,7 +68,7 @@ public class RepeatingExtentPattern extends AbstractPattern { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -77,19 +77,19 @@ public class RepeatingExtentPattern extends AbstractPattern { * * @param offset the offset */ - public void setOffset(Vector offset) { + public void setOffset(BlockVector3 offset) { checkNotNull(offset); this.offset = offset; } @Override - public BlockStateHolder apply(Vector position) { - Vector base = position.add(offset); - Vector size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1); + public BlockStateHolder apply(BlockVector3 position) { + BlockVector3 base = position.add(offset); + BlockVector3 size = extent.getMaximumPoint().subtract(extent.getMinimumPoint()).add(1, 1, 1); int x = base.getBlockX() % size.getBlockX(); int y = base.getBlockY() % size.getBlockY(); int z = base.getBlockZ() % size.getBlockZ(); - return extent.getFullBlock(new Vector(x, y, z)); + return extent.getFullBlock(new BlockVector3(x, y, z)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/FlatRegionOffset.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/FlatRegionOffset.java index 6a21a50c3..9682ff378 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/FlatRegionOffset.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/FlatRegionOffset.java @@ -21,16 +21,16 @@ package com.sk89q.worldedit.function.util; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.FlatRegionFunction; +import com.sk89q.worldedit.math.BlockVector2; /** * Offsets the position parameter by adding a given offset vector. */ public class FlatRegionOffset implements FlatRegionFunction { - private Vector2D offset; + private BlockVector2 offset; private final FlatRegionFunction function; /** @@ -39,7 +39,7 @@ public class FlatRegionOffset implements FlatRegionFunction { * @param offset the offset * @param function the function that is called with the offset position */ - public FlatRegionOffset(Vector2D offset, FlatRegionFunction function) { + public FlatRegionOffset(BlockVector2 offset, FlatRegionFunction function) { checkNotNull(function); setOffset(offset); this.function = function; @@ -50,7 +50,7 @@ public class FlatRegionOffset implements FlatRegionFunction { * * @return the offset */ - public Vector2D getOffset() { + public BlockVector2 getOffset() { return offset; } @@ -59,13 +59,13 @@ public class FlatRegionOffset implements FlatRegionFunction { * * @param offset the offset */ - public void setOffset(Vector2D offset) { + public void setOffset(BlockVector2 offset) { checkNotNull(offset); this.offset = offset; } @Override - public boolean apply(Vector2D position) throws WorldEditException { + public boolean apply(BlockVector2 position) throws WorldEditException { return function.apply(position.add(offset)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/RegionOffset.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/RegionOffset.java index c1f395be6..7ac57da1f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/RegionOffset.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/util/RegionOffset.java @@ -21,16 +21,16 @@ package com.sk89q.worldedit.function.util; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; /** * Offsets the position parameter by adding a given offset vector. */ public class RegionOffset implements RegionFunction { - private Vector offset; + private BlockVector3 offset; private final RegionFunction function; /** @@ -39,7 +39,7 @@ public class RegionOffset implements RegionFunction { * @param offset the offset * @param function the function that is called with the offset position */ - public RegionOffset(Vector offset, RegionFunction function) { + public RegionOffset(BlockVector3 offset, RegionFunction function) { checkNotNull(function); setOffset(offset); this.function = function; @@ -50,7 +50,7 @@ public class RegionOffset implements RegionFunction { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -59,13 +59,13 @@ public class RegionOffset implements RegionFunction { * * @param offset the offset */ - public void setOffset(Vector offset) { + public void setOffset(BlockVector3 offset) { checkNotNull(offset); this.offset = offset; } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return function.apply(position.add(offset)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 1601caf40..c1ff8e53b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -21,12 +21,11 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector3; import java.util.ArrayDeque; import java.util.ArrayList; @@ -38,9 +37,9 @@ import java.util.Set; /** * Performs a breadth-first search starting from points added with - * {@link #visit(com.sk89q.worldedit.Vector)}. The search continues + * {@link #visit(BlockVector3)}. The search continues * to a certain adjacent point provided that the method - * {@link #isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)} + * {@link #isVisitable(BlockVector3, BlockVector3)} * returns true for that point. * *

As an abstract implementation, this class can be used to implement @@ -50,9 +49,9 @@ import java.util.Set; public abstract class BreadthFirstSearch implements Operation { private final RegionFunction function; - private final Queue queue = new ArrayDeque<>(); - private final Set visited = new HashSet<>(); - private final List directions = new ArrayList<>(); + private final Queue queue = new ArrayDeque<>(); + private final Set visited = new HashSet<>(); + private final List directions = new ArrayList<>(); private int affected = 0; /** @@ -69,16 +68,16 @@ public abstract class BreadthFirstSearch implements Operation { /** * Get the list of directions will be visited. * - *

Directions are {@link com.sk89q.worldedit.Vector}s that determine + *

Directions are {@link BlockVector3}s that determine * what adjacent points area available. Vectors should not be * unit vectors. An example of a valid direction is - * {@code new Vector(1, 0, 1)}.

+ * {@code new BlockVector3(1, 0, 1)}.

* *

The list of directions can be cleared.

* * @return the list of directions */ - protected Collection getDirections() { + protected Collection getDirections() { return directions; } @@ -86,29 +85,29 @@ public abstract class BreadthFirstSearch implements Operation { * Add the directions along the axes as directions to visit. */ protected void addAxes() { - directions.add(new Vector(0, -1, 0)); - directions.add(new Vector(0, 1, 0)); - directions.add(new Vector(-1, 0, 0)); - directions.add(new Vector(1, 0, 0)); - directions.add(new Vector(0, 0, -1)); - directions.add(new Vector(0, 0, 1)); + directions.add(new BlockVector3(0, -1, 0)); + directions.add(new BlockVector3(0, 1, 0)); + directions.add(new BlockVector3(-1, 0, 0)); + directions.add(new BlockVector3(1, 0, 0)); + directions.add(new BlockVector3(0, 0, -1)); + directions.add(new BlockVector3(0, 0, 1)); } /** * Add the diagonal directions as directions to visit. */ protected void addDiagonal() { - directions.add(new Vector(1, 0, 1)); - directions.add(new Vector(-1, 0, -1)); - directions.add(new Vector(1, 0, -1)); - directions.add(new Vector(-1, 0, 1)); + directions.add(new BlockVector3(1, 0, 1)); + directions.add(new BlockVector3(-1, 0, -1)); + directions.add(new BlockVector3(1, 0, -1)); + directions.add(new BlockVector3(-1, 0, 1)); } /** * Add the given location to the list of locations to visit, provided * that it has not been visited. The position passed to this method * will still be visited even if it fails - * {@link #isVisitable(com.sk89q.worldedit.Vector, com.sk89q.worldedit.Vector)}. + * {@link #isVisitable(BlockVector3, BlockVector3)}. * *

This method should be used before the search begins, because if * the position does fail the test, and the search has already @@ -118,8 +117,8 @@ public abstract class BreadthFirstSearch implements Operation { * * @param position the position */ - public void visit(Vector position) { - BlockVector blockVector = position.toBlockVector(); + public void visit(BlockVector3 position) { + BlockVector3 blockVector = position; if (!visited.contains(blockVector)) { queue.add(blockVector); visited.add(blockVector); @@ -132,8 +131,8 @@ public abstract class BreadthFirstSearch implements Operation { * @param from the origin block * @param to the block under question */ - private void visit(Vector from, Vector to) { - BlockVector blockVector = to.toBlockVector(); + private void visit(BlockVector3 from, BlockVector3 to) { + BlockVector3 blockVector = to; if (!visited.contains(blockVector)) { visited.add(blockVector); if (isVisitable(from, to)) { @@ -150,7 +149,7 @@ public abstract class BreadthFirstSearch implements Operation { * @param to the block under question * @return true if the 'to' block should be visited */ - protected abstract boolean isVisitable(Vector from, Vector to); + protected abstract boolean isVisitable(BlockVector3 from, BlockVector3 to); /** * Get the number of affected objects. @@ -163,14 +162,14 @@ public abstract class BreadthFirstSearch implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - Vector position; + BlockVector3 position; while ((position = queue.poll()) != null) { if (function.apply(position)) { affected++; } - for (Vector dir : directions) { + for (BlockVector3 dir : directions) { visit(position, position.add(dir)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java index 3788d547d..62363a205 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DownwardVisitor.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import java.util.Collection; @@ -51,17 +51,17 @@ public class DownwardVisitor extends RecursiveVisitor { this.baseY = baseY; - Collection directions = getDirections(); + Collection directions = getDirections(); directions.clear(); - directions.add(new Vector(1, 0, 0)); - directions.add(new Vector(-1, 0, 0)); - directions.add(new Vector(0, 0, 1)); - directions.add(new Vector(0, 0, -1)); - directions.add(new Vector(0, -1, 0)); + directions.add(new BlockVector3(1, 0, 0)); + directions.add(new BlockVector3(-1, 0, 0)); + directions.add(new BlockVector3(0, 0, 1)); + directions.add(new BlockVector3(0, 0, -1)); + directions.add(new BlockVector3(0, -1, 0)); } @Override - protected boolean isVisitable(Vector from, Vector to) { + protected boolean isVisitable(BlockVector3 from, BlockVector3 to) { int fromY = from.getBlockY(); return (fromY == baseY || to.subtract(from).getBlockY() < 0) && super.isVisitable(from, to); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 1f0d96e42..46ef33dc0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.FlatRegion; import java.util.List; @@ -64,7 +64,7 @@ public class FlatRegionVisitor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - for (Vector2D pt : flatRegion.asFlatRegion()) { + for (BlockVector2 pt : flatRegion.asFlatRegion()) { if (function.apply(pt)) { affected++; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java index b6dcf4882..f3a191e12 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/LayerVisitor.java @@ -22,14 +22,14 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.LayerFunction; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.FlatRegion; import java.util.List; @@ -92,20 +92,20 @@ public class LayerVisitor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - for (Vector2D column : flatRegion.asFlatRegion()) { + for (BlockVector2 column : flatRegion.asFlatRegion()) { if (!mask.test(column)) { continue; } // Abort if we are underground - if (function.isGround(column.toVector(maxY + 1))) { + if (function.isGround(column.toBlockVector3(maxY + 1))) { return null; } boolean found = false; int groundY = 0; for (int y = maxY; y >= minY; --y) { - Vector test = column.toVector(y); + BlockVector3 test = column.toBlockVector3(y); if (!found) { if (function.isGround(test)) { found = true; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java index 8be7466b1..21aa8b6f6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/NonRisingVisitor.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.function.visitor; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import java.util.Collection; @@ -38,13 +38,13 @@ public class NonRisingVisitor extends RecursiveVisitor { */ public NonRisingVisitor(Mask mask, RegionFunction function) { super(mask, function); - Collection directions = getDirections(); + Collection directions = getDirections(); directions.clear(); - directions.add(new Vector(1, 0, 0)); - directions.add(new Vector(-1, 0, 0)); - directions.add(new Vector(0, 0, 1)); - directions.add(new Vector(0, 0, -1)); - directions.add(new Vector(0, -1, 0)); + directions.add(new BlockVector3(1, 0, 0)); + directions.add(new BlockVector3(-1, 0, 0)); + directions.add(new BlockVector3(0, 0, 1)); + directions.add(new BlockVector3(0, 0, -1)); + directions.add(new BlockVector3(0, -1, 0)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java index ac89393a3..d3dda04f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RecursiveVisitor.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.function.visitor; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; /** * An implementation of an {@link BreadthFirstSearch} that uses a mask to @@ -46,7 +46,7 @@ public class RecursiveVisitor extends BreadthFirstSearch { } @Override - protected boolean isVisitable(Vector from, Vector to) { + protected boolean isVisitable(BlockVector3 from, BlockVector3 to) { return mask.test(to); } } 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 d6fc7d45c..12a955c0d 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 @@ -19,11 +19,11 @@ package com.sk89q.worldedit.function.visitor; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import java.util.List; @@ -53,7 +53,7 @@ public class RegionVisitor implements Operation { @Override public Operation resume(RunContext run) throws WorldEditException { - for (Vector pt : region) { + for (BlockVector3 pt : region) { if (function.apply(pt)) { affected++; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java index 4bb94aa09..1bbef8ab0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/change/BlockChange.java @@ -21,10 +21,10 @@ package com.sk89q.worldedit.history.change; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.history.UndoContext; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; /** @@ -36,7 +36,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; */ public class BlockChange implements Change { - private final BlockVector position; + private final BlockVector3 position; private final BlockStateHolder previous; private final BlockStateHolder current; @@ -47,7 +47,7 @@ public class BlockChange implements Change { * @param previous the previous block * @param current the current block */ - public BlockChange(BlockVector position, BlockStateHolder previous, BlockStateHolder current) { + public BlockChange(BlockVector3 position, BlockStateHolder previous, BlockStateHolder current) { checkNotNull(position); checkNotNull(previous); checkNotNull(current); @@ -61,7 +61,7 @@ public class BlockChange implements Change { * * @return the position */ - public BlockVector getPosition() { + public BlockVector3 getPosition() { return position; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java index 23f724110..9c9ad2a85 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java @@ -22,9 +22,9 @@ package com.sk89q.worldedit.history.changeset; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Iterators; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.history.change.BlockChange; import com.sk89q.worldedit.history.change.Change; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.LocatedBlock; import com.sk89q.worldedit.util.collection.LocatedBlockList; @@ -42,7 +42,7 @@ import java.util.Iterator; public class BlockOptimizedHistory extends ArrayListHistory { private static Change createChange(LocatedBlock block) { - return new BlockChange(block.getLocation().toBlockPoint(), block.getBlock(), block.getBlock()); + return new BlockChange(block.getLocation(), block.getBlock(), block.getBlock()); } private final LocatedBlockList previous = new LocatedBlockList(); @@ -54,7 +54,7 @@ public class BlockOptimizedHistory extends ArrayListHistory { if (change instanceof BlockChange) { BlockChange blockChange = (BlockChange) change; - BlockVector position = blockChange.getPosition(); + BlockVector3 position = blockChange.getPosition(); previous.add(position, blockChange.getPrevious()); current.add(position, blockChange.getCurrent()); } else { @@ -80,5 +80,4 @@ public class BlockOptimizedHistory extends ArrayListHistory { public int size() { return super.size() + previous.size(); } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java index eac88237c..7f42b3a36 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/annotation/Direction.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.internal.annotation; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; @@ -27,7 +27,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; /** - * Annotates a {@link Vector} parameter to inject a direction. + * Annotates a {@link Vector3} parameter to inject a direction. */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java index a6371961f..262bdd0af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandLoggingHandler.java @@ -26,10 +26,10 @@ import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.command.parametric.AbstractInvokeListener; import com.sk89q.worldedit.util.command.parametric.InvokeHandler; import com.sk89q.worldedit.util.command.parametric.ParameterData; @@ -102,13 +102,13 @@ public class CommandLoggingHandler extends AbstractInvokeListener implements Inv } if (logMode != null && sender.isPlayer()) { - Vector position = player.getLocation().toVector(); + Vector3 position = player.getLocation().toVector(); LocalSession session = worldEdit.getSessionManager().get(player); switch (logMode) { case PLACEMENT: try { - position = session.getPlacementPosition(player); + position = session.getPlacementPosition(player).toVector3(); } catch (IncompleteRegionException e) { break; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java index 1bdeee5c5..4cdebe5cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/WorldEditBinding.java @@ -23,10 +23,8 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.UnknownDirectionException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.NoMatchException; @@ -38,6 +36,7 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.annotation.Direction; import com.sk89q.worldedit.internal.annotation.Selection; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator.TreeType; @@ -49,6 +48,7 @@ import com.sk89q.worldedit.util.command.parametric.ParameterException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.biome.Biomes; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.registry.BiomeRegistry; @@ -258,10 +258,10 @@ public class WorldEditBinding extends BindingHelper { * @throws UnknownDirectionException on an unknown direction */ @BindingMatch(classifier = Direction.class, - type = Vector.class, + type = BlockVector3.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) - public Vector getDirection(ArgumentStack context, Direction direction) + public BlockVector3 getDirection(ArgumentStack context, Direction direction) throws ParameterException, UnknownDirectionException { Player sender = getPlayer(context); return worldEdit.getDirection(sender, context.next()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java index d23fd9a74..d10f5fb68 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionCylinderEvent.java @@ -21,15 +21,15 @@ package com.sk89q.worldedit.internal.cui; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; public class SelectionCylinderEvent implements CUIEvent { - protected final Vector pos; - protected final Vector2D radius; + protected final BlockVector3 pos; + protected final Vector2 radius; - public SelectionCylinderEvent(Vector pos, Vector2D radius) { + public SelectionCylinderEvent(BlockVector3 pos, Vector2 radius) { this.pos = pos; this.radius = radius; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java index 3e371b105..e8c051040 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionEllipsoidPointEvent.java @@ -19,14 +19,14 @@ package com.sk89q.worldedit.internal.cui; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; public class SelectionEllipsoidPointEvent implements CUIEvent { protected final int id; - protected final Vector pos; + protected final BlockVector3 pos; - public SelectionEllipsoidPointEvent(int id, Vector pos) { + public SelectionEllipsoidPointEvent(int id, BlockVector3 pos) { this.id = id; this.pos = pos; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java index dc4d0adaa..1586dced9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPoint2DEvent.java @@ -19,27 +19,27 @@ package com.sk89q.worldedit.internal.cui; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; public class SelectionPoint2DEvent implements CUIEvent { protected final int id; - protected final int blockx; - protected final int blockz; + protected final int blockX; + protected final int blockZ; protected final int area; - public SelectionPoint2DEvent(int id, Vector2D pos, int area) { + public SelectionPoint2DEvent(int id, BlockVector2 pos, int area) { this.id = id; - this.blockx = pos.getBlockX(); - this.blockz = pos.getBlockZ(); + this.blockX = pos.getX(); + this.blockZ = pos.getZ(); this.area = area; } - public SelectionPoint2DEvent(int id, Vector pos, int area) { + public SelectionPoint2DEvent(int id, BlockVector3 pos, int area) { this.id = id; - this.blockx = pos.getBlockX(); - this.blockz = pos.getBlockZ(); + this.blockX = pos.getX(); + this.blockZ = pos.getZ(); this.area = area; } @@ -52,8 +52,8 @@ public class SelectionPoint2DEvent implements CUIEvent { public String[] getParameters() { return new String[] { String.valueOf(id), - String.valueOf(blockx), - String.valueOf(blockz), + String.valueOf(blockX), + String.valueOf(blockZ), String.valueOf(area) }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java index e719b1855..baac3ab1f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/SelectionPointEvent.java @@ -19,15 +19,15 @@ package com.sk89q.worldedit.internal.cui; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; public class SelectionPointEvent implements CUIEvent { protected final int id; - protected final Vector pos; + protected final BlockVector3 pos; protected final int area; - public SelectionPointEvent(int id, Vector pos, int area) { + public SelectionPointEvent(int id, BlockVector3 pos, int area) { this.id = id; this.pos = pos; this.area = area; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java index af63bebe0..5a13140db 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java @@ -26,9 +26,9 @@ import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; @@ -85,7 +85,7 @@ public class ServerCUIHandler { } } else { CuboidRegion region = ((CuboidRegionSelector) regionSelector).getIncompleteRegion(); - Vector point; + BlockVector3 point; if (region.getPos1() != null) { point = region.getPos1(); } else if (region.getPos2() != null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java index 4b4cbad13..9f7eaceb1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/expression/runtime/Functions.java @@ -19,9 +19,9 @@ package com.sk89q.worldedit.internal.expression.runtime; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.runtime.Function.Dynamic; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.noise.PerlinNoise; import com.sk89q.worldedit.math.noise.RidgedMultiFractalNoise; import com.sk89q.worldedit.math.noise.VoronoiNoise; @@ -392,7 +392,7 @@ public final class Functions { } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Perlin noise error: " + e.getMessage()); } - return perlin.noise(new Vector(x.getValue(), y.getValue(), z.getValue())); + return perlin.noise(new Vector3(x.getValue(), y.getValue(), z.getValue())); } private static final ThreadLocal localVoronoi = ThreadLocal.withInitial(VoronoiNoise::new); @@ -405,7 +405,7 @@ public final class Functions { } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Voronoi error: " + e.getMessage()); } - return voronoi.noise(new Vector(x.getValue(), y.getValue(), z.getValue())); + return voronoi.noise(new Vector3(x.getValue(), y.getValue(), z.getValue())); } private static final ThreadLocal localRidgedMulti = ThreadLocal.withInitial(RidgedMultiFractalNoise::new); @@ -419,7 +419,7 @@ public final class Functions { } catch (IllegalArgumentException e) { throw new EvaluationException(0, "Ridged multi error: " + e.getMessage()); } - return ridgedMulti.noise(new Vector(x.getValue(), y.getValue(), z.getValue())); + return ridgedMulti.noise(new Vector3(x.getValue(), y.getValue(), z.getValue())); } private static double queryInternal(RValue type, RValue data, double typeId, double dataValue) throws EvaluationException { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java new file mode 100644 index 000000000..864e8c19c --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector2.java @@ -0,0 +1,529 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.math; + +import com.google.common.collect.ComparisonChain; +import com.sk89q.worldedit.math.transform.AffineTransform; + +import java.util.Comparator; + +/** + * An immutable 2-dimensional vector. + */ +public final class BlockVector2 { + + public static final BlockVector2 ZERO = new BlockVector2(0, 0); + public static final BlockVector2 UNIT_X = new BlockVector2(1, 0); + public static final BlockVector2 UNIT_Z = new BlockVector2(0, 1); + public static final BlockVector2 ONE = new BlockVector2(1, 1); + + /** + * A comparator for BlockVector2ds that orders the vectors by rows, with x as the + * column and z as the row. + * + * For example, if x is the horizontal axis and z is the vertical axis, it + * sorts like so: + * + *

+     * 0123
+     * 4567
+     * 90ab
+     * cdef
+     * 
+ */ + public static final Comparator COMPARING_GRID_ARRANGEMENT = (a, b) -> { + return ComparisonChain.start() + .compare(a.getBlockZ(), b.getBlockZ()) + .compare(a.getBlockX(), b.getBlockX()) + .result(); + }; + + private final int x, z; + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param z the Z coordinate + */ + public BlockVector2(double x, double z) { + this((int) Math.floor(x), (int) Math.floor(z)); + } + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param z the Z coordinate + */ + public BlockVector2(int x, int z) { + this.x = x; + this.z = z; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public int getX() { + return x; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public int getBlockX() { + return x; + } + + /** + * Set the X coordinate. + * + * @param x the new X + * @return a new vector + */ + public BlockVector2 withX(int x) { + return new BlockVector2(x, z); + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public int getZ() { + return z; + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public int getBlockZ() { + return z; + } + + /** + * Set the Z coordinate. + * + * @param z the new Z + * @return a new vector + */ + public BlockVector2 withZ(int z) { + return new BlockVector2(x, z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector2 add(BlockVector2 other) { + return add(other.x, other.z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param x the value to add + * @param z the value to add + * @return a new vector + */ + public BlockVector2 add(int x, int z) { + return new BlockVector2(this.x + x, this.z + z); + } + + /** + * Add a list of vectors to this vector and return the + * result as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector2 add(BlockVector2... others) { + int newX = x, newZ = z; + + for (BlockVector2 other : others) { + newX += other.x; + newZ += other.z; + } + + return new BlockVector2(newX, newZ); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector2 subtract(BlockVector2 other) { + return subtract(other.x, other.z); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param x the value to subtract + * @param z the value to subtract + * @return a new vector + */ + public BlockVector2 subtract(int x, int z) { + return new BlockVector2(this.x - x, this.z - z); + } + + /** + * Subtract a list of vectors from this vector and return the result + * as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector2 subtract(BlockVector2... others) { + int newX = x, newZ = z; + + for (BlockVector2 other : others) { + newX -= other.x; + newZ -= other.z; + } + + return new BlockVector2(newX, newZ); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector2 multiply(BlockVector2 other) { + return multiply(other.x, other.z); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param x the value to multiply + * @param z the value to multiply + * @return a new vector + */ + public BlockVector2 multiply(int x, int z) { + return new BlockVector2(this.x * x, this.z * z); + } + + /** + * Multiply this vector by zero or more vectors on each component. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector2 multiply(BlockVector2... others) { + int newX = x, newZ = z; + + for (BlockVector2 other : others) { + newX *= other.x; + newZ *= other.z; + } + + return new BlockVector2(newX, newZ); + } + + /** + * Perform scalar multiplication and return a new vector. + * + * @param n the value to multiply + * @return a new vector + */ + public BlockVector2 multiply(int n) { + return multiply(n, n); + } + + /** + * Divide this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector2 divide(BlockVector2 other) { + return divide(other.x, other.z); + } + + /** + * Divide this vector by another vector on each component. + * + * @param x the value to divide by + * @param z the value to divide by + * @return a new vector + */ + public BlockVector2 divide(int x, int z) { + return new BlockVector2(this.x / x, this.z / z); + } + + /** + * Perform scalar division and return a new vector. + * + * @param n the value to divide by + * @return a new vector + */ + public BlockVector2 divide(int n) { + return divide(n, n); + } + + /** + * Get the length of the vector. + * + * @return length + */ + public double length() { + return Math.sqrt(lengthSq()); + } + + /** + * Get the length, squared, of the vector. + * + * @return length, squared + */ + public int lengthSq() { + return x * x + z * z; + } + + /** + * Get the distance between this vector and another vector. + * + * @param other the other vector + * @return distance + */ + public double distance(BlockVector2 other) { + return Math.sqrt(distanceSq(other)); + } + + /** + * Get the distance between this vector and another vector, squared. + * + * @param other the other vector + * @return distance + */ + public int distanceSq(BlockVector2 other) { + int dx = other.x - x; + int dz = other.z - z; + return dx * dx + dz * dz; + } + + /** + * Get the normalized vector, which is the vector divided by its + * length, as a new vector. + * + * @return a new vector + */ + public BlockVector2 normalize() { + double len = length(); + double x = this.x / len; + double z = this.z / len; + return new BlockVector2(x, z); + } + + /** + * Gets the dot product of this and another vector. + * + * @param other the other vector + * @return the dot product of this and the other vector + */ + public int dot(BlockVector2 other) { + return x * other.x + z * other.z; + } + + /** + * Checks to see if a vector is contained with another. + * + * @param min the minimum point (X, Y, and Z are the lowest) + * @param max the maximum point (X, Y, and Z are the lowest) + * @return true if the vector is contained + */ + public boolean containedWithin(BlockVector2 min, BlockVector2 max) { + return x >= min.x && x <= max.x + && z >= min.z && z <= max.z; + } + + /** + * Floors the values of all components. + * + * @return a new vector + */ + public BlockVector2 floor() { + // already floored, kept for feature parity with Vector2 + return this; + } + + /** + * Rounds all components up. + * + * @return a new vector + */ + public BlockVector2 ceil() { + // already raised, kept for feature parity with Vector2 + return this; + } + + /** + * Rounds all components to the closest integer. + * + *

Components < 0.5 are rounded down, otherwise up.

+ * + * @return a new vector + */ + public BlockVector2 round() { + // already rounded, kept for feature parity with Vector2 + return this; + } + + /** + * Returns a vector with the absolute values of the components of + * this vector. + * + * @return a new vector + */ + public BlockVector2 abs() { + return new BlockVector2(Math.abs(x), Math.abs(z)); + } + + /** + * Perform a 2D transformation on this vector and return a new one. + * + * @param angle in degrees + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation + * @return a new vector + * @see AffineTransform another method to transform vectors + */ + public BlockVector2 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + angle = Math.toRadians(angle); + double x = this.x - aboutX; + double z = this.z - aboutZ; + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x2 = x * cos - z * sin; + double z2 = x * sin + z * cos; + return new BlockVector2( + x2 + aboutX + translateX, + z2 + aboutZ + translateZ); + } + + /** + * Gets the minimum components of two vectors. + * + * @param v2 the second vector + * @return minimum + */ + public BlockVector2 getMinimum(BlockVector2 v2) { + return new BlockVector2( + Math.min(x, v2.x), + Math.min(z, v2.z) + ); + } + + /** + * Gets the maximum components of two vectors. + * + * @param v2 the second vector + * @return maximum + */ + public BlockVector2 getMaximum(BlockVector2 v2) { + return new BlockVector2( + Math.max(x, v2.x), + Math.max(z, v2.z) + ); + } + + public Vector2 toVector2() { + return new Vector2(x, z); + } + + /** + * Creates a 3D vector by adding a zero Y component to this vector. + * + * @return a new vector + */ + public Vector3 toVector3() { + return toVector3(0); + } + + /** + * Creates a 3D vector by adding the specified Y component to this vector. + * + * @param y the Y component + * @return a new vector + */ + public Vector3 toVector3(double y) { + return new Vector3(x, y, z); + } + + /** + * Creates a 3D vector by adding a zero Y component to this vector. + * + * @return a new vector + */ + public BlockVector3 toBlockVector3() { + return toBlockVector3(0); + } + + /** + * Creates a 3D vector by adding the specified Y component to this vector. + * + * @param y the Y component + * @return a new vector + */ + public BlockVector3 toBlockVector3(int y) { + return new BlockVector3(x, y, z); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BlockVector2)) { + return false; + } + + BlockVector2 other = (BlockVector2) obj; + return other.x == this.x && other.z == this.z; + + } + + @Override + public int hashCode() { + int hash = 17; + hash = 31 * hash + Integer.hashCode(x); + hash = 31 * hash + Integer.hashCode(z); + return hash; + } + + @Override + public String toString() { + return "(" + x + ", " + z + ")"; + } + +} \ No newline at end of file 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 new file mode 100644 index 000000000..efe56e8af --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/BlockVector3.java @@ -0,0 +1,613 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.math; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.collect.ComparisonChain; +import com.sk89q.worldedit.math.transform.AffineTransform; + +import java.util.Comparator; + +/** + * An immutable 3-dimensional vector. + */ +public final class BlockVector3 { + + public static final BlockVector3 ZERO = new BlockVector3(0, 0, 0); + public static final BlockVector3 UNIT_X = new BlockVector3(1, 0, 0); + public static final BlockVector3 UNIT_Y = new BlockVector3(0, 1, 0); + public static final BlockVector3 UNIT_Z = new BlockVector3(0, 0, 1); + public static final BlockVector3 ONE = new BlockVector3(1, 1, 1); + + // thread-safe initialization idiom + private static final class YzxOrderComparator { + private static final Comparator YZX_ORDER = (a, b) -> { + return ComparisonChain.start() + .compare(a.y, b.y) + .compare(a.z, b.z) + .compare(a.x, b.x) + .result(); + }; + } + + /** + * Returns a comparator that sorts vectors first by Y, then Z, then X. + * + *

+ * Useful for sorting by chunk block storage order. + */ + public static Comparator sortByCoordsYzx() { + return YzxOrderComparator.YZX_ORDER; + } + + private final int x, y, z; + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + */ + public BlockVector3(double x, double y, double z) { + this((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); + } + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + */ + public BlockVector3(int x, int y, int z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public int getX() { + return x; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public int getBlockX() { + return x; + } + + /** + * Set the X coordinate. + * + * @param x the new X + * @return a new vector + */ + public BlockVector3 withX(int x) { + return new BlockVector3(x, y, z); + } + + /** + * Get the Y coordinate. + * + * @return the y coordinate + */ + public int getY() { + return y; + } + + /** + * Get the Y coordinate. + * + * @return the y coordinate + */ + public int getBlockY() { + return y; + } + + /** + * Set the Y coordinate. + * + * @param y the new Y + * @return a new vector + */ + public BlockVector3 withY(int y) { + return new BlockVector3(x, y, z); + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public int getZ() { + return z; + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public int getBlockZ() { + return z; + } + + /** + * Set the Z coordinate. + * + * @param z the new Z + * @return a new vector + */ + public BlockVector3 withZ(int z) { + return new BlockVector3(x, y, z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector3 add(BlockVector3 other) { + return add(other.x, other.y, other.z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param x the value to add + * @param y the value to add + * @param z the value to add + * @return a new vector + */ + public BlockVector3 add(int x, int y, int z) { + return new BlockVector3(this.x + x, this.y + y, this.z + z); + } + + /** + * Add a list of vectors to this vector and return the + * result as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector3 add(BlockVector3... others) { + int newX = x, newY = y, newZ = z; + + for (BlockVector3 other : others) { + newX += other.x; + newY += other.y; + newZ += other.z; + } + + return new BlockVector3(newX, newY, newZ); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector3 subtract(BlockVector3 other) { + return subtract(other.x, other.y, other.z); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param x the value to subtract + * @param y the value to subtract + * @param z the value to subtract + * @return a new vector + */ + public BlockVector3 subtract(int x, int y, int z) { + return new BlockVector3(this.x - x, this.y - y, this.z - z); + } + + /** + * Subtract a list of vectors from this vector and return the result + * as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector3 subtract(BlockVector3... others) { + int newX = x, newY = y, newZ = z; + + for (BlockVector3 other : others) { + newX -= other.x; + newY -= other.y; + newZ -= other.z; + } + + return new BlockVector3(newX, newY, newZ); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector3 multiply(BlockVector3 other) { + return multiply(other.x, other.y, other.z); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param x the value to multiply + * @param y the value to multiply + * @param z the value to multiply + * @return a new vector + */ + public BlockVector3 multiply(int x, int y, int z) { + return new BlockVector3(this.x * x, this.y * y, this.z * z); + } + + /** + * Multiply this vector by zero or more vectors on each component. + * + * @param others an array of vectors + * @return a new vector + */ + public BlockVector3 multiply(BlockVector3... others) { + int newX = x, newY = y, newZ = z; + + for (BlockVector3 other : others) { + newX *= other.x; + newY *= other.y; + newZ *= other.z; + } + + return new BlockVector3(newX, newY, newZ); + } + + /** + * Perform scalar multiplication and return a new vector. + * + * @param n the value to multiply + * @return a new vector + */ + public BlockVector3 multiply(int n) { + return multiply(n, n, n); + } + + /** + * Divide this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public BlockVector3 divide(BlockVector3 other) { + return divide(other.x, other.y, other.z); + } + + /** + * Divide this vector by another vector on each component. + * + * @param x the value to divide by + * @param y the value to divide by + * @param z the value to divide by + * @return a new vector + */ + public BlockVector3 divide(int x, int y, int z) { + return new BlockVector3(this.x / x, this.y / y, this.z / z); + } + + /** + * Perform scalar division and return a new vector. + * + * @param n the value to divide by + * @return a new vector + */ + public BlockVector3 divide(int n) { + return divide(n, n, n); + } + + /** + * Get the length of the vector. + * + * @return length + */ + public double length() { + return Math.sqrt(lengthSq()); + } + + /** + * Get the length, squared, of the vector. + * + * @return length, squared + */ + public int lengthSq() { + return x * x + y * y + z * z; + } + + /** + * Get the distance between this vector and another vector. + * + * @param other the other vector + * @return distance + */ + public double distance(BlockVector3 other) { + return Math.sqrt(distanceSq(other)); + } + + /** + * Get the distance between this vector and another vector, squared. + * + * @param other the other vector + * @return distance + */ + public int distanceSq(BlockVector3 other) { + int dx = other.x - x; + int dy = other.y - y; + int dz = other.z - z; + return dx * dx + dy * dy + dz * dz; + } + + /** + * Get the normalized vector, which is the vector divided by its + * length, as a new vector. + * + * @return a new vector + */ + public BlockVector3 normalize() { + double len = length(); + double x = this.x / len; + double y = this.y / len; + double z = this.z / len; + return new BlockVector3(x, y, z); + } + + /** + * Gets the dot product of this and another vector. + * + * @param other the other vector + * @return the dot product of this and the other vector + */ + public double dot(BlockVector3 other) { + return x * other.x + y * other.y + z * other.z; + } + + /** + * Gets the cross product of this and another vector. + * + * @param other the other vector + * @return the cross product of this and the other vector + */ + public BlockVector3 cross(BlockVector3 other) { + return new BlockVector3( + y * other.z - z * other.y, + z * other.x - x * other.z, + x * other.y - y * other.x + ); + } + + /** + * Checks to see if a vector is contained with another. + * + * @param min the minimum point (X, Y, and Z are the lowest) + * @param max the maximum point (X, Y, and Z are the lowest) + * @return true if the vector is contained + */ + public boolean containedWithin(BlockVector3 min, BlockVector3 max) { + return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z; + } + + /** + * Clamp the Y component. + * + * @param min the minimum value + * @param max the maximum value + * @return a new vector + */ + public BlockVector3 clampY(int min, int max) { + checkArgument(min <= max, "minimum cannot be greater than maximum"); + if (y < min) { + return new BlockVector3(x, min, z); + } + if (y > max) { + return new BlockVector3(x, max, z); + } + return this; + } + + /** + * Floors the values of all components. + * + * @return a new vector + */ + public BlockVector3 floor() { + // already floored, kept for feature parity with Vector3 + return this; + } + + /** + * Rounds all components up. + * + * @return a new vector + */ + public BlockVector3 ceil() { + // already raised, kept for feature parity with Vector3 + return this; + } + + /** + * Rounds all components to the closest integer. + * + *

Components < 0.5 are rounded down, otherwise up.

+ * + * @return a new vector + */ + public BlockVector3 round() { + // already rounded, kept for feature parity with Vector3 + return this; + } + + /** + * Returns a vector with the absolute values of the components of + * this vector. + * + * @return a new vector + */ + public BlockVector3 abs() { + return new BlockVector3(Math.abs(x), Math.abs(y), Math.abs(z)); + } + + /** + * Perform a 2D transformation on this vector and return a new one. + * + * @param angle in degrees + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation + * @return a new vector + * @see AffineTransform another method to transform vectors + */ + public BlockVector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + angle = Math.toRadians(angle); + double x = this.x - aboutX; + double z = this.z - aboutZ; + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x2 = x * cos - z * sin; + double z2 = x * sin + z * cos; + + return new BlockVector3( + x2 + aboutX + translateX, + y, + z2 + aboutZ + translateZ + ); + } + + /** + * Get this vector's pitch as used within the game. + * + * @return pitch in radians + */ + public double toPitch() { + double x = getX(); + double z = getZ(); + + if (x == 0 && z == 0) { + return getY() > 0 ? -90 : 90; + } else { + double x2 = x * x; + double z2 = z * z; + double xz = Math.sqrt(x2 + z2); + return Math.toDegrees(Math.atan(-getY() / xz)); + } + } + + /** + * Get this vector's yaw as used within the game. + * + * @return yaw in radians + */ + public double toYaw() { + double x = getX(); + double z = getZ(); + + double t = Math.atan2(-x, z); + double tau = 2 * Math.PI; + + return Math.toDegrees(((t + tau) % tau)); + } + + /** + * Gets the minimum components of two vectors. + * + * @param v2 the second vector + * @return minimum + */ + public BlockVector3 getMinimum(BlockVector3 v2) { + return new BlockVector3( + Math.min(x, v2.x), + Math.min(y, v2.y), + Math.min(z, v2.z) + ); + } + + /** + * Gets the maximum components of two vectors. + * + * @param v2 the second vector + * @return maximum + */ + public BlockVector3 getMaximum(BlockVector3 v2) { + return new BlockVector3( + Math.max(x, v2.x), + Math.max(y, v2.y), + Math.max(z, v2.z) + ); + } + + /** + * Creates a 2D vector by dropping the Y component from this vector. + * + * @return a new {@link BlockVector2} + */ + public BlockVector2 toBlockVector2() { + return new BlockVector2(x, z); + } + + public Vector3 toVector3() { + return new Vector3(x, y, z); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof BlockVector3)) { + return false; + } + + BlockVector3 other = (BlockVector3) obj; + return other.x == this.x && other.y == this.y && other.z == this.z; + } + + @Override + public int hashCode() { + int hash = 17; + hash = 31 * hash + Integer.hashCode(x); + hash = 31 * hash + Integer.hashCode(y); + hash = 31 * hash + Integer.hashCode(z); + return hash; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java new file mode 100644 index 000000000..e403cc5ea --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector2.java @@ -0,0 +1,471 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.math; + +import com.sk89q.worldedit.math.transform.AffineTransform; + +/** + * An immutable 2-dimensional vector. + */ +public final class Vector2 { + + public static final Vector2 ZERO = new Vector2(0, 0); + public static final Vector2 UNIT_X = new Vector2(1, 0); + public static final Vector2 UNIT_Z = new Vector2(0, 1); + public static final Vector2 ONE = new Vector2(1, 1); + + private final double x, z; + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param z the Z coordinate + */ + public Vector2(double x, double z) { + this.x = x; + this.z = z; + } + + /** + * Copy another vector. + * + * @param other the other vector + */ + public Vector2(Vector2 other) { + this.x = other.x; + this.z = other.z; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public double getX() { + return x; + } + + /** + * Set the X coordinate. + * + * @param x the new X + * @return a new vector + */ + public Vector2 withX(double x) { + return new Vector2(x, z); + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public double getZ() { + return z; + } + + /** + * Set the Z coordinate. + * + * @param z the new Z + * @return a new vector + */ + public Vector2 withZ(double z) { + return new Vector2(x, z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public Vector2 add(Vector2 other) { + return add(other.x, other.z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param x the value to add + * @param z the value to add + * @return a new vector + */ + public Vector2 add(double x, double z) { + return new Vector2(this.x + x, this.z + z); + } + + /** + * Add a list of vectors to this vector and return the + * result as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector2 add(Vector2... others) { + double newX = x, newZ = z; + + for (Vector2 other : others) { + newX += other.x; + newZ += other.z; + } + + return new Vector2(newX, newZ); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public Vector2 subtract(Vector2 other) { + return subtract(other.x, other.z); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param x the value to subtract + * @param z the value to subtract + * @return a new vector + */ + public Vector2 subtract(double x, double z) { + return new Vector2(this.x - x, this.z - z); + } + + /** + * Subtract a list of vectors from this vector and return the result + * as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector2 subtract(Vector2... others) { + double newX = x, newZ = z; + + for (Vector2 other : others) { + newX -= other.x; + newZ -= other.z; + } + + return new Vector2(newX, newZ); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public Vector2 multiply(Vector2 other) { + return multiply(other.x, other.z); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param x the value to multiply + * @param z the value to multiply + * @return a new vector + */ + public Vector2 multiply(double x, double z) { + return new Vector2(this.x * x, this.z * z); + } + + /** + * Multiply this vector by zero or more vectors on each component. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector2 multiply(Vector2... others) { + double newX = x, newZ = z; + + for (Vector2 other : others) { + newX *= other.x; + newZ *= other.z; + } + + return new Vector2(newX, newZ); + } + + /** + * Perform scalar multiplication and return a new vector. + * + * @param n the value to multiply + * @return a new vector + */ + public Vector2 multiply(double n) { + return multiply(n, n); + } + + /** + * Divide this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public Vector2 divide(Vector2 other) { + return divide(other.x, other.z); + } + + /** + * Divide this vector by another vector on each component. + * + * @param x the value to divide by + * @param z the value to divide by + * @return a new vector + */ + public Vector2 divide(double x, double z) { + return new Vector2(this.x / x, this.z / z); + } + + /** + * Perform scalar division and return a new vector. + * + * @param n the value to divide by + * @return a new vector + */ + public Vector2 divide(double n) { + return divide(n, n); + } + + /** + * Get the length of the vector. + * + * @return length + */ + public double length() { + return Math.sqrt(lengthSq()); + } + + /** + * Get the length, squared, of the vector. + * + * @return length, squared + */ + public double lengthSq() { + return x * x + z * z; + } + + /** + * Get the distance between this vector and another vector. + * + * @param other the other vector + * @return distance + */ + public double distance(Vector2 other) { + return Math.sqrt(distanceSq(other)); + } + + /** + * Get the distance between this vector and another vector, squared. + * + * @param other the other vector + * @return distance + */ + public double distanceSq(Vector2 other) { + double dx = other.x - x; + double dz = other.z - z; + return dx * dx + dz * dz; + } + + /** + * Get the normalized vector, which is the vector divided by its + * length, as a new vector. + * + * @return a new vector + */ + public Vector2 normalize() { + return divide(length()); + } + + /** + * Gets the dot product of this and another vector. + * + * @param other the other vector + * @return the dot product of this and the other vector + */ + public double dot(Vector2 other) { + return x * other.x + z * other.z; + } + + /** + * Checks to see if a vector is contained with another. + * + * @param min the minimum point (X, Y, and Z are the lowest) + * @param max the maximum point (X, Y, and Z are the lowest) + * @return true if the vector is contained + */ + public boolean containedWithin(Vector2 min, Vector2 max) { + return x >= min.x && x <= max.x + && z >= min.z && z <= max.z; + } + + /** + * Floors the values of all components. + * + * @return a new vector + */ + public Vector2 floor() { + return new Vector2(Math.floor(x), Math.floor(z)); + } + + /** + * Rounds all components up. + * + * @return a new vector + */ + public Vector2 ceil() { + return new Vector2(Math.ceil(x), Math.ceil(z)); + } + + /** + * Rounds all components to the closest integer. + * + *

Components < 0.5 are rounded down, otherwise up.

+ * + * @return a new vector + */ + public Vector2 round() { + return new Vector2(Math.floor(x + 0.5), Math.floor(z + 0.5)); + } + + /** + * Returns a vector with the absolute values of the components of + * this vector. + * + * @return a new vector + */ + public Vector2 abs() { + return new Vector2(Math.abs(x), Math.abs(z)); + } + + /** + * Perform a 2D transformation on this vector and return a new one. + * + * @param angle in degrees + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation + * @return a new vector + * @see AffineTransform another method to transform vectors + */ + public Vector2 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + angle = Math.toRadians(angle); + double x = this.x - aboutX; + double z = this.z - aboutZ; + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x2 = x * cos - z * sin; + double z2 = x * sin + z * cos; + return new Vector2( + x2 + aboutX + translateX, + z2 + aboutZ + translateZ); + } + + /** + * Gets the minimum components of two vectors. + * + * @param v2 the second vector + * @return minimum + */ + public Vector2 getMinimum(Vector2 v2) { + return new Vector2( + Math.min(x, v2.x), + Math.min(z, v2.z) + ); + } + + /** + * Gets the maximum components of two vectors. + * + * @param v2 the second vector + * @return maximum + */ + public Vector2 getMaximum(Vector2 v2) { + return new Vector2( + Math.max(x, v2.x), + Math.max(z, v2.z) + ); + } + + public static BlockVector2 toBlockPoint(double x, double z) { + return new BlockVector2(x, z); + } + + /** + * Create a new {@link BlockVector2} from this vector. + * + * @return a new {@link BlockVector2} + */ + public BlockVector2 toBlockPoint() { + return toBlockPoint(x, z); + } + + /** + * Creates a 3D vector by adding a zero Y component to this vector. + * + * @return a new vector + */ + public Vector3 toVector3() { + return toVector3(0); + } + + /** + * Creates a 3D vector by adding the specified Y component to this vector. + * + * @param y the Y component + * @return a new vector + */ + public Vector3 toVector3(double y) { + return new Vector3(x, y, z); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Vector2)) { + return false; + } + + Vector2 other = (Vector2) obj; + return other.x == this.x && other.z == this.z; + + } + + @Override + public int hashCode() { + int hash = 17; + hash = 31 * hash + Double.hashCode(x); + hash = 31 * hash + Double.hashCode(z); + return hash; + } + + @Override + public String toString() { + return "(" + x + ", " + z + ")"; + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java new file mode 100644 index 000000000..59847cbf2 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/Vector3.java @@ -0,0 +1,596 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * 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 . + */ + +package com.sk89q.worldedit.math; + +import static com.google.common.base.Preconditions.checkArgument; + +import com.google.common.collect.ComparisonChain; +import com.sk89q.worldedit.math.transform.AffineTransform; + +import java.util.Comparator; + +/** + * An immutable 3-dimensional vector. + */ +public final class Vector3 { + + public static final Vector3 ZERO = new Vector3(0, 0, 0); + public static final Vector3 UNIT_X = new Vector3(1, 0, 0); + public static final Vector3 UNIT_Y = new Vector3(0, 1, 0); + public static final Vector3 UNIT_Z = new Vector3(0, 0, 1); + public static final Vector3 ONE = new Vector3(1, 1, 1); + + // thread-safe initialization idiom + private static final class YzxOrderComparator { + private static final Comparator YZX_ORDER = (a, b) -> { + return ComparisonChain.start() + .compare(a.y, b.y) + .compare(a.z, b.z) + .compare(a.x, b.x) + .result(); + }; + } + + /** + * Returns a comparator that sorts vectors first by Y, then Z, then X. + * + *

+ * Useful for sorting by chunk block storage order. + */ + public static Comparator sortByCoordsYzx() { + return YzxOrderComparator.YZX_ORDER; + } + + private final double x, y, z; + + /** + * Construct an instance. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + */ + public Vector3(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** + * Copy another vector. + * + * @param other another vector to make a copy of + */ + public Vector3(Vector3 other) { + this.x = other.x; + this.y = other.y; + this.z = other.z; + } + + /** + * Get the X coordinate. + * + * @return the x coordinate + */ + public double getX() { + return x; + } + + /** + * Set the X coordinate. + * + * @param x the new X + * @return a new vector + */ + public Vector3 withX(double x) { + return new Vector3(x, y, z); + } + + /** + * Get the Y coordinate. + * + * @return the y coordinate + */ + public double getY() { + return y; + } + + /** + * Set the Y coordinate. + * + * @param y the new Y + * @return a new vector + */ + public Vector3 withY(double y) { + return new Vector3(x, y, z); + } + + /** + * Get the Z coordinate. + * + * @return the z coordinate + */ + public double getZ() { + return z; + } + + /** + * Set the Z coordinate. + * + * @param z the new Z + * @return a new vector + */ + public Vector3 withZ(double z) { + return new Vector3(x, y, z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public Vector3 add(Vector3 other) { + return add(other.x, other.y, other.z); + } + + /** + * Add another vector to this vector and return the result as a new vector. + * + * @param x the value to add + * @param y the value to add + * @param z the value to add + * @return a new vector + */ + public Vector3 add(double x, double y, double z) { + return new Vector3(this.x + x, this.y + y, this.z + z); + } + + /** + * Add a list of vectors to this vector and return the + * result as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector3 add(Vector3... others) { + double newX = x, newY = y, newZ = z; + + for (Vector3 other : others) { + newX += other.x; + newY += other.y; + newZ += other.z; + } + + return new Vector3(newX, newY, newZ); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param other the other vector + * @return a new vector + */ + public Vector3 subtract(Vector3 other) { + return subtract(other.x, other.y, other.z); + } + + /** + * Subtract another vector from this vector and return the result + * as a new vector. + * + * @param x the value to subtract + * @param y the value to subtract + * @param z the value to subtract + * @return a new vector + */ + public Vector3 subtract(double x, double y, double z) { + return new Vector3(this.x - x, this.y - y, this.z - z); + } + + /** + * Subtract a list of vectors from this vector and return the result + * as a new vector. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector3 subtract(Vector3... others) { + double newX = x, newY = y, newZ = z; + + for (Vector3 other : others) { + newX -= other.x; + newY -= other.y; + newZ -= other.z; + } + + return new Vector3(newX, newY, newZ); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public Vector3 multiply(Vector3 other) { + return multiply(other.x, other.y, other.z); + } + + /** + * Multiply this vector by another vector on each component. + * + * @param x the value to multiply + * @param y the value to multiply + * @param z the value to multiply + * @return a new vector + */ + public Vector3 multiply(double x, double y, double z) { + return new Vector3(this.x * x, this.y * y, this.z * z); + } + + /** + * Multiply this vector by zero or more vectors on each component. + * + * @param others an array of vectors + * @return a new vector + */ + public Vector3 multiply(Vector3... others) { + double newX = x, newY = y, newZ = z; + + for (Vector3 other : others) { + newX *= other.x; + newY *= other.y; + newZ *= other.z; + } + + return new Vector3(newX, newY, newZ); + } + + /** + * Perform scalar multiplication and return a new vector. + * + * @param n the value to multiply + * @return a new vector + */ + public Vector3 multiply(double n) { + return multiply(n, n, n); + } + + /** + * Divide this vector by another vector on each component. + * + * @param other the other vector + * @return a new vector + */ + public Vector3 divide(Vector3 other) { + return divide(other.x, other.y, other.z); + } + + /** + * Divide this vector by another vector on each component. + * + * @param x the value to divide by + * @param y the value to divide by + * @param z the value to divide by + * @return a new vector + */ + public Vector3 divide(double x, double y, double z) { + return new Vector3(this.x / x, this.y / y, this.z / z); + } + + /** + * Perform scalar division and return a new vector. + * + * @param n the value to divide by + * @return a new vector + */ + public Vector3 divide(double n) { + return divide(n, n, n); + } + + /** + * Get the length of the vector. + * + * @return length + */ + public double length() { + return Math.sqrt(lengthSq()); + } + + /** + * Get the length, squared, of the vector. + * + * @return length, squared + */ + public double lengthSq() { + return x * x + y * y + z * z; + } + + /** + * Get the distance between this vector and another vector. + * + * @param other the other vector + * @return distance + */ + public double distance(Vector3 other) { + return Math.sqrt(distanceSq(other)); + } + + /** + * Get the distance between this vector and another vector, squared. + * + * @param other the other vector + * @return distance + */ + public double distanceSq(Vector3 other) { + double dx = other.x - x; + double dy = other.y - y; + double dz = other.z - z; + return dx * dx + dy * dy + dz * dz; + } + + /** + * Get the normalized vector, which is the vector divided by its + * length, as a new vector. + * + * @return a new vector + */ + public Vector3 normalize() { + return divide(length()); + } + + /** + * Gets the dot product of this and another vector. + * + * @param other the other vector + * @return the dot product of this and the other vector + */ + public double dot(Vector3 other) { + return x * other.x + y * other.y + z * other.z; + } + + /** + * Gets the cross product of this and another vector. + * + * @param other the other vector + * @return the cross product of this and the other vector + */ + public Vector3 cross(Vector3 other) { + return new Vector3( + y * other.z - z * other.y, + z * other.x - x * other.z, + x * other.y - y * other.x + ); + } + + /** + * Checks to see if a vector is contained with another. + * + * @param min the minimum point (X, Y, and Z are the lowest) + * @param max the maximum point (X, Y, and Z are the lowest) + * @return true if the vector is contained + */ + public boolean containedWithin(Vector3 min, Vector3 max) { + return x >= min.x && x <= max.x && y >= min.y && y <= max.y && z >= min.z && z <= max.z; + } + + /** + * Clamp the Y component. + * + * @param min the minimum value + * @param max the maximum value + * @return a new vector + */ + public Vector3 clampY(int min, int max) { + checkArgument(min <= max, "minimum cannot be greater than maximum"); + if (y < min) { + return new Vector3(x, min, z); + } + if (y > max) { + return new Vector3(x, max, z); + } + return this; + } + + /** + * Floors the values of all components. + * + * @return a new vector + */ + public Vector3 floor() { + return new Vector3(Math.floor(x), Math.floor(y), Math.floor(z)); + } + + /** + * Rounds all components up. + * + * @return a new vector + */ + public Vector3 ceil() { + return new Vector3(Math.ceil(x), Math.ceil(y), Math.ceil(z)); + } + + /** + * Rounds all components to the closest integer. + * + *

Components < 0.5 are rounded down, otherwise up.

+ * + * @return a new vector + */ + public Vector3 round() { + return new Vector3(Math.floor(x + 0.5), Math.floor(y + 0.5), Math.floor(z + 0.5)); + } + + /** + * Returns a vector with the absolute values of the components of + * this vector. + * + * @return a new vector + */ + public Vector3 abs() { + return new Vector3(Math.abs(x), Math.abs(y), Math.abs(z)); + } + + /** + * Perform a 2D transformation on this vector and return a new one. + * + * @param angle in degrees + * @param aboutX about which x coordinate to rotate + * @param aboutZ about which z coordinate to rotate + * @param translateX what to add after rotation + * @param translateZ what to add after rotation + * @return a new vector + * @see AffineTransform another method to transform vectors + */ + public Vector3 transform2D(double angle, double aboutX, double aboutZ, double translateX, double translateZ) { + angle = Math.toRadians(angle); + double x = this.x - aboutX; + double z = this.z - aboutZ; + double cos = Math.cos(angle); + double sin = Math.sin(angle); + double x2 = x * cos - z * sin; + double z2 = x * sin + z * cos; + + return new Vector3( + x2 + aboutX + translateX, + y, + z2 + aboutZ + translateZ + ); + } + + /** + * Get this vector's pitch as used within the game. + * + * @return pitch in radians + */ + public double toPitch() { + double x = getX(); + double z = getZ(); + + if (x == 0 && z == 0) { + return getY() > 0 ? -90 : 90; + } else { + double x2 = x * x; + double z2 = z * z; + double xz = Math.sqrt(x2 + z2); + return Math.toDegrees(Math.atan(-getY() / xz)); + } + } + + /** + * Get this vector's yaw as used within the game. + * + * @return yaw in radians + */ + public double toYaw() { + double x = getX(); + double z = getZ(); + + double t = Math.atan2(-x, z); + double tau = 2 * Math.PI; + + return Math.toDegrees(((t + tau) % tau)); + } + + /** + * Gets the minimum components of two vectors. + * + * @param v2 the second vector + * @return minimum + */ + public Vector3 getMinimum(Vector3 v2) { + return new Vector3( + Math.min(x, v2.x), + Math.min(y, v2.y), + Math.min(z, v2.z) + ); + } + + /** + * Gets the maximum components of two vectors. + * + * @param v2 the second vector + * @return maximum + */ + public Vector3 getMaximum(Vector3 v2) { + return new Vector3( + Math.max(x, v2.x), + Math.max(y, v2.y), + Math.max(z, v2.z) + ); + } + + /** + * Create a new {@code BlockVector} using the given components. + * + * @param x the X coordinate + * @param y the Y coordinate + * @param z the Z coordinate + * @return a new {@code BlockVector} + */ + public static BlockVector3 toBlockPoint(double x, double y, double z) { + return new BlockVector3(x, y, z); + } + + /** + * Create a new {@code BlockVector} from this vector. + * + * @return a new {@code BlockVector} + */ + public BlockVector3 toBlockPoint() { + return toBlockPoint(x, y, z); + } + + /** + * Creates a 2D vector by dropping the Y component from this vector. + * + * @return a new {@link Vector2} + */ + public Vector2 toVector2() { + return new Vector2(x, z); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof Vector3)) { + return false; + } + + Vector3 other = (Vector3) obj; + return other.x == this.x && other.y == this.y && other.z == this.z; + } + + @Override + public int hashCode() { + int hash = 17; + hash = 31 * hash + Double.hashCode(x); + hash = 31 * hash + Double.hashCode(y); + hash = 31 * hash + Double.hashCode(z); + return hash; + } + + @Override + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } + +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java index 0cfd4c35f..c12beee56 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/convolution/HeightMap.java @@ -23,7 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -105,7 +105,7 @@ public class HeightMap { public int apply(int[] data) throws MaxChangedBlocksException { checkNotNull(data); - Vector minY = region.getMinimumPoint(); + BlockVector3 minY = region.getMinimumPoint(); int originX = minY.getBlockX(); int originY = minY.getBlockY(); int originZ = minY.getBlockZ(); @@ -134,17 +134,17 @@ public class HeightMap { // Depending on growing or shrinking we need to start at the bottom or top if (newHeight > curHeight) { // Set the top block of the column to be the same type (this might go wrong with rounding) - BlockState existing = session.getBlock(new Vector(xr, curHeight, zr)); + BlockState existing = session.getBlock(new BlockVector3(xr, curHeight, zr)); // Skip water/lava if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) { - session.setBlock(new Vector(xr, newHeight, zr), existing); + session.setBlock(new BlockVector3(xr, newHeight, zr), existing); ++blocksChanged; // Grow -- start from 1 below top replacing airblocks for (int y = newHeight - 1 - originY; y >= 0; --y) { int copyFrom = (int) (y * scale); - session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr))); + session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr))); ++blocksChanged; } } @@ -152,18 +152,18 @@ public class HeightMap { // Shrink -- start from bottom for (int y = 0; y < newHeight - originY; ++y) { int copyFrom = (int) (y * scale); - session.setBlock(new Vector(xr, originY + y, zr), session.getBlock(new Vector(xr, originY + copyFrom, zr))); + session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr))); ++blocksChanged; } // Set the top block of the column to be the same type // (this could otherwise go wrong with rounding) - session.setBlock(new Vector(xr, newHeight, zr), session.getBlock(new Vector(xr, curHeight, zr))); + session.setBlock(new BlockVector3(xr, newHeight, zr), session.getBlock(new BlockVector3(xr, curHeight, zr))); ++blocksChanged; // Fill rest with air for (int y = newHeight + 1; y <= curHeight; ++y) { - session.setBlock(new Vector(xr, y, zr), fillerAir); + session.setBlock(new BlockVector3(xr, y, zr), fillerAir); ++blocksChanged; } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java index 007977d58..af191dc72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/geom/Polygons.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.math.geom; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.Vector2; import java.util.ArrayList; import java.util.List; @@ -40,9 +40,9 @@ public final class Polygons { * @param center the center point of the cylinder * @param radius the radius of the cylinder * @param maxPoints max points to be used for the calculation - * @return a list of {@link BlockVector2D} which resemble the shape as a polygon + * @return a list of {@link BlockVector2} which resemble the shape as a polygon */ - public static List polygonizeCylinder(Vector2D center, Vector2D radius, int maxPoints) { + public static List polygonizeCylinder(BlockVector2 center, Vector2 radius, int maxPoints) { int nPoints = (int) Math.ceil(Math.PI*radius.length()); // These strange semantics for maxPoints are copied from the selectSecondary method. @@ -50,11 +50,11 @@ public final class Polygons { nPoints = maxPoints - 1; } - final List points = new ArrayList<>(nPoints); + final List points = new ArrayList<>(nPoints); for (int i = 0; i < nPoints; ++i) { double angle = i * (2.0 * Math.PI) / nPoints; - final Vector2D pos = new Vector2D(Math.cos(angle), Math.sin(angle)); - final BlockVector2D blockVector2D = pos.multiply(radius).add(center).toBlockVector2D(); + final Vector2 pos = new Vector2(Math.cos(angle), Math.sin(angle)); + final BlockVector2 blockVector2D = pos.multiply(radius).toBlockPoint().add(center); points.add(blockVector2D); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java index 68df24b0d..28ce2c492 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Interpolation.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.math.interpolation; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.util.List; @@ -44,7 +44,7 @@ public interface Interpolation { * @param position the position to interpolate * @return the result */ - Vector getPosition(double position); + Vector3 getPosition(double position); /** * Gets the result of f'(position). @@ -52,7 +52,7 @@ public interface Interpolation { * @param position the position to interpolate * @return the result */ - Vector get1stDerivative(double position); + Vector3 get1stDerivative(double position); /** * Gets the result of ∫ab|f'(t)| dt.
diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java index f5f41313b..3d87135f9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/KochanekBartelsInterpolation.java @@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.util.Collections; import java.util.List; @@ -37,10 +37,10 @@ import java.util.List; public class KochanekBartelsInterpolation implements Interpolation { private List nodes; - private Vector[] coeffA; - private Vector[] coeffB; - private Vector[] coeffC; - private Vector[] coeffD; + private Vector3[] coeffA; + private Vector3[] coeffB; + private Vector3[] coeffC; + private Vector3[] coeffD; private double scaling; public KochanekBartelsInterpolation() { @@ -57,10 +57,10 @@ public class KochanekBartelsInterpolation implements Interpolation { private void recalc() { final int nNodes = nodes.size(); - coeffA = new Vector[nNodes]; - coeffB = new Vector[nNodes]; - coeffC = new Vector[nNodes]; - coeffD = new Vector[nNodes]; + coeffA = new Vector3[nNodes]; + coeffB = new Vector3[nNodes]; + coeffC = new Vector3[nNodes]; + coeffD = new Vector3[nNodes]; if (nNodes == 0) return; @@ -107,11 +107,11 @@ public class KochanekBartelsInterpolation implements Interpolation { * @param f4 coefficient for baseIndex+2 * @return linear combination of nodes[n-1..n+2] with f1..4 */ - private Vector linearCombination(int baseIndex, double f1, double f2, double f3, double f4) { - final Vector r1 = retrieve(baseIndex - 1).multiply(f1); - final Vector r2 = retrieve(baseIndex ).multiply(f2); - final Vector r3 = retrieve(baseIndex + 1).multiply(f3); - final Vector r4 = retrieve(baseIndex + 2).multiply(f4); + private Vector3 linearCombination(int baseIndex, double f1, double f2, double f3, double f4) { + final Vector3 r1 = retrieve(baseIndex - 1).multiply(f1); + final Vector3 r2 = retrieve(baseIndex ).multiply(f2); + final Vector3 r3 = retrieve(baseIndex + 1).multiply(f3); + final Vector3 r4 = retrieve(baseIndex + 2).multiply(f4); return r1.add(r2).add(r3).add(r4); } @@ -122,7 +122,7 @@ public class KochanekBartelsInterpolation implements Interpolation { * @param index node index to retrieve * @return nodes[clamp(0, nodes.length-1)] */ - private Vector retrieve(int index) { + private Vector3 retrieve(int index) { if (index < 0) return fastRetrieve(0); @@ -132,12 +132,12 @@ public class KochanekBartelsInterpolation implements Interpolation { return fastRetrieve(index); } - private Vector fastRetrieve(int index) { + private Vector3 fastRetrieve(int index) { return nodes.get(index).getPosition(); } @Override - public Vector getPosition(double position) { + public Vector3 getPosition(double position) { if (coeffA == null) throw new IllegalStateException("Must call setNodes first."); @@ -149,16 +149,16 @@ public class KochanekBartelsInterpolation implements Interpolation { final int index = (int) Math.floor(position); final double remainder = position - index; - final Vector a = coeffA[index]; - final Vector b = coeffB[index]; - final Vector c = coeffC[index]; - final Vector d = coeffD[index]; + final Vector3 a = coeffA[index]; + final Vector3 b = coeffB[index]; + final Vector3 c = coeffC[index]; + final Vector3 d = coeffD[index]; return a.multiply(remainder).add(b).multiply(remainder).add(c).multiply(remainder).add(d); } @Override - public Vector get1stDerivative(double position) { + public Vector3 get1stDerivative(double position) { if (coeffA == null) throw new IllegalStateException("Must call setNodes first."); @@ -170,9 +170,9 @@ public class KochanekBartelsInterpolation implements Interpolation { final int index = (int) Math.floor(position); //final double remainder = position - index; - final Vector a = coeffA[index]; - final Vector b = coeffB[index]; - final Vector c = coeffC[index]; + final Vector3 a = coeffA[index]; + final Vector3 b = coeffB[index]; + final Vector3 c = coeffC[index]; return a.multiply(1.5*position - 3.0*index).add(b).multiply(2.0*position).add(a.multiply(1.5*index).subtract(b).multiply(2.0*index)).add(c).multiply(scaling); } @@ -219,9 +219,9 @@ public class KochanekBartelsInterpolation implements Interpolation { } private double arcLengthRecursive(int index, double remainderLeft, double remainderRight) { - final Vector a = coeffA[index].multiply(3.0); - final Vector b = coeffB[index].multiply(2.0); - final Vector c = coeffC[index]; + final Vector3 a = coeffA[index].multiply(3.0); + final Vector3 b = coeffB[index].multiply(2.0); + final Vector3 c = coeffC[index]; final int nPoints = 8; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java index ea1962119..7b701f5fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/LinearInterpolation.java @@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.util.List; @@ -42,7 +42,7 @@ public class LinearInterpolation implements Interpolation { } @Override - public Vector getPosition(double position) { + public Vector3 getPosition(double position) { if (nodes == null) throw new IllegalStateException("Must call setNodes first."); @@ -54,8 +54,8 @@ public class LinearInterpolation implements Interpolation { final int index1 = (int) Math.floor(position); final double remainder = position - index1; - final Vector position1 = nodes.get(index1).getPosition(); - final Vector position2 = nodes.get(index1 + 1).getPosition(); + final Vector3 position1 = nodes.get(index1).getPosition(); + final Vector3 position2 = nodes.get(index1 + 1).getPosition(); return position1.multiply(1.0 - remainder).add(position2.multiply(remainder)); } @@ -76,7 +76,7 @@ public class LinearInterpolation implements Interpolation { */ @Override - public Vector get1stDerivative(double position) { + public Vector3 get1stDerivative(double position) { if (nodes == null) throw new IllegalStateException("Must call setNodes first."); @@ -87,8 +87,8 @@ public class LinearInterpolation implements Interpolation { final int index1 = (int) Math.floor(position); - final Vector position1 = nodes.get(index1).getPosition(); - final Vector position2 = nodes.get(index1 + 1).getPosition(); + final Vector3 position1 = nodes.get(index1).getPosition(); + final Vector3 position2 = nodes.get(index1 + 1).getPosition(); return position2.subtract(position1); } @@ -135,8 +135,8 @@ public class LinearInterpolation implements Interpolation { } private double arcLengthRecursive(int index, double remainderA, double remainderB) { - final Vector position1 = nodes.get(index).getPosition(); - final Vector position2 = nodes.get(index + 1).getPosition(); + final Vector3 position1 = nodes.get(index).getPosition(); + final Vector3 position2 = nodes.get(index + 1).getPosition(); return position1.distance(position2) * (remainderB - remainderA); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java index ce604824c..c2bc1e93b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/Node.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.math.interpolation; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; /** * Represents a node for interpolation. @@ -31,14 +31,14 @@ import com.sk89q.worldedit.Vector; */ public class Node { - private Vector position; + private Vector3 position; private double tension; private double bias; private double continuity; public Node() { - this(new Vector(0, 0, 0)); + this(new Vector3(0, 0, 0)); } public Node(Node other) { @@ -49,16 +49,16 @@ public class Node { this.continuity = other.continuity; } - public Node(Vector position) { + public Node(Vector3 position) { this.position = position; } - public Vector getPosition() { + public Vector3 getPosition() { return position; } - public void setPosition(Vector position) { + public void setPosition(Vector3 position) { this.position = position; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java index d6920b829..29a3ee5ee 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/interpolation/ReparametrisingInterpolation.java @@ -23,7 +23,7 @@ package com.sk89q.worldedit.math.interpolation; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.util.List; import java.util.Map.Entry; @@ -65,7 +65,7 @@ public class ReparametrisingInterpolation implements Interpolation { } @Override - public Vector getPosition(double position) { + public Vector3 getPosition(double position) { if (position > 1) return null; @@ -73,7 +73,7 @@ public class ReparametrisingInterpolation implements Interpolation { } @Override - public Vector get1stDerivative(double position) { + public Vector3 get1stDerivative(double position) { if (position > 1) return null; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java index dbf7720fd..1da9d5b2d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/JLibNoiseGenerator.java @@ -19,8 +19,9 @@ package com.sk89q.worldedit.math.noise; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; + import net.royawesome.jlibnoise.module.Module; import java.util.Random; @@ -46,12 +47,12 @@ abstract class JLibNoiseGenerator implements NoiseGenerator { public abstract int getSeed(); @Override - public float noise(Vector2D position) { + public float noise(Vector2 position) { return forceRange(module.GetValue(position.getX(), 0, position.getZ())); } @Override - public float noise(Vector position) { + public float noise(Vector3 position) { return forceRange(module.GetValue(position.getX(), position.getY(), position.getZ())); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java index bb57d23f0..185e41fbb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/NoiseGenerator.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.math.noise; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; /** * Generates noise in a deterministic or non-deterministic manner. @@ -34,7 +34,7 @@ public interface NoiseGenerator { * @param position the position * @return a noise value between 0 (inclusive) and 1 (inclusive) */ - float noise(Vector2D position); + float noise(Vector2 position); /** * Get the noise value for the given position. The returned value may @@ -43,6 +43,6 @@ public interface NoiseGenerator { * @param position the position * @return a noise value between 0 (inclusive) and 1 (inclusive) */ - float noise(Vector position); + float noise(Vector3 position); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java index 6daed2841..ff3421404 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/noise/RandomNoise.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.math.noise; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import java.util.Random; @@ -50,12 +50,12 @@ public class RandomNoise implements NoiseGenerator { } @Override - public float noise(Vector2D position) { + public float noise(Vector2 position) { return random.nextFloat(); } @Override - public float noise(Vector position) { + public float noise(Vector3 position) { return random.nextFloat(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java index 36db0566c..376fd0b33 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/AffineTransform.java @@ -19,8 +19,9 @@ package com.sk89q.worldedit.math.transform; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.MathUtils; +import com.sk89q.worldedit.math.Vector3; /** * An affine transform. @@ -236,7 +237,11 @@ public class AffineTransform implements Transform { n20, n21, n22, n23); } - public AffineTransform translate(Vector vec) { + public AffineTransform translate(Vector3 vec) { + return translate(vec.getX(), vec.getY(), vec.getZ()); + } + + public AffineTransform translate(BlockVector3 vec) { return translate(vec.getX(), vec.getY(), vec.getZ()); } @@ -282,13 +287,13 @@ public class AffineTransform implements Transform { return concatenate(new AffineTransform(sx, 0, 0, 0, 0, sy, 0, 0, 0, 0, sz, 0)); } - public AffineTransform scale(Vector vec) { + public AffineTransform scale(Vector3 vec) { return scale(vec.getX(), vec.getY(), vec.getZ()); } @Override - public Vector apply(Vector vector) { - return new Vector( + public Vector3 apply(Vector3 vector) { + return new Vector3( vector.getX() * m00 + vector.getY() * m01 + vector.getZ() * m02 + m03, vector.getX() * m10 + vector.getY() * m11 + vector.getZ() * m12 + m13, vector.getX() * m20 + vector.getY() * m21 + vector.getZ() * m22 + m23); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java index 646e2a209..e5f2a2586 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/CombinedTransform.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.math.transform; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.util.ArrayList; import java.util.Arrays; @@ -66,7 +66,7 @@ public class CombinedTransform implements Transform { } @Override - public Vector apply(Vector vector) { + public Vector3 apply(Vector3 vector) { for (Transform transform : transforms) { vector = transform.apply(vector); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java index b0f4dddef..f9f1ed125 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Identity.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.math.transform; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; /** * Makes no transformation to given vectors. @@ -32,7 +32,7 @@ public class Identity implements Transform { } @Override - public Vector apply(Vector vector) { + public Vector3 apply(Vector3 vector) { return vector; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java index b8df8bcbd..e12030022 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/transform/Transform.java @@ -19,10 +19,10 @@ package com.sk89q.worldedit.math.transform; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; /** - * Makes a transformation of {@link Vector}s. + * Makes a transformation of {@link Vector3}s. */ public interface Transform { @@ -41,7 +41,7 @@ public interface Transform { * @param input the input * @return the result */ - Vector apply(Vector input); + Vector3 apply(Vector3 input); /** * Create a new inverse transform. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java index 44f7070cb..cdaf362db 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/AbstractRegion.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.iterator.RegionIterator; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -42,8 +41,8 @@ public abstract class AbstractRegion implements Region { } @Override - public Vector getCenter() { - return getMinimumPoint().add(getMaximumPoint()).divide(2); + public Vector3 getCenter() { + return getMinimumPoint().add(getMaximumPoint()).toVector3().divide(2); } /** @@ -52,7 +51,7 @@ public abstract class AbstractRegion implements Region { * @return iterator of points inside the region */ @Override - public Iterator iterator() { + public Iterator iterator() { return new RegionIterator(this); } @@ -67,7 +66,7 @@ public abstract class AbstractRegion implements Region { } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { expand(change); contract(change); } @@ -82,20 +81,20 @@ public abstract class AbstractRegion implements Region { } @Override - public List polygonize(int maxPoints) { + public List polygonize(int maxPoints) { if (maxPoints >= 0 && maxPoints < 4) { throw new IllegalArgumentException("Cannot polygonize an AbstractRegion with no overridden polygonize method into less than 4 points."); } - final BlockVector min = getMinimumPoint().toBlockVector(); - final BlockVector max = getMaximumPoint().toBlockVector(); + final BlockVector3 min = getMinimumPoint(); + final BlockVector3 max = getMaximumPoint(); - final List points = new ArrayList<>(4); + final List points = new ArrayList<>(4); - points.add(new BlockVector2D(min.getX(), min.getZ())); - points.add(new BlockVector2D(min.getX(), max.getZ())); - points.add(new BlockVector2D(max.getX(), max.getZ())); - points.add(new BlockVector2D(max.getX(), min.getZ())); + points.add(new BlockVector2(min.getX(), min.getZ())); + points.add(new BlockVector2(min.getX(), max.getZ())); + points.add(new BlockVector2(max.getX(), max.getZ())); + points.add(new BlockVector2(max.getX(), min.getZ())); return points; } @@ -107,12 +106,12 @@ public abstract class AbstractRegion implements Region { */ @Override public int getArea() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - return (int)((max.getX() - min.getX() + 1) * - (max.getY() - min.getY() + 1) * - (max.getZ() - min.getZ() + 1)); + return (max.getX() - min.getX() + 1) * + (max.getY() - min.getY() + 1) * + (max.getZ() - min.getZ() + 1); } /** @@ -122,10 +121,10 @@ public abstract class AbstractRegion implements Region { */ @Override public int getWidth() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - return (int) (max.getX() - min.getX() + 1); + return max.getX() - min.getX() + 1; } /** @@ -135,10 +134,10 @@ public abstract class AbstractRegion implements Region { */ @Override public int getHeight() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - return (int) (max.getY() - min.getY() + 1); + return max.getY() - min.getY() + 1; } /** @@ -148,10 +147,10 @@ public abstract class AbstractRegion implements Region { */ @Override public int getLength() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - return (int) (max.getZ() - min.getZ() + 1); + return max.getZ() - min.getZ() + 1; } /** @@ -160,21 +159,21 @@ public abstract class AbstractRegion implements Region { * @return a set of chunks */ @Override - public Set getChunks() { - final Set chunks = new HashSet<>(); + public Set getChunks() { + final Set chunks = new HashSet<>(); - final Vector min = getMinimumPoint(); - final Vector max = getMaximumPoint(); + final BlockVector3 min = getMinimumPoint(); + final BlockVector3 max = getMaximumPoint(); final int minY = min.getBlockY(); for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - if (!contains(new Vector(x, minY, z))) { + if (!contains(new BlockVector3(x, minY, z))) { continue; } - chunks.add(new BlockVector2D( + chunks.add(new BlockVector2( x >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS )); @@ -185,20 +184,20 @@ public abstract class AbstractRegion implements Region { } @Override - public Set getChunkCubes() { - final Set chunks = new HashSet<>(); + public Set getChunkCubes() { + final Set chunks = new HashSet<>(); - final Vector min = getMinimumPoint(); - final Vector max = getMaximumPoint(); + final BlockVector3 min = getMinimumPoint(); + final BlockVector3 max = getMaximumPoint(); for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - if (!contains(new Vector(x, y, z))) { + if (!contains(new BlockVector3(x, y, z))) { continue; } - chunks.add(new BlockVector( + chunks.add(new BlockVector3( x >> ChunkStore.CHUNK_SHIFTS, y >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java index fce016e23..ce1fc5b22 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/ConvexPolyhedralRegion.java @@ -21,7 +21,8 @@ package com.sk89q.worldedit.regions; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.polyhedron.Edge; import com.sk89q.worldedit.regions.polyhedron.Triangle; import com.sk89q.worldedit.world.World; @@ -40,7 +41,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { /** * Vertices that are contained in the convex hull. */ - private final Set vertices = new LinkedHashSet<>(); + private final Set vertices = new LinkedHashSet<>(); /** * Triangles that form the convex hull. @@ -50,25 +51,25 @@ public class ConvexPolyhedralRegion extends AbstractRegion { /** * Vertices that are coplanar to the first 3 vertices. */ - private final Set vertexBacklog = new LinkedHashSet<>(); + private final Set vertexBacklog = new LinkedHashSet<>(); /** * Minimum point of the axis-aligned bounding box. */ - private Vector minimumPoint; + private BlockVector3 minimumPoint; /** * Maximum point of the axis-aligned bounding box. */ - private Vector maximumPoint; + private BlockVector3 maximumPoint; /** * Accumulator for the barycenter of the polyhedron. Divide by vertices.size() to get the actual center. */ - private Vector centerAccum = Vector.ZERO; + private BlockVector3 centerAccum = BlockVector3.ZERO; /** - * The last triangle that caused a {@link #contains(Vector)} to classify a point as "outside". Used for optimization. + * The last triangle that caused a {@link #contains(Vector3)} to classify a point as "outside". Used for optimization. */ private Triangle lastTriangle; @@ -108,7 +109,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { minimumPoint = null; maximumPoint = null; - centerAccum = Vector.ZERO; + centerAccum = BlockVector3.ZERO; lastTriangle = null; } @@ -118,7 +119,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { * @param vertex the vertex * @return true, if something changed. */ - public boolean addVertex(Vector vertex) { + public boolean addVertex(BlockVector3 vertex) { checkNotNull(vertex); lastTriangle = null; // Probably not necessary @@ -132,7 +133,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { return false; } - if (containsRaw(vertex)) { + if (containsRaw(vertex.toVector3())) { return vertexBacklog.add(vertex); } } @@ -144,8 +145,8 @@ public class ConvexPolyhedralRegion extends AbstractRegion { if (minimumPoint == null) { minimumPoint = maximumPoint = vertex; } else { - minimumPoint = Vector.getMinimum(minimumPoint, vertex); - maximumPoint = Vector.getMaximum(maximumPoint, vertex); + minimumPoint = minimumPoint.getMinimum(vertex); + maximumPoint = maximumPoint.getMaximum(vertex); } @@ -158,10 +159,10 @@ public class ConvexPolyhedralRegion extends AbstractRegion { case 3: // Generate minimal mesh to start from - final Vector[] v = vertices.toArray(new Vector[vertices.size()]); + final BlockVector3[] v = vertices.toArray(new BlockVector3[vertices.size()]); - triangles.add((new Triangle(v[0], v[1], v[2]))); - triangles.add((new Triangle(v[0], v[2], v[1]))); + triangles.add((new Triangle(v[0].toVector3(), v[1].toVector3(), v[2].toVector3()))); + triangles.add((new Triangle(v[0].toVector3(), v[2].toVector3(), v[1].toVector3()))); return true; } @@ -171,7 +172,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { final Triangle triangle = it.next(); // If the triangle can't be seen, it's not relevant - if (!triangle.above(vertex)) { + if (!triangle.above(vertex.toVector3())) { continue; } @@ -191,7 +192,7 @@ public class ConvexPolyhedralRegion extends AbstractRegion { // Add triangles between the remembered edges and the new vertex. for (Edge edge : borderEdges) { - triangles.add(edge.createTriangle(vertex)); + triangles.add(edge.createTriangle(vertex.toVector3())); } if (!vertexBacklog.isEmpty()) { @@ -199,9 +200,9 @@ public class ConvexPolyhedralRegion extends AbstractRegion { vertices.remove(vertex); // Clone, clear and work through the backlog - final List vertexBacklog2 = new ArrayList<>(vertexBacklog); + final List vertexBacklog2 = new ArrayList<>(vertexBacklog); vertexBacklog.clear(); - for (Vector vertex2 : vertexBacklog2) { + for (BlockVector3 vertex2 : vertexBacklog2) { addVertex(vertex2); } @@ -217,39 +218,40 @@ public class ConvexPolyhedralRegion extends AbstractRegion { } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return minimumPoint; } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return maximumPoint; } @Override - public Vector getCenter() { - return centerAccum.divide(vertices.size()); + public Vector3 getCenter() { + return centerAccum.toVector3().divide(vertices.size()); } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { + Vector3 vec = change.toVector3(); shiftCollection(vertices, change); shiftCollection(vertexBacklog, change); for (int i = 0; i < triangles.size(); ++i) { final Triangle triangle = triangles.get(i); - final Vector v0 = change.add(triangle.getVertex(0)); - final Vector v1 = change.add(triangle.getVertex(1)); - final Vector v2 = change.add(triangle.getVertex(2)); + final Vector3 v0 = vec.add(triangle.getVertex(0)); + final Vector3 v1 = vec.add(triangle.getVertex(1)); + final Vector3 v2 = vec.add(triangle.getVertex(2)); triangles.set(i, new Triangle(v0, v1, v2)); } @@ -260,16 +262,16 @@ public class ConvexPolyhedralRegion extends AbstractRegion { lastTriangle = null; } - private static void shiftCollection(Collection collection, Vector change) { - final List tmp = new ArrayList<>(collection); + private static void shiftCollection(Collection collection, BlockVector3 change) { + final List tmp = new ArrayList<>(collection); collection.clear(); - for (Vector vertex : tmp) { + for (BlockVector3 vertex : tmp) { collection.add(change.add(vertex)); } } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { if (!isDefined()) { return false; } @@ -278,8 +280,8 @@ public class ConvexPolyhedralRegion extends AbstractRegion { final int y = position.getBlockY(); final int z = position.getBlockZ(); - final Vector min = getMinimumPoint(); - final Vector max = getMaximumPoint(); + final BlockVector3 min = getMinimumPoint(); + final BlockVector3 max = getMaximumPoint(); if (x < min.getBlockX()) return false; if (x > max.getBlockX()) return false; @@ -288,10 +290,10 @@ public class ConvexPolyhedralRegion extends AbstractRegion { if (z < min.getBlockZ()) return false; if (z > max.getBlockZ()) return false; - return containsRaw(position); + return containsRaw(position.toVector3()); } - private boolean containsRaw(Vector pt) { + private boolean containsRaw(Vector3 pt) { if (lastTriangle != null && lastTriangle.above(pt)) { return false; } @@ -310,12 +312,12 @@ public class ConvexPolyhedralRegion extends AbstractRegion { return true; } - public Collection getVertices() { + public Collection getVertices() { if (vertexBacklog.isEmpty()) { return vertices; } - final List ret = new ArrayList<>(vertices); + final List ret = new ArrayList<>(vertices); ret.addAll(vertexBacklog); return ret; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java index 942e92d6e..cebd62098 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CuboidRegion.java @@ -22,15 +22,14 @@ package com.sk89q.worldedit.regions; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; import java.util.HashSet; import java.util.Iterator; +import java.util.NoSuchElementException; import java.util.Set; /** @@ -38,8 +37,8 @@ import java.util.Set; */ public class CuboidRegion extends AbstractRegion implements FlatRegion { - private Vector pos1; - private Vector pos2; + private BlockVector3 pos1; + private BlockVector3 pos2; /** * Construct a new instance of this cuboid using two corners of the cuboid. @@ -47,7 +46,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * @param pos1 the first position * @param pos2 the second position */ - public CuboidRegion(Vector pos1, Vector pos2) { + public CuboidRegion(BlockVector3 pos1, BlockVector3 pos2) { this(null, pos1, pos2); } @@ -58,7 +57,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * @param pos1 the first position * @param pos2 the second position */ - public CuboidRegion(World world, Vector pos1, Vector pos2) { + public CuboidRegion(World world, BlockVector3 pos1, BlockVector3 pos2) { super(world); checkNotNull(pos1); checkNotNull(pos2); @@ -72,7 +71,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @return a position */ - public Vector getPos1() { + public BlockVector3 getPos1() { return pos1; } @@ -81,7 +80,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @param pos1 a position */ - public void setPos1(Vector pos1) { + public void setPos1(BlockVector3 pos1) { this.pos1 = pos1; } @@ -90,7 +89,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @return a position */ - public Vector getPos2() { + public BlockVector3 getPos2() { return pos2; } @@ -99,7 +98,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @param pos2 a position */ - public void setPos2(Vector pos2) { + public void setPos2(BlockVector3 pos2) { this.pos2 = pos2; } @@ -117,21 +116,21 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * @return a new complex region */ public Region getFaces() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); return new RegionIntersection( // Project to Z-Y plane - new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())), - new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())), + new CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())), + new CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())), // Project to X-Y plane - new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())), - new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ())), + new CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())), + new CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ())), // Project to the X-Z plane - new CuboidRegion(pos1.setY(min.getY()), pos2.setY(min.getY())), - new CuboidRegion(pos1.setY(max.getY()), pos2.setY(max.getY()))); + new CuboidRegion(pos1.withY(min.getY()), pos2.withY(min.getY())), + new CuboidRegion(pos1.withY(max.getY()), pos2.withY(max.getY()))); } /** @@ -141,31 +140,27 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * @return a new complex region */ public Region getWalls() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); return new RegionIntersection( // Project to Z-Y plane - new CuboidRegion(pos1.setX(min.getX()), pos2.setX(min.getX())), - new CuboidRegion(pos1.setX(max.getX()), pos2.setX(max.getX())), + new CuboidRegion(pos1.withX(min.getX()), pos2.withX(min.getX())), + new CuboidRegion(pos1.withX(max.getX()), pos2.withX(max.getX())), // Project to X-Y plane - new CuboidRegion(pos1.setZ(min.getZ()), pos2.setZ(min.getZ())), - new CuboidRegion(pos1.setZ(max.getZ()), pos2.setZ(max.getZ()))); + new CuboidRegion(pos1.withZ(min.getZ()), pos2.withZ(min.getZ())), + new CuboidRegion(pos1.withZ(max.getZ()), pos2.withZ(max.getZ()))); } @Override - public Vector getMinimumPoint() { - return new Vector(Math.min(pos1.getX(), pos2.getX()), - Math.min(pos1.getY(), pos2.getY()), - Math.min(pos1.getZ(), pos2.getZ())); + public BlockVector3 getMinimumPoint() { + return pos1.getMinimum(pos2); } @Override - public Vector getMaximumPoint() { - return new Vector(Math.max(pos1.getX(), pos2.getX()), - Math.max(pos1.getY(), pos2.getY()), - Math.max(pos1.getZ(), pos2.getZ())); + public BlockVector3 getMaximumPoint() { + return pos1.getMaximum(pos2); } @Override @@ -179,49 +174,49 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public void expand(Vector... changes) { + public void expand(BlockVector3... changes) { checkNotNull(changes); - for (Vector change : changes) { + for (BlockVector3 change : changes) { if (change.getX() > 0) { if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) { - pos1 = pos1.add(new Vector(change.getX(), 0, 0)); + pos1 = pos1.add(change.getX(), 0, 0); } else { - pos2 = pos2.add(new Vector(change.getX(), 0, 0)); + pos2 = pos2.add(change.getX(), 0, 0); } } else { if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) { - pos1 = pos1.add(new Vector(change.getX(), 0, 0)); + pos1 = pos1.add(change.getX(), 0, 0); } else { - pos2 = pos2.add(new Vector(change.getX(), 0, 0)); + pos2 = pos2.add(change.getX(), 0, 0); } } if (change.getY() > 0) { if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) { - pos1 = pos1.add(new Vector(0, change.getY(), 0)); + pos1 = pos1.add(0, change.getY(), 0); } else { - pos2 = pos2.add(new Vector(0, change.getY(), 0)); + pos2 = pos2.add(0, change.getY(), 0); } } else { if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) { - pos1 = pos1.add(new Vector(0, change.getY(), 0)); + pos1 = pos1.add(0, change.getY(), 0); } else { - pos2 = pos2.add(new Vector(0, change.getY(), 0)); + pos2 = pos2.add(0, change.getY(), 0); } } if (change.getZ() > 0) { if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) { - pos1 = pos1.add(new Vector(0, 0, change.getZ())); + pos1 = pos1.add(0, 0, change.getZ()); } else { - pos2 = pos2.add(new Vector(0, 0, change.getZ())); + pos2 = pos2.add(0, 0, change.getZ()); } } else { if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) { - pos1 = pos1.add(new Vector(0, 0, change.getZ())); + pos1 = pos1.add(0, 0, change.getZ()); } else { - pos2 = pos2.add(new Vector(0, 0, change.getZ())); + pos2 = pos2.add(0, 0, change.getZ()); } } } @@ -230,49 +225,49 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public void contract(Vector... changes) { + public void contract(BlockVector3... changes) { checkNotNull(changes); - for (Vector change : changes) { + for (BlockVector3 change : changes) { if (change.getX() < 0) { if (Math.max(pos1.getX(), pos2.getX()) == pos1.getX()) { - pos1 = pos1.add(new Vector(change.getX(), 0, 0)); + pos1 = pos1.add(change.getX(), 0, 0); } else { - pos2 = pos2.add(new Vector(change.getX(), 0, 0)); + pos2 = pos2.add(change.getX(), 0, 0); } } else { if (Math.min(pos1.getX(), pos2.getX()) == pos1.getX()) { - pos1 = pos1.add(new Vector(change.getX(), 0, 0)); + pos1 = pos1.add(change.getX(), 0, 0); } else { - pos2 = pos2.add(new Vector(change.getX(), 0, 0)); + pos2 = pos2.add(change.getX(), 0, 0); } } if (change.getY() < 0) { if (Math.max(pos1.getY(), pos2.getY()) == pos1.getY()) { - pos1 = pos1.add(new Vector(0, change.getY(), 0)); + pos1 = pos1.add(0, change.getY(), 0); } else { - pos2 = pos2.add(new Vector(0, change.getY(), 0)); + pos2 = pos2.add(0, change.getY(), 0); } } else { if (Math.min(pos1.getY(), pos2.getY()) == pos1.getY()) { - pos1 = pos1.add(new Vector(0, change.getY(), 0)); + pos1 = pos1.add(0, change.getY(), 0); } else { - pos2 = pos2.add(new Vector(0, change.getY(), 0)); + pos2 = pos2.add(0, change.getY(), 0); } } if (change.getZ() < 0) { if (Math.max(pos1.getZ(), pos2.getZ()) == pos1.getZ()) { - pos1 = pos1.add(new Vector(0, 0, change.getZ())); + pos1 = pos1.add(0, 0, change.getZ()); } else { - pos2 = pos2.add(new Vector(0, 0, change.getZ())); + pos2 = pos2.add(0, 0, change.getZ()); } } else { if (Math.min(pos1.getZ(), pos2.getZ()) == pos1.getZ()) { - pos1 = pos1.add(new Vector(0, 0, change.getZ())); + pos1 = pos1.add(0, 0, change.getZ()); } else { - pos2 = pos2.add(new Vector(0, 0, change.getZ())); + pos2 = pos2.add(0, 0, change.getZ()); } } } @@ -281,7 +276,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { pos1 = pos1.add(change); pos2 = pos2.add(change); @@ -289,15 +284,15 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Set getChunks() { - Set chunks = new HashSet<>(); + public Set getChunks() { + Set chunks = new HashSet<>(); - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) { for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) { - chunks.add(new BlockVector2D(x, z)); + chunks.add(new BlockVector2(x, z)); } } @@ -305,16 +300,16 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Set getChunkCubes() { - Set chunks = new HashSet<>(); + public Set getChunkCubes() { + Set chunks = new HashSet<>(); - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); for (int x = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x <= max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; ++x) { for (int z = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z <= max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; ++z) { for (int y = min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y <= max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; ++y) { - chunks.add(new BlockVector(x, y, z)); + chunks.add(new BlockVector3(x, y, z)); } } } @@ -323,24 +318,18 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public boolean contains(Vector position) { - int x = position.getBlockX(); - int y = position.getBlockY(); - int z = position.getBlockZ(); + public boolean contains(BlockVector3 position) { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); - - return x >= min.getBlockX() && x <= max.getBlockX() - && y >= min.getBlockY() && y <= max.getBlockY() - && z >= min.getBlockZ() && z <= max.getBlockZ(); + return position.containedWithin(min, max); } @Override - public Iterator iterator() { - return new Iterator() { - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); + public Iterator iterator() { + return new Iterator() { + private BlockVector3 min = getMinimumPoint(); + private BlockVector3 max = getMaximumPoint(); private int nextX = min.getBlockX(); private int nextY = min.getBlockY(); private int nextZ = min.getBlockZ(); @@ -351,9 +340,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public BlockVector next() { - if (!hasNext()) throw new java.util.NoSuchElementException(); - BlockVector answer = new BlockVector(nextX, nextY, nextZ); + public BlockVector3 next() { + if (!hasNext()) throw new NoSuchElementException(); + BlockVector3 answer = new BlockVector3(nextX, nextY, nextZ); if (++nextX > max.getBlockX()) { nextX = min.getBlockX(); if (++nextY > max.getBlockY()) { @@ -365,19 +354,14 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } return answer; } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } }; } @Override - public Iterable asFlatRegion() { - return () -> new Iterator() { - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); + public Iterable asFlatRegion() { + return () -> new Iterator() { + private BlockVector3 min = getMinimumPoint(); + private BlockVector3 max = getMaximumPoint(); private int nextX = min.getBlockX(); private int nextZ = min.getBlockZ(); @@ -387,9 +371,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Vector2D next() { - if (!hasNext()) throw new java.util.NoSuchElementException(); - Vector2D answer = new Vector2D(nextX, nextZ); + public BlockVector2 next() { + if (!hasNext()) throw new NoSuchElementException(); + BlockVector2 answer = new BlockVector2(nextX, nextZ); if (++nextX > max.getBlockX()) { nextX = min.getBlockX(); if (++nextZ > max.getBlockZ()) { @@ -398,11 +382,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } return answer; } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } }; } @@ -435,10 +414,10 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * @param apothem the apothem, where 0 is the minimum value to make a 1x1 cuboid * @return a cuboid region */ - public static CuboidRegion fromCenter(Vector origin, int apothem) { + public static CuboidRegion fromCenter(BlockVector3 origin, int apothem) { checkNotNull(origin); checkArgument(apothem >= 0, "apothem => 0 required"); - Vector size = new Vector(1, 1, 1).multiply(apothem); + BlockVector3 size = BlockVector3.ONE.multiply(apothem); return new CuboidRegion(origin.subtract(size), origin.add(size)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java index ed0e70822..acff65c3a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/CylinderRegion.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit.regions; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.geom.Polygons; import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator; import com.sk89q.worldedit.regions.iterator.FlatRegionIterator; @@ -39,8 +39,8 @@ import java.util.List; */ public class CylinderRegion extends AbstractRegion implements FlatRegion { - private Vector2D center; - private Vector2D radius; + private BlockVector2 center; + private Vector2 radius; private int minY; private int maxY; private boolean hasY = false; @@ -58,7 +58,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @param world the world */ public CylinderRegion(World world) { - this(world, new Vector(), new Vector2D(), 0, 0); + this(world, BlockVector3.ZERO, Vector2.ZERO, 0, 0); hasY = false; } @@ -71,9 +71,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @param minY the minimum Y, inclusive * @param maxY the maximum Y, inclusive */ - public CylinderRegion(World world, Vector center, Vector2D radius, int minY, int maxY) { + public CylinderRegion(World world, BlockVector3 center, Vector2 radius, int minY, int maxY) { super(world); - setCenter(center.toVector2D()); + setCenter(center.toBlockVector2()); setRadius(radius); this.minY = minY; this.maxY = maxY; @@ -88,9 +88,9 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @param minY the minimum Y, inclusive * @param maxY the maximum Y, inclusive */ - public CylinderRegion(Vector center, Vector2D radius, int minY, int maxY) { + public CylinderRegion(BlockVector3 center, Vector2 radius, int minY, int maxY) { super(null); - setCenter(center.toVector2D()); + setCenter(center.toBlockVector2()); setRadius(radius); this.minY = minY; this.maxY = maxY; @@ -98,13 +98,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } public CylinderRegion(CylinderRegion region) { - this(region.world, region.getCenter(), region.getRadius(), region.minY, region.maxY); + this(region.world, region.getCenter().toBlockPoint(), region.getRadius(), region.minY, region.maxY); hasY = region.hasY; } @Override - public Vector getCenter() { - return center.toVector((maxY + minY) / 2); + public Vector3 getCenter() { + return center.toVector3((maxY + minY) / 2); } /** @@ -112,7 +112,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @param center the center point */ - public void setCenter(Vector2D center) { + public void setCenter(BlockVector2 center) { this.center = center; } @@ -121,7 +121,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @return the radius along the X and Z axes */ - public Vector2D getRadius() { + public Vector2 getRadius() { return radius.subtract(0.5, 0.5); } @@ -130,7 +130,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @param radius the radius along the X and Z axes */ - public void setRadius(Vector2D radius) { + public void setRadius(Vector2 radius) { this.radius = radius.add(0.5, 0.5); } @@ -139,8 +139,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @param minRadius the minimum radius */ - public void extendRadius(Vector2D minRadius) { - setRadius(Vector2D.getMaximum(minRadius, getRadius())); + public void extendRadius(Vector2 minRadius) { + setRadius(minRadius.getMaximum(getRadius())); } /** @@ -164,13 +164,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public Vector getMinimumPoint() { - return center.subtract(getRadius()).toVector(minY); + public BlockVector3 getMinimumPoint() { + return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint(); } @Override - public Vector getMaximumPoint() { - return center.add(getRadius()).toVector(maxY); + public BlockVector3 getMaximumPoint() { + return center.toVector2().add(getRadius()).toVector3(maxY).toBlockPoint(); } @Override @@ -203,10 +203,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { return (int) (2 * radius.getZ()); } - private Vector2D calculateDiff2D(Vector... changes) throws RegionOperationException { - Vector2D diff = new Vector2D(); - for (Vector change : changes) { - diff = diff.add(change.toVector2D()); + private BlockVector2 calculateDiff2D(BlockVector3... changes) throws RegionOperationException { + BlockVector2 diff = BlockVector2.ZERO; + for (BlockVector3 change : changes) { + diff = diff.add(change.toBlockVector2()); } if ((diff.getBlockX() & 1) + (diff.getBlockZ() & 1) != 0) { @@ -216,10 +216,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { return diff.divide(2).floor(); } - private Vector2D calculateChanges2D(Vector... changes) { - Vector2D total = new Vector2D(); - for (Vector change : changes) { - total = total.add(change.toVector2D().positive()); + private BlockVector2 calculateChanges2D(BlockVector3... changes) { + BlockVector2 total = BlockVector2.ZERO; + for (BlockVector3 change : changes) { + total = total.add(change.toBlockVector2().abs()); } return total.divide(2).floor(); @@ -233,10 +233,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @throws RegionOperationException */ @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { center = center.add(calculateDiff2D(changes)); - radius = radius.add(calculateChanges2D(changes)); - for (Vector change : changes) { + radius = radius.add(calculateChanges2D(changes).toVector2()); + for (BlockVector3 change : changes) { int changeY = change.getBlockY(); if (changeY > 0) { maxY += changeY; @@ -253,11 +253,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @throws RegionOperationException */ @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { center = center.subtract(calculateDiff2D(changes)); - Vector2D newRadius = radius.subtract(calculateChanges2D(changes)); - radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius); - for (Vector change : changes) { + Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2()); + radius = new Vector2(1.5, 1.5).getMaximum(newRadius); + for (BlockVector3 change : changes) { int height = maxY - minY; int changeY = change.getBlockY(); if (changeY > 0) { @@ -269,8 +269,8 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public void shift(Vector change) throws RegionOperationException { - center = center.add(change.toVector2D()); + public void shift(BlockVector3 change) throws RegionOperationException { + center = center.add(change.toBlockVector2()); int changeY = change.getBlockY(); maxY += changeY; @@ -281,13 +281,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * Checks to see if a point is inside this region. */ @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { final int blockY = position.getBlockY(); if (blockY < minY || blockY > maxY) { return false; } - return position.toVector2D().subtract(center).divide(radius).lengthSq() <= 1; + return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1; } @@ -315,12 +315,12 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public Iterator iterator() { + public Iterator iterator() { return new FlatRegion3DIterator(this); } @Override - public Iterable asFlatRegion() { + public Iterable asFlatRegion() { return () -> new FlatRegionIterator(CylinderRegion.this); } @@ -341,7 +341,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public List polygonize(int maxPoints) { + public List polygonize(int maxPoints) { return Polygons.polygonizeCylinder(center, radius, maxPoints); } @@ -355,10 +355,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @param radius the radius in the X and Z axes * @return a region */ - public static CylinderRegion createRadius(Extent extent, Vector center, double radius) { + public static CylinderRegion createRadius(Extent extent, BlockVector3 center, double radius) { checkNotNull(extent); checkNotNull(center); - Vector2D radiusVec = new Vector2D(radius, radius); + Vector2 radiusVec = new Vector2(radius, radius); int minY = extent.getMinimumPoint().getBlockY(); int maxY = extent.getMaximumPoint().getBlockY(); return new CylinderRegion(center, radiusVec, minY, maxY); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java index 069cdaff3..0cf5e4b59 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/EllipsoidRegion.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -37,12 +36,12 @@ public class EllipsoidRegion extends AbstractRegion { /** * Stores the center. */ - private Vector center; + private BlockVector3 center; /** * Stores the radii plus 0.5 on each axis. */ - private Vector radius; + private Vector3 radius; /** * Construct a new instance of this ellipsoid region. @@ -50,7 +49,7 @@ public class EllipsoidRegion extends AbstractRegion { * @param pos1 the first position * @param pos2 the second position */ - public EllipsoidRegion(Vector pos1, Vector pos2) { + public EllipsoidRegion(BlockVector3 pos1, Vector3 pos2) { this(null, pos1, pos2); } @@ -61,7 +60,7 @@ public class EllipsoidRegion extends AbstractRegion { * @param center the center * @param radius the radius */ - public EllipsoidRegion(World world, Vector center, Vector radius) { + public EllipsoidRegion(World world, BlockVector3 center, Vector3 radius) { super(world); this.center = center; setRadius(radius); @@ -72,13 +71,13 @@ public class EllipsoidRegion extends AbstractRegion { } @Override - public Vector getMinimumPoint() { - return center.subtract(getRadius()); + public BlockVector3 getMinimumPoint() { + return center.toVector3().subtract(getRadius()).toBlockPoint(); } @Override - public Vector getMaximumPoint() { - return center.add(getRadius()); + public BlockVector3 getMaximumPoint() { + return center.toVector3().add(getRadius()).toBlockPoint(); } @Override @@ -101,8 +100,8 @@ public class EllipsoidRegion extends AbstractRegion { return (int) (2 * radius.getZ()); } - private Vector calculateDiff(Vector... changes) throws RegionOperationException { - Vector diff = new Vector().add(changes); + private BlockVector3 calculateDiff(BlockVector3... changes) throws RegionOperationException { + BlockVector3 diff = BlockVector3.ZERO.add(changes); if ((diff.getBlockX() & 1) + (diff.getBlockY() & 1) + (diff.getBlockZ() & 1) != 0) { throw new RegionOperationException( @@ -112,30 +111,30 @@ public class EllipsoidRegion extends AbstractRegion { return diff.divide(2).floor(); } - private Vector calculateChanges(Vector... changes) { - Vector total = new Vector(); - for (Vector change : changes) { - total = total.add(change.positive()); + private Vector3 calculateChanges(BlockVector3... changes) { + Vector3 total = Vector3.ZERO; + for (BlockVector3 change : changes) { + total = total.add(change.abs().toVector3()); } return total.divide(2).floor(); } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { center = center.add(calculateDiff(changes)); radius = radius.add(calculateChanges(changes)); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { center = center.subtract(calculateDiff(changes)); - Vector newRadius = radius.subtract(calculateChanges(changes)); - radius = Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius); + Vector3 newRadius = radius.subtract(calculateChanges(changes)); + radius = new Vector3(1.5, 1.5, 1.5).getMaximum(newRadius); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { center = center.add(change); } @@ -145,8 +144,8 @@ public class EllipsoidRegion extends AbstractRegion { * @return center */ @Override - public Vector getCenter() { - return center; + public Vector3 getCenter() { + return center.toVector3(); } /** @@ -154,7 +153,7 @@ public class EllipsoidRegion extends AbstractRegion { * * @param center the center */ - public void setCenter(Vector center) { + public void setCenter(BlockVector3 center) { this.center = center; } @@ -163,7 +162,7 @@ public class EllipsoidRegion extends AbstractRegion { * * @return radii */ - public Vector getRadius() { + public Vector3 getRadius() { return radius.subtract(0.5, 0.5, 0.5); } @@ -172,25 +171,25 @@ public class EllipsoidRegion extends AbstractRegion { * * @param radius the radius */ - public void setRadius(Vector radius) { + public void setRadius(Vector3 radius) { this.radius = radius.add(0.5, 0.5, 0.5); } @Override - public Set getChunks() { - final Set chunks = new HashSet<>(); + public Set getChunks() { + final Set chunks = new HashSet<>(); - final Vector min = getMinimumPoint(); - final Vector max = getMaximumPoint(); - final int centerY = getCenter().getBlockY(); + final BlockVector3 min = getMinimumPoint(); + final BlockVector3 max = getMaximumPoint(); + final int centerY = center.getBlockY(); for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - if (!contains(new BlockVector(x, centerY, z))) { + if (!contains(new BlockVector3(x, centerY, z))) { continue; } - chunks.add(new BlockVector2D( + chunks.add(new BlockVector2( x >> ChunkStore.CHUNK_SHIFTS, z >> ChunkStore.CHUNK_SHIFTS )); @@ -201,8 +200,8 @@ public class EllipsoidRegion extends AbstractRegion { } @Override - public boolean contains(Vector position) { - return position.subtract(center).divide(radius).lengthSq() <= 1; + public boolean contains(BlockVector3 position) { + return position.subtract(center).toVector3().divide(radius).lengthSq() <= 1; } /** @@ -216,8 +215,8 @@ public class EllipsoidRegion extends AbstractRegion { return center + " - " + getRadius(); } - public void extendRadius(Vector minRadius) { - setRadius(Vector.getMaximum(minRadius, getRadius())); + public void extendRadius(Vector3 minRadius) { + setRadius(minRadius.getMaximum(getRadius())); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java index 92cdf6e36..bd4561e4d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/FlatRegion.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; public interface FlatRegion extends Region { @@ -42,5 +42,5 @@ public interface FlatRegion extends Region { * * @return a flat region iterable */ - Iterable asFlatRegion(); + Iterable asFlatRegion(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java index 5f1c9653e..58e1d2197 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/NullRegion.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import java.util.Collections; @@ -39,18 +38,18 @@ public class NullRegion implements Region { private World world; @Override - public Vector getMinimumPoint() { - return new Vector(0, 0, 0); + public BlockVector3 getMinimumPoint() { + return BlockVector3.ZERO; } @Override - public Vector getMaximumPoint() { - return new Vector(0, 0, 0); + public BlockVector3 getMaximumPoint() { + return BlockVector3.ZERO; } @Override - public Vector getCenter() { - return new Vector(0, 0, 0); + public Vector3 getCenter() { + return Vector3.ZERO; } @Override @@ -74,32 +73,32 @@ public class NullRegion implements Region { } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Cannot change NullRegion"); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Cannot change NullRegion"); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { throw new RegionOperationException("Cannot change NullRegion"); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { return false; } @Override - public Set getChunks() { + public Set getChunks() { return Collections.emptySet(); } @Override - public Set getChunkCubes() { + public Set getChunkCubes() { return Collections.emptySet(); } @@ -119,27 +118,22 @@ public class NullRegion implements Region { } @Override - public List polygonize(int maxPoints) { + public List polygonize(int maxPoints) { return Collections.emptyList(); } @Override - public Iterator iterator() { - return new Iterator() { + public Iterator iterator() { + return new Iterator() { @Override public boolean hasNext() { return false; } @Override - public BlockVector next() { + public BlockVector3 next() { throw new NoSuchElementException(); } - - @Override - public void remove() { - throw new UnsupportedOperationException("Cannot remove"); - } }; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java index b7d607d9d..41cdeebff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Polygonal2DRegion.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; import com.sk89q.worldedit.regions.iterator.FlatRegion3DIterator; import com.sk89q.worldedit.regions.iterator.FlatRegionIterator; import com.sk89q.worldedit.world.World; @@ -37,9 +36,9 @@ import java.util.List; */ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { - private List points; - private Vector2D min; - private Vector2D max; + private List points; + private BlockVector2 min; + private BlockVector2 max; private int minY; private int maxY; private boolean hasY = false; @@ -57,7 +56,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * @param world the world */ public Polygonal2DRegion(World world) { - this(world, Collections.emptyList(), 0, 0); + this(world, Collections.emptyList(), 0, 0); hasY = false; } @@ -69,7 +68,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * @param minY minimum Y * @param maxY maximum Y */ - public Polygonal2DRegion(World world, List points, int minY, int maxY) { + public Polygonal2DRegion(World world, List points, int minY, int maxY) { super(world); this.points = new ArrayList<>(points); this.minY = minY; @@ -93,7 +92,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * * @return a list of points */ - public List getPoints() { + public List getPoints() { return Collections.unmodifiableList(points); } @@ -103,9 +102,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { */ protected void recalculate() { if (points.isEmpty()) { - min = new Vector2D(0, 0); + min = BlockVector2.ZERO; minY = 0; - max = new Vector2D(0, 0); + max = BlockVector2.ZERO; maxY = 0; return; } @@ -115,7 +114,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { int maxX = points.get(0).getBlockX(); int maxZ = points.get(0).getBlockZ(); - for (BlockVector2D v : points) { + for (BlockVector2 v : points) { int x = v.getBlockX(); int z = v.getBlockZ(); if (x < minX) minX = x; @@ -132,8 +131,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { minY = Math.min(Math.max(0, minY), world == null ? 255 : world.getMaxY()); maxY = Math.min(Math.max(0, maxY), world == null ? 255 : world.getMaxY()); - min = new Vector2D(minX, minZ); - max = new Vector2D(maxX, maxZ); + min = new BlockVector2(minX, minZ); + max = new BlockVector2(maxX, maxZ); } /** @@ -141,17 +140,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * * @param position the position */ - public void addPoint(Vector2D position) { - points.add(position.toBlockVector2D()); - recalculate(); - } - - /** - * Add a point to the list. - * - * @param position the position - */ - public void addPoint(BlockVector2D position) { + public void addPoint(BlockVector2 position) { points.add(position); recalculate(); } @@ -161,8 +150,8 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * * @param position the position */ - public void addPoint(Vector position) { - points.add(new BlockVector2D(position.getBlockX(), position.getBlockZ())); + public void addPoint(BlockVector3 position) { + points.add(new BlockVector2(position.getBlockX(), position.getBlockZ())); recalculate(); } @@ -199,13 +188,13 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public Vector getMinimumPoint() { - return min.toVector(minY); + public BlockVector3 getMinimumPoint() { + return min.toBlockVector3(minY); } @Override - public Vector getMaximumPoint() { - return max.toVector(maxY); + public BlockVector3 getMaximumPoint() { + return max.toBlockVector3(maxY); } @Override @@ -239,14 +228,11 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public void expand(Vector... changes) throws RegionOperationException { - for (Vector change : changes) { + public void expand(BlockVector3... changes) throws RegionOperationException { + for (BlockVector3 change : changes) { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { throw new RegionOperationException("Polygons can only be expanded vertically."); } - } - - for (Vector change : changes) { int changeY = change.getBlockY(); if (changeY > 0) { maxY += changeY; @@ -258,14 +244,11 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public void contract(Vector... changes) throws RegionOperationException { - for (Vector change : changes) { + public void contract(BlockVector3... changes) throws RegionOperationException { + for (BlockVector3 change : changes) { if (change.getBlockX() != 0 || change.getBlockZ() != 0) { throw new RegionOperationException("Polygons can only be contracted vertically."); } - } - - for (Vector change : changes) { int changeY = change.getBlockY(); if (changeY > 0) { minY += changeY; @@ -277,14 +260,14 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { final double changeX = change.getX(); final double changeY = change.getY(); final double changeZ = change.getZ(); for (int i = 0; i < points.size(); ++i) { - BlockVector2D point = points.get(i); - points.set(i, new BlockVector2D(point.getX() + changeX, point.getZ() + changeZ)); + BlockVector2 point = points.get(i); + points.set(i, new BlockVector2(point.getX() + changeX, point.getZ() + changeZ)); } minY += changeY; @@ -294,7 +277,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { return contains(points, minY, maxY, position); } @@ -307,7 +290,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { * @param pt the position to check * @return true if the given polygon contains the given point */ - public static boolean contains(List points, int minY, int maxY, Vector pt) { + public static boolean contains(List points, int minY, int maxY, BlockVector3 pt) { if (points.size() < 3) { return false; } @@ -398,12 +381,12 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public Iterator iterator() { + public Iterator iterator() { return new FlatRegion3DIterator(this); } @Override - public Iterable asFlatRegion() { + public Iterable asFlatRegion() { return () -> new FlatRegionIterator(Polygonal2DRegion.this); } @@ -416,10 +399,10 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { @Override public String toString() { StringBuilder sb = new StringBuilder(); - List pts = getPoints(); - Iterator it = pts.iterator(); + List pts = getPoints(); + Iterator it = pts.iterator(); while (it.hasNext()) { - BlockVector2D current = it.next(); + BlockVector2 current = it.next(); sb.append("(").append(current.getBlockX()).append(", ").append(current.getBlockZ()).append(")"); if (it.hasNext()) sb.append(" - "); } @@ -435,7 +418,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override - public List polygonize(int maxPoints) { + public List polygonize(int maxPoints) { if (maxPoints >= 0 && maxPoints < points.size()) { throw new IllegalArgumentException("Cannot polygonize a this Polygonal2DRegion into the amount of points given."); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java index 77bfa8440..2d1c88f0a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/Region.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import java.util.List; @@ -33,21 +32,21 @@ import javax.annotation.Nullable; /** * Represents a physical shape. */ -public interface Region extends Iterable, Cloneable { +public interface Region extends Iterable, Cloneable { /** * Get the lower point of a region. * * @return min. point */ - Vector getMinimumPoint(); + BlockVector3 getMinimumPoint(); /** * Get the upper point of a region. * * @return max. point */ - Vector getMaximumPoint(); + BlockVector3 getMaximumPoint(); /** * Get the center point of a region. @@ -56,7 +55,7 @@ public interface Region extends Iterable, Cloneable { * * @return center point */ - Vector getCenter(); + Vector3 getCenter(); /** * Get the number of blocks in the region. @@ -92,7 +91,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - void expand(Vector... changes) throws RegionOperationException; + void expand(BlockVector3... changes) throws RegionOperationException; /** * Contract the region. @@ -100,7 +99,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - void contract(Vector... changes) throws RegionOperationException; + void contract(BlockVector3... changes) throws RegionOperationException; /** * Shift the region. @@ -108,7 +107,7 @@ public interface Region extends Iterable, Cloneable { * @param change the change * @throws RegionOperationException */ - void shift(Vector change) throws RegionOperationException; + void shift(BlockVector3 change) throws RegionOperationException; /** * Returns true based on whether the region contains the point. @@ -116,21 +115,21 @@ public interface Region extends Iterable, Cloneable { * @param position the position * @return true if contained */ - boolean contains(Vector position); + boolean contains(BlockVector3 position); /** * Get a list of chunks. * * @return a list of chunk coordinates */ - Set getChunks(); + Set getChunks(); /** * Return a list of 16*16*16 chunks in a region * * @return the chunk cubes this region overlaps with */ - Set getChunkCubes(); + Set getChunkCubes(); /** * Sets the world that the selection is in. @@ -159,5 +158,5 @@ public interface Region extends Iterable, Cloneable { * @param maxPoints maximum number of points to generate. -1 for no limit. * @return the points. */ - List polygonize(int maxPoints); + List polygonize(int maxPoints); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java index ad93903ee..5b26672cb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionIntersection.java @@ -23,8 +23,7 @@ import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.collect.Iterators; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import java.util.ArrayList; @@ -90,37 +89,37 @@ public class RegionIntersection extends AbstractRegion { } @Override - public Vector getMinimumPoint() { - Vector minimum = regions.get(0).getMinimumPoint(); + public BlockVector3 getMinimumPoint() { + BlockVector3 minimum = regions.get(0).getMinimumPoint(); for (int i = 1; i < regions.size(); i++) { - minimum = Vector.getMinimum(regions.get(i).getMinimumPoint(), minimum); + minimum = regions.get(i).getMinimumPoint().getMinimum(minimum); } return minimum; } @Override - public Vector getMaximumPoint() { - Vector maximum = regions.get(0).getMaximumPoint(); + public BlockVector3 getMaximumPoint() { + BlockVector3 maximum = regions.get(0).getMaximumPoint(); for (int i = 1; i < regions.size(); i++) { - maximum = Vector.getMaximum(regions.get(i).getMaximumPoint(), maximum); + maximum = regions.get(i).getMaximumPoint().getMaximum(maximum); } return maximum; } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { checkNotNull(changes); throw new RegionOperationException("Cannot expand a region intersection"); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { checkNotNull(changes); throw new RegionOperationException("Cannot contract a region intersection"); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { checkNotNull(position); for (Region region : regions) { @@ -134,8 +133,8 @@ public class RegionIntersection extends AbstractRegion { @SuppressWarnings({"unchecked", "rawtypes"}) @Override - public Iterator iterator() { - Iterator[] iterators = (Iterator[]) new Iterator[regions.size()]; + public Iterator iterator() { + Iterator[] iterators = (Iterator[]) new Iterator[regions.size()]; for (int i = 0; i < regions.size(); i++) { iterators[i] = regions.get(i).iterator(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 278ae4815..fea83d30a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -19,11 +19,10 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; @@ -59,7 +58,7 @@ public interface RegionSelector { * @param position the position * @return true if something changed */ - boolean selectPrimary(Vector position, SelectorLimits limits); + boolean selectPrimary(BlockVector3 position, SelectorLimits limits); /** * Called when the second point is selected. @@ -67,7 +66,7 @@ public interface RegionSelector { * @param position the position * @return true if something changed */ - boolean selectSecondary(Vector position, SelectorLimits limits); + boolean selectSecondary(BlockVector3 position, SelectorLimits limits); /** * Tell the player information about his/her primary selection. @@ -76,7 +75,7 @@ public interface RegionSelector { * @param session the session * @param position position */ - void explainPrimarySelection(Actor actor, LocalSession session, Vector position); + void explainPrimarySelection(Actor actor, LocalSession session, BlockVector3 position); /** * Tell the player information about his/her secondary selection. @@ -85,7 +84,7 @@ public interface RegionSelector { * @param session the session * @param position position */ - void explainSecondarySelection(Actor actor, LocalSession session, Vector position); + void explainSecondarySelection(Actor actor, LocalSession session, BlockVector3 position); /** * The the player information about the region's changes. This may resend @@ -102,7 +101,7 @@ public interface RegionSelector { * @return the primary position * @throws IncompleteRegionException thrown if a region has not been fully defined */ - BlockVector getPrimaryPosition() throws IncompleteRegionException; + BlockVector3 getPrimaryPosition() throws IncompleteRegionException; /** * Get the selection. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java index 338d5f0e9..911e40b8b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/TransformRegion.java @@ -21,9 +21,9 @@ package com.sk89q.worldedit.regions; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; +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; @@ -98,17 +98,17 @@ public class TransformRegion extends AbstractRegion { } @Override - public Vector getMinimumPoint() { - return transform.apply(region.getMinimumPoint()); + public BlockVector3 getMinimumPoint() { + return transform.apply(region.getMinimumPoint().toVector3()).toBlockPoint(); } @Override - public Vector getMaximumPoint() { - return transform.apply(region.getMaximumPoint()); + public BlockVector3 getMaximumPoint() { + return transform.apply(region.getMaximumPoint().toVector3()).toBlockPoint(); } @Override - public Vector getCenter() { + public Vector3 getCenter() { return transform.apply(region.getCenter()); } @@ -133,50 +133,50 @@ public class TransformRegion extends AbstractRegion { } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Can't expand a TransformedRegion"); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Can't contract a TransformedRegion"); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { throw new RegionOperationException("Can't change a TransformedRegion"); } @Override - public boolean contains(Vector position) { - return region.contains(transform.inverse().apply(position)); + public boolean contains(BlockVector3 position) { + return region.contains(transform.inverse().apply(position.toVector3()).toBlockPoint()); } @Override - public List polygonize(int maxPoints) { - List origPoints = region.polygonize(maxPoints); - List transformedPoints = new ArrayList<>(); - for (BlockVector2D vector : origPoints) { - transformedPoints.add(transform.apply(vector.toVector(0)).toVector2D().toBlockVector2D()); + public List polygonize(int maxPoints) { + List origPoints = region.polygonize(maxPoints); + List transformedPoints = new ArrayList<>(); + for (BlockVector2 vector : origPoints) { + transformedPoints.add(transform.apply(vector.toVector3(0)).toVector2().toBlockPoint()); } return transformedPoints; } @Override - public Iterator iterator() { - final Iterator it = region.iterator(); + public Iterator iterator() { + final Iterator it = region.iterator(); - return new Iterator() { + return new Iterator() { @Override public boolean hasNext() { return it.hasNext(); } @Override - public BlockVector next() { - BlockVector next = it.next(); + public BlockVector3 next() { + BlockVector3 next = it.next(); if (next != null) { - return transform.apply(next).toBlockVector(); + return transform.apply(next.toVector3()).toBlockPoint(); } else { return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CuboidRegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CuboidRegionFactory.java index 2f533f9fe..24be870a0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CuboidRegionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CuboidRegionFactory.java @@ -19,14 +19,14 @@ package com.sk89q.worldedit.regions.factory; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; public class CuboidRegionFactory implements RegionFactory { @Override - public Region createCenteredAt(Vector position, double size) { + public Region createCenteredAt(BlockVector3 position, double size) { return CuboidRegion.fromCenter(position, (int) size); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CylinderRegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CylinderRegionFactory.java index aa2c83cdd..ed3896d06 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CylinderRegionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/CylinderRegionFactory.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.regions.factory; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; @@ -33,8 +33,8 @@ public class CylinderRegionFactory implements RegionFactory { } @Override - public Region createCenteredAt(Vector position, double size) { - return new CylinderRegion(position, new Vector2D(size, size), position.getBlockY() - (int) (height / 2), position.getBlockY() + (int) (height / 2)); + public Region createCenteredAt(BlockVector3 position, double size) { + return new CylinderRegion(position, new Vector2(size, size), position.getBlockY() - (int) (height / 2), position.getBlockY() + (int) (height / 2)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/RegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/RegionFactory.java index 51cf3bc1f..8294b0c11 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/RegionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/RegionFactory.java @@ -19,11 +19,11 @@ package com.sk89q.worldedit.regions.factory; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; public interface RegionFactory { - Region createCenteredAt(Vector position, double size); + Region createCenteredAt(BlockVector3 position, double size); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/SphereRegionFactory.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/SphereRegionFactory.java index cf0f488f8..4ad8d4125 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/SphereRegionFactory.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/factory/SphereRegionFactory.java @@ -19,15 +19,16 @@ package com.sk89q.worldedit.regions.factory; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.EllipsoidRegion; import com.sk89q.worldedit.regions.Region; public class SphereRegionFactory implements RegionFactory { @Override - public Region createCenteredAt(Vector position, double size) { - return new EllipsoidRegion(position, new Vector(size, size, size)); + public Region createCenteredAt(BlockVector3 position, double size) { + return new EllipsoidRegion(position, new Vector3(size, size, size)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegion3DIterator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegion3DIterator.java index 8c6628616..786e04a2b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegion3DIterator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegion3DIterator.java @@ -21,23 +21,23 @@ package com.sk89q.worldedit.regions.iterator; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.FlatRegion; import java.util.Iterator; import java.util.NoSuchElementException; -public class FlatRegion3DIterator implements Iterator { +public class FlatRegion3DIterator implements Iterator { - private Iterator flatIterator; + private Iterator flatIterator; private int minY; private int maxY; - private Vector2D next2D; + private BlockVector2 next2D; private int nextY; - public FlatRegion3DIterator(FlatRegion region, Iterator flatIterator) { + public FlatRegion3DIterator(FlatRegion region, Iterator flatIterator) { checkNotNull(region); checkNotNull(flatIterator); @@ -63,12 +63,12 @@ public class FlatRegion3DIterator implements Iterator { } @Override - public BlockVector next() { + public BlockVector3 next() { if (!hasNext()) { throw new NoSuchElementException(); } - BlockVector current = new BlockVector(next2D.getBlockX(), nextY, next2D.getBlockZ()); + BlockVector3 current = new BlockVector3(next2D.getBlockX(), nextY, next2D.getBlockZ()); if (nextY < maxY) { nextY++; } else if (flatIterator.hasNext()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegionIterator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegionIterator.java index 60018afeb..e4cd6457c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegionIterator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/FlatRegionIterator.java @@ -21,13 +21,14 @@ package com.sk89q.worldedit.regions.iterator; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import java.util.Iterator; +import java.util.NoSuchElementException; -public class FlatRegionIterator implements Iterator { +public class FlatRegionIterator implements Iterator { private Region region; private int y; @@ -42,8 +43,8 @@ public class FlatRegionIterator implements Iterator { this.region = region; - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); this.y = min.getBlockY(); @@ -64,18 +65,18 @@ public class FlatRegionIterator implements Iterator { } private void forward() { - while (hasNext() && !region.contains(new Vector(nextX, y, nextZ))) { + while (hasNext() && !region.contains(new BlockVector3(nextX, y, nextZ))) { forwardOne(); } } @Override - public Vector2D next() { + public BlockVector2 next() { if (!hasNext()) { - throw new java.util.NoSuchElementException(); + throw new NoSuchElementException(); } - Vector2D answer = new Vector2D(nextX, nextZ); + BlockVector2 answer = new BlockVector2(nextX, nextZ); forwardOne(); forward(); @@ -95,9 +96,4 @@ public class FlatRegionIterator implements Iterator { nextX = Integer.MIN_VALUE; } - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/RegionIterator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/RegionIterator.java index 35700595c..d2ab586d8 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/RegionIterator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/iterator/RegionIterator.java @@ -21,19 +21,18 @@ package com.sk89q.worldedit.regions.iterator; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import java.util.Iterator; -public class RegionIterator implements Iterator { +public class RegionIterator implements Iterator { private final Region region; private final int maxX; private final int maxY; private final int maxZ; - private final Vector min; + private final BlockVector3 min; private int nextX; private int nextY; private int nextZ; @@ -43,7 +42,7 @@ public class RegionIterator implements Iterator { this.region = region; - Vector max = region.getMaximumPoint(); + BlockVector3 max = region.getMaximumPoint(); this.maxX = max.getBlockX(); this.maxY = max.getBlockY(); this.maxZ = max.getBlockZ(); @@ -62,16 +61,16 @@ public class RegionIterator implements Iterator { } private void forward() { - while (hasNext() && !region.contains(new BlockVector(nextX, nextY, nextZ))) { + while (hasNext() && !region.contains(new BlockVector3(nextX, nextY, nextZ))) { forwardOne(); } } @Override - public BlockVector next() { + public BlockVector3 next() { if (!hasNext()) throw new java.util.NoSuchElementException(); - BlockVector answer = new BlockVector(nextX, nextY, nextZ); + BlockVector3 answer = new BlockVector3(nextX, nextY, nextZ); forwardOne(); forward(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Edge.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Edge.java index 3495fee83..dcf098d3c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Edge.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Edge.java @@ -21,14 +21,14 @@ package com.sk89q.worldedit.regions.polyhedron; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; public class Edge { - private final Vector start; - private final Vector end; + private final Vector3 start; + private final Vector3 end; - public Edge(Vector start, Vector end) { + public Edge(Vector3 start, Vector3 end) { checkNotNull(start); checkNotNull(end); @@ -71,7 +71,7 @@ public class Edge { * @param vertex the 3rd vertex for the triangle * @return a triangle */ - public Triangle createTriangle(Vector vertex) { + public Triangle createTriangle(Vector3 vertex) { checkNotNull(vertex); return new Triangle(this.start, this.end, vertex); } @@ -82,7 +82,7 @@ public class Edge { * @param vertex the second vertex * @return a new triangle */ - public Triangle createTriangle2(Vector vertex) { + public Triangle createTriangle2(Vector3 vertex) { checkNotNull(vertex); return new Triangle(this.start, vertex, this.end); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Triangle.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Triangle.java index 01bd7f8ae..5e5f7a770 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Triangle.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/polyhedron/Triangle.java @@ -21,13 +21,13 @@ package com.sk89q.worldedit.regions.polyhedron; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; public class Triangle { private String tag = "Triangle"; - private final Vector[] vertices; - private final Vector normal; + private final Vector3[] vertices; + private final Vector3 normal; private final double b; /** @@ -37,12 +37,12 @@ public class Triangle { * @param v1 second vertex * @param v2 third vertex */ - public Triangle(Vector v0, Vector v1, Vector v2) { + public Triangle(Vector3 v0, Vector3 v1, Vector3 v2) { checkNotNull(v0); checkNotNull(v1); checkNotNull(v2); - vertices = new Vector[] { v0, v1, v2 }; + vertices = new Vector3[] { v0, v1, v2 }; this.normal = v1.subtract(v0).cross(v2.subtract(v0)).normalize(); this.b = Math.max(Math.max(normal.dot(v0), normal.dot(v1)), normal.dot(v2)); @@ -54,7 +54,7 @@ public class Triangle { * @param index Vertex index. Valid input: 0..2 * @return a vertex */ - public Vector getVertex(int index) { + public Vector3 getVertex(int index) { return vertices[index]; } @@ -77,7 +77,7 @@ public class Triangle { * @param pt the point to test * @return true if the point is below */ - public boolean below(Vector pt) { + public boolean below(Vector3 pt) { checkNotNull(pt); return normal.dot(pt) < b; } @@ -88,7 +88,7 @@ public class Triangle { * @param pt the point to test * @return true if the point is above */ - public boolean above(Vector pt) { + public boolean above(Vector3 pt) { checkNotNull(pt); return normal.dot(pt) > b; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java index afbcb1ae1..1c16ec77a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ConvexPolyhedralRegionSelector.java @@ -21,15 +21,14 @@ package com.sk89q.worldedit.regions.selector; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; import com.sk89q.worldedit.internal.cui.SelectionPolygonEvent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.ConvexPolyhedralRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -52,7 +51,7 @@ import javax.annotation.Nullable; public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion { private final transient ConvexPolyhedralRegion region; - private transient BlockVector pos1; + private transient BlockVector3 pos1; /** * Create a new selector with a {@code null} world. @@ -97,9 +96,9 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion region = new ConvexPolyhedralRegion(oldRegion.getWorld()); - for (final BlockVector2D pt : new ArrayList<>(oldRegion.polygonize(Integer.MAX_VALUE))) { - region.addVertex(pt.toVector(minY)); - region.addVertex(pt.toVector(maxY)); + for (final BlockVector2 pt : new ArrayList<>(oldRegion.polygonize(Integer.MAX_VALUE))) { + region.addVertex(pt.toBlockVector3(minY)); + region.addVertex(pt.toBlockVector3(maxY)); } learnChanges(); @@ -118,15 +117,15 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); clear(); - pos1 = position.toBlockVector(); + pos1 = position; return region.addVertex(position); } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); Optional vertexLimit = limits.getPolyhedronVertexLimit(); @@ -139,7 +138,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { return pos1; } @@ -169,7 +168,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion @Override public void learnChanges() { - pos1 = region.getVertices().iterator().next().toBlockVector(); + pos1 = region.getVertices().iterator().next(); } @Override @@ -194,7 +193,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { checkNotNull(player); checkNotNull(session); checkNotNull(pos); @@ -205,7 +204,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { checkNotNull(player); checkNotNull(session); checkNotNull(pos); @@ -237,12 +236,12 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion checkNotNull(player); checkNotNull(session); - Collection vertices = region.getVertices(); + Collection vertices = region.getVertices(); Collection triangles = region.getTriangles(); - Map vertexIds = new HashMap<>(vertices.size()); + Map vertexIds = new HashMap<>(vertices.size()); int lastVertexId = -1; - for (Vector vertex : vertices) { + for (BlockVector3 vertex : vertices) { vertexIds.put(vertex, ++lastVertexId); session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea())); } @@ -250,7 +249,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion for (Triangle triangle : triangles) { final int[] v = new int[3]; for (int i = 0; i < 3; ++i) { - v[i] = vertexIds.get(triangle.getVertex(i)); + v[i] = vertexIds.get(triangle.getVertex(i).toBlockPoint()); } session.dispatchCUIEvent(player, new SelectionPolygonEvent(v)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java index 182c08f0f..9eab91500 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CuboidRegionSelector.java @@ -21,13 +21,12 @@ package com.sk89q.worldedit.regions.selector; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -44,8 +43,8 @@ import javax.annotation.Nullable; */ public class CuboidRegionSelector implements RegionSelector, CUIRegion { - protected transient BlockVector position1; - protected transient BlockVector position2; + protected transient BlockVector3 position1; + protected transient BlockVector3 position2; protected transient CuboidRegion region; /** @@ -61,7 +60,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { * @param world the world, which may be {@code null} */ public CuboidRegionSelector(@Nullable World world) { - region = new CuboidRegion(world, new Vector(), new Vector()); + region = new CuboidRegion(world, BlockVector3.ZERO, BlockVector3.ZERO); } /** @@ -85,8 +84,8 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { return; } - position1 = oldRegion.getMinimumPoint().toBlockVector(); - position2 = oldRegion.getMaximumPoint().toBlockVector(); + position1 = oldRegion.getMinimumPoint(); + position2 = oldRegion.getMaximumPoint(); } region.setPos1(position1); @@ -100,12 +99,12 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { * @param position1 position 1 * @param position2 position 2 */ - public CuboidRegionSelector(@Nullable World world, Vector position1, Vector position2) { + public CuboidRegionSelector(@Nullable World world, BlockVector3 position1, BlockVector3 position2) { this(world); checkNotNull(position1); checkNotNull(position2); - this.position1 = position1.toBlockVector(); - this.position2 = position2.toBlockVector(); + this.position1 = position1; + this.position2 = position2; region.setPos1(position1); region.setPos2(position2); } @@ -122,33 +121,33 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); - if (position1 != null && (position.compareTo(position1) == 0)) { + if (position1 != null && position1.equals(position)) { return false; } - position1 = position.toBlockVector(); + position1 = position; region.setPos1(position1); return true; } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { checkNotNull(position); - if (position2 != null && (position.compareTo(position2)) == 0) { + if (position2 != null && position2.equals(position)) { return false; } - position2 = position.toBlockVector(); + position2 = position; region.setPos2(position2); return true; } @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { checkNotNull(player); checkNotNull(session); checkNotNull(pos); @@ -163,7 +162,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { checkNotNull(player); checkNotNull(session); checkNotNull(pos); @@ -192,7 +191,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { if (position1 == null) { throw new IncompleteRegionException(); } @@ -221,8 +220,8 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { @Override public void learnChanges() { - position1 = region.getPos1().toBlockVector(); - position2 = region.getPos2().toBlockVector(); + position1 = region.getPos1(); + position2 = region.getPos2(); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java index 8e4ce873c..ae442482c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/CylinderRegionSelector.java @@ -21,16 +21,17 @@ package com.sk89q.worldedit.regions.selector; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionCylinderEvent; import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.CylinderRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -92,12 +93,12 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { return; } - Vector pos1 = oldRegion.getMinimumPoint(); - Vector pos2 = oldRegion.getMaximumPoint(); + BlockVector3 pos1 = oldRegion.getMinimumPoint(); + BlockVector3 pos2 = oldRegion.getMaximumPoint(); - Vector center = pos1.add(pos2).divide(2).floor(); - region.setCenter(center.toVector2D()); - region.setRadius(pos2.toVector2D().subtract(center.toVector2D())); + BlockVector3 center = pos1.add(pos2).divide(2).floor(); + region.setCenter(center.toBlockVector2()); + region.setRadius(pos2.toBlockVector2().subtract(center.toBlockVector2()).toVector2()); region.setMaximumY(Math.max(pos1.getBlockY(), pos2.getBlockY())); region.setMinimumY(Math.min(pos1.getBlockY(), pos2.getBlockY())); @@ -113,7 +114,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { * @param minY the minimum Y * @param maxY the maximum Y */ - public CylinderRegionSelector(@Nullable World world, Vector2D center, Vector2D radius, int minY, int maxY) { + public CylinderRegionSelector(@Nullable World world, BlockVector2 center, Vector2 radius, int minY, int maxY) { this(world); region.setCenter(center); @@ -135,27 +136,27 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { - if (!region.getCenter().equals(Vector.ZERO) && position.compareTo(region.getCenter()) == 0) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { + if (!region.getCenter().equals(Vector3.ZERO) && position.equals(region.getCenter().toBlockPoint())) { return false; } region = new CylinderRegion(region.getWorld()); - region.setCenter(position.toVector2D()); + region.setCenter(position.toBlockVector2()); region.setY(position.getBlockY()); return true; } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { - Vector center = region.getCenter(); - if ((center.compareTo(Vector.ZERO)) == 0) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { + Vector3 center = region.getCenter(); + if (center.equals(Vector3.ZERO)) { return true; } - final Vector2D diff = position.subtract(center).toVector2D(); - final Vector2D minRadius = Vector2D.getMaximum(diff, diff.multiply(-1.0)); + final Vector2 diff = position.toVector3().subtract(center).toVector2(); + final Vector2 minRadius = diff.getMaximum(diff.multiply(-1.0)); region.extendRadius(minRadius); region.setY(position.getBlockY()); @@ -164,17 +165,17 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { } @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { player.print("Starting a new cylindrical selection at " + pos + "."); session.describeCUI(player); } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { - Vector center = region.getCenter(); + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { + Vector3 center = region.getCenter(); - if (!center.equals(Vector.ZERO)) { + if (!center.equals(Vector3.ZERO)) { player.print("Radius set to " + NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()) + " blocks. (" + region.getArea() + ")."); } else { player.printError("You must select the center point before setting the radius."); @@ -190,12 +191,12 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { if (!isDefined()) { throw new IncompleteRegionException(); } - return region.getCenter().toBlockVector(); + return region.getCenter().toBlockPoint(); } @Override @@ -214,7 +215,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { @Override public boolean isDefined() { - return !region.getRadius().equals(Vector2D.ZERO); + return !region.getRadius().equals(Vector2.ZERO); } @Override @@ -235,10 +236,10 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { public List getInformationLines() { final List lines = new ArrayList<>(); - if (!region.getCenter().equals(Vector.ZERO)) { + if (!region.getCenter().equals(Vector3.ZERO)) { lines.add("Center: " + region.getCenter()); } - if (!region.getRadius().equals(Vector2D.ZERO)) { + if (!region.getRadius().equals(Vector2.ZERO)) { lines.add("Radius: " + region.getRadius()); } @@ -252,7 +253,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { @Override public void describeCUI(LocalSession session, Actor player) { - session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter(), region.getRadius())); + session.dispatchCUIEvent(player, new SelectionCylinderEvent(region.getCenter().toBlockPoint(), region.getRadius())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java index ca32ac3dc..8274a6e7b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/EllipsoidRegionSelector.java @@ -21,14 +21,14 @@ package com.sk89q.worldedit.regions.selector; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionEllipsoidPointEvent; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.EllipsoidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -61,7 +61,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { * @param world the world, which may be {@code null} */ public EllipsoidRegionSelector(@Nullable World world) { - region = new EllipsoidRegion(world, new Vector(), new Vector()); + region = new EllipsoidRegion(world, BlockVector3.ZERO, Vector3.ZERO); } /** @@ -83,12 +83,12 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { return; } - BlockVector pos1 = oldRegion.getMinimumPoint().toBlockVector(); - BlockVector pos2 = oldRegion.getMaximumPoint().toBlockVector(); + BlockVector3 pos1 = oldRegion.getMinimumPoint(); + BlockVector3 pos2 = oldRegion.getMaximumPoint(); - Vector center = pos1.add(pos2).divide(2).floor(); + BlockVector3 center = pos1.add(pos2).divide(2).floor(); region.setCenter(center); - region.setRadius(pos2.subtract(center)); + region.setRadius(pos2.subtract(center).toVector3()); } } @@ -99,7 +99,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { * @param center the center * @param radius the radius */ - public EllipsoidRegionSelector(@Nullable World world, Vector center, Vector radius) { + public EllipsoidRegionSelector(@Nullable World world, BlockVector3 center, Vector3 radius) { this(world); region.setCenter(center); @@ -118,32 +118,32 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { if (position.equals(region.getCenter()) && region.getRadius().lengthSq() == 0) { return false; } - region.setCenter(position.toBlockVector()); - region.setRadius(new Vector()); + region.setCenter(position); + region.setRadius(Vector3.ZERO); started = true; return true; } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { if (!started) { return false; } - final Vector diff = position.subtract(region.getCenter()); - final Vector minRadius = Vector.getMaximum(diff, diff.multiply(-1.0)); + final Vector3 diff = position.toVector3().subtract(region.getCenter()); + final Vector3 minRadius = diff.getMaximum(diff.multiply(-1.0)); region.extendRadius(minRadius); return true; } @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ")."); } else { @@ -154,7 +154,7 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ")."); } else { @@ -194,8 +194,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { @Override public void clear() { - region.setCenter(new Vector()); - region.setRadius(new Vector()); + region.setCenter(BlockVector3.ZERO); + region.setRadius(Vector3.ZERO); } @Override @@ -207,12 +207,12 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { public List getInformationLines() { final List lines = new ArrayList<>(); - final Vector center = region.getCenter(); + final Vector3 center = region.getCenter(); if (center.lengthSq() > 0) { lines.add("Center: " + center); } - final Vector radius = region.getRadius(); + final Vector3 radius = region.getRadius(); if (radius.lengthSq() > 0) { lines.add("X/Y/Z radius: " + radius); } @@ -227,8 +227,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { @Override public void describeCUI(LocalSession session, Actor player) { - session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter())); - session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius())); + session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(0, region.getCenter().toBlockPoint())); + session.dispatchCUIEvent(player, new SelectionEllipsoidPointEvent(1, region.getRadius().toBlockPoint())); } @Override @@ -253,8 +253,8 @@ public class EllipsoidRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { - return region.getCenter().toBlockVector(); + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { + return region.getCenter().toBlockPoint(); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java index 0e239f0d3..bf5aeaace 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/ExtendingCuboidRegionSelector.java @@ -19,10 +19,9 @@ package com.sk89q.worldedit.regions.selector; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; @@ -63,8 +62,8 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { return; } - position1 = region.getMinimumPoint().toBlockVector(); - position2 = region.getMaximumPoint().toBlockVector(); + position1 = region.getMinimumPoint(); + position2 = region.getMaximumPoint(); region.setPos1(position1); region.setPos2(position2); } @@ -76,28 +75,28 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { * @param position1 the first position * @param position2 the second position */ - public ExtendingCuboidRegionSelector(@Nullable World world, Vector position1, Vector position2) { + public ExtendingCuboidRegionSelector(@Nullable World world, BlockVector3 position1, BlockVector3 position2) { this(world); - position1 = Vector.getMinimum(position1, position2); - position2 = Vector.getMaximum(position1, position2); + position1 = position1.getMinimum(position2); + position2 = position1.getMaximum(position2); region.setPos1(position1); region.setPos2(position2); } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { - if (position1 != null && position2 != null && position.compareTo(position1) == 0 && position.compareTo(position2) == 0) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { + if (position1 != null && position2 != null && position.equals(position1) && position.equals(position2)) { return false; } - position1 = position2 = position.toBlockVector(); + position1 = position2 = position; region.setPos1(position1); region.setPos2(position2); return true; } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { if (position1 == null || position2 == null) { return selectPrimary(position, limits); } @@ -114,10 +113,10 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { double y2 = Math.max(position.getY(), position2.getY()); double z2 = Math.max(position.getZ(), position2.getZ()); - final BlockVector o1 = position1; - final BlockVector o2 = position2; - position1 = new BlockVector(x1, y1, z1); - position2 = new BlockVector(x2, y2, z2); + final BlockVector3 o1 = position1; + final BlockVector3 o2 = position2; + position1 = new BlockVector3(x1, y1, z1); + position2 = new BlockVector3(x2, y2, z2); region.setPos1(position1); region.setPos2(position2); @@ -129,14 +128,14 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { } @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { player.print("Started selection at " + pos + " (" + region.getArea() + ")."); explainRegionAdjust(player, session); } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { player.print("Extended selection to encompass " + pos + " (" + region.getArea() + ")."); explainRegionAdjust(player, session); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java index 2cf8682b8..fbc2bd123 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/Polygonal2DRegionSelector.java @@ -21,16 +21,15 @@ package com.sk89q.worldedit.regions.selector; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIRegion; import com.sk89q.worldedit.internal.cui.SelectionMinMaxEvent; import com.sk89q.worldedit.internal.cui.SelectionPoint2DEvent; import com.sk89q.worldedit.internal.cui.SelectionShapeEvent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Polygonal2DRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionSelector; @@ -48,7 +47,7 @@ import javax.annotation.Nullable; */ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { - private transient BlockVector pos1; + private transient BlockVector3 pos1; private transient Polygonal2DRegion region; /** @@ -91,9 +90,9 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { final int minY = oldRegion.getMinimumPoint().getBlockY(); final int maxY = oldRegion.getMaximumPoint().getBlockY(); - List points = oldRegion.polygonize(Integer.MAX_VALUE); + List points = oldRegion.polygonize(Integer.MAX_VALUE); - pos1 = points.get(0).toVector(minY).toBlockVector(); + pos1 = points.get(0).toBlockVector3(minY); region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY); } } @@ -106,11 +105,11 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { * @param minY the minimum Y * @param maxY the maximum Y */ - public Polygonal2DRegionSelector(@Nullable World world, List points, int minY, int maxY) { + public Polygonal2DRegionSelector(@Nullable World world, List points, int minY, int maxY) { checkNotNull(points); - final BlockVector2D pos2D = points.get(0); - pos1 = new BlockVector(pos2D.getX(), minY, pos2D.getZ()); + final BlockVector2 pos2D = points.get(0); + pos1 = new BlockVector3(pos2D.getX(), minY, pos2D.getZ()); region = new Polygonal2DRegion(world, points, minY, maxY); } @@ -126,12 +125,12 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public boolean selectPrimary(Vector position, SelectorLimits limits) { + public boolean selectPrimary(BlockVector3 position, SelectorLimits limits) { if (position.equals(pos1)) { return false; } - pos1 = position.toBlockVector(); + pos1 = position; region = new Polygonal2DRegion(region.getWorld()); region.addPoint(position); region.expandY(position.getBlockY()); @@ -140,11 +139,11 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { if (region.size() > 0) { - final List points = region.getPoints(); + final List points = region.getPoints(); - final BlockVector2D lastPoint = points.get(region.size() - 1); + final BlockVector2 lastPoint = points.get(region.size() - 1); if (lastPoint.getBlockX() == position.getBlockX() && lastPoint.getBlockZ() == position.getBlockZ()) { return false; } @@ -163,7 +162,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { player.print("Starting a new polygon at " + pos + "."); session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID())); @@ -172,7 +171,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { player.print("Added point #" + region.size() + " at " + pos + "."); session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea())); @@ -186,7 +185,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { if (pos1 == null) { throw new IncompleteRegionException(); } @@ -215,8 +214,8 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { @Override public void learnChanges() { - BlockVector2D pt = region.getPoints().get(0); - pos1 = new BlockVector(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ()); + BlockVector2 pt = region.getPoints().get(0); + pos1 = new BlockVector3(pt.getBlockX(), region.getMinimumPoint().getBlockY(), pt.getBlockZ()); } @Override @@ -251,7 +250,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { @Override public void describeCUI(LocalSession session, Actor player) { - final List points = region.getPoints(); + final List points = region.getPoints(); for (int id = 0; id < points.size(); id++) { session.dispatchCUIEvent(player, new SelectionPoint2DEvent(id, points.get(id), getArea())); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java index 8141748f3..6414c2cde 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/selector/SphereRegionSelector.java @@ -20,8 +20,9 @@ package com.sk89q.worldedit.regions.selector; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extension.platform.Actor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.RegionSelector; import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.world.World; @@ -56,9 +57,9 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { */ public SphereRegionSelector(RegionSelector oldSelector) { super(oldSelector); - final Vector radius = region.getRadius(); + final Vector3 radius = region.getRadius(); final double radiusScalar = Math.max(Math.max(radius.getX(), radius.getY()), radius.getZ()); - region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); + region.setRadius(new Vector3(radiusScalar, radiusScalar, radiusScalar)); } /** @@ -68,24 +69,24 @@ public class SphereRegionSelector extends EllipsoidRegionSelector { * @param center the center position * @param radius the radius */ - public SphereRegionSelector(@Nullable World world, Vector center, int radius) { - super(world, center, new Vector(radius, radius, radius)); + public SphereRegionSelector(@Nullable World world, BlockVector3 center, int radius) { + super(world, center, new Vector3(radius, radius, radius)); } @Override - public boolean selectSecondary(Vector position, SelectorLimits limits) { + public boolean selectSecondary(BlockVector3 position, SelectorLimits limits) { if (!started) { return false; } - final double radiusScalar = Math.ceil(position.distance(region.getCenter())); - region.setRadius(new Vector(radiusScalar, radiusScalar, radiusScalar)); + final double radiusScalar = Math.ceil(position.toVector3().distance(region.getCenter())); + region.setRadius(new Vector3(radiusScalar, radiusScalar, radiusScalar)); return true; } @Override - public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { if (isDefined()) { player.print("Radius set to " + region.getRadius().getX() + " (" + region.getArea() + ")."); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java index 942b55c6c..0ebdc7393 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryBiomeShape.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.regions.shape; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.FlatRegion; import com.sk89q.worldedit.regions.Region; @@ -48,8 +48,8 @@ public abstract class ArbitraryBiomeShape { this.extent = new CuboidRegion(extent.getWorld(), extent.getMinimumPoint(), extent.getMaximumPoint()); } - Vector2D min = extent.getMinimumPoint().toVector2D(); - Vector2D max = extent.getMaximumPoint().toVector2D(); + BlockVector2 min = extent.getMinimumPoint().toBlockVector2(); + BlockVector2 max = extent.getMaximumPoint().toBlockVector2(); cacheOffsetX = min.getBlockX() - 1; cacheOffsetZ = min.getBlockZ() - 1; @@ -60,7 +60,7 @@ public abstract class ArbitraryBiomeShape { cache = new BaseBiome[cacheSizeX * cacheSizeZ]; } - protected Iterable getExtent() { + protected Iterable getExtent() { return extent.asFlatRegion(); } @@ -130,7 +130,7 @@ public abstract class ArbitraryBiomeShape { public int generate(EditSession editSession, BaseBiome baseBiome, boolean hollow) { int affected = 0; - for (Vector2D position : getExtent()) { + for (BlockVector2 position : getExtent()) { int x = position.getBlockX(); int z = position.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java index 7629637d4..a361b528f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/ArbitraryShape.java @@ -19,10 +19,10 @@ package com.sk89q.worldedit.regions.shape; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -65,7 +65,7 @@ public abstract class ArbitraryShape { public int generate(EditSession editSession, Pattern pattern, boolean hollow) throws MaxChangedBlocksException { int affected = 0; - for (BlockVector position : getExtent()) { + for (BlockVector3 position : getExtent()) { int x = position.getBlockX(); int y = position.getBlockY(); int z = position.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/RegionShape.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/RegionShape.java index e8419cf00..08994c717 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/RegionShape.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/RegionShape.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.regions.shape; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -35,7 +35,7 @@ public class RegionShape extends ArbitraryShape { @Override protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) { - if (!this.extent.contains(new Vector(x, y, z))) { + if (!this.extent.contains(new BlockVector3(x, y, z))) { return null; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java index 8757235a3..5022c90af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/shape/WorldEditExpressionEnvironment.java @@ -19,30 +19,30 @@ package com.sk89q.worldedit.regions.shape; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.internal.expression.runtime.ExpressionEnvironment; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; public class WorldEditExpressionEnvironment implements ExpressionEnvironment { - private final Vector unit; - private final Vector zero2; - private Vector current = new Vector(); + private final Vector3 unit; + private final Vector3 zero2; + private Vector3 current = Vector3.ZERO; private EditSession editSession; - public WorldEditExpressionEnvironment(EditSession editSession, Vector unit, Vector zero) { + public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vector3 zero) { this.editSession = editSession; this.unit = unit; this.zero2 = zero.add(0.5, 0.5, 0.5); } - public BlockVector toWorld(double x, double y, double z) { + public BlockVector3 toWorld(double x, double y, double z) { // unscale, unoffset, round-nearest - return new Vector(x, y, z).multiply(unit).add(zero2).toBlockPoint(); + return new Vector3(x, y, z).multiply(unit).add(zero2).toBlockPoint(); } - public Vector toWorldRel(double x, double y, double z) { + public Vector3 toWorldRel(double x, double y, double z) { return current.add(x, y, z); } @@ -76,7 +76,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { return 0; } - public void setCurrentBlock(Vector current) { + public void setCurrentBlock(Vector3 current) { this.current = current; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java index e4a9ade5a..d50a277ac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/PasteBuilder.java @@ -21,13 +21,13 @@ package com.sk89q.worldedit.session; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.Transform; /** @@ -39,7 +39,7 @@ public class PasteBuilder { private final Transform transform; private final Extent targetExtent; - private Vector to = new Vector(); + private BlockVector3 to = BlockVector3.ZERO; private boolean ignoreAirBlocks; /** @@ -62,7 +62,7 @@ public class PasteBuilder { * @param to the target location * @return this builder instance */ - public PasteBuilder to(Vector to) { + public PasteBuilder to(BlockVector3 to) { this.to = to; return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java index 72ae6ef2b..9e37e4da0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/session/request/RequestSelection.java @@ -19,12 +19,11 @@ package com.sk89q.worldedit.session.request; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; @@ -64,17 +63,17 @@ public class RequestSelection implements Region { } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return getRegion().getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return getRegion().getMaximumPoint(); } @Override - public Vector getCenter() { + public Vector3 getCenter() { return getRegion().getCenter(); } @@ -99,32 +98,32 @@ public class RequestSelection implements Region { } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { getRegion().expand(changes); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { getRegion().contract(changes); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { getRegion().shift(change); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { return getRegion().contains(position); } @Override - public Set getChunks() { + public Set getChunks() { return getRegion().getChunks(); } @Override - public Set getChunkCubes() { + public Set getChunkCubes() { return getRegion().getChunkCubes(); } @@ -144,12 +143,12 @@ public class RequestSelection implements Region { } @Override - public List polygonize(int maxPoints) { + public List polygonize(int maxPoints) { return getRegion().polygonize(maxPoints); } @Override - public Iterator iterator() { + public Iterator iterator() { return getRegion().iterator(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java index 0907753a4..e62796bd7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Direction.java @@ -19,7 +19,8 @@ package com.sk89q.worldedit.util; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import javax.annotation.Nullable; @@ -28,32 +29,32 @@ import javax.annotation.Nullable; */ public enum Direction { - NORTH(new Vector(0, 0, -1), Flag.CARDINAL), - EAST(new Vector(1, 0, 0), Flag.CARDINAL), - SOUTH(new Vector(0, 0, 1), Flag.CARDINAL), - WEST(new Vector(-1, 0, 0), Flag.CARDINAL), + NORTH(new Vector3(0, 0, -1), Flag.CARDINAL), + EAST(new Vector3(1, 0, 0), Flag.CARDINAL), + SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL), + WEST(new Vector3(-1, 0, 0), Flag.CARDINAL), - UP(new Vector(0, 1, 0), Flag.UPRIGHT), - DOWN(new Vector(0, -1, 0), Flag.UPRIGHT), + UP(new Vector3(0, 1, 0), Flag.UPRIGHT), + DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT), - NORTHEAST(new Vector(1, 0, -1), Flag.ORDINAL), - NORTHWEST(new Vector(-1, 0, -1), Flag.ORDINAL), - SOUTHEAST(new Vector(1, 0, 1), Flag.ORDINAL), - SOUTHWEST(new Vector(-1, 0, 1), Flag.ORDINAL), + NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL), + NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL), + SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL), + SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL), - WEST_NORTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - WEST_SOUTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - NORTH_NORTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - NORTH_NORTHEAST(new Vector(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - EAST_NORTHEAST(new Vector(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - EAST_SOUTHEAST(new Vector(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - SOUTH_SOUTHEAST(new Vector(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), - SOUTH_SOUTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL); + WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL), + SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL); - private final Vector direction; + private final Vector3 direction; private final int flags; - Direction(Vector vector, int flags) { + Direction(Vector3 vector, int flags) { this.direction = vector.normalize(); this.flags = flags; } @@ -105,10 +106,19 @@ public enum Direction { * * @return the vector */ - public Vector toVector() { + public Vector3 toVector() { return direction; } + /** + * Get the vector. + * + * @return the vector + */ + public BlockVector3 toBlockVector() { + return direction.toBlockPoint(); + } + /** * Find the closest direction to the given direction vector. * @@ -117,9 +127,9 @@ public enum Direction { * @return the closest direction, or null if no direction can be returned */ @Nullable - public static Direction findClosest(Vector vector, int flags) { + public static Direction findClosest(Vector3 vector, int flags) { if ((flags & Flag.UPRIGHT) == 0) { - vector = vector.setY(0); + vector = vector.withY(0); } vector = vector.normalize(); @@ -141,7 +151,7 @@ public enum Direction { } /** - * Flags to use with {@link #findClosest(Vector, int)}. + * Flags to use with {@link #findClosest(Vector3, int)}. */ public static final class Flag { public static int CARDINAL = 0x1; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java index 9a768e33d..35552b8d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.util; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.Objects; @@ -31,15 +31,15 @@ import java.util.Objects; */ public final class LocatedBlock { - private final Vector location; + private final BlockVector3 location; private final BlockStateHolder block; - public LocatedBlock(Vector location, BlockStateHolder block) { + public LocatedBlock(BlockVector3 location, BlockStateHolder block) { this.location = checkNotNull(location); this.block = checkNotNull(block); } - public Vector getLocation() { + public BlockVector3 getLocation() { return location; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java index 521545b37..82186bbb1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/Location.java @@ -21,8 +21,8 @@ package com.sk89q.worldedit.util; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.Vector3; /** * Represents a location in a world with has a direction. @@ -37,7 +37,7 @@ import com.sk89q.worldedit.extent.Extent; public class Location { private final Extent extent; - private final Vector position; + private final Vector3 position; private final float pitch; private final float yaw; @@ -48,7 +48,7 @@ public class Location { * @param extent the extent */ public Location(Extent extent) { - this(extent, new Vector(), new Vector()); + this(extent, Vector3.ZERO, Vector3.ZERO); } /** @@ -61,7 +61,7 @@ public class Location { * @param z the Z coordinate */ public Location(Extent extent, double x, double y, double z) { - this(extent, new Vector(x, y, z), new Vector()); + this(extent, new Vector3(x, y, z), Vector3.ZERO); } /** @@ -71,8 +71,8 @@ public class Location { * @param extent the extent * @param position the position vector */ - public Location(Extent extent, Vector position) { - this(extent, position, new Vector()); + public Location(Extent extent, Vector3 position) { + this(extent, position, Vector3.ZERO); } /** @@ -85,8 +85,8 @@ public class Location { * @param z the Z coordinate * @param direction the direction vector */ - public Location(Extent extent, double x, double y, double z, Vector direction) { - this(extent, new Vector(x, y, z), direction); + public Location(Extent extent, double x, double y, double z, Vector3 direction) { + this(extent, new Vector3(x, y, z), direction); } /** @@ -101,7 +101,7 @@ public class Location { * @param pitch the pitch, in degrees */ public Location(Extent extent, double x, double y, double z, float yaw, float pitch) { - this(extent, new Vector(x, y, z), yaw, pitch); + this(extent, new Vector3(x, y, z), yaw, pitch); } /** @@ -112,8 +112,8 @@ public class Location { * @param position the position vector * @param direction the direction vector */ - public Location(Extent extent, Vector position, Vector direction) { - this(extent, position, direction.toYaw(), direction.toPitch()); + public Location(Extent extent, Vector3 position, Vector3 direction) { + this(extent, position, (float) direction.toYaw(), (float) direction.toPitch()); } /** @@ -125,7 +125,7 @@ public class Location { * @param yaw the yaw, in degrees * @param pitch the pitch, in degrees */ - public Location(Extent extent, Vector position, float yaw, float pitch) { + public Location(Extent extent, Vector3 position, float yaw, float pitch) { checkNotNull(extent); checkNotNull(position); this.extent = extent; @@ -207,11 +207,11 @@ public class Location { * * @return the direction vector */ - public Vector getDirection() { + public Vector3 getDirection() { double yaw = Math.toRadians(this.getYaw()); double pitch = Math.toRadians(this.getPitch()); double xz = Math.cos(pitch); - return new Vector( + return new Vector3( -xz * Math.sin(yaw), -Math.sin(pitch), xz * Math.cos(yaw)); @@ -232,16 +232,16 @@ public class Location { * @param direction the new direction * @return the new instance */ - public Location setDirection(Vector direction) { - return new Location(extent, position, direction.toYaw(), direction.toPitch()); + public Location setDirection(Vector3 direction) { + return new Location(extent, position, (float) direction.toYaw(), (float) direction.toPitch()); } /** - * Get a {@link Vector} form of this location's position. + * Get a {@link Vector3} form of this location's position. * * @return a vector */ - public Vector toVector() { + public Vector3 toVector() { return position; } @@ -260,7 +260,7 @@ public class Location { * @return the rounded X component */ public int getBlockX() { - return position.getBlockX(); + return (int) Math.floor(position.getX()); } /** @@ -271,18 +271,7 @@ public class Location { * @return a new immutable instance */ public Location setX(double x) { - return new Location(extent, position.setX(x), yaw, pitch); - } - - /** - * Return a copy of this object with the X component of the new object - * set to the given value. - * - * @param x the new value for the X component - * @return a new immutable instance - */ - public Location setX(int x) { - return new Location(extent, position.setX(x), yaw, pitch); + return new Location(extent, position.withX(x), yaw, pitch); } /** @@ -300,7 +289,7 @@ public class Location { * @return the rounded Y component */ public int getBlockY() { - return position.getBlockY(); + return (int) Math.floor(position.getY()); } /** @@ -311,18 +300,7 @@ public class Location { * @return a new immutable instance */ public Location setY(double y) { - return new Location(extent, position.setY(y), yaw, pitch); - } - - /** - * Return a copy of this object with the Y component of the new object - * set to the given value. - * - * @param y the new value for the Y component - * @return a new immutable instance - */ - public Location setY(int y) { - return new Location(extent, position.setY(y), yaw, pitch); + return new Location(extent, position.withY(y), yaw, pitch); } /** @@ -340,7 +318,7 @@ public class Location { * @return the rounded Z component */ public int getBlockZ() { - return position.getBlockZ(); + return (int) Math.floor(position.getZ()); } /** @@ -351,18 +329,7 @@ public class Location { * @return a new immutable instance */ public Location setZ(double z) { - return new Location(extent, position.setZ(z), yaw, pitch); - } - - /** - * Return a copy of this object with the Z component of the new object - * set to the given value. - * - * @param z the new value for the Y component - * @return a new immutable instance - */ - public Location setZ(int z) { - return new Location(extent, position.setZ(z), yaw, pitch); + return new Location(extent, position.withZ(z), yaw, pitch); } /** @@ -371,7 +338,7 @@ public class Location { * @param position The new position * @return a new immutable instance */ - public Location setPosition(Vector position) { + public Location setPosition(Vector3 position) { return new Location(extent, position, yaw, pitch); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java index be654ec17..1c2a97b3f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java @@ -19,8 +19,9 @@ package com.sk89q.worldedit.util; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; /** @@ -35,10 +36,10 @@ public class TargetBlock { private World world; private int maxDistance; private double checkDistance, curDistance; - private Vector targetPos = new Vector(); - private Vector targetPosDouble = new Vector(); - private Vector prevPos = new Vector(); - private Vector offset = new Vector(); + private BlockVector3 targetPos = BlockVector3.ZERO; + private Vector3 targetPosDouble = Vector3.ZERO; + private BlockVector3 prevPos = BlockVector3.ZERO; + private Vector3 offset = Vector3.ZERO; /** * Constructor requiring a player, uses default values @@ -73,7 +74,7 @@ public class TargetBlock { * @param viewHeight where the view is positioned in y-axis * @param checkDistance how often to check for blocks, the smaller the more precise */ - private void setValues(Vector loc, double xRotation, double yRotation, int maxDistance, double viewHeight, double checkDistance) { + private void setValues(Vector3 loc, double xRotation, double yRotation, int maxDistance, double viewHeight, double checkDistance) { this.maxDistance = maxDistance; this.checkDistance = checkDistance; this.curDistance = 0; @@ -82,7 +83,7 @@ public class TargetBlock { double h = (checkDistance * Math.cos(Math.toRadians(yRotation))); - offset = new Vector((h * Math.cos(Math.toRadians(xRotation))), + offset = new Vector3((h * Math.cos(Math.toRadians(xRotation))), (checkDistance * Math.sin(Math.toRadians(yRotation))), (h * Math.sin(Math.toRadians(xRotation)))); @@ -101,7 +102,7 @@ public class TargetBlock { boolean searchForLastBlock = true; Location lastBlock = null; while (getNextBlock() != null) { - if (world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) { + if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) { if (searchForLastBlock) { lastBlock = getCurrentBlock(); if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { @@ -123,7 +124,7 @@ public class TargetBlock { * @return Block */ public Location getTargetBlock() { - while (getNextBlock() != null && world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) ; + while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ; return getCurrentBlock(); } @@ -134,7 +135,7 @@ public class TargetBlock { * @return Block */ public Location getSolidTargetBlock() { - while (getNextBlock() != null && !world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isMovementBlocker()) ; + while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ; return getCurrentBlock(); } @@ -161,7 +162,7 @@ public class TargetBlock { return null; } - return new Location(world, targetPos); + return new Location(world, targetPos.toVector3()); } /** @@ -173,7 +174,7 @@ public class TargetBlock { if (curDistance > maxDistance) { return null; } else { - return new Location(world, targetPos); + return new Location(world, targetPos.toVector3()); } } @@ -183,7 +184,7 @@ public class TargetBlock { * @return block position */ public Location getPreviousBlock() { - return new Location(world, prevPos); + return new Location(world, prevPos.toVector3()); } public Location getAnyTargetBlockFace() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java index 58f32b480..7532f947f 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java @@ -22,7 +22,7 @@ package com.sk89q.worldedit.util; import com.google.common.collect.Sets; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -49,7 +49,7 @@ public class TreeGenerator { MEGA_REDWOOD("Large spruce tree", "largespruce", "megaredwood"), RANDOM_REDWOOD("Random spruce tree", "randspruce", "randredwood", "randomredwood", "anyredwood") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { TreeType[] choices = { REDWOOD, TALL_REDWOOD, MEGA_REDWOOD }; return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } @@ -58,7 +58,7 @@ public class TreeGenerator { TALL_BIRCH("Tall birch tree", "tallbirch"), RANDOM_BIRCH("Random birch tree", "randbirch", "randombirch") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { TreeType[] choices = { BIRCH, TALL_BIRCH }; return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } @@ -67,13 +67,13 @@ public class TreeGenerator { SMALL_JUNGLE("Small jungle tree", "shortjungle", "smalljungle"), SHORT_JUNGLE("Short jungle tree") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { return SMALL_JUNGLE.generate(editSession, pos); } }, RANDOM_JUNGLE("Random jungle tree", "randjungle", "randomjungle") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { TreeType[] choices = { JUNGLE, SMALL_JUNGLE }; return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } @@ -83,7 +83,7 @@ public class TreeGenerator { BROWN_MUSHROOM("Brown mushroom", "brownmushroom", "browngiantmushroom"), RANDOM_MUSHROOM("Random mushroom", "randmushroom", "randommushroom") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { TreeType[] choices = { RED_MUSHROOM, BROWN_MUSHROOM }; return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } @@ -93,14 +93,14 @@ public class TreeGenerator { DARK_OAK("Dark oak tree", "darkoak"), PINE("Pine tree", "pine") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { makePineTree(editSession, pos); return true; } }, RANDOM("Random tree", "rand", "random") { @Override - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { TreeType[] choices = TreeType.values(); return choices[TreeGenerator.RANDOM.nextInt(choices.length)].generate(editSession, pos); } @@ -139,7 +139,7 @@ public class TreeGenerator { return Collections.unmodifiableSet(primaryAliases); } - public boolean generate(EditSession editSession, Vector pos) throws MaxChangedBlocksException { + public boolean generate(EditSession editSession, BlockVector3 pos) throws MaxChangedBlocksException { return editSession.getWorld().generateTree(this, editSession, pos); } @@ -174,7 +174,7 @@ public class TreeGenerator { * * @param basePosition the base position */ - private static void makePineTree(EditSession editSession, Vector basePosition) + private static void makePineTree(EditSession editSession, BlockVector3 basePosition) throws MaxChangedBlocksException { int trunkHeight = (int) Math.floor(Math.random() * 2) + 3; int height = (int) Math.floor(Math.random() * 5) + 8; @@ -250,7 +250,7 @@ public class TreeGenerator { * @return whether a block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - private static boolean setChanceBlockIfAir(EditSession session, Vector position, BlockStateHolder block, double probability) + private static boolean setChanceBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block, double probability) throws MaxChangedBlocksException { return Math.random() <= probability && setBlockIfAir(session, position, block); } @@ -263,7 +263,7 @@ public class TreeGenerator { * @return if block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { + private static boolean setBlockIfAir(EditSession session, BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java index 7c821b0f3..4f303acd6 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.util.collection; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.LocatedBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -51,7 +51,7 @@ public class LocatedBlockList implements Iterable { list.add(setBlockCall); } - public void add(Vector location, BlockStateHolder block) { + public void add(BlockVector3 location, BlockStateHolder block) { add(new LocatedBlock(location, block)); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java index 8d6d4dd2b..5d73c68ea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/GsonUtil.java @@ -21,7 +21,7 @@ package com.sk89q.worldedit.util.gson; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; /** * Utility methods for Google's GSON library. @@ -38,7 +38,7 @@ public final class GsonUtil { */ public static GsonBuilder createBuilder() { GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter()); + gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); return gsonBuilder; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/VectorAdapter.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/VectorAdapter.java index a1e876dfe..4524e64f9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/VectorAdapter.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/gson/VectorAdapter.java @@ -24,17 +24,17 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonDeserializer; import com.google.gson.JsonElement; import com.google.gson.JsonParseException; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import java.lang.reflect.Type; /** * Deserializes {@code Vector}s for GSON. */ -public class VectorAdapter implements JsonDeserializer { +public class VectorAdapter implements JsonDeserializer { @Override - public Vector deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { + public Vector3 deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { JsonArray jsonArray = json.getAsJsonArray(); if (jsonArray.size() != 3) { throw new JsonParseException("Expected array of 3 length for Vector"); @@ -44,6 +44,6 @@ public class VectorAdapter implements JsonDeserializer { double y = jsonArray.get(1).getAsDouble(); double z = jsonArray.get(2).getAsDouble(); - return new Vector(x, y, z); + return new Vector3(x, y, z); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java index 4007125f6..124187fdd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java @@ -19,8 +19,6 @@ package com.sk89q.worldedit.world; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; @@ -28,6 +26,9 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -46,12 +47,12 @@ public abstract class AbstractWorld implements World { private int taskId = -1; @Override - public boolean useItem(Vector position, BaseItem item, Direction face) { + public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { return false; } @Override - public final boolean setBlock(Vector pt, BlockStateHolder block) throws WorldEditException { + public final boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException { return setBlock(pt, block, true); } @@ -66,31 +67,31 @@ public abstract class AbstractWorld implements World { } @Override - public void dropItem(Vector pt, BaseItemStack item, int times) { + public void dropItem(Vector3 pt, BaseItemStack item, int times) { for (int i = 0; i < times; ++i) { dropItem(pt, item); } } @Override - public void checkLoadedChunk(Vector pt) { + public void checkLoadedChunk(BlockVector3 pt) { } @Override - public void fixAfterFastMode(Iterable chunks) { + public void fixAfterFastMode(Iterable chunks) { } @Override - public void fixLighting(Iterable chunks) { + public void fixLighting(Iterable chunks) { } @Override - public boolean playEffect(Vector position, int type, int data) { + public boolean playEffect(Vector3 position, int type, int data) { return false; } @Override - public boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority) { + public boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) { if (taskId == -1) { taskId = server.schedule(0, 1, () -> { int max = Math.max(1, Math.min(30, effectQueue.size() / 3)); @@ -106,19 +107,19 @@ public abstract class AbstractWorld implements World { return false; } - effectQueue.offer(new QueuedEffect(position, blockType, priority)); + effectQueue.offer(new QueuedEffect(position.toVector3(), blockType, priority)); return true; } @Override - public Vector getMinimumPoint() { - return new Vector(-30000000, 0, -30000000); + public BlockVector3 getMinimumPoint() { + return new BlockVector3(-30000000, 0, -30000000); } @Override - public Vector getMaximumPoint() { - return new Vector(30000000, 255, 30000000); + public BlockVector3 getMaximumPoint() { + return new BlockVector3(30000000, 255, 30000000); } @Override @@ -127,11 +128,11 @@ public abstract class AbstractWorld implements World { } private class QueuedEffect implements Comparable { - private final Vector position; + private final Vector3 position; private final BlockType blockType; private final double priority; - private QueuedEffect(Vector position, BlockType blockType, double priority) { + private QueuedEffect(Vector3 position, BlockType blockType, double priority) { this.position = position; this.blockType = blockType; this.priority = priority; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java index 4542d19e2..43ee77e39 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/NullWorld.java @@ -21,12 +21,13 @@ package com.sk89q.worldedit.world; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.TreeGenerator.TreeType; @@ -59,36 +60,36 @@ public class NullWorld extends AbstractWorld { } @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { return false; } @Override - public int getBlockLightLevel(Vector position) { + public int getBlockLightLevel(BlockVector3 position) { return 0; } @Override - public boolean clearContainerBlockContents(Vector position) { + public boolean clearContainerBlockContents(BlockVector3 position) { return false; } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return null; } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return false; } @Override - public void dropItem(Vector position, BaseItemStack item) { + public void dropItem(Vector3 position, BaseItemStack item) { } @Override - public void simulateBlockMine(Vector position) { + public void simulateBlockMine(BlockVector3 position) { } @Override @@ -97,7 +98,7 @@ public class NullWorld extends AbstractWorld { } @Override - public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { + public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { return false; } @@ -120,12 +121,12 @@ public class NullWorld extends AbstractWorld { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { return getBlock(position).toBaseBlock(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java index ed0234e6c..3e7bbf88c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java @@ -19,16 +19,17 @@ package com.sk89q.worldedit.world; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.TreeGenerator; @@ -72,10 +73,10 @@ public interface World extends Extent { * @param face The face * @return Whether it succeeded */ - boolean useItem(Vector position, BaseItem item, Direction face); + boolean useItem(BlockVector3 position, BaseItem item, Direction face); /** - * Similar to {@link Extent#setBlock(Vector, BlockStateHolder)} but a + * Similar to {@link Extent#setBlock(BlockVector3, BlockStateHolder)} but a * {@code notifyAndLight} parameter indicates whether adjacent blocks * should be notified that changes have been made and lighting operations * should be executed. @@ -92,7 +93,7 @@ public interface World extends Extent { * @param notifyAndLight true to to notify and light * @return true if the block was successfully set (return value may not be accurate) */ - boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException; + boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException; /** * Get the light level at the given block. @@ -100,7 +101,7 @@ public interface World extends Extent { * @param position the position * @return the light level (0-15) */ - int getBlockLightLevel(Vector position); + int getBlockLightLevel(BlockVector3 position); /** * Clear a chest's contents. @@ -108,7 +109,7 @@ public interface World extends Extent { * @param position the position * @return true if the container was cleared */ - boolean clearContainerBlockContents(Vector position); + boolean clearContainerBlockContents(BlockVector3 position); /** * Drop an item at the given position. @@ -117,23 +118,23 @@ public interface World extends Extent { * @param item the item to drop * @param count the number of individual stacks to drop (number of item entities) */ - void dropItem(Vector position, BaseItemStack item, int count); + void dropItem(Vector3 position, BaseItemStack item, int count); /** * Drop one stack of the item at the given position. * * @param position the position * @param item the item to drop - * @see #dropItem(Vector, BaseItemStack, int) shortcut method to specify the number of stacks + * @see #dropItem(Vector3, BaseItemStack, int) shortcut method to specify the number of stacks */ - void dropItem(Vector position, BaseItemStack item); + void dropItem(Vector3 position, BaseItemStack item); /** * Simulate a block being mined at the given position. * * @param position the position */ - void simulateBlockMine(Vector position); + void simulateBlockMine(BlockVector3 position); /** * Regenerate an area. @@ -153,19 +154,19 @@ public interface World extends Extent { * @return true if generation was successful * @throws MaxChangedBlocksException thrown if too many blocks were changed */ - boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException; + boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException; /** * Load the chunk at the given position if it isn't loaded. * * @param position the position */ - void checkLoadedChunk(Vector position); + void checkLoadedChunk(BlockVector3 position); /** * Fix the given chunks after fast mode was used. * - *

Fast mode makes calls to {@link #setBlock(Vector, BlockStateHolder, boolean)} + *

Fast mode makes calls to {@link #setBlock(BlockVector3, BlockStateHolder, boolean)} * with {@code false} for the {@code notifyAndLight} parameter, which * may causes lighting errors to accumulate. Use of this method, if * it is implemented by the underlying world, corrects those lighting @@ -173,14 +174,14 @@ public interface World extends Extent { * * @param chunks a list of chunk coordinates to fix */ - void fixAfterFastMode(Iterable chunks); + void fixAfterFastMode(Iterable chunks); /** * Relight the given chunks if possible. * * @param chunks a list of chunk coordinates to fix */ - void fixLighting(Iterable chunks); + void fixLighting(Iterable chunks); /** * Play the given effect. @@ -190,7 +191,7 @@ public interface World extends Extent { * @param data the effect data * @return true if the effect was played */ - boolean playEffect(Vector position, int type, int data); + boolean playEffect(Vector3 position, int type, int data); /** * Queue a block break effect. @@ -201,7 +202,7 @@ public interface World extends Extent { * @param priority the priority * @return true if the effect was played */ - boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority); + boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority); /** * Gets the weather type of the world. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java index 6b1265854..65f76cd41 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk.java @@ -26,9 +26,8 @@ import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -52,7 +51,7 @@ public class AnvilChunk implements Chunk { private int rootX; private int rootZ; - private Map> tileEntities; + private Map> tileEntities; /** * Construct the chunk with a compound tag. @@ -119,10 +118,10 @@ public class AnvilChunk implements Chunk { } } - private int getBlockID(Vector position) throws DataException { - int x = position.getBlockX() - rootX * 16; - int y = position.getBlockY(); - int z = position.getBlockZ() - rootZ * 16; + private int getBlockID(BlockVector3 position) throws DataException { + int x = position.getX() - rootX * 16; + int y = position.getY(); + int z = position.getZ() - rootZ * 16; int section = y >> 4; if (section < 0 || section >= blocks.length) { @@ -152,10 +151,10 @@ public class AnvilChunk implements Chunk { } } - private int getBlockData(Vector position) throws DataException { - int x = position.getBlockX() - rootX * 16; - int y = position.getBlockY(); - int z = position.getBlockZ() - rootZ * 16; + private int getBlockData(BlockVector3 position) throws DataException { + int x = position.getX() - rootX * 16; + int y = position.getY(); + int z = position.getZ() - rootZ * 16; int section = y >> 4; int yIndex = y & 0x0F; @@ -225,7 +224,7 @@ public class AnvilChunk implements Chunk { values.put(entry.getKey(), entry.getValue()); } - BlockVector vec = new BlockVector(x, y, z); + BlockVector3 vec = new BlockVector3(x, y, z); tileEntities.put(vec, values); } } @@ -240,12 +239,12 @@ public class AnvilChunk implements Chunk { * @throws DataException thrown if there is a data error */ @Nullable - private CompoundTag getBlockTileEntity(Vector position) throws DataException { + private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException { if (tileEntities == null) { populateTileEntities(); } - Map values = tileEntities.get(new BlockVector(position)); + Map values = tileEntities.get(position); if (values == null) { return null; } @@ -254,7 +253,7 @@ public class AnvilChunk implements Chunk { } @Override - public BlockStateHolder getBlock(Vector position) throws DataException { + public BlockStateHolder getBlock(BlockVector3 position) throws DataException { int id = getBlockID(position); int data = getBlockData(position); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java index 025390c66..cda59cbda 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/AnvilChunk13.java @@ -26,8 +26,7 @@ import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.LongArrayTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BlockState; @@ -52,7 +51,7 @@ public class AnvilChunk13 implements Chunk { private int rootX; private int rootZ; - private Map> tileEntities; + private Map> tileEntities; /** * Construct the chunk with a compound tag. @@ -201,7 +200,7 @@ public class AnvilChunk13 implements Chunk { values.put(entry.getKey(), entry.getValue()); } - BlockVector vec = new BlockVector(x, y, z); + BlockVector3 vec = new BlockVector3(x, y, z); tileEntities.put(vec, values); } } @@ -216,12 +215,12 @@ public class AnvilChunk13 implements Chunk { * @throws DataException thrown if there is a data error */ @Nullable - private CompoundTag getBlockTileEntity(Vector position) throws DataException { + private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException { if (tileEntities == null) { populateTileEntities(); } - Map values = tileEntities.get(new BlockVector(position)); + Map values = tileEntities.get(position); if (values == null) { return null; } @@ -230,10 +229,10 @@ public class AnvilChunk13 implements Chunk { } @Override - public BlockStateHolder getBlock(Vector position) throws DataException { - int x = position.getBlockX() - rootX * 16; - int y = position.getBlockY(); - int z = position.getBlockZ() - rootZ * 16; + public BlockStateHolder getBlock(BlockVector3 position) throws DataException { + int x = position.getX() - rootX * 16; + int y = position.getY(); + int z = position.getZ() - rootZ * 16; int section = y >> 4; int yIndex = y & 0x0F; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java index 2f261570e..7a1ef7612 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/Chunk.java @@ -19,7 +19,7 @@ package com.sk89q.worldedit.world.chunk; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -35,6 +35,6 @@ public interface Chunk { * @return block the block * @throws DataException thrown on data error */ - BlockStateHolder getBlock(Vector position) throws DataException; + BlockStateHolder getBlock(BlockVector3 position) throws DataException; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java index c6f983ced..4a3336e86 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java @@ -25,9 +25,8 @@ import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -51,7 +50,7 @@ public class OldChunk implements Chunk { private int rootX; private int rootZ; - private Map> tileEntities; + private Map> tileEntities; /** * Construct the chunk with a compound tag. @@ -127,7 +126,7 @@ public class OldChunk implements Chunk { values.put(entry.getKey(), entry.getValue()); } - BlockVector vec = new BlockVector(x, y, z); + BlockVector3 vec = new BlockVector3(x, y, z); tileEntities.put(vec, values); } } @@ -141,12 +140,12 @@ public class OldChunk implements Chunk { * @return a tag * @throws DataException */ - private CompoundTag getBlockTileEntity(Vector position) throws DataException { + private CompoundTag getBlockTileEntity(BlockVector3 position) throws DataException { if (tileEntities == null) { populateTileEntities(); } - Map values = tileEntities.get(new BlockVector(position)); + Map values = tileEntities.get(position); if (values == null) { return null; } @@ -154,13 +153,13 @@ public class OldChunk implements Chunk { } @Override - public BlockStateHolder getBlock(Vector position) throws DataException { - if(position.getBlockY() >= 128) BlockTypes.VOID_AIR.getDefaultState().toBaseBlock(); + public BlockStateHolder getBlock(BlockVector3 position) throws DataException { + if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock(); int id, dataVal; - int x = position.getBlockX() - rootX * 16; - int y = position.getBlockY(); - int z = position.getBlockZ() - rootZ * 16; + int x = position.getX() - rootX * 16; + int y = position.getY(); + int z = position.getZ() - rootZ * 16; int index = y + (z * 128 + (x * 128 * 16)); try { id = blocks[index]; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java index afe73c368..b98238dc0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledBlockData.java @@ -23,7 +23,7 @@ import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; import java.io.IOException; @@ -73,7 +73,7 @@ public class BundledBlockData { */ private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter()); + gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.create(); URL url = BundledBlockData.class.getResource("blocks.json"); if (url == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java index 00cafb244..2867b2e56 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BundledItemData.java @@ -23,7 +23,7 @@ import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; import java.io.IOException; @@ -73,7 +73,7 @@ public class BundledItemData { */ private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter()); + gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.create(); URL url = BundledItemData.class.getResource("items.json"); if (url == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java index 78bc48131..5ea6044f3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/LegacyMapper.java @@ -25,9 +25,9 @@ import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.ParserContext; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.gson.VectorAdapter; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemType; @@ -71,7 +71,7 @@ public class LegacyMapper { */ private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); - gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter()); + gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); Gson gson = gsonBuilder.disableHtmlEscaping().create(); URL url = LegacyMapper.class.getResource("legacy.json"); if (url == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java index a7ef7ca9d..5b6691b85 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/snapshot/SnapshotRestore.java @@ -19,12 +19,10 @@ package com.sk89q.worldedit.world.snapshot; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; -import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.DataException; @@ -43,11 +41,11 @@ import java.util.Map; */ public class SnapshotRestore { - private final Map> neededChunks = new LinkedHashMap<>(); + private final Map> neededChunks = new LinkedHashMap<>(); private final ChunkStore chunkStore; private final EditSession editSession; - private ArrayList missingChunks; - private ArrayList errorChunks; + private ArrayList missingChunks; + private ArrayList errorChunks; private String lastErrorMessage; /** @@ -74,15 +72,15 @@ public class SnapshotRestore { * @param region The {@link Region} to iterate */ private void findNeededCuboidChunks(Region region) { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); // First, we need to group points by chunk so that we only need // to keep one chunk in memory at any given moment for (int x = min.getBlockX(); x <= max.getBlockX(); ++x) { for (int y = min.getBlockY(); y <= max.getBlockY(); ++y) { for (int z = min.getBlockZ(); z <= max.getBlockZ(); ++z) { - Vector pos = new Vector(x, y, z); + BlockVector3 pos = new BlockVector3(x, y, z); checkAndAddBlock(pos); } } @@ -97,16 +95,16 @@ public class SnapshotRestore { private void findNeededChunks(Region region) { // First, we need to group points by chunk so that we only need // to keep one chunk in memory at any given moment - for (Vector pos : region) { + for (BlockVector3 pos : region) { checkAndAddBlock(pos); } } - private void checkAndAddBlock(Vector pos) { + private void checkAndAddBlock(BlockVector3 pos) { if (editSession.getMask() != null && !editSession.getMask().test(pos)) return; - BlockVector2D chunkPos = ChunkStore.toChunk(pos); + BlockVector2 chunkPos = ChunkStore.toChunk(pos); // Unidentified chunk if (!neededChunks.containsKey(chunkPos)) { @@ -136,8 +134,8 @@ public class SnapshotRestore { errorChunks = new ArrayList<>(); // Now let's start restoring! - for (Map.Entry> entry : neededChunks.entrySet()) { - BlockVector2D chunkPos = entry.getKey(); + for (Map.Entry> entry : neededChunks.entrySet()) { + BlockVector2 chunkPos = entry.getKey(); Chunk chunk; try { @@ -145,7 +143,7 @@ public class SnapshotRestore { // Good, the chunk could be at least loaded // Now just copy blocks! - for (Vector pos : entry.getValue()) { + for (BlockVector3 pos : entry.getValue()) { try { editSession.setBlock(pos, chunk.getBlock(pos)); } catch (DataException e) { @@ -167,7 +165,7 @@ public class SnapshotRestore { * * @return a list of coordinates */ - public List getMissingChunks() { + public List getMissingChunks() { return missingChunks; } @@ -177,7 +175,7 @@ public class SnapshotRestore { * * @return a list of coordinates */ - public List getErrorChunks() { + public List getErrorChunks() { return errorChunks; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java index a2d5da198..07a4e06a5 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/ChunkStore.java @@ -21,9 +21,8 @@ package com.sk89q.worldedit.world.storage; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.chunk.AnvilChunk; @@ -57,11 +56,8 @@ public abstract class ChunkStore implements Closeable { * @param position the position * @return chunk coordinates */ - public static BlockVector2D toChunk(Vector position) { - int chunkX = (int) Math.floor(position.getBlockX() / 16.0); - int chunkZ = (int) Math.floor(position.getBlockZ() / 16.0); - - return new BlockVector2D(chunkX, chunkZ); + public static BlockVector2 toChunk(BlockVector3 position) { + return new BlockVector2(position.getX() >> CHUNK_SHIFTS, position.getZ() >> CHUNK_SHIFTS); } /** @@ -72,7 +68,7 @@ public abstract class ChunkStore implements Closeable { * @throws DataException thrown on data error * @throws IOException thrown on I/O error */ - public abstract CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException; + public abstract CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException; /** * Get a chunk at a location. @@ -83,7 +79,7 @@ public abstract class ChunkStore implements Closeable { * @throws DataException thrown on data error * @throws IOException thrown on I/O error */ - public Chunk getChunk(Vector2D position, World world) throws DataException, IOException { + public Chunk getChunk(BlockVector2 position, World world) throws DataException, IOException { CompoundTag rootTag = getChunkTag(position, world); Map children = rootTag.getValue(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/LegacyChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/LegacyChunkStore.java index 0bdf4c6da..b3b5728fe 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/LegacyChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/LegacyChunkStore.java @@ -22,14 +22,13 @@ package com.sk89q.worldedit.world.storage; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.util.Map; import java.util.zip.GZIPInputStream; /** @@ -46,7 +45,7 @@ public abstract class LegacyChunkStore extends ChunkStore { * @param separator folder separator character * @return pathname */ - public static String getFilename(Vector2D position, String separator) { + public static String getFilename(BlockVector2 position, String separator) { int x = position.getBlockX(); int z = position.getBlockZ(); @@ -65,12 +64,12 @@ public abstract class LegacyChunkStore extends ChunkStore { * @param position chunk position * @return pathname */ - public static String getFilename(Vector2D position) { + public static String getFilename(BlockVector2 position) { return getFilename(position, File.separator); } @Override - public CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException { + public CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException { int x = position.getBlockX(); int z = position.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java index 7959d8a37..5c4eabfd9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionChunkStore.java @@ -22,13 +22,12 @@ package com.sk89q.worldedit.world.storage; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import java.io.IOException; import java.io.InputStream; -import java.util.Map; public abstract class McRegionChunkStore extends ChunkStore { @@ -41,14 +40,14 @@ public abstract class McRegionChunkStore extends ChunkStore { * @param position chunk position * @return the filename */ - public static String getFilename(Vector2D position) { + public static String getFilename(BlockVector2 position) { int x = position.getBlockX(); int z = position.getBlockZ(); return "r." + (x >> 5) + "." + (z >> 5) + ".mca"; } - protected McRegionReader getReader(Vector2D pos, String worldname) throws DataException, IOException { + protected McRegionReader getReader(BlockVector2 pos, String worldname) throws DataException, IOException { String filename = getFilename(pos); if (curFilename != null) { if (curFilename.equals(filename)) { @@ -67,7 +66,7 @@ public abstract class McRegionChunkStore extends ChunkStore { } @Override - public CompoundTag getChunkTag(Vector2D position, World world) throws DataException, IOException { + public CompoundTag getChunkTag(BlockVector2 position, World world) throws DataException, IOException { McRegionReader reader = getReader(position, world.getName()); InputStream stream = reader.getChunkInputStream(position); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionReader.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionReader.java index 6f4509267..e991216ae 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionReader.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/McRegionReader.java @@ -55,7 +55,7 @@ package com.sk89q.worldedit.world.storage; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.util.io.ForwardSeekableInputStream; import com.sk89q.worldedit.world.DataException; @@ -120,7 +120,7 @@ public class McRegionReader { * @throws IOException * @throws DataException */ - public synchronized InputStream getChunkInputStream(Vector2D position) throws IOException, DataException { + public synchronized InputStream getChunkInputStream(BlockVector2 position) throws IOException, DataException { int x = position.getBlockX() & 31; int z = position.getBlockZ() & 31; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/MissingChunkException.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/MissingChunkException.java index 0ed5c0554..9d1d7c3a1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/MissingChunkException.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/storage/MissingChunkException.java @@ -19,20 +19,20 @@ package com.sk89q.worldedit.world.storage; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.Vector2; /** * Thrown if a chunk is missing. */ public class MissingChunkException extends ChunkStoreException { - private Vector2D position; + private Vector2 position; public MissingChunkException() { super(); } - public MissingChunkException(Vector2D position) { + public MissingChunkException(Vector2 position) { super(); this.position = position; } @@ -42,7 +42,7 @@ public class MissingChunkException extends ChunkStoreException { * * @return a chunk position */ - public Vector2D getChunkPosition() { + public Vector2 getChunkPosition() { return position; } diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/VectorTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/VectorTest.java deleted file mode 100644 index 51d50f93b..000000000 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/VectorTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * 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 . - */ - -package com.sk89q.worldedit; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class VectorTest { - @Test - public void collinearityTest() { - assertCollinear(0,0,0, 0,0,0); - - assertCollinear(0,0,0, 1,0,0); - assertCollinear(0,0,0, 0,1,0); - assertCollinear(0,0,0, 0,0,1); - - assertCollinear(1,0,0, 0,0,0); - assertCollinear(0,1,0, 0,0,0); - assertCollinear(0,0,1, 0,0,0); - - assertCollinear(1,0,0, 2,0,0); - assertNotCollinear(1,0,0, 0,1,0); - - assertNotCollinear(2,2,2, 8,4,4); - assertCollinear(8,2,2, 8,2,2); - assertNotCollinear(4,2,4, 4,4,4); - assertNotCollinear(1,1,2, 4,8,2); - assertNotCollinear(4,1,8, 1,4,4); - assertCollinear(2,4,2, 1,2,1); - assertNotCollinear(2,2,4, 1,2,1); - assertNotCollinear(4,4,1, 4,4,4); - assertNotCollinear(4,1,4, 1,8,2); - assertCollinear(8,8,4, 4,4,2); - assertNotCollinear(2,1,8, 1,1,2); - assertNotCollinear(8,1,2, 2,1,2); - assertNotCollinear(4,4,8, 2,2,8); - assertNotCollinear(8,4,8, 1,4,8); - assertNotCollinear(2,2,2, 1,4,2); - assertNotCollinear(1,1,2, 8,8,2); - assertNotCollinear(4,4,8, 8,4,4); - assertNotCollinear(1,8,2, 4,4,4); - assertNotCollinear(8,4,2, 1,2,2); - assertNotCollinear(1,8,2, 8,1,4); - assertNotCollinear(4,8,1, 4,8,8); - assertNotCollinear(8,1,8, 8,8,8); - assertNotCollinear(8,4,1, 4,2,2); - assertNotCollinear(4,8,1, 4,2,1); - assertNotCollinear(8,8,1, 2,4,2); - assertCollinear(8,1,4, 8,1,4); - assertNotCollinear(4,1,1, 2,4,8); - assertNotCollinear(4,2,8, 1,4,1); - assertNotCollinear(1,8,2, 1,8,1); - assertNotCollinear(1,1,2, 4,2,2); - - assertCollinear(0,0, 0,0); - - assertCollinear(0,0, 1,0); - assertCollinear(0,0, 0,1); - assertCollinear(0,0, 0,0); - - assertCollinear(1,0, 0,0); - assertCollinear(0,1, 0,0); - assertCollinear(0,0, 0,0); - - assertCollinear(1,0, 2,0); - assertNotCollinear(1,0, 0,1); - - assertNotCollinear(2,2, 8,4); - assertCollinear(8,2, 8,2); - assertNotCollinear(4,2, 4,4); - assertNotCollinear(1,1, 4,8); - assertNotCollinear(4,1, 1,4); - assertCollinear(2,4, 1,2); - assertNotCollinear(2,2, 1,2); - assertCollinear(4,4, 4,4); - assertNotCollinear(4,1, 1,8); - assertCollinear(8,8, 4,4); - assertNotCollinear(2,1, 1,1); - assertNotCollinear(8,1, 2,1); - assertCollinear(4,4, 2,2); - assertNotCollinear(8,4, 1,4); - assertNotCollinear(2,2, 1,4); - assertCollinear(1,1, 8,8); - assertNotCollinear(4,4, 8,4); - assertNotCollinear(1,8, 4,4); - assertNotCollinear(8,4, 1,2); - assertNotCollinear(1,8, 8,1); - assertCollinear(4,8, 4,8); - assertNotCollinear(8,1, 8,8); - assertCollinear(8,4, 4,2); - assertNotCollinear(4,8, 4,2); - assertNotCollinear(8,8, 2,4); - assertCollinear(8,1, 8,1); - assertNotCollinear(4,1, 2,4); - assertNotCollinear(4,2, 1,4); - assertCollinear(1,8, 1,8); - assertNotCollinear(1,1, 4,2); - } - - private void assertCollinear(double ax, double ay, double az, double bx, double by, double bz) { - final Vector a = new Vector(ax,ay,az); - final Vector b = new Vector(bx,by,bz); - assertTrue(a.isCollinearWith(b)); - assertTrue(b.isCollinearWith(a)); - assertTrue(a.multiply(-1.0).isCollinearWith(b)); - assertTrue(a.isCollinearWith(b.multiply(-1.0))); - } - private void assertNotCollinear(double ax, double ay, double az, double bx, double by, double bz) { - final Vector a = new Vector(ax,ay,az); - final Vector b = new Vector(bx,by,bz); - assertFalse(a.isCollinearWith(b)); - assertFalse(b.isCollinearWith(a)); - assertFalse(a.multiply(-1.0).isCollinearWith(b)); - assertFalse(a.isCollinearWith(b.multiply(-1.0))); - } - - private void assertCollinear(double ax, double az, double bx, double bz) { - final Vector2D a = new Vector2D(ax,az); - final Vector2D b = new Vector2D(bx,bz); - assertTrue(a.isCollinearWith(b)); - assertTrue(b.isCollinearWith(a)); - assertTrue(a.multiply(-1.0).isCollinearWith(b)); - assertTrue(a.isCollinearWith(b.multiply(-1.0))); - } - private void assertNotCollinear(double ax, double az, double bx, double bz) { - final Vector2D a = new Vector2D(ax,az); - final Vector2D b = new Vector2D(bx,bz); - assertFalse(a.isCollinearWith(b)); - assertFalse(b.isCollinearWith(a)); - assertFalse(a.multiply(-1.0).isCollinearWith(b)); - assertFalse(a.isCollinearWith(b.multiply(-1.0))); - } -} diff --git a/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java index b7944d476..d7633c15c 100644 --- a/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java +++ b/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java @@ -22,7 +22,7 @@ package com.sk89q.worldedit.util; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import org.junit.Test; @@ -54,7 +54,7 @@ public class LocationTest { @Test public void testToVector() throws Exception { World world = mock(World.class); - Vector position = new Vector(1, 1, 1); + Vector3 position = new Vector3(1, 1, 1); Location location = new Location(world, position); assertEquals(position, location.toVector()); } @@ -62,21 +62,21 @@ public class LocationTest { @Test public void testGetX() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(TEST_VALUE, 0, 0)); + Location location = new Location(world, new Vector3(TEST_VALUE, 0, 0)); assertEquals(TEST_VALUE, location.getX(), EPSILON); } @Test public void testGetBlockX() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(TEST_VALUE, 0, 0)); + Location location = new Location(world, new Vector3(TEST_VALUE, 0, 0)); assertEquals(TEST_VALUE, location.getBlockX()); } @Test public void testSetX() throws Exception { World world = mock(World.class); - Location location1 = new Location(world, new Vector()); + Location location1 = new Location(world, Vector3.ZERO); Location location2 = location1.setX(TEST_VALUE); assertEquals(0, location1.getX(), EPSILON); assertEquals(TEST_VALUE, location2.getX(), EPSILON); @@ -87,21 +87,21 @@ public class LocationTest { @Test public void testGetY() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(0, TEST_VALUE, 0)); + Location location = new Location(world, new Vector3(0, TEST_VALUE, 0)); assertEquals(TEST_VALUE, location.getY(), EPSILON); } @Test public void testGetBlockY() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(0, TEST_VALUE, 0)); + Location location = new Location(world, new Vector3(0, TEST_VALUE, 0)); assertEquals(TEST_VALUE, location.getBlockY()); } @Test public void testSetY() throws Exception { World world = mock(World.class); - Location location1 = new Location(world, new Vector()); + Location location1 = new Location(world, Vector3.ZERO); Location location2 = location1.setY(TEST_VALUE); assertEquals(0, location1.getY(), EPSILON); assertEquals(0, location2.getX(), EPSILON); @@ -112,21 +112,21 @@ public class LocationTest { @Test public void testGetZ() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(0, 0, TEST_VALUE)); + Location location = new Location(world, new Vector3(0, 0, TEST_VALUE)); assertEquals(TEST_VALUE, location.getZ(), EPSILON); } @Test public void testGetBlockZ() throws Exception { World world = mock(World.class); - Location location = new Location(world, new Vector(0, 0, TEST_VALUE)); + Location location = new Location(world, new Vector3(0, 0, TEST_VALUE)); assertEquals(TEST_VALUE, location.getBlockZ()); } @Test public void testSetZ() throws Exception { World world = mock(World.class); - Location location1 = new Location(world, new Vector()); + Location location1 = new Location(world, Vector3.ZERO); Location location2 = location1.setZ(TEST_VALUE); assertEquals(0, location1.getZ(), EPSILON); assertEquals(0, location2.getX(), EPSILON); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java index 18311a5c5..335ef497d 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeAdapter.java @@ -20,7 +20,8 @@ package com.sk89q.worldedit.forge; import com.google.common.collect.ImmutableList; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.registry.state.BooleanProperty; import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.registry.state.EnumProperty; @@ -49,15 +50,15 @@ final class ForgeAdapter { return new ForgeWorld(world); } - public static Vector adapt(Vec3d vector) { - return new Vector(vector.x, vector.y, vector.z); + public static Vector3 adapt(Vec3d vector) { + return new Vector3(vector.x, vector.y, vector.z); } - public static Vector adapt(BlockPos pos) { - return new Vector(pos.getX(), pos.getY(), pos.getZ()); + public static Vector3 adapt(BlockPos pos) { + return new Vector3(pos.getX(), pos.getY(), pos.getZ()); } - public static Vec3d toVec3(Vector vector) { + public static Vec3d toVec3(BlockVector3 vector) { return new Vec3d(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); } @@ -87,7 +88,7 @@ final class ForgeAdapter { } } - public static BlockPos toBlockPos(Vector vector) { + public static BlockPos toBlockPos(BlockVector3 vector) { return new BlockPos(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java index 54e28c244..94bb3c8a5 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeEntity.java @@ -21,11 +21,11 @@ package com.sk89q.worldedit.forge; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.metadata.EntityProperties; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.NullWorld; import com.sk89q.worldedit.world.entity.EntityTypes; @@ -66,7 +66,7 @@ class ForgeEntity implements Entity { public Location getLocation() { net.minecraft.entity.Entity entity = entityRef.get(); if (entity != null) { - Vector position = new Vector(entity.posX, entity.posY, entity.posZ); + Vector3 position = new Vector3(entity.posX, entity.posY, entity.posZ); float yaw = entity.rotationYaw; float pitch = entity.rotationPitch; diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index 817315e92..a09c472da 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -20,19 +20,20 @@ package com.sk89q.worldedit.forge; import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemTypes; -import io.netty.buffer.Unpooled; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -49,6 +50,8 @@ import java.util.UUID; import javax.annotation.Nullable; +import io.netty.buffer.Unpooled; + public class ForgePlayer extends AbstractPlayerActor { private final EntityPlayerMP player; @@ -81,7 +84,7 @@ public class ForgePlayer extends AbstractPlayerActor { @Override public Location getLocation() { - Vector position = new Vector(this.player.posX, this.player.posY, this.player.posZ); + Vector3 position = new Vector3(this.player.posX, this.player.posY, this.player.posZ); return new Location( ForgeWorldEdit.inst.getWorld(this.player.world), position, @@ -143,7 +146,7 @@ public class ForgePlayer extends AbstractPlayerActor { } @Override - public void setPosition(Vector pos, float pitch, float yaw) { + public void setPosition(Vector3 pos, float pitch, float yaw) { this.player.connection.setPlayerLocation(pos.getX(), pos.getY(), pos.getZ(), yaw, pitch); } @@ -169,8 +172,8 @@ public class ForgePlayer extends AbstractPlayerActor { } @Override - public void sendFakeBlock(Vector pos, BlockStateHolder block) { - BlockPos loc = new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { + BlockPos loc = ForgeAdapter.toBlockPos(pos); if (block == null) { // TODO // player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java index abd4e8151..e579711e9 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgeWorld.java @@ -23,18 +23,17 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.io.Files; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.internal.Constants; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; @@ -170,7 +169,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { checkNotNull(position); checkNotNull(block); @@ -237,15 +236,15 @@ public class ForgeWorld extends AbstractWorld { } @Override - public int getBlockLightLevel(Vector position) { + public int getBlockLightLevel(BlockVector3 position) { checkNotNull(position); - return getWorld().getLight(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ())); + return getWorld().getLight(ForgeAdapter.toBlockPos(position)); } @Override - public boolean clearContainerBlockContents(Vector position) { + public boolean clearContainerBlockContents(BlockVector3 position) { checkNotNull(position); - TileEntity tile = getWorld().getTileEntity(new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ())); + TileEntity tile = getWorld().getTileEntity(ForgeAdapter.toBlockPos(position)); if ((tile instanceof IInventory)) { IInventory inv = (IInventory) tile; int size = inv.getSizeInventory(); @@ -258,13 +257,13 @@ public class ForgeWorld extends AbstractWorld { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { checkNotNull(position); return new BaseBiome(Biome.getIdForBiome(getWorld().getBiomeForCoordsBody(new BlockPos(position.getBlockX(), 0, position.getBlockZ())))); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { checkNotNull(position); checkNotNull(biome); @@ -278,7 +277,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public boolean useItem(Vector position, BaseItem item, Direction face) { + public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { Item nativeItem = Item.getByNameOrId(item.getType().getId()); ItemStack stack = null; if (item.getNbtData() == null) { @@ -293,7 +292,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public void dropItem(Vector position, BaseItemStack item) { + public void dropItem(Vector3 position, BaseItemStack item) { checkNotNull(position); checkNotNull(item); @@ -307,7 +306,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public void simulateBlockMine(Vector position) { + public void simulateBlockMine(BlockVector3 position) { BlockPos pos = ForgeAdapter.toBlockPos(position); IBlockState state = getWorld().getBlockState(pos); state.getBlock().dropBlockAsItem(getWorld(), pos, state, 0); @@ -338,13 +337,13 @@ public class ForgeWorld extends AbstractWorld { // Pre-gen all the chunks // We need to also pull one more chunk in every direction CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16)); - for (Vector2D chunk : expandedPreGen.getChunks()) { + for (BlockVector2 chunk : expandedPreGen.getChunks()) { freshWorld.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ()); } ForgeWorld from = new ForgeWorld(freshWorld); try { - for (BlockVector vec : region) { + for (BlockVector3 vec : region) { editSession.setBlock(vec, from.getFullBlock(vec)); } } catch (MaxChangedBlocksException e) { @@ -386,32 +385,32 @@ public class ForgeWorld extends AbstractWorld { } @Override - public boolean generateTree(TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { + public boolean generateTree(TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { WorldGenerator generator = createWorldGenerator(type); return generator != null && generator.generate(getWorld(), random, ForgeAdapter.toBlockPos(position)); } @Override - public void checkLoadedChunk(Vector pt) { + public void checkLoadedChunk(BlockVector3 pt) { getWorld().getChunkFromBlockCoords(ForgeAdapter.toBlockPos(pt)); } @Override - public void fixAfterFastMode(Iterable chunks) { + public void fixAfterFastMode(Iterable chunks) { fixLighting(chunks); } @Override - public void fixLighting(Iterable chunks) { + public void fixLighting(Iterable chunks) { World world = getWorld(); - for (BlockVector2D chunk : chunks) { + for (BlockVector2 chunk : chunks) { world.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ()).resetRelightChecks(); } } @Override - public boolean playEffect(Vector position, int type, int data) { - getWorld().playEvent(type, ForgeAdapter.toBlockPos(position), data); + public boolean playEffect(Vector3 position, int type, int data) { + getWorld().playEvent(type, ForgeAdapter.toBlockPos(position.toBlockPoint()), data); return true; } @@ -463,7 +462,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { World world = getWorld(); BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); IBlockState mcState = world.getBlockState(pos); @@ -487,7 +486,7 @@ public class ForgeWorld extends AbstractWorld { } @Override - public BaseBlock getFullBlock(Vector position) { + public BaseBlock getFullBlock(BlockVector3 position) { BlockPos pos = new BlockPos(position.getBlockX(), position.getBlockY(), position.getBlockZ()); TileEntity tile = getWorld().getTileEntity(pos); @@ -523,7 +522,7 @@ public class ForgeWorld extends AbstractWorld { public List getEntities(Region region) { List entities = new ArrayList<>(); for (net.minecraft.entity.Entity entity : getWorld().loadedEntityList) { - if (region.contains(new Vector(entity.posX, entity.posY, entity.posZ))) { + if (region.contains(new BlockVector3(entity.posX, entity.posY, entity.posZ))) { entities.add(new ForgeEntity(entity)); } } diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java index f87293db8..4147d835c 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/TileEntityUtils.java @@ -21,7 +21,8 @@ package com.sk89q.worldedit.forge; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; + import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagInt; import net.minecraft.tileentity.TileEntity; @@ -47,7 +48,7 @@ final class TileEntityUtils { * @param position the position * @return a tag compound */ - private static NBTTagCompound updateForSet(NBTTagCompound tag, Vector position) { + private static NBTTagCompound updateForSet(NBTTagCompound tag, BlockVector3 position) { checkNotNull(tag); checkNotNull(position); @@ -66,7 +67,7 @@ final class TileEntityUtils { * @param clazz the tile entity class * @param tag the tag for the tile entity (may be null to not set NBT data) */ - static void setTileEntity(World world, Vector position, Class clazz, @Nullable NBTTagCompound tag) { + static void setTileEntity(World world, BlockVector3 position, Class clazz, @Nullable NBTTagCompound tag) { checkNotNull(world); checkNotNull(position); checkNotNull(clazz); @@ -94,7 +95,7 @@ final class TileEntityUtils { * @param position the position * @param tag the tag for the tile entity (may be null to do nothing) */ - static void setTileEntity(World world, Vector position, @Nullable NBTTagCompound tag) { + static void setTileEntity(World world, BlockVector3 position, @Nullable NBTTagCompound tag) { if (tag != null) { updateForSet(tag, position); TileEntity tileEntity = TileEntity.create(world, tag); @@ -113,7 +114,7 @@ final class TileEntityUtils { * @return a tile entity (may be null if it failed) */ @Nullable - static TileEntity constructTileEntity(World world, Vector position, Class clazz) { + static TileEntity constructTileEntity(World world, BlockVector3 position, Class clazz) { Constructor baseConstructor; try { baseConstructor = clazz.getConstructor(); // creates "blank" TE diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 662d65e55..fba1c81fc 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -21,12 +21,13 @@ package com.sk89q.worldedit.sponge; import com.flowpowered.math.vector.Vector3d; import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extension.platform.AbstractPlayerActor; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.cui.CUIEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; @@ -34,6 +35,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemTypes; + import org.spongepowered.api.Sponge; import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; @@ -144,7 +146,7 @@ public class SpongePlayer extends AbstractPlayerActor { } @Override - public void setPosition(Vector pos, float pitch, float yaw) { + public void setPosition(Vector3 pos, float pitch, float yaw) { org.spongepowered.api.world.Location loc = new org.spongepowered.api.world.Location<>( this.player.getWorld(), pos.getX(), pos.getY(), pos.getZ() ); @@ -185,7 +187,7 @@ public class SpongePlayer extends AbstractPlayerActor { } @Override - public void sendFakeBlock(Vector pos, BlockStateHolder block) { + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { org.spongepowered.api.world.Location loc = player.getWorld().getLocation(pos.getX(), pos.getY(), pos.getZ()); if (block == null) { player.sendBlockChange(loc.getBlockPosition(), loc.getBlock()); diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java index fe3db9e16..b62bee328 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorld.java @@ -24,22 +24,24 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.flowpowered.math.vector.Vector3d; import com.flowpowered.math.vector.Vector3i; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.biome.BaseBiome; +import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; + import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockSnapshot; import org.spongepowered.api.block.BlockState; @@ -134,7 +136,7 @@ public abstract class SpongeWorld extends AbstractWorld { private static final BlockSnapshot.Builder builder = BlockSnapshot.builder(); @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { checkNotNull(position); checkNotNull(block); @@ -167,7 +169,7 @@ public abstract class SpongeWorld extends AbstractWorld { } @Override - public int getBlockLightLevel(Vector position) { + public int getBlockLightLevel(BlockVector3 position) { checkNotNull(position); BlockState state = getWorld().getBlock(new Vector3i(position.getX(), position.getY(), position.getZ())); @@ -185,13 +187,13 @@ public abstract class SpongeWorld extends AbstractWorld { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { checkNotNull(position); return new BaseBiome(SpongeWorldEdit.inst().getAdapter().resolve(getWorld().getBiome(position.getBlockX(), 0, position.getBlockZ()))); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { checkNotNull(position); checkNotNull(biome); @@ -200,7 +202,7 @@ public abstract class SpongeWorld extends AbstractWorld { } @Override - public void dropItem(Vector position, BaseItemStack item) { + public void dropItem(Vector3 position, BaseItemStack item) { checkNotNull(position); checkNotNull(item); @@ -218,7 +220,7 @@ public abstract class SpongeWorld extends AbstractWorld { } @Override - public void simulateBlockMine(Vector position) { + public void simulateBlockMine(BlockVector3 position) { // TODO } @@ -247,7 +249,7 @@ public abstract class SpongeWorld extends AbstractWorld { List entities = new ArrayList<>(); for (org.spongepowered.api.entity.Entity entity : getWorld().getEntities()) { org.spongepowered.api.world.Location loc = entity.getLocation(); - if (region.contains(new Vector(loc.getX(), loc.getY(), loc.getZ()))) { + if (region.contains(new BlockVector3(loc.getX(), loc.getY(), loc.getZ()))) { entities.add(new SpongeEntity(entity)); } } @@ -279,7 +281,7 @@ public abstract class SpongeWorld extends AbstractWorld { } // Overwrite any data set by the NBT application - Vector dir = location.getDirection(); + Vector3 dir = location.getDirection(); newEnt.setLocationAndRotation( new org.spongepowered.api.world.Location<>(getWorld(), pos), diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplAdapter.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplAdapter.java index a134e1ac3..01cc7dfc0 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplAdapter.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/adapter/SpongeImplAdapter.java @@ -20,11 +20,12 @@ package com.sk89q.worldedit.sponge.adapter; import com.flowpowered.math.vector.Vector3d; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.sponge.SpongeWorld; import com.sk89q.worldedit.util.Location; + import org.spongepowered.api.entity.Entity; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.world.World; @@ -56,7 +57,7 @@ public interface SpongeImplAdapter { } default Location adapt(org.spongepowered.api.world.Location loc, Vector3d rot) { - Vector position = new Vector(loc.getX(), loc.getY(), loc.getZ()); + Vector3 position = new Vector3(loc.getX(), loc.getY(), loc.getZ()); return new Location(getWorld(loc.getExtent()), position, (float) rot.getY(), (float) rot.getX()); }