From d4157b7e0e6421c1fc8525834695d88eed9f7ea1 Mon Sep 17 00:00:00 2001 From: IronApollo Date: Sun, 23 Dec 2018 11:19:33 -0500 Subject: [PATCH] Current progress with update --- .../adapter/v1_13_1/Spigot_v1_13_R2.java | 20 +- .../bukkit/filter/GriefPreventionFilter.java | 7 +- .../fawe/bukkit/filter/WorldGuardFilter.java | 16 +- .../bukkit/listener/BukkitImageListener.java | 7 +- .../bukkit/listener/CFIPacketListener.java | 58 +- .../fawe/bukkit/regions/BukkitMask.java | 5 +- .../fawe/bukkit/regions/FreeBuildRegion.java | 6 +- .../bukkit/regions/PreciousStonesFeature.java | 7 +- .../fawe/bukkit/regions/Worldguard.java | 20 +- .../fawe/bukkit/regions/WorldguardFlag.java | 24 +- .../fawe/bukkit/util/cui/StructureCUI.java | 19 +- .../fawe/bukkit/v0/FaweAdapter_All.java | 2 +- .../sk89q/worldedit/bukkit/BukkitAdapter.java | 16 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 14 +- .../sk89q/worldedit/bukkit/BukkitWorld.java | 54 +- .../EditSessionBlockChangeDelegate.java | 10 +- .../bukkit/adapter/BukkitImplAdapter.java | 12 + .../bukkit/adapter/IBukkitAdapter.java | 28 +- .../main/java/com/boydti/fawe/FaweAPI.java | 17 +- .../boydti/fawe/command/AnvilCommands.java | 12 +- .../com/boydti/fawe/command/CFICommands.java | 8 +- .../fawe/command/FawePrimitiveBinding.java | 16 +- .../fawe/database/RollbackDatabase.java | 5 +- .../fawe/jnbt/CorruptSchematicStreamer.java | 25 +- .../boydti/fawe/jnbt/SchematicStreamer.java | 34 +- .../jnbt/anvil/HeightMapMCAGenerator.java | 67 +- .../boydti/fawe/jnbt/anvil/MCAClipboard.java | 8 +- .../com/boydti/fawe/jnbt/anvil/MCAQueue.java | 6 +- .../com/boydti/fawe/jnbt/anvil/MCAWorld.java | 26 +- .../filters/MappedReplacePatternFilter.java | 3 +- .../fawe/jnbt/anvil/generator/CavesGen.java | 12 +- .../fawe/jnbt/anvil/generator/GenBase.java | 13 +- .../fawe/jnbt/anvil/generator/OreGen.java | 2 +- .../fawe/jnbt/anvil/generator/SchemGen.java | 2 +- .../rollback/RollbackOptimizedHistory.java | 4 +- .../boydti/fawe/object/DataAnglePattern.java | 8 +- .../com/boydti/fawe/object/FawePlayer.java | 23 +- .../com/boydti/fawe/object/FaweQueue.java | 26 +- .../com/boydti/fawe/object/HistoryExtent.java | 9 +- .../boydti/fawe/object/MaskedFaweQueue.java | 8 +- .../com/boydti/fawe/object/RegionWrapper.java | 10 +- .../boydti/fawe/object/brush/AngleBrush.java | 4 +- .../boydti/fawe/object/brush/BlendBall.java | 4 +- .../boydti/fawe/object/brush/BlobBrush.java | 22 +- .../fawe/object/brush/CatenaryBrush.java | 29 +- .../boydti/fawe/object/brush/CircleBrush.java | 13 +- .../fawe/object/brush/CommandBrush.java | 8 +- .../fawe/object/brush/CopyPastaBrush.java | 6 +- .../boydti/fawe/object/brush/ErodeBrush.java | 12 +- .../fawe/object/brush/FallingSphere.java | 4 +- .../fawe/object/brush/FlattenBrush.java | 5 +- .../boydti/fawe/object/brush/HeightBrush.java | 18 +- .../boydti/fawe/object/brush/ImageBrush.java | 18 +- .../fawe/object/brush/InspectBrush.java | 7 +- .../boydti/fawe/object/brush/LayerBrush.java | 10 +- .../boydti/fawe/object/brush/LineBrush.java | 6 +- .../fawe/object/brush/PopulateSchem.java | 8 +- .../boydti/fawe/object/brush/RaiseBrush.java | 4 +- .../fawe/object/brush/RecurseBrush.java | 8 +- .../boydti/fawe/object/brush/RockBrush.java | 10 +- .../fawe/object/brush/ScatterBrush.java | 15 +- .../fawe/object/brush/ScatterCommand.java | 6 +- .../object/brush/ScatterOverlayBrush.java | 10 +- .../fawe/object/brush/ShatterBrush.java | 12 +- .../boydti/fawe/object/brush/SpikeBrush.java | 4 +- .../fawe/object/brush/SplatterBrush.java | 9 +- .../boydti/fawe/object/brush/SplineBrush.java | 50 +- .../fawe/object/brush/StencilBrush.java | 21 +- .../fawe/object/brush/SurfaceSphereBrush.java | 5 +- .../fawe/object/brush/SurfaceSpline.java | 19 +- .../object/brush/heightmap/HeightMap.java | 24 +- .../brush/heightmap/RotatableHeightMap.java | 10 +- .../brush/heightmap/ScalableHeightMap.java | 12 +- .../object/brush/sweep/ClipboardSpline.java | 17 +- .../fawe/object/brush/sweep/Spline.java | 22 +- .../fawe/object/brush/sweep/SweepBrush.java | 20 +- .../visualization/ImmutableVirtualWorld.java | 19 +- .../brush/visualization/VirtualWorld.java | 15 +- .../brush/visualization/VisualExtent.java | 8 +- .../object/change/MutableBiomeChange.java | 2 +- .../changeset/AbstractDelegateChangeSet.java | 4 +- .../object/changeset/BlockBagChangeSet.java | 4 +- .../fawe/object/changeset/FaweChangeSet.java | 7 +- .../AbstractDelegateFaweClipboard.java | 8 +- .../clipboard/CPUOptimizedClipboard.java | 8 +- .../clipboard/DiskOptimizedClipboard.java | 14 +- .../fawe/object/clipboard/EmptyClipboard.java | 34 +- .../fawe/object/clipboard/FaweClipboard.java | 8 +- .../clipboard/MemoryOptimizedClipboard.java | 8 +- .../object/clipboard/ReadOnlyClipboard.java | 8 +- .../clipboard/ResizableClipboardBuilder.java | 6 +- .../object/clipboard/WorldCopyClipboard.java | 17 +- .../clipboard/remap/ClipboardRemapper.java | 2 - .../object/collection/BlockVectorSet.java | 37 +- .../collection/LocalBlockVector2DSet.java | 36 +- .../collection/LocalBlockVectorSet.java | 40 +- .../object/extent/BlockTranslateExtent.java | 16 +- .../fawe/object/extent/EmptyExtent.java | 22 +- .../object/extent/FastWorldEditExtent.java | 14 +- .../fawe/object/extent/FaweRegionExtent.java | 18 +- .../object/extent/MemoryCheckingExtent.java | 4 +- .../fawe/object/extent/MultiTransform.java | 8 +- .../boydti/fawe/object/extent/NullExtent.java | 22 +- .../fawe/object/extent/OffsetExtent.java | 10 +- .../fawe/object/extent/PatternTransform.java | 4 +- .../extent/PositionTransformExtent.java | 42 +- .../fawe/object/extent/ProcessedWEExtent.java | 12 +- .../object/extent/RandomOffsetTransform.java | 10 +- .../fawe/object/extent/ResettableExtent.java | 6 +- .../fawe/object/extent/ScaleTransform.java | 30 +- .../fawe/object/extent/SelectTransform.java | 12 +- .../boydti/fawe/object/extent/SlowExtent.java | 4 +- .../fawe/object/extent/SourceMaskExtent.java | 6 +- .../fawe/object/extent/StripNBTExtent.java | 4 +- .../fawe/object/extent/TemporalExtent.java | 10 +- .../fawe/object/extent/TransformExtent.java | 57 +- .../object/function/NullRegionFunction.java | 4 +- .../function/SurfaceRegionFunction.java | 6 +- .../fawe/object/function/block/BiomeCopy.java | 6 +- .../function/block/CombinedBlockCopy.java | 4 +- .../function/block/SimpleBlockCopy.java | 4 +- .../function/mask/AbstractDelegateMask.java | 5 +- .../fawe/object/mask/AdjacentAnyMask.java | 8 +- .../boydti/fawe/object/mask/AdjacentMask.java | 8 +- .../boydti/fawe/object/mask/AngleMask.java | 9 +- .../boydti/fawe/object/mask/BiomeMask.java | 10 +- .../fawe/object/mask/BlockLightMask.java | 5 +- .../fawe/object/mask/BrightnessMask.java | 5 +- .../boydti/fawe/object/mask/CachedMask.java | 6 +- .../com/boydti/fawe/object/mask/DataMask.java | 5 +- .../boydti/fawe/object/mask/IdDataMask.java | 5 +- .../com/boydti/fawe/object/mask/IdMask.java | 5 +- .../boydti/fawe/object/mask/LightMask.java | 5 +- .../fawe/object/mask/MaskedTargetBlock.java | 2 +- .../boydti/fawe/object/mask/OpacityMask.java | 5 +- .../boydti/fawe/object/mask/PlaneMask.java | 5 +- .../boydti/fawe/object/mask/RadiusMask.java | 10 +- .../boydti/fawe/object/mask/RandomMask.java | 5 +- .../boydti/fawe/object/mask/SimplexMask.java | 4 +- .../boydti/fawe/object/mask/SkyLightMask.java | 5 +- .../fawe/object/mask/SolidPlaneMask.java | 7 +- .../boydti/fawe/object/mask/SurfaceMask.java | 4 +- .../com/boydti/fawe/object/mask/WallMask.java | 8 +- .../boydti/fawe/object/mask/XAxisMask.java | 5 +- .../boydti/fawe/object/mask/YAxisMask.java | 5 +- .../boydti/fawe/object/mask/ZAxisMask.java | 5 +- .../object/pattern/AngleColorPattern.java | 8 +- .../object/pattern/AverageColorPattern.java | 6 +- .../fawe/object/pattern/BiomePattern.java | 8 +- .../fawe/object/pattern/BufferedPattern.java | 8 +- .../object/pattern/BufferedPattern2D.java | 4 +- .../fawe/object/pattern/DataPattern.java | 4 +- .../object/pattern/DesaturatePattern.java | 6 +- .../fawe/object/pattern/ExistingPattern.java | 6 +- .../object/pattern/ExpressionPattern.java | 6 +- .../object/pattern/FullClipboardPattern.java | 8 +- .../object/pattern/IdDataMaskPattern.java | 4 +- .../boydti/fawe/object/pattern/IdPattern.java | 4 +- .../object/pattern/Linear2DBlockPattern.java | 6 +- .../object/pattern/Linear3DBlockPattern.java | 6 +- .../object/pattern/LinearBlockPattern.java | 6 +- .../fawe/object/pattern/MaskedPattern.java | 6 +- .../fawe/object/pattern/NoXPattern.java | 8 +- .../fawe/object/pattern/NoYPattern.java | 8 +- .../fawe/object/pattern/NoZPattern.java | 8 +- .../fawe/object/pattern/OffsetPattern.java | 8 +- .../fawe/object/pattern/PatternExtent.java | 34 +- .../fawe/object/pattern/PropertyPattern.java | 6 +- .../pattern/RandomFullClipboardPattern.java | 11 +- .../object/pattern/RandomOffsetPattern.java | 8 +- .../fawe/object/pattern/RelativePattern.java | 14 +- .../fawe/object/pattern/SaturatePattern.java | 6 +- .../fawe/object/pattern/ShadePattern.java | 4 +- .../pattern/SolidRandomOffsetPattern.java | 8 +- .../pattern/SurfaceRandomOffsetPattern.java | 15 +- .../object/queue/FaweQueueDelegateExtent.java | 16 +- .../fawe/object/queue/IDelegateFaweQueue.java | 22 +- .../fawe/object/queue/NullFaweQueue.java | 4 +- .../fawe/object/regions/FuzzyRegion.java | 25 +- .../fawe/object/schematic/Schematic.java | 20 +- .../object/visitor/DFSRecursiveVisitor.java | 5 +- .../fawe/object/visitor/DFSVisitor.java | 29 +- .../com/boydti/fawe/regions/FaweMask.java | 6 +- .../regions/general/CuboidRegionFilter.java | 4 +- .../main/java/com/sk89q/jnbt/NBTUtils.java | 8 +- .../java/com/sk89q/util/yaml/YAMLNode.java | 40 +- .../java/com/sk89q/worldedit/BlockVector.java | 120 --- .../com/sk89q/worldedit/BlockVector2D.java | 93 -- .../java/com/sk89q/worldedit/EditSession.java | 645 ++++++++---- .../com/sk89q/worldedit/LocalSession.java | 62 +- .../com/sk89q/worldedit/PlayerDirection.java | 27 +- .../main/java/com/sk89q/worldedit/Vector.java | 915 ------------------ .../java/com/sk89q/worldedit/Vector2D.java | 681 ------------- .../java/com/sk89q/worldedit/WorldEdit.java | 6 +- .../worldedit/command/BiomeCommands.java | 31 +- .../worldedit/command/BrushCommands.java | 25 +- .../worldedit/command/ChunkCommands.java | 25 +- .../worldedit/command/ClipboardCommands.java | 40 +- .../command/FlattenedClipboardTransform.java | 37 +- .../worldedit/command/GenerationCommands.java | 126 ++- .../worldedit/command/RegionCommands.java | 80 +- .../worldedit/command/SelectionCommands.java | 149 ++- .../worldedit/command/UtilityCommands.java | 63 ++ .../command/argument/ItemUseParser.java | 4 +- .../command/composition/DeformCommand.java | 2 +- .../worldedit/command/tool/AreaPickaxe.java | 30 +- .../command/tool/BlockDataCyler.java | 45 + .../worldedit/command/tool/BlockReplacer.java | 18 +- .../worldedit/command/tool/BrushTool.java | 9 + .../worldedit/command/tool/DistanceWand.java | 11 +- .../command/tool/FloatingTreeRemover.java | 46 +- .../worldedit/command/tool/FloodFillTool.java | 42 +- .../command/tool/LongRangeBuildTool.java | 33 + .../worldedit/command/tool/QueryTool.java | 6 +- .../command/tool/RecursivePickaxe.java | 62 ++ .../worldedit/command/tool/SinglePickaxe.java | 17 + .../worldedit/command/tool/TreePlanter.java | 8 + .../worldedit/command/tool/brush/Brush.java | 5 +- .../command/tool/brush/ButcherBrush.java | 4 +- .../command/tool/brush/ClipboardBrush.java | 6 +- .../command/tool/brush/CylinderBrush.java | 6 +- .../command/tool/brush/GravityBrush.java | 28 +- .../tool/brush/HollowCylinderBrush.java | 8 +- .../command/tool/brush/HollowSphereBrush.java | 8 +- .../tool/brush/OperationFactoryBrush.java | 4 +- .../command/tool/brush/SmoothBrush.java | 13 +- .../command/tool/brush/SphereBrush.java | 7 +- .../com/sk89q/worldedit/entity/Player.java | 22 +- .../event/extent/EditSessionEvent.java | 8 + .../extension/factory/DefaultBlockParser.java | 17 + .../extension/factory/DefaultMaskParser.java | 65 ++ .../platform/AbstractPlayerActor.java | 111 ++- .../extension/platform/PlatformManager.java | 49 + .../extension/platform/PlayerProxy.java | 21 +- .../extent/AbstractDelegateExtent.java | 38 +- .../worldedit/extent/ChangeSetExtent.java | 18 + .../com/sk89q/worldedit/extent/Extent.java | 33 +- .../sk89q/worldedit/extent/InputExtent.java | 18 +- .../sk89q/worldedit/extent/MaskingExtent.java | 11 +- .../sk89q/worldedit/extent/NullExtent.java | 42 +- .../sk89q/worldedit/extent/OutputExtent.java | 8 +- .../extent/buffer/ForgetfulExtentBuffer.java | 46 +- .../extent/cache/LastAccessExtentCache.java | 17 +- .../extent/clipboard/BlockArrayClipboard.java | 82 +- .../worldedit/extent/clipboard/Clipboard.java | 8 +- .../clipboard/io/MCEditSchematicReader.java | 316 ++++++ .../clipboard/io/SpongeSchematicReader.java | 70 ++ .../clipboard/io/SpongeSchematicWriter.java | 58 ++ .../extent/inventory/BlockBagExtent.java | 14 + .../extent/reorder/ChunkBatchingExtent.java | 118 +++ .../extent/reorder/MultiStageReorder.java | 43 +- .../transform/BlockTransformExtent.java | 83 ++ .../extent/validation/BlockChangeLimiter.java | 8 +- .../validation/DataValidatorExtent.java | 8 +- .../extent/world/BlockQuirkExtent.java | 10 +- .../extent/world/ChunkLoadingExtent.java | 8 +- .../extent/world/FastModeExtent.java | 13 +- .../extent/world/SurvivalModeExtent.java | 8 +- .../function/CombinedRegionFunction.java | 6 +- .../function/FlatRegionFunction.java | 4 +- .../function/FlatRegionMaskingFilter.java | 10 +- .../worldedit/function/GroundFunction.java | 10 +- .../worldedit/function/LayerFunction.java | 6 +- .../worldedit/function/RegionFunction.java | 4 +- .../function/RegionMaskingFilter.java | 10 +- .../function/biome/BiomeReplace.java | 8 +- .../block/BlockDistributionCounter.java | 77 ++ .../function/block/BlockReplace.java | 11 + .../worldedit/function/block/Counter.java | 11 +- .../function/block/ExtentBlockCopy.java | 29 +- .../worldedit/function/block/Naturalizer.java | 10 +- .../function/entity/ExtentEntityCopy.java | 33 +- .../worldedit/function/factory/Deform.java | 34 +- .../function/generator/FloraGenerator.java | 9 +- .../function/generator/ForestGenerator.java | 9 +- .../generator/GardenPatchGenerator.java | 16 +- .../worldedit/function/mask/BiomeMask2D.java | 8 +- .../function/mask/BlockCategoryMask.java | 4 +- .../worldedit/function/mask/BlockMask.java | 15 + .../function/mask/BlockTypeMask.java | 17 + .../function/mask/BoundedHeightMask.java | 8 +- .../function/mask/ExistingBlockMask.java | 9 + .../function/mask/ExpressionMask.java | 10 +- .../function/mask/ExpressionMask2D.java | 8 +- .../sk89q/worldedit/function/mask/Mask.java | 4 +- .../sk89q/worldedit/function/mask/Mask2D.java | 4 +- .../function/mask/MaskIntersection.java | 15 + .../function/mask/MaskIntersection2D.java | 8 +- .../worldedit/function/mask/MaskUnion.java | 10 + .../worldedit/function/mask/MaskUnion2D.java | 4 +- .../sk89q/worldedit/function/mask/Masks.java | 49 +- .../worldedit/function/mask/NoiseFilter.java | 11 +- .../function/mask/NoiseFilter2D.java | 11 +- .../worldedit/function/mask/OffsetMask.java | 24 +- .../worldedit/function/mask/OffsetMask2D.java | 16 +- .../worldedit/function/mask/RegionMask.java | 8 +- .../function/mask/SolidBlockMask.java | 13 + .../function/operation/ForwardExtentCopy.java | 30 +- .../function/pattern/BlockPattern.java | 16 + .../function/pattern/ClipboardPattern.java | 19 + .../worldedit/function/pattern/Pattern.java | 12 +- .../function/pattern/RandomPattern.java | 22 + .../pattern/RepeatingExtentPattern.java | 25 +- .../function/util/FlatRegionOffset.java | 16 +- .../worldedit/function/util/RegionOffset.java | 16 +- .../function/visitor/BreadthFirstSearch.java | 101 +- .../function/visitor/DirectionalVisitor.java | 29 +- .../function/visitor/DownwardVisitor.java | 30 +- .../function/visitor/FlatRegionVisitor.java | 13 + .../function/visitor/LayerVisitor.java | 23 + .../function/visitor/NonRisingVisitor.java | 22 +- .../function/visitor/RecursiveVisitor.java | 11 + .../function/visitor/RegionVisitor.java | 21 +- .../worldedit/history/change/BlockChange.java | 16 +- .../changeset/BlockOptimizedHistory.java | 83 ++ .../internal/annotation/Direction.java | 4 +- .../command/CommandLoggingHandler.java | 11 +- .../internal/command/WorldEditBinding.java | 13 +- .../internal/cui/SelectionCylinderEvent.java | 10 +- .../cui/SelectionEllipsoidPointEvent.java | 6 +- .../internal/cui/SelectionPoint2DEvent.java | 24 +- .../internal/cui/SelectionPointEvent.java | 6 +- .../internal/cui/ServerCUIHandler.java | 155 +++ .../expression/runtime/Functions.java | 10 +- .../sk89q/worldedit/math/BlockVector2.java | 529 ++++++++++ .../sk89q/worldedit/math/BlockVector3.java | 613 ++++++++++++ .../com/sk89q/worldedit/math/MathUtils.java | 30 + .../{ => math}/MutableBlockVector.java | 32 +- .../{ => math}/MutableBlockVector2D.java | 14 +- .../sk89q/worldedit/math/MutableVector.java | 109 +++ .../com/sk89q/worldedit/math/Vector2.java | 471 +++++++++ .../com/sk89q/worldedit/math/Vector3.java | 596 ++++++++++++ .../worldedit/math/convolution/HeightMap.java | 36 +- .../sk89q/worldedit/math/geom/Polygons.java | 14 +- .../math/interpolation/Interpolation.java | 6 +- .../KochanekBartelsInterpolation.java | 65 +- .../interpolation/LinearInterpolation.java | 22 +- .../worldedit/math/interpolation/Node.java | 12 +- .../ReparametrisingInterpolation.java | 10 +- .../math/noise/JLibNoiseGenerator.java | 9 +- .../worldedit/math/noise/NoiseGenerator.java | 8 +- .../worldedit/math/noise/RandomNoise.java | 8 +- .../math/transform/AffineTransform.java | 23 +- .../math/transform/CombinedTransform.java | 8 +- .../worldedit/math/transform/Identity.java | 4 +- .../worldedit/math/transform/Transform.java | 6 +- .../com/sk89q/worldedit/patterns/Pattern.java | 3 +- .../worldedit/regions/AbstractRegion.java | 82 +- .../regions/ConvexPolyhedralRegion.java | 80 +- .../sk89q/worldedit/regions/CuboidRegion.java | 239 +++-- .../worldedit/regions/CylinderRegion.java | 116 ++- .../worldedit/regions/EllipsoidRegion.java | 132 +-- .../sk89q/worldedit/regions/FlatRegion.java | 4 +- .../worldedit/regions/IDelegateRegion.java | 26 +- .../sk89q/worldedit/regions/NullRegion.java | 43 +- .../worldedit/regions/Polygonal2DRegion.java | 91 +- .../com/sk89q/worldedit/regions/Region.java | 46 +- .../worldedit/regions/RegionIntersection.java | 25 +- .../worldedit/regions/RegionSelector.java | 13 +- .../worldedit/regions/TransformRegion.java | 50 +- .../regions/factory/CuboidRegionFactory.java | 4 +- .../factory/CylinderRegionFactory.java | 8 +- .../regions/factory/RegionFactory.java | 4 +- .../regions/factory/SphereRegionFactory.java | 7 +- .../iterator/FlatRegion3DIterator.java | 21 +- .../regions/iterator/FlatRegionIterator.java | 31 +- .../regions/iterator/RegionIterator.java | 20 +- .../worldedit/regions/polyhedron/Edge.java | 16 +- .../regions/polyhedron/Triangle.java | 20 +- .../ConvexPolyhedralRegionSelector.java | 40 +- .../selector/CuboidRegionSelector.java | 48 +- .../selector/CylinderRegionSelector.java | 65 +- .../selector/EllipsoidRegionSelector.java | 66 +- .../ExtendingCuboidRegionSelector.java | 41 +- .../selector/Polygonal2DRegionSelector.java | 48 +- .../selector/SphereRegionSelector.java | 26 +- .../regions/shape/ArbitraryBiomeShape.java | 10 +- .../regions/shape/ArbitraryShape.java | 4 +- .../worldedit/regions/shape/RegionShape.java | 7 +- .../shape/WorldEditExpressionEnvironment.java | 24 +- .../sk89q/worldedit/session/PasteBuilder.java | 10 +- .../session/request/RequestSelection.java | 30 +- .../com/sk89q/worldedit/util/Direction.java | 69 +- .../sk89q/worldedit/util/LocatedBlock.java | 67 ++ .../com/sk89q/worldedit/util/Location.java | 131 +-- .../com/sk89q/worldedit/util/TargetBlock.java | 41 +- .../sk89q/worldedit/util/TreeGenerator.java | 25 +- .../util/collection/LocatedBlockList.java | 88 ++ .../sk89q/worldedit/util/gson/GsonUtil.java | 4 +- .../worldedit/util/gson/VectorAdapter.java | 8 +- .../sk89q/worldedit/world/AbstractWorld.java | 37 +- .../com/sk89q/worldedit/world/NullWorld.java | 32 +- .../sk89q/worldedit/world/SimpleWorld.java | 37 +- .../java/com/sk89q/worldedit/world/World.java | 37 +- .../worldedit/world/block/BlockTypes.java | 1 - .../worldedit/world/chunk/AnvilChunk.java | 32 +- .../worldedit/world/chunk/AnvilChunk13.java | 20 +- .../sk89q/worldedit/world/chunk/Chunk.java | 7 +- .../sk89q/worldedit/world/chunk/OldChunk.java | 25 +- .../world/registry/BundledBlockData.java | 8 + .../world/registry/BundledItemData.java | 4 +- .../world/registry/LegacyMapper.java | 9 +- .../world/snapshot/SnapshotRestore.java | 34 +- .../worldedit/world/storage/ChunkStore.java | 16 +- .../world/storage/LegacyChunkStore.java | 11 +- .../world/storage/McRegionChunkStore.java | 9 +- .../world/storage/McRegionReader.java | 4 +- .../world/storage/MissingChunkException.java | 8 +- .../sk89q/worldedit/util/LocationTest.java | 27 +- .../sk89q/worldedit/forge/ForgeAdapter.java | 38 +- .../sk89q/worldedit/forge/ForgeEntity.java | 4 +- .../sk89q/worldedit/forge/ForgePlayer.java | 32 +- .../com/sk89q/worldedit/forge/ForgeWorld.java | 67 +- .../worldedit/forge/TileEntityUtils.java | 11 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 26 +- .../sk89q/worldedit/sponge/SpongeWorld.java | 24 +- .../sponge/adapter/SpongeImplAdapter.java | 5 +- 417 files changed, 8994 insertions(+), 4644 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/extent/clipboard/io/MCEditSchematicReader.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.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 rename worldedit-core/src/main/java/com/sk89q/worldedit/{ => math}/MutableBlockVector.java (84%) rename worldedit-core/src/main/java/com/sk89q/worldedit/{ => math}/MutableBlockVector2D.java (92%) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector.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 create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java index 5d1987cf9..aecb6df3d 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/adapter/v1_13_1/Spigot_v1_13_R2.java @@ -31,7 +31,9 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.CachedBukkitAdapter; import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.internal.Constants; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.*; import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.block.BlockState; @@ -411,15 +413,15 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit } return new CompoundTag(values); } else if (foreign instanceof NBTTagByte) { - return new ByteTag(((NBTTagByte) foreign).g()); // getByte + return new ByteTag(((NBTTagByte) foreign).asByte()); // getByte } else if (foreign instanceof NBTTagByteArray) { return new ByteArrayTag(((NBTTagByteArray) foreign).c()); // data } else if (foreign instanceof NBTTagDouble) { return new DoubleTag(((NBTTagDouble) foreign).asDouble()); // getDouble } else if (foreign instanceof NBTTagFloat) { - return new FloatTag(((NBTTagFloat) foreign).i()); // getFloat + return new FloatTag(((NBTTagFloat) foreign).asByte()); // getFloat } else if (foreign instanceof NBTTagInt) { - return new IntTag(((NBTTagInt) foreign).e()); // getInt + return new IntTag(((NBTTagInt) foreign).asInt()); // getInt } else if (foreign instanceof NBTTagIntArray) { return new IntArrayTag(((NBTTagIntArray) foreign).d()); // data } else if (foreign instanceof NBTTagList) { @@ -430,11 +432,11 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit return new ListTag(ByteTag.class, new ArrayList()); } } else if (foreign instanceof NBTTagLong) { - return new LongTag(((NBTTagLong) foreign).d()); // getLong + return new LongTag(((NBTTagLong) foreign).asLong()); // getLong } else if (foreign instanceof NBTTagShort) { - return new ShortTag(((NBTTagShort) foreign).f()); // getShort + return new ShortTag(((NBTTagShort) foreign).asShort()); // getShort } else if (foreign instanceof NBTTagString) { - return new StringTag(foreign.b_()); // data + return new StringTag(foreign.asString()); // data } else if (foreign instanceof NBTTagEnd) { return EndTag.INSTANCE; } else { @@ -539,4 +541,10 @@ public final class Spigot_v1_13_R2 extends CachedBukkitAdapter implements Bukkit BlockMaterial_1_13 material = (BlockMaterial_1_13) state.getMaterial(); return material.getCraftBlockData(); } + + @Override + public void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData) { + // TODO Auto-generated method stub + + } } \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/GriefPreventionFilter.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/GriefPreventionFilter.java index a67438547..0b0ff34ef 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/GriefPreventionFilter.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/GriefPreventionFilter.java @@ -3,7 +3,8 @@ package com.boydti.fawe.bukkit.filter; import com.boydti.fawe.regions.general.CuboidRegionFilter; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.TaskManager; -import com.sk89q.worldedit.BlockVector2D; +import com.sk89q.worldedit.math.BlockVector2; + import java.util.ArrayDeque; import java.util.Collection; import me.ryanhamshire.GriefPrevention.Claim; @@ -34,8 +35,8 @@ public class GriefPreventionFilter extends CuboidRegionFilter { org.bukkit.Location bot = claim.getGreaterBoundaryCorner(); if (world.equals(bot.getWorld())) { org.bukkit.Location top = claim.getGreaterBoundaryCorner(); - BlockVector2D pos1 = new BlockVector2D(bot.getBlockX(), bot.getBlockZ()); - BlockVector2D pos2 = new BlockVector2D(top.getBlockX(), top.getBlockZ()); + BlockVector2 pos1 = new BlockVector2(bot.getBlockX(), bot.getBlockZ()); + BlockVector2 pos2 = new BlockVector2(top.getBlockX(), top.getBlockZ()); add(pos1, pos2); } } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/WorldGuardFilter.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/WorldGuardFilter.java index e9b8a6bf3..2925b4842 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/WorldGuardFilter.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/filter/WorldGuardFilter.java @@ -5,7 +5,7 @@ import com.boydti.fawe.FaweAPI; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.regions.general.CuboidRegionFilter; import com.boydti.fawe.util.TaskManager; -import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.ApplicableRegionSet; @@ -33,14 +33,14 @@ public class WorldGuardFilter extends CuboidRegionFilter { public void run(Object value) { WorldGuardFilter.this.manager = WorldGuard.getInstance().getPlatform().getRegionContainer().get(FaweAPI.getWorld(world.getName())); for (ProtectedRegion region : manager.getRegions().values()) { - BlockVector min = region.getMinimumPoint(); - BlockVector max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); if (max.getBlockX() - min.getBlockX() > 1024 || max.getBlockZ() - min.getBlockZ() > 1024) { Fawe.debug("Large or complex region shapes cannot be optimized. Filtering will be slower"); large = true; break; } - add(min.toVector2D(), max.toVector2D()); + add(min.toBlockVector2(), max.toBlockVector2()); } } }); @@ -49,8 +49,8 @@ public class WorldGuardFilter extends CuboidRegionFilter { @Override public boolean containsChunk(int chunkX, int chunkZ) { if (!large) return super.containsChunk(chunkX, chunkZ); - BlockVector pos1 = new BlockVector(chunkX << 4, 0, chunkZ << 4); - BlockVector pos2 = new BlockVector(pos1.getBlockX() + 15, 255, pos1.getBlockZ() + 15); + BlockVector3 pos1 = new BlockVector3(chunkX << 4, 0, chunkZ << 4); + BlockVector3 pos2 = new BlockVector3(pos1.getBlockX() + 15, 255, pos1.getBlockZ() + 15); ProtectedCuboidRegion chunkRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2); ApplicableRegionSet set = manager.getApplicableRegions(chunkRegion); return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__"); @@ -59,8 +59,8 @@ public class WorldGuardFilter extends CuboidRegionFilter { @Override public boolean containsRegion(int mcaX, int mcaZ) { if (!large) return super.containsRegion(mcaX, mcaZ); - BlockVector pos1 = new BlockVector(mcaX << 9, 0, mcaZ << 9); - BlockVector pos2 = new BlockVector(pos1.getBlockX() + 511, 255, pos1.getBlockZ() + 511); + BlockVector3 pos1 = new BlockVector3(mcaX << 9, 0, mcaZ << 9); + BlockVector3 pos2 = new BlockVector3(pos1.getBlockX() + 511, 255, pos1.getBlockZ() + 511); ProtectedCuboidRegion regionRegion = new ProtectedCuboidRegion("unimportant", pos1, pos2); ApplicableRegionSet set = manager.getApplicableRegions(regionRegion); return set.size() > 0 && !set.getRegions().iterator().next().getId().equals("__global__"); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java index 68bb97377..ebc9f77ad 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/BukkitImageListener.java @@ -14,6 +14,9 @@ import com.sk89q.worldedit.*; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.InvalidToolBindException; import com.sk89q.worldedit.command.tool.brush.Brush; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; + import java.util.ArrayDeque; import java.util.Collection; import java.util.Iterator; @@ -246,14 +249,14 @@ public class BukkitImageListener implements Listener { if (worldX < 0 || worldX > width || worldZ < 0 || worldZ > length) return; - Vector wPos = new Vector(worldX, 0, worldZ); fp.runAction(new Runnable() { @Override public void run() { + BlockVector3 wPos = new BlockVector3(worldX, 0, worldZ); viewer.refresh(); int topY = generator.getNearestSurfaceTerrainBlock(wPos.getBlockX(), wPos.getBlockZ(), 255, 0, 255); - wPos.mutY(topY); + wPos = wPos.withY(topY); EditSession es = new EditSessionBuilder(fp.getWorld()).player(fp).combineStages(false).autoQueue(false).blockBag(null).limitUnlimited().build(); ExtentTraverser last = new ExtentTraverser(es.getExtent()).last(); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java index f5e2fe05c..e7e73d2de 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/listener/CFIPacketListener.java @@ -22,7 +22,6 @@ import com.comphenix.protocol.wrappers.ChunkCoordIntPair; import com.comphenix.protocol.wrappers.EnumWrappers; import com.comphenix.protocol.wrappers.WrappedBlockData; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; @@ -31,6 +30,9 @@ import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.event.platform.BlockInteractEvent; import com.sk89q.worldedit.event.platform.Interaction; import com.sk89q.worldedit.extension.platform.PlatformManager; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; + import java.lang.reflect.InvocationTargetException; import java.util.List; @@ -62,12 +64,12 @@ public class CFIPacketListener implements Listener { this.protocolmanager = ProtocolLibrary.getProtocolManager(); // Direct digging to the virtual world - registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3() { + registerBlockEvent(PacketType.Play.Client.BLOCK_DIG, false, new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, Vector pt) { + public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { try { Player plr = event.getPlayer(); - Vector realPos = pt.add(gen.getOrigin()); + BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint()); if (!sendBlockChange(plr, gen, pt, Interaction.HIT)) { gen.setBlock(pt, EditSession.nullBlock); } @@ -78,9 +80,9 @@ public class CFIPacketListener implements Listener { }); // Direct placing to the virtual world - RunnableVal3 placeTask = new RunnableVal3() { + RunnableVal3 placeTask = new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, Vector pt) { + public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { try { Player plr = event.getPlayer(); List hands = event.getPacket().getHands().getValues(); @@ -113,9 +115,9 @@ public class CFIPacketListener implements Listener { registerBlockEvent(PacketType.Play.Client.USE_ITEM, true, placeTask); // Cancel block change packets where the real world overlaps with the virtual one - registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3() { + registerBlockEvent(PacketType.Play.Server.BLOCK_CHANGE, false, new RunnableVal3() { @Override - public void run(PacketEvent event, VirtualWorld gen, Vector pt) { + public void run(PacketEvent event, VirtualWorld gen, BlockVector3 pt) { // Do nothing } }); @@ -128,7 +130,7 @@ public class CFIPacketListener implements Listener { VirtualWorld gen = getGenerator(event); if (gen != null) { - Vector origin = gen.getOrigin(); + BlockVector3 origin = gen.getOrigin().toBlockPoint(); PacketContainer packet = event.getPacket(); StructureModifier ints = packet.getIntegers(); int cx = ints.read(0); @@ -137,7 +139,7 @@ public class CFIPacketListener implements Listener { int ocx = origin.getBlockX() >> 4; int ocz = origin.getBlockZ() >> 4; - if (gen.contains(new Vector((cx - ocx) << 4, 0, (cz - ocz) << 4))) { + if (gen.contains(new BlockVector3((cx - ocx) << 4, 0, (cz - ocz) << 4))) { event.setCancelled(true); Player plr = event.getPlayer(); @@ -163,8 +165,8 @@ public class CFIPacketListener implements Listener { Location pos = player.getLocation(); VirtualWorld gen = getGenerator(event); if (gen != null) { - Vector origin = gen.getOrigin(); - Vector pt = new Vector(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + BlockVector3 origin = gen.getOrigin().toBlockPoint(); + BlockVector3 pt = new BlockVector3(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); StructureModifier ints = event.getPacket().getIntegers(); int id = ints.read(0); @@ -188,12 +190,12 @@ public class CFIPacketListener implements Listener { Location pos = player.getLocation(); VirtualWorld gen = getGenerator(event); if (gen != null) { - Vector origin = gen.getOrigin(); - Vector from = new Vector(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); + BlockVector3 origin = gen.getOrigin().toBlockPoint(); + BlockVector3 from = new BlockVector3(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); PacketContainer packet = event.getPacket(); StructureModifier doubles = packet.getDoubles(); - Vector to = new Vector(doubles.read(0), doubles.read(1), doubles.read(2)); + BlockVector3 to = new BlockVector3(doubles.read(0), doubles.read(1), doubles.read(2)); if (gen.contains(to.subtract(origin)) && from.distanceSq(to) < 8) { int id = packet.getIntegers().read(0); PacketContainer reply = new PacketContainer(PacketType.Play.Client.TELEPORT_ACCEPT); @@ -220,10 +222,10 @@ public class CFIPacketListener implements Listener { if (gen != null) { PacketContainer packet = event.getPacket(); ChunkCoordIntPair chunk = packet.getChunkCoordIntPairs().read(0); - Vector origin = gen.getOrigin(); + BlockVector3 origin = gen.getOrigin().toBlockPoint(); int cx = chunk.getChunkX() - (origin.getBlockX() >> 4); int cz = chunk.getChunkZ() - (origin.getBlockX() >> 4); - if (gen.contains(new Vector(cx << 4, 0, cz << 4))) { + if (gen.contains(new BlockVector3(cx << 4, 0, cz << 4))) { event.setCancelled(true); } } @@ -246,14 +248,14 @@ public class CFIPacketListener implements Listener { } } - private boolean sendBlockChange(Player plr, VirtualWorld gen, Vector pt, Interaction action) { + private boolean sendBlockChange(Player plr, VirtualWorld gen, BlockVector3 pt, Interaction action) { PlatformManager platform = WorldEdit.getInstance().getPlatformManager(); com.sk89q.worldedit.entity.Player actor = FawePlayer.wrap(plr).getPlayer(); - com.sk89q.worldedit.util.Location location = new com.sk89q.worldedit.util.Location(actor.getWorld(), pt); + com.sk89q.worldedit.util.Location location = new com.sk89q.worldedit.util.Location(actor.getWorld(), pt.toVector3()); BlockInteractEvent toCall = new BlockInteractEvent(actor, location, action); platform.handleBlockInteract(toCall); if (toCall.isCancelled() || action == Interaction.OPEN) { - Vector realPos = pt.add(gen.getOrigin()); + BlockVector3 realPos = pt.add(gen.getOrigin().toBlockPoint()); BlockStateHolder block = gen.getBlock(pt); sendBlockChange(plr, realPos, block); return true; @@ -261,7 +263,7 @@ public class CFIPacketListener implements Listener { return false; } - private void sendBlockChange(Player plr, Vector pt, BlockStateHolder block) { + private void sendBlockChange(Player plr, BlockVector3 pt, BlockStateHolder block) { plr.sendBlockChange(new Location(plr.getWorld(), pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()), BukkitAdapter.adapt(block)); } @@ -280,20 +282,20 @@ public class CFIPacketListener implements Listener { return null; } - private Vector getRelPos(PacketEvent event, VirtualWorld generator) { + private BlockVector3 getRelPos(PacketEvent event, VirtualWorld generator) { PacketContainer packet = event.getPacket(); StructureModifier position = packet.getBlockPositionModifier(); BlockPosition loc = position.readSafely(0); if (loc == null) return null; - Vector origin = generator.getOrigin(); - Vector pt = new Vector(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ()); + BlockVector3 origin = generator.getOrigin().toBlockPoint(); + BlockVector3 pt = new BlockVector3(loc.getX() - origin.getBlockX(), loc.getY() - origin.getBlockY(), loc.getZ() - origin.getBlockZ()); return pt; } - private void handleBlockEvent(PacketEvent event, boolean relative, RunnableVal3 task) { + private void handleBlockEvent(PacketEvent event, boolean relative, RunnableVal3 task) { VirtualWorld gen = getGenerator(event); if (gen != null) { - Vector pt = getRelPos(event, gen); + BlockVector3 pt = getRelPos(event, gen); if (pt != null) { if (relative) pt = getRelative(event, pt); if (gen.contains(pt)) { @@ -304,7 +306,7 @@ public class CFIPacketListener implements Listener { } } - private void registerBlockEvent(PacketType type, boolean relative, RunnableVal3 task) { + private void registerBlockEvent(PacketType type, boolean relative, RunnableVal3 task) { protocolmanager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.NORMAL, type) { @Override public void onPacketReceiving(final PacketEvent event) { @@ -318,7 +320,7 @@ public class CFIPacketListener implements Listener { }); } - private Vector getRelative(PacketEvent container, Vector pt) { + private BlockVector3 getRelative(PacketEvent container, BlockVector3 pt) { PacketContainer packet = container.getPacket(); StructureModifier dirs = packet.getDirections(); EnumWrappers.Direction dir = dirs.readSafely(0); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMask.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMask.java index 701cd3e30..97a3ccaf1 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMask.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/BukkitMask.java @@ -1,7 +1,8 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.regions.FaweMask; -import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.math.BlockVector3; + import org.bukkit.Location; public class BukkitMask extends FaweMask { @@ -11,6 +12,6 @@ public class BukkitMask extends FaweMask { } public BukkitMask(Location pos1, Location pos2, String name) { - super(new BlockVector(pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ()), new BlockVector(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ()), name); + super(new BlockVector3(pos1.getBlockX(), pos1.getBlockY(), pos1.getBlockZ()), new BlockVector3(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ()), name); } } \ No newline at end of file diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java index 1ef42cdcb..541c023af 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/FreeBuildRegion.java @@ -5,8 +5,8 @@ import com.boydti.fawe.bukkit.wrapper.AsyncWorld; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.queue.NullFaweQueue; import com.boydti.fawe.regions.FaweMask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.block.BlockTypes; @@ -55,8 +55,8 @@ public class FreeBuildRegion extends BukkitMaskManager { World bukkitWorld = player.parent.getWorld(); AsyncWorld asyncWorld = AsyncWorld.wrap(bukkitWorld); - Vector vec1 = new Vector(0, 0, 0); - Vector vec2 = vec1; + BlockVector3 vec1 = new BlockVector3(0, 0, 0); + BlockVector3 vec2 = vec1; Location pos1 = BukkitAdapter.adapt(bukkitWorld, vec1); Location pos2 = BukkitAdapter.adapt(bukkitWorld, vec2); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java index dccb3952a..a751c7540 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/PreciousStonesFeature.java @@ -3,7 +3,8 @@ package com.boydti.fawe.bukkit.regions; import com.boydti.fawe.bukkit.FaweBukkit; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; -import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.List; import net.sacredlabyrinth.Phaed.PreciousStones.PreciousStones; import net.sacredlabyrinth.Phaed.PreciousStones.field.Field; @@ -40,8 +41,8 @@ public class PreciousStonesFeature extends BukkitMaskManager implements Listener boolean member = fp.hasPermission("fawe.preciousstones.member"); for (final Field myField : fields) { if (isAllowed(player, myField, type, member)) { - BlockVector pos1 = new BlockVector(myField.getMinx(), myField.getMiny(), myField.getMinz()); - BlockVector pos2 = new BlockVector(myField.getMaxx(), myField.getMaxy(), myField.getMaxz()); + BlockVector3 pos1 = new BlockVector3(myField.getMinx(), myField.getMiny(), myField.getMinz()); + BlockVector3 pos2 = new BlockVector3(myField.getMaxx(), myField.getMaxy(), myField.getMaxz()); return new FaweMask(pos1, pos2, "FIELD: " + myField) { @Override public boolean isValid(FawePlayer player, MaskType type) { diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java index 156753f4a..8e1668915 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/Worldguard.java @@ -7,8 +7,8 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.RegionWrapper; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.general.RegionFilter; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Polygonal2DRegion; @@ -61,7 +61,7 @@ public class Worldguard extends BukkitMaskManager implements Listener { if (global != null && isAllowed(player, global)) { return global; } - final ApplicableRegionSet regions = manager.getApplicableRegions(new Vector(loc.getX(), loc.getY(), loc.getZ())); + final ApplicableRegionSet regions = manager.getApplicableRegions(new BlockVector3(loc.getX(), loc.getY(), loc.getZ())); for (final ProtectedRegion region : regions) { if (isAllowed(player, region)) { return region; @@ -145,27 +145,27 @@ public class Worldguard extends BukkitMaskManager implements Listener { } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return region.getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return region.getMaximumPoint(); } @Override - public void expand(Vector... changes) { + public void expand(BlockVector3... changes) { throw new UnsupportedOperationException("Region is immutable"); } @Override - public void contract(Vector... changes) { + public void contract(BlockVector3... changes) { throw new UnsupportedOperationException("Region is immutable"); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { return region.contains(position); } } @@ -179,8 +179,8 @@ public class Worldguard extends BukkitMaskManager implements Listener { } if (region instanceof ProtectedPolygonalRegion) { ProtectedPolygonalRegion casted = (ProtectedPolygonalRegion) region; - BlockVector max = region.getMaximumPoint(); - BlockVector min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); return new Polygonal2DRegion(null, casted.getPoints(), min.getBlockY(), max.getBlockY()); } return new AdaptedRegion(region); diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java index 21e673f41..3f3f1a842 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/regions/WorldguardFlag.java @@ -5,7 +5,7 @@ import com.boydti.fawe.bukkit.filter.WorldGuardFilter; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.regions.FaweMask; import com.boydti.fawe.regions.general.RegionFilter; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; @@ -65,45 +65,45 @@ public class WorldguardFlag extends BukkitMaskManager implements Listener { } @Override - public Vector getMinimumPoint() { - Vector point = null; + public BlockVector3 getMinimumPoint() { + BlockVector3 point = null; for (Map.Entry entry : manager.getRegions().entrySet()) { - Vector p = entry.getValue().getMinimumPoint(); + BlockVector3 p = entry.getValue().getMinimumPoint(); if (point == null) { point = p; continue; } - point = Vector.getMinimum(point, p); + point = point.getMinimum(p); } return point; } @Override - public Vector getMaximumPoint() { - Vector point = null; + public BlockVector3 getMaximumPoint() { + BlockVector3 point = null; for (Map.Entry entry : manager.getRegions().entrySet()) { - Vector p = entry.getValue().getMaximumPoint(); + BlockVector3 p = entry.getValue().getMaximumPoint(); if (point == null) { point = p; continue; } - point = Vector.getMaximum(point, p); + point = point.getMaximum(p); } return point; } @Override - public void expand(Vector... changes) { + public void expand(BlockVector3... changes) { throw new UnsupportedOperationException("Region is immutable"); } @Override - public void contract(Vector... changes) { + public void contract(BlockVector3... changes) { throw new UnsupportedOperationException("Region is immutable"); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { // Make sure that all these flags are not denied. Denies override allows. WorldGuardExtraFlags can add Flags.WORLDEDIT return manager.getApplicableRegions(position).testState(localplayer, Flags.BUILD, Flags.BLOCK_PLACE, Flags.BLOCK_BREAK); } diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java index 15a397bf8..c4d16e9f9 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/util/cui/StructureCUI.java @@ -13,11 +13,12 @@ import com.comphenix.protocol.wrappers.BlockPosition; import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtCompound; import com.comphenix.protocol.wrappers.nbt.NbtFactory; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.internal.cui.SelectionPointEvent; import com.sk89q.worldedit.internal.cui.SelectionShapeEvent; +import com.sk89q.worldedit.math.BlockVector3; + import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.Map; @@ -33,10 +34,10 @@ import org.bukkit.entity.Player; public class StructureCUI extends CUI { private boolean cuboid = true; - private Vector pos1; - private Vector pos2; + private BlockVector3 pos1; + private BlockVector3 pos2; - private Vector remove; + private BlockVector3 remove; private NbtCompound removeTag; private BlockState state; @@ -56,7 +57,7 @@ public class StructureCUI extends CUI { int x = Integer.parseInt(param[1]); int y = Integer.parseInt(param[2]); int z = Integer.parseInt(param[3]); - Vector pos = new Vector(x, y, z); + BlockVector3 pos = new BlockVector3(x, y, z); if (id == 0) { pos1 = pos; } else { @@ -123,7 +124,7 @@ public class StructureCUI extends CUI { } } - private void sendNbt(Vector pos, NbtCompound compound) { + private void sendNbt(BlockVector3 pos, NbtCompound compound) { Player player = this.getPlayer().parent; ProtocolManager manager = ProtocolLibrary.getProtocolManager(); @@ -158,8 +159,8 @@ public class StructureCUI extends CUI { remove = null; } if (pos1 == null || pos2 == null) return; - Vector min = Vector.getMinimum(pos1, pos2); - Vector max = Vector.getMaximum(pos1, pos2); + BlockVector3 min = pos1.getMinimum(pos2); + BlockVector3 max = pos1.getMaximum(pos2); // Position double rotX = playerLoc.getYaw(); @@ -187,7 +188,7 @@ public class StructureCUI extends CUI { NbtCompound compound = constructStructureNbt(x, y, z, posX, posY, posZ, sizeX, sizeY, sizeZ); Block block = player.getWorld().getBlockAt(x, y, z); - remove = new Vector(x, y, z); + remove = new BlockVector3(x, y, z); state = BukkitAdapter.adapt(block.getBlockData()); removeTag = compound; diff --git a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java index 781cfe9b8..6c8dbb19b 100644 --- a/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java +++ b/worldedit-bukkit/src/main/java/com/boydti/fawe/bukkit/v0/FaweAdapter_All.java @@ -18,7 +18,7 @@ //import com.sk89q.jnbt.StringTag; //import com.sk89q.jnbt.Tag; //import com.sk89q.worldedit.blocks.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; +//import com.sk89q.worldedit.world.block.BlockState; //import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; //import com.sk89q.worldedit.entity.BaseEntity; //import com.sk89q.worldedit.internal.Constants; 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 885a961b3..3e92817dd 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 @@ -19,12 +19,13 @@ package com.sk89q.worldedit.bukkit; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.IBukkitAdapter; import com.sk89q.worldedit.bukkit.adapter.SimpleBukkitAdapter; import com.sk89q.worldedit.entity.Entity; +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; @@ -34,6 +35,7 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.entity.EntityType; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.item.ItemType; + import org.bukkit.Material; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Player; @@ -84,7 +86,11 @@ public enum BukkitAdapter { return getAdapter().adapt(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) { + return getAdapter().adapt(world, position); + } + + public static org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position) { return getAdapter().adapt(world, position); } @@ -92,10 +98,14 @@ public enum BukkitAdapter { return getAdapter().adapt(world, location); } - public static Vector asVector(org.bukkit.Location location) { + public static Vector3 asVector(org.bukkit.Location location) { return getAdapter().asVector(location); } + public static BlockVector3 asBlockVector(org.bukkit.Location location) { + return getAdapter().asBlockVector(location); + } + public static Entity adapt(org.bukkit.entity.Entity entity) { return getAdapter().adapt(entity); } 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 be3f6ff1f..f14f28ad4 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 @@ -22,20 +22,26 @@ package com.sk89q.worldedit.bukkit; import com.boydti.fawe.object.RunnableVal; import com.boydti.fawe.util.TaskManager; import com.sk89q.util.StringUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.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.BlockState; +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.Material; @@ -147,7 +153,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)); } @@ -205,7 +211,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); } @@ -217,7 +223,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, 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 b328523c7..0ceea15b0 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,13 +21,20 @@ package com.sk89q.worldedit.bukkit; import com.boydti.fawe.Fawe; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.blocks.LazyBlock; 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; @@ -35,6 +42,7 @@ import com.sk89q.worldedit.world.biome.BaseBiome; 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; @@ -53,8 +61,6 @@ import java.util.*; import java.util.logging.Level; import java.util.logging.Logger; -import static com.google.common.base.Preconditions.checkNotNull; - public class BukkitWorld extends AbstractWorld { private static final Logger logger = WorldEdit.logger; @@ -84,7 +90,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()))) { addEntities(ent, entities); } } @@ -185,7 +191,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(); } @@ -193,14 +199,14 @@ public class BukkitWorld extends AbstractWorld { public boolean regenerate(Region region, EditSession editSession) { com.sk89q.worldedit.world.block.BlockStateHolder[] history = new com.sk89q.worldedit.world.block.BlockState[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); } @@ -217,14 +223,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))); } } } @@ -263,7 +269,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; @@ -317,7 +323,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, @@ -325,13 +331,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)) { @@ -363,15 +369,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); @@ -430,18 +436,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) { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { try { @@ -467,12 +473,12 @@ public class BukkitWorld extends AbstractWorld { } @Override - public com.sk89q.worldedit.world.block.BlockState getLazyBlock(Vector position) { + public com.sk89q.worldedit.world.block.BlockState getLazyBlock(BlockVector3 position) { return getBlock(position); } @Override - public com.sk89q.worldedit.world.block.BlockState getFullBlock(Vector position) { + public com.sk89q.worldedit.world.block.BlockState getFullBlock(BlockVector3 position) { BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); if (adapter != null) { return adapter.getBlock(BukkitAdapter.adapt(getWorld(), position)); @@ -482,7 +488,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())); @@ -493,7 +499,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 140873d8b..366b2a974 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 @@ -23,6 +23,10 @@ import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockMaterial; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.entity.BaseEntity; +import com.sk89q.worldedit.entity.Player; +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.BlockState; @@ -104,6 +108,14 @@ public interface BukkitImplAdapter extends IBukkitAdapter { default BlockMaterial getMaterial(BlockType blockType) { return null; } + /** + * Send the given NBT data to the player. + * + * @param player The player + * @param pos The position + * @param nbtData The NBT Data + */ + void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData); default BlockMaterial getMaterial(BlockState blockState) { return null; diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java index 1e7e9e014..95d5cde29 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/adapter/IBukkitAdapter.java @@ -1,10 +1,11 @@ package com.sk89q.worldedit.bukkit.adapter; import com.sk89q.worldedit.NotABlockException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.bukkit.*; import com.sk89q.worldedit.entity.Entity; +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; @@ -96,7 +97,7 @@ public interface IBukkitAdapter { */ default 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, @@ -112,7 +113,7 @@ public interface IBukkitAdapter { */ default 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(), @@ -127,13 +128,17 @@ public interface IBukkitAdapter { * @param position the WorldEdit position * @return a Bukkit location */ - default org.bukkit.Location adapt(org.bukkit.World world, Vector position) { + default 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()); } + + default org.bukkit.Location adapt(org.bukkit.World world, BlockVector3 position){ + return adapt(world, position.toVector3()); + } /** * Create a Bukkit location from a WorldEdit location with a Bukkit world. @@ -158,9 +163,20 @@ public interface IBukkitAdapter { * @param location The Bukkit location * @return a WorldEdit vector */ - default Vector asVector(org.bukkit.Location location) { + default 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 + */ + default BlockVector3 asBlockVector(org.bukkit.Location location) { + checkNotNull(location); + return new BlockVector3(location.getX(), location.getY(), location.getZ()); } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java index 435524283..a05e5d697 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/FaweAPI.java @@ -19,13 +19,7 @@ import com.boydti.fawe.util.SetQueue; import com.boydti.fawe.util.TaskManager; import com.boydti.fawe.util.WEManager; import com.boydti.fawe.wrappers.WorldWrapper; -import com.sk89q.jnbt.ByteArrayTag; -import com.sk89q.jnbt.IntTag; -import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.jnbt.ShortTag; -import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extension.factory.DefaultMaskParser; @@ -39,27 +33,22 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.internal.registry.AbstractFactory; import com.sk89q.worldedit.internal.registry.InputParser; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.AbstractWorld; import com.sk89q.worldedit.world.World; import java.io.File; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.lang.reflect.Field; import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import java.util.UUID; -import java.util.zip.GZIPInputStream; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -468,8 +457,8 @@ public class FaweAPI { * @return */ public static int fixLighting(World world, Region selection, @Nullable FaweQueue queue, final FaweQueue.RelightMode mode) { - final Vector bot = selection.getMinimumPoint(); - final Vector top = selection.getMaximumPoint(); + final BlockVector3 bot = selection.getMinimumPoint(); + final BlockVector3 top = selection.getMaximumPoint(); final int minX = bot.getBlockX() >> 4; final int minZ = bot.getBlockZ() >> 4; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java index a39c0f203..63778d71b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/AnvilCommands.java @@ -21,7 +21,6 @@ import com.boydti.fawe.util.StringMan; import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BlockType; @@ -29,6 +28,7 @@ import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.internal.annotation.Selection; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.command.binding.Switch; @@ -396,8 +396,8 @@ public class AnvilCommands { ) @CommandPermissions("worldedit.anvil.clear") public void unset(Player player, EditSession editSession, @Selection Region selection) throws WorldEditException { - Vector bot = selection.getMinimumPoint(); - Vector top = selection.getMaximumPoint(); + BlockVector3 bot = selection.getMinimumPoint(); + BlockVector3 top = selection.getMaximumPoint(); RegionWrapper region = new RegionWrapper(bot, top); MCAFilterCounter filter = new MCAFilterCounter() { @@ -618,8 +618,8 @@ public class AnvilCommands { ) @CommandPermissions("worldedit.anvil.removelayer") public void removeLayers(Player player, EditSession editSession, @Selection Region selection, int id) throws WorldEditException { - Vector min = selection.getMinimumPoint(); - Vector max = selection.getMaximumPoint(); + BlockVector3 min = selection.getMinimumPoint(); + BlockVector3 max = selection.getMaximumPoint(); int minY = min.getBlockY(); int maxY = max.getBlockY(); RemoveLayerFilter filter = new RemoveLayerFilter(minY, maxY, id); @@ -644,7 +644,7 @@ public class AnvilCommands { String worldName = Fawe.imp().getWorldName(editSession.getWorld()); FaweQueue tmp = SetQueue.IMP.getNewQueue(worldName, true, false); MCAQueue queue = new MCAQueue(tmp); - Vector origin = session.getPlacementPosition(player); + BlockVector3 origin = session.getPlacementPosition(player); MCAClipboard clipboard = new MCAClipboard(queue, cuboid, origin); FawePlayer fp = FawePlayer.wrap(player); fp.setMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD, clipboard); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java index e5cb2539b..d7da435bd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/CFICommands.java @@ -41,6 +41,8 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.request.Request; @@ -421,7 +423,7 @@ public class CFICommands extends MethodCommands { ClipboardHolder holder = fp.getSession().getClipboard(); Clipboard clipboard = holder.getClipboard(); boolean[] ids = new boolean[BlockTypes.size()]; - for (Vector pt : clipboard.getRegion()) { + for (BlockVector3 pt : clipboard.getRegion()) { ids[clipboard.getBlock(pt).getInternalBlockTypeId()] = true; } blocks = new HashSet<>(); @@ -447,7 +449,7 @@ public class CFICommands extends MethodCommands { BlockType type = BlockTypes.get(typeId); BlockStateHolder block = type.getDefaultState(); pattern.setBlock(block); - if (mask.test(Vector.ZERO)) blocks.add(type); + if (mask.test(BlockVector3.ZERO)) blocks.add(type); } break; } @@ -663,7 +665,7 @@ public class CFICommands extends MethodCommands { public void tp(FawePlayer fp) throws ParameterException, WorldEditException { HeightMapMCAGenerator gen = assertSettings(fp).getGenerator(); msg("Teleporting...").send(fp); - Vector origin = gen.getOrigin(); + Vector3 origin = gen.getOrigin(); Player player = fp.getPlayer(); player.setPosition(origin.subtract(16, 0, 16)); player.findFreePosition(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java b/worldedit-core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java index c3c6b6a94..ec14c5ac5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/command/FawePrimitiveBinding.java @@ -9,8 +9,6 @@ import com.boydti.fawe.util.TextureUtil; import com.boydti.fawe.util.image.ImageUtil; 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.entity.Entity; import com.sk89q.worldedit.entity.Player; @@ -22,6 +20,8 @@ import com.sk89q.worldedit.extent.Extent; 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.Vector2; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.command.binding.Range; import com.sk89q.worldedit.util.command.binding.Text; @@ -257,11 +257,11 @@ public class FawePrimitiveBinding extends BindingHelper { * @return the requested type * @throws ParameterException on error */ - @BindingMatch(type = Vector.class, + @BindingMatch(type = Vector3.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) - public Vector getVector(ArgumentStack context, Annotation[] modifiers) throws ParameterException { + public Vector3 getVector(ArgumentStack context, Annotation[] modifiers) throws ParameterException { String radiusString = context.next(); String[] radii = radiusString.split(","); final double radiusX, radiusY, radiusZ; @@ -279,7 +279,7 @@ public class FawePrimitiveBinding extends BindingHelper { default: throw new ParameterException("You must either specify 1 or 3 radius values."); } - return new Vector(radiusX, radiusY, radiusZ); + return new Vector3(radiusX, radiusY, radiusZ); } @@ -290,11 +290,11 @@ public class FawePrimitiveBinding extends BindingHelper { * @return the requested type * @throws ParameterException on error */ - @BindingMatch(type = Vector2D.class, + @BindingMatch(type = Vector2.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1, provideModifiers = true) - public Vector2D getVector2D(ArgumentStack context, Annotation[] modifiers) throws ParameterException { + public Vector2 getVector2D(ArgumentStack context, Annotation[] modifiers) throws ParameterException { String radiusString = context.next(); String[] radii = radiusString.split(","); final double radiusX, radiusZ; @@ -311,7 +311,7 @@ public class FawePrimitiveBinding extends BindingHelper { default: throw new ParameterException("You must either specify 1 or 2 radius values."); } - return new Vector2D(radiusX, radiusZ); + return new Vector2(radiusX, radiusZ); } /** diff --git a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java index f29066d04..6e11ca542 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/database/RollbackDatabase.java @@ -9,7 +9,8 @@ import com.boydti.fawe.object.changeset.DiskStorageHistory; import com.boydti.fawe.object.task.AsyncNotifyQueue; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.World; import java.io.File; import java.io.IOException; @@ -126,7 +127,7 @@ public class RollbackDatabase extends AsyncNotifyQueue { }); } - public void getPotentialEdits(final UUID uuid, final long minTime, final Vector pos1, final Vector pos2, final RunnableVal onEach, final Runnable whenDone, final boolean delete, final boolean ascending) { + public void getPotentialEdits(final UUID uuid, final long minTime, final BlockVector3 pos1, final BlockVector3 pos2, final RunnableVal onEach, final Runnable whenDone, final boolean delete, final boolean ascending) { final World world = FaweAPI.getWorld(this.worldName); addTask(new Runnable() { @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java index a58f9f377..c6bad5c59 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/CorruptSchematicStreamer.java @@ -9,10 +9,11 @@ import com.boydti.fawe.object.clipboard.MemoryOptimizedClipboard; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTInputStream; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.CuboidRegion; import java.io.BufferedInputStream; import java.io.DataInputStream; @@ -81,7 +82,7 @@ public class CorruptSchematicStreamer { if (fc != null) { return fc; } - Vector dimensions = guessDimensions(volume.get(), width.get(), height.get(), length.get()); + BlockVector3 dimensions = guessDimensions(volume.get(), width.get(), height.get(), length.get()); if (width.get() == 0 || height.get() == 0 || length.get() == 0) { Fawe.debug("No dimensions found! Estimating based on factors:" + dimensions); } @@ -265,21 +266,21 @@ public class CorruptSchematicStreamer { // } } - private Vector guessDimensions(int volume, int width, int height, int length) { + private BlockVector3 guessDimensions(int volume, int width, int height, int length) { if (volume == 0) { - return new Vector(width, height, length); + return new BlockVector3(width, height, length); } if (volume == width * height * length) { - return new Vector(width, height, length); + return new BlockVector3(width, height, length); } if (width == 0 && height != 0 && length != 0 && volume % (height * length) == 0 && height * length <= volume) { - return new Vector(volume / (height * length), height, length); + return new BlockVector3(volume / (height * length), height, length); } if (height == 0 && width != 0 && length != 0 && volume % (width * length) == 0 && width * length <= volume) { - return new Vector(width, volume / (width * length), length); + return new BlockVector3(width, volume / (width * length), length); } if (length == 0 && height != 0 && width != 0 && volume % (height * width) == 0 && height * width <= volume) { - return new Vector(width, height, volume / (width * height)); + return new BlockVector3(width, height, volume / (width * height)); } List factors = new ArrayList<>(); for (int i = (int) Math.sqrt(volume); i > 0; i--) { @@ -289,7 +290,7 @@ public class CorruptSchematicStreamer { } } int min = Integer.MAX_VALUE; - Vector dimensions = new Vector(); + int vx = 0, vy = 0, vz = 0; for (int x = 0; x < factors.size(); x++) { int xValue = factors.get(x); for (int y = 0; y < factors.size(); y++) { @@ -300,12 +301,14 @@ public class CorruptSchematicStreamer { int max = Math.max(Math.max(xValue, yValue), z); if (max < min) { min = max; - dimensions = new Vector(xValue, z, yValue); + vx = xValue; + vz = z; + vy = yValue; } } } } - return dimensions; + return new BlockVector3(vx, vz, vy); } public interface CorruptReader { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java index 670107c7b..628830d4f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/SchematicStreamer.java @@ -14,12 +14,12 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.StringTag; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockMaterial; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.registry.state.PropertyKey; import com.sk89q.worldedit.util.Direction; @@ -49,7 +49,7 @@ public class SchematicStreamer extends NBTStreamer { public SchematicStreamer(NBTInputStream stream, UUID uuid) { super(stream); this.uuid = uuid; - clipboard = new BlockArrayClipboard(new CuboidRegion(new Vector(0, 0, 0), new Vector(0, 0, 0)), fc); + clipboard = new BlockArrayClipboard(new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(0, 0, 0)), fc); } public void addBlockReaders() throws IOException { @@ -180,7 +180,7 @@ public class SchematicStreamer extends NBTStreamer { FaweInputStream dataIn = new FaweInputStream(new LZ4BlockInputStream(new FastByteArraysInputStream(dataOut.toByteArrays()))); LegacyMapper remap = LegacyMapper.getInstance(); - Vector dimensions = fc.getDimensions(); + BlockVector3 dimensions = fc.getDimensions(); int length = dimensions.getBlockX() * dimensions.getBlockY() * dimensions.getBlockZ(); if (adds == null) { for (int i = 0; i < length; i++) { @@ -223,7 +223,7 @@ public class SchematicStreamer extends NBTStreamer { Object half = block.getState(PropertyKey.HALF); Direction facing = block.getState(PropertyKey.FACING); - BlockVector forward = facing.toBlockVector(); + BlockVector3 forward = facing.toBlockVector(); Direction left = facing.getLeft(); Direction right = facing.getRight(); @@ -419,7 +419,7 @@ public class SchematicStreamer extends NBTStreamer { private FaweClipboard setupClipboard(int size) { if (fc != null) { if (fc.getDimensions().getX() == 0) { - fc.setDimensions(new Vector(size, 1, 1)); + fc.setDimensions(new BlockVector3(size, 1, 1)); } return fc; } @@ -432,16 +432,16 @@ public class SchematicStreamer extends NBTStreamer { } } - public Vector getOrigin() { - return new Vector(originX, originY, originZ); + public BlockVector3 getOrigin() { + return new BlockVector3(originX, originY, originZ); } - public Vector getOffset() { - return new Vector(offsetX, offsetY, offsetZ); + public BlockVector3 getOffset() { + return new BlockVector3(offsetX, offsetY, offsetZ); } - public Vector getDimensions() { - return new Vector(width, height, length); + public BlockVector3 getDimensions() { + return new BlockVector3(width, height, length); } public void setClipboard(FaweClipboard clipboard) { @@ -453,13 +453,13 @@ public class SchematicStreamer extends NBTStreamer { addDimensionReaders(); addBlockReaders(); readFully(); - Vector min = new Vector(originX, originY, originZ); - Vector offset = new Vector(offsetX, offsetY, offsetZ); - Vector origin = min.subtract(offset); - Vector dimensions = new Vector(width, height, length); + BlockVector3 min = new BlockVector3(originX, originY, originZ); + BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ); + BlockVector3 origin = min.subtract(offset); + BlockVector3 dimensions = new BlockVector3(width, height, length); fc.setDimensions(dimensions); fixStates(); - CuboidRegion region = new CuboidRegion(min, min.add(width, height, length).subtract(Vector.ONE)); + CuboidRegion region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); clipboard.init(region, fc); clipboard.setOrigin(origin); return clipboard; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java index c8118e4d1..524ab74ee 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/HeightMapMCAGenerator.java @@ -16,13 +16,17 @@ import com.boydti.fawe.util.image.Drawable; import com.boydti.fawe.util.image.ImageViewer; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector2; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.CuboidRegion; @@ -194,7 +198,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr // These three variables should be set together // private FaweQueue packetQueue; private FawePlayer player; - private Vector2D chunkOffset = Vector2D.ZERO; + private BlockVector2 chunkOffset = BlockVector2.ZERO; private EditSession editSession; // end @@ -229,8 +233,8 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public Vector getOrigin() { - return new BlockVector(chunkOffset.getBlockX() << 4, 0, chunkOffset.getBlockZ() << 4); + public Vector3 getOrigin() { + return new Vector3(chunkOffset.getBlockX() << 4, 0, chunkOffset.getBlockZ() << 4); } public boolean hasPacketViewer() { @@ -241,7 +245,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr this.player = player; if (player != null) { FaweLocation pos = player.getLocation(); - this.chunkOffset = new Vector2D(1 + (pos.x >> 4), 1 + (pos.z >> 4)); + this.chunkOffset = new BlockVector2(1 + (pos.x >> 4), 1 + (pos.z >> 4)); } } @@ -375,7 +379,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr smooth(null, mask, false, radius, iterations); } - public void smooth(Vector2D min, Vector2D max, int radius, int iterations) { + public void smooth(BlockVector2 min, BlockVector2 max, int radius, int iterations) { int snowLayer = BlockTypes.SNOW.getInternalId(); int snowBlock = BlockTypes.SNOW_BLOCK.getInternalId(); @@ -550,13 +554,13 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } public void addCaves() throws WorldEditException { - CuboidRegion region = new CuboidRegion(new Vector(0, 0, 0), new Vector(getWidth() -1, 255, getLength() -1)); + CuboidRegion region = new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(getWidth() -1, 255, getLength() -1)); addCaves(region); } @Deprecated public void addSchems(Mask mask, List clipboards, int rarity, boolean rotate) throws WorldEditException { - CuboidRegion region = new CuboidRegion(new Vector(0, 0, 0), new Vector(getWidth() -1, 255, getLength() -1)); + CuboidRegion region = new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(getWidth() -1, 255, getLength() -1)); addSchems(region, mask, clipboards, rarity, rotate); } @@ -661,17 +665,17 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } public void addOre(Mask mask, Pattern material, int size, int frequency, int rarity, int minY, int maxY) throws WorldEditException { - CuboidRegion region = new CuboidRegion(new Vector(0, 0, 0), new Vector(getWidth() -1, 255, getLength() -1)); + CuboidRegion region = new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(getWidth() -1, 255, getLength() -1)); addOre(region, mask, material, size, frequency, rarity, minY, maxY); } public void addDefaultOres(Mask mask) throws WorldEditException { - addOres(new CuboidRegion(new Vector(0, 0, 0), new Vector(getWidth() -1, 255, getLength() -1)), mask); + addOres(new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(getWidth() -1, 255, getLength() -1)), mask); } @Override - public Vector getMinimumPoint() { - return new Vector(0, 0, 0); + public BlockVector3 getMinimumPoint() { + return new BlockVector3(0, 0, 0); } @Override @@ -680,17 +684,17 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public Vector getMaximumPoint() { - return new Vector(getWidth() - 1, 255, getLength() - 1); + public BlockVector3 getMaximumPoint() { + return new BlockVector3(getWidth() - 1, 255, getLength() - 1); } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return setBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ(), block); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return this.setBiome(position.getBlockX(), position.getBlockZ(), biome); } @@ -1011,12 +1015,12 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return FaweCache.CACHE_BIOME[getBiomeId(position.getBlockX(), position.getBlockZ())]; } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return getLazyBlock(position); } @@ -1040,7 +1044,7 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } @@ -2240,33 +2244,40 @@ public class HeightMapMCAGenerator extends MCAWriter implements StreamChange, Dr } @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { return setBlock(position, block); } // These aren't implemented yet... @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 void dropItem(Vector position, BaseItemStack item) { - - } - @Override public boolean regenerate(Region region, EditSession editSession) { return false; } @Override - public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { + public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { return false; } + + @Override + public void dropItem(Vector3 position, BaseItemStack item) { + // TODO Auto-generated method stub + + } + + @Override + public boolean playEffect(Vector3 position, int type, int data) { + // TODO Auto-generated method stub + return false; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAClipboard.java index 9a12188d3..0315da413 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAClipboard.java @@ -1,14 +1,14 @@ package com.boydti.fawe.jnbt.anvil; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; public class MCAClipboard { private final MCAQueue queue; private final CuboidRegion region; - private final Vector origin; + private final BlockVector3 origin; - public MCAClipboard(MCAQueue queue, CuboidRegion region, Vector origin) { + public MCAClipboard(MCAQueue queue, CuboidRegion region, BlockVector3 origin) { this.queue = queue; this.region = region; this.origin = origin; @@ -22,7 +22,7 @@ public class MCAClipboard { return region; } - public Vector getOrigin() { + public BlockVector3 getOrigin() { return origin; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java index 7a3206e67..28dab081e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/MCAQueue.java @@ -16,7 +16,7 @@ import com.boydti.fawe.object.RunnableVal4; import com.boydti.fawe.object.collection.IterableThreadLocal; import com.boydti.fawe.util.MainUtil; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; import java.io.File; import java.io.IOException; @@ -155,11 +155,11 @@ public class MCAQueue extends NMSMappedFaweQueue nbt = ReflectionUtils.getMap(block.getNbtData().getValue()); @@ -75,7 +77,7 @@ public class MCAWorld implements SimpleWorld { } @Override - public void dropItem(Vector position, BaseItemStack item) { + public void dropItem(Vector3 position, BaseItemStack item) { } @@ -101,17 +103,23 @@ public class MCAWorld implements SimpleWorld { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return extent.getLazyBlock(position); } @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 boolean playEffect(Vector3 position, int type, int data) { + // TODO Auto-generated method stub + return false; + } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/MappedReplacePatternFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/MappedReplacePatternFilter.java index 76ac980ba..678f165be 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/MappedReplacePatternFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/filters/MappedReplacePatternFilter.java @@ -4,7 +4,6 @@ import com.boydti.fawe.FaweCache; import com.boydti.fawe.jnbt.anvil.MCAFilterCounter; import com.boydti.fawe.object.number.MutableLong; import com.boydti.fawe.util.StringMan; -import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extension.input.InputParseException; @@ -53,7 +52,7 @@ public class MappedReplacePatternFilter extends MCAFilterCounter { // map[block.getCombined()] = pattern; } - private final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); +// private final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); @Override public void applyBlock(int x, int y, int z, BaseBlock block, MutableLong ignore) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java index 5787f5bf1..00541a2c2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/CavesGen.java @@ -3,11 +3,11 @@ package com.boydti.fawe.jnbt.anvil.generator; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -42,11 +42,11 @@ public class CavesGen extends GenBase { this.caveSystemPocketMaxSize = caveSystemPocketMaxSize; } - protected void generateLargeCaveNode(long seed, Vector2D pos, Extent chunk, double x, double y, double z) throws WorldEditException { + protected void generateLargeCaveNode(long seed, BlockVector2 pos, Extent chunk, double x, double y, double z) throws WorldEditException { generateCaveNode(seed, pos, chunk, x, y, z, 1.0F + PseudoRandom.random.nextDouble() * 6.0F, 0.0F, 0.0F, -1, -1, 0.5D); } - protected void generateCaveNode(long seed, Vector2D chunkPos, Extent chunk, double x, double y, double z, double paramdouble1, double paramdouble2, double paramdouble3, int angle, int maxAngle, double paramDouble4) throws WorldEditException { + protected void generateCaveNode(long seed, BlockVector2 chunkPos, Extent chunk, double x, double y, double z, double paramdouble1, double paramdouble2, double paramdouble3, int angle, int maxAngle, double paramDouble4) throws WorldEditException { int bx = (chunkPos.getBlockX() << 4); int bz = (chunkPos.getBlockZ() << 4); double real_x = bx + 7; @@ -220,7 +220,7 @@ public class CavesGen extends GenBase { } @Override - public void generateChunk(Vector2D adjacentChunk, Vector2D originChunk, Extent chunk) throws WorldEditException { + public void generateChunk(int chunkX, int chunkZ, BlockVector2 originChunk, Extent chunk) throws WorldEditException { PseudoRandom random = getRandom(); int i = random.nextInt(random.nextInt(random.nextInt(this.caveFrequency) + 1) + 1); if (this.evenCaveDistribution) @@ -229,7 +229,7 @@ public class CavesGen extends GenBase { i = 0; for (int j = 0; j < i; j++) { - double x = (adjacentChunk.getBlockX() << 4) + random.nextInt(16); + double x = (chunkX << 4) + random.nextInt(16); double y; @@ -238,7 +238,7 @@ public class CavesGen extends GenBase { else y = random.nextInt(random.nextInt(this.caveMaxAltitude - this.caveMinAltitude + 1) + 1) + this.caveMinAltitude; - double z = (adjacentChunk.getBlockZ() << 4) + random.nextInt(16); + double z = (chunkZ << 4) + random.nextInt(16); int count = this.caveSystemFrequency; boolean largeCaveSpawned = false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/GenBase.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/GenBase.java index ca46d4fef..2cbb53af2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/GenBase.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/GenBase.java @@ -1,10 +1,9 @@ package com.boydti.fawe.jnbt.anvil.generator; import com.boydti.fawe.object.PseudoRandom; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; public abstract class GenBase { @@ -12,7 +11,6 @@ public abstract class GenBase { private final PseudoRandom random; private final long seed; private final long worldSeed1, worldSeed2; - private MutableBlockVector2D mutable = new MutableBlockVector2D(); public GenBase(int area) { this.random = new PseudoRandom(); @@ -30,20 +28,17 @@ public abstract class GenBase { return random; } - public void generate(Vector2D chunkPos, Extent chunk) throws WorldEditException { + public void generate(BlockVector2 chunkPos, Extent chunk) throws WorldEditException { int i = this.checkAreaSize; int chunkX = chunkPos.getBlockX(); int chunkZ = chunkPos.getBlockZ(); - for (int x = chunkX - i; x <= chunkX + i; x++) { - mutable.mutX(x); for (int z = chunkZ - i; z <= chunkZ + i; z++) { - mutable.mutZ(z); this.random.setSeed(worldSeed1 * x ^ worldSeed2 * z ^ seed); - generateChunk(mutable, chunkPos, chunk); + generateChunk(x, z, chunkPos, chunk); } } } - public abstract void generateChunk(Vector2D adjacentChunk, Vector2D originChunk, Extent chunk) throws WorldEditException; + public abstract void generateChunk(int x, int z, BlockVector2 originChunk, Extent chunk) throws WorldEditException; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/OreGen.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/OreGen.java index c9af936e1..47e78d776 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/OreGen.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/OreGen.java @@ -2,11 +2,11 @@ package com.boydti.fawe.jnbt.anvil.generator; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.MutableBlockVector; import java.util.Random; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/SchemGen.java b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/SchemGen.java index 020a9ca9a..d39f3b9c3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/SchemGen.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/jnbt/anvil/generator/SchemGen.java @@ -2,7 +2,7 @@ package com.boydti.fawe.jnbt.anvil.generator; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.schematic.Schematic; -import com.sk89q.worldedit.MutableBlockVector; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java index 50251c4ac..78351c6b7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/logging/rollback/RollbackOptimizedHistory.java @@ -4,7 +4,7 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.database.DBHandler; import com.boydti.fawe.database.RollbackDatabase; import com.boydti.fawe.object.changeset.DiskStorageHistory; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import java.io.IOException; import java.io.OutputStream; @@ -68,7 +68,7 @@ public class RollbackOptimizedHistory extends DiskStorageHistory { return maxZ; } - public void setDimensions(Vector pos1, Vector pos2) { + public void setDimensions(BlockVector3 pos1, BlockVector3 pos2) { this.minX = pos1.getBlockX(); this.minY = pos1.getBlockY(); this.minZ = pos1.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java index 37e924fc8..2819e376d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/DataAnglePattern.java @@ -2,12 +2,12 @@ package com.boydti.fawe.object; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.extent.ExtentHeightCacher; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -24,7 +24,7 @@ public class DataAnglePattern extends AbstractPattern { this.FACTOR = (1D / distance) * (1D / 255); } - public int getSlope(BlockStateHolder block, Vector vector) { + public int getSlope(BlockStateHolder block, BlockVector3 vector) { int x = vector.getBlockX(); int y = vector.getBlockY(); int z = vector.getBlockZ(); @@ -41,7 +41,7 @@ public class DataAnglePattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder block = extent.getBlock(position); int slope = getSlope(block, position); if (slope == -1) return block; @@ -50,7 +50,7 @@ public class DataAnglePattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { BlockStateHolder block = extent.getBlock(getPosition); int slope = getSlope(block, getPosition); if (slope == -1) return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java index 81ff10de0..068b5564e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FawePlayer.java @@ -17,13 +17,14 @@ import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper; import com.boydti.fawe.wrappers.PlayerWrapper; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.worldedit.*; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.Tool; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.*; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.regions.*; import com.sk89q.worldedit.regions.selector.ConvexPolyhedralRegionSelector; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; @@ -208,12 +209,13 @@ public abstract class FawePlayer extends Metadatable { public void checkConfirmationStack(@Nullable Runnable task, String command, Region region, int times, CommandContext context) throws RegionOperationException { if (command != null && !getMeta("cmdConfirmRunning", false)) { if (region != null) { - Vector min = region.getMinimumPoint().toBlockVector(); - Vector max = region.getMaximumPoint().toBlockVector(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); long area = (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)) * times; if (area > 2 << 18) { setConfirmTask(task, context, command); - long volume = (long) max.subtract(min).add(Vector.ONE).volume() * times; + BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); + long volume = (long) base.getX() * base.getZ() * base.getY() * times; throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command, NumberFormat.getNumberInstance().format(volume))); } } @@ -224,12 +226,13 @@ public abstract class FawePlayer extends Metadatable { public void checkConfirmationRegion(@Nullable Runnable task, String command, Region region, CommandContext context) throws RegionOperationException { if (command != null && !getMeta("cmdConfirmRunning", false)) { if (region != null) { - Vector min = region.getMinimumPoint().toBlockVector(); - Vector max = region.getMaximumPoint().toBlockVector(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); long area = (long) ((max.getX() - min.getX()) * (max.getZ() - min.getZ() + 1)); if (area > 2 << 18) { setConfirmTask(task, context, command); - long volume = (long) max.subtract(min).add(Vector.ONE).volume(); + BlockVector3 base = max.subtract(min).add(BlockVector3.ONE); + long volume = (long) base.getX() * base.getZ() * base.getY(); throw new RegionOperationException(BBC.WORLDEDIT_CANCEL_REASON_CONFIRM.f(min, max, command, NumberFormat.getNumberInstance().format(volume))); } } @@ -561,8 +564,8 @@ public abstract class FawePlayer extends Metadatable { @Deprecated public void setSelection(final RegionWrapper region) { final Player player = this.getPlayer(); - Vector top = region.getMaximumPoint(); - top.mutY(getWorld().getMaxY()); + BlockVector3 top = region.getMaximumPoint(); + top.withY(getWorld().getMaxY()); final RegionSelector selector = new CuboidRegionSelector(player.getWorld(), region.getMinimumPoint(), top); this.getSession().setRegionSelector(player.getWorld(), selector); } @@ -692,7 +695,7 @@ public abstract class FawePlayer extends Metadatable { PlayerProxy proxy = new PlayerProxy(player, permActor, cuiActor, world); if (world instanceof VirtualWorld) { - proxy.setOffset(Vector.ZERO.subtract(((VirtualWorld) world).getOrigin())); + proxy.setOffset(Vector3.ZERO.subtract(((VirtualWorld) world).getOrigin())); } return proxy; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java index cd82ce393..153342707 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/FaweQueue.java @@ -12,13 +12,13 @@ import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.SetQueue; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -61,13 +61,13 @@ public interface FaweQueue extends HasFaweQueue, Extent { } @Override - default Vector getMinimumPoint() { - return new Vector(-30000000, 0, -30000000); + default BlockVector3 getMinimumPoint() { + return new BlockVector3(-30000000, 0, -30000000); } @Override - default Vector getMaximumPoint() { - return new Vector(30000000, getMaxY(), 30000000); + default BlockVector3 getMaximumPoint() { + return new BlockVector3(30000000, getMaxY(), 30000000); } @Override @@ -94,17 +94,17 @@ public interface FaweQueue extends HasFaweQueue, Extent { } @Override - default BlockState getFullBlock(Vector position) { + default BlockState getFullBlock(BlockVector3 position) { return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } @Override - default BaseBiome getBiome(Vector2D position) { + default BaseBiome getBiome(BlockVector2 position) { return null; } @Override - default boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + default boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return setBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ(), block); } @@ -119,7 +119,7 @@ public interface FaweQueue extends HasFaweQueue, Extent { } @Override - default boolean setBiome(Vector2D position, BaseBiome biome) { + default boolean setBiome(BlockVector2 position, BaseBiome biome) { return setBiome(position.getBlockX(), position.getBlockZ(), biome); } @@ -262,7 +262,7 @@ public interface FaweQueue extends HasFaweQueue, Extent { void addTask(Runnable whenFree); - default void forEachBlockInChunk(int cx, int cz, RunnableVal2 onEach) { + default void forEachBlockInChunk(int cx, int cz, RunnableVal2 onEach) { int bx = cx << 4; int bz = cz << 4; MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); @@ -295,7 +295,7 @@ public interface FaweQueue extends HasFaweQueue, Extent { } } - default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { + default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { int bx = cx << 4; int bz = cz << 4; MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java index 9d858e8d3..8785fe3f4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/HistoryExtent.java @@ -12,6 +12,9 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.history.changeset.ChangeSet; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector2; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -69,7 +72,7 @@ public class HistoryExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(final Vector location, final BlockStateHolder block) throws WorldEditException { + public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @@ -102,7 +105,7 @@ public class HistoryExtent extends AbstractDelegateExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome newBiome) { + public boolean setBiome(BlockVector2 position, BaseBiome newBiome) { BaseBiome oldBiome = this.getBiome(position); if (oldBiome.getId() != newBiome.getId()) { this.changeSet.addBiomeChange(position.getBlockX(), position.getBlockZ(), oldBiome, newBiome); @@ -114,7 +117,7 @@ public class HistoryExtent extends AbstractDelegateExtent { @Override public boolean setBiome(int x, int y, int z, BaseBiome newBiome) { - BaseBiome oldBiome = this.getBiome(MutableBlockVector2D.get(x, z)); + BaseBiome oldBiome = this.getBiome(new BlockVector2(x, z)); if (oldBiome.getId() != newBiome.getId()) { this.changeSet.addBiomeChange(x, z, oldBiome, newBiome); return getExtent().setBiome(x, y, z, newBiome); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/MaskedFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/MaskedFaweQueue.java index a6cdb24b0..5169095fe 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/MaskedFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/MaskedFaweQueue.java @@ -6,10 +6,10 @@ import com.boydti.fawe.object.extent.MultiRegionExtent; import com.boydti.fawe.object.extent.SingleRegionExtent; import com.boydti.fawe.object.queue.DelegateFaweQueue; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -73,7 +73,7 @@ public class MaskedFaweQueue extends DelegateFaweQueue { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { if (region.contains(position.getBlockX(), position.getBlockZ())) { return super.setBlock(position, block); } @@ -89,7 +89,7 @@ public class MaskedFaweQueue extends DelegateFaweQueue { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { if (region.contains(position.getBlockX(), position.getBlockZ())) { return super.setBiome(position, biome); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/RegionWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/object/RegionWrapper.java index ed60c8fc7..1179fa003 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/RegionWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/RegionWrapper.java @@ -1,6 +1,6 @@ package com.boydti.fawe.object; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; @Deprecated @@ -23,10 +23,10 @@ public class RegionWrapper extends CuboidRegion { } public RegionWrapper(final int minX, final int maxX, final int minY, final int maxY, final int minZ, final int maxZ) { - this(new Vector(minX, 0, minZ), new Vector(maxX, 255, maxZ)); + this(new BlockVector3(minX, 0, minZ), new BlockVector3(maxX, 255, maxZ)); } - public RegionWrapper(final Vector pos1, final Vector pos2) { + public RegionWrapper(final BlockVector3 pos1, final BlockVector3 pos2) { super(pos1, pos2); this.minX = Math.min(pos1.getBlockX(), pos2.getBlockX()); this.minZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); @@ -39,8 +39,8 @@ public class RegionWrapper extends CuboidRegion { @Override protected void recalculate() { super.recalculate(); - Vector pos1 = getMinimumPoint(); - Vector pos2 = getMaximumPoint(); + BlockVector3 pos1 = getMinimumPoint(); + BlockVector3 pos2 = getMaximumPoint(); this.minX = Math.min(pos1.getBlockX(), pos2.getBlockX()); this.minZ = Math.min(pos1.getBlockZ(), pos2.getBlockZ()); this.maxX = Math.max(pos1.getBlockX(), pos2.getBlockX()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AngleBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AngleBrush.java index ea1ae8d15..fdc04129a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AngleBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/AngleBrush.java @@ -4,10 +4,10 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; public class AngleBrush implements Brush { @@ -18,7 +18,7 @@ public class AngleBrush 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 { SurfaceMask surface = new SurfaceMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java index ccf36e92c..bb94e1a66 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlendBall.java @@ -3,9 +3,9 @@ package com.boydti.fawe.object.brush; import com.google.common.collect.Maps; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; 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; @@ -15,7 +15,7 @@ import java.util.Map; public class BlendBall 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 int outsetSize = (int) (size + 1); double brushSizeSquared = size * size; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java index 5e32fa456..80a6c53d7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/BlobBrush.java @@ -4,20 +4,22 @@ import com.boydti.fawe.object.random.SimplexNoise; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import java.util.concurrent.ThreadLocalRandom; public class BlobBrush implements Brush { private final double amplitude; private final double frequency; - private final Vector radius; + private final Vector3 radius; private final double sphericity; - public BlobBrush(Vector radius, double frequency, double amplitude, double sphericity) { + public BlobBrush(Vector3 radius, double frequency, double amplitude, double sphericity) { this.frequency = frequency; this.amplitude = amplitude; this.radius = radius; @@ -25,7 +27,7 @@ public class BlobBrush 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 { double seedX = ThreadLocalRandom.current().nextDouble(); double seedY = ThreadLocalRandom.current().nextDouble(); double seedZ = ThreadLocalRandom.current().nextDouble(); @@ -70,7 +72,7 @@ public class BlobBrush implements Brush { double manScaleY = (1.25 + seedY * 0.5); double manScaleZ = (1.25 + seedZ * 0.5); - MutableBlockVector mutable = new MutableBlockVector(); + MutableVector mutable = new MutableVector(); double roughness = 1 - sphericity; for (int xr = -sizeInt; xr <= sizeInt; xr++) { mutable.mutX(xr); @@ -78,10 +80,10 @@ public class BlobBrush implements Brush { mutable.mutY(yr); for (int zr = -sizeInt; zr <= sizeInt; zr++) { mutable.mutZ(zr); - Vector pt = transform.apply(mutable); - int x = MathMan.roundInt(pt.getBlockX()); - int y = MathMan.roundInt(pt.getBlockY()); - int z = MathMan.roundInt(pt.getBlockZ()); + Vector3 pt = transform.apply(mutable); + int x = MathMan.roundInt(pt.getX()); + int y = MathMan.roundInt(pt.getY()); + int z = MathMan.roundInt(pt.getZ()); double xScaled = Math.abs(x) * modX; double yScaled = Math.abs(y) * modY; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java index 193f350ac..2010772a6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CatenaryBrush.java @@ -2,12 +2,15 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.brush.visualization.VisualExtent; +import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MathUtils; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.util.Location; import java.util.Arrays; @@ -18,9 +21,9 @@ public class CatenaryBrush implements Brush, ResettableTool { private final boolean shell, select, direction; private final double slack; - private Vector pos1; - private Vector pos2; - private Vector vertex; + private BlockVector3 pos1; + private BlockVector3 pos2; + private BlockVector3 vertex; public CatenaryBrush(boolean shell, boolean select, boolean direction, double lengthFactor) { this.shell = shell; @@ -30,7 +33,7 @@ public class CatenaryBrush implements Brush, ResettableTool { } @Override - public void build(EditSession editSession, Vector pos2, final Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 pos2, final Pattern pattern, double size) throws MaxChangedBlocksException { boolean visual = (editSession.getExtent() instanceof VisualExtent); if (pos1 == null || pos2.equals(pos1)) { if (!visual) { @@ -47,12 +50,12 @@ public class CatenaryBrush implements Brush, ResettableTool { } } else if (this.direction) { Location loc = editSession.getPlayer().getPlayer().getLocation(); - Vector facing = loc.getDirection().normalize(); - Vector midpoint = pos1.add(pos2).divide(2); - Vector offset = midpoint.subtract(vertex); - vertex = midpoint.add(facing.multiply(offset.length())); + Vector3 facing = loc.getDirection().normalize(); + BlockVector3 midpoint = pos1.add(pos2).divide(2); + BlockVector3 offset = midpoint.subtract(vertex); + vertex = midpoint.add(facing.multiply(offset.length()).toBlockPoint()); } - List nodes = Arrays.asList(pos1, vertex, pos2); + List nodes = Arrays.asList(pos1, vertex, pos2); vertex = null; try { editSession.drawSpline(pattern, nodes, 0, 0, 0, 10, size, !shell); @@ -76,8 +79,8 @@ public class CatenaryBrush implements Brush, ResettableTool { return true; } - public static Vector getVertex(Vector pos1, Vector pos2, double lenPercent) { - if (lenPercent <= 1) return Vector.getMidpoint(pos1, pos2); + public static BlockVector3 getVertex(BlockVector3 pos1, BlockVector3 pos2, double lenPercent) { + if (lenPercent <= 1) return MathUtils.midpoint(pos1, pos2); double curveLen = pos1.distance(pos2) * lenPercent; double dy = pos2.getY() - pos1.getY(); double dx = pos2.getX() - pos1.getX(); @@ -90,6 +93,6 @@ public class CatenaryBrush implements Brush, ResettableTool { double z = (dh/2)/a; double oY = (dy - curveLen * (Math.cosh(z) / Math.sinh(z))) / 2; double vertY = a * 1 + oY; - return pos1.add(pos2.subtract(pos1).multiply(vertX / dh).add(0, vertY, 0)).round(); + return pos1.add(pos2.subtract(pos1).multiply(MathMan.roundInt(vertX / dh)).add(0, MathMan.roundInt(vertY), 0)).round(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CircleBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CircleBrush.java index 024a279fb..704729876 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CircleBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CircleBrush.java @@ -3,10 +3,11 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.wrappers.LocationMaskedPlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; public class CircleBrush implements Brush { @@ -17,21 +18,21 @@ public class CircleBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { - Vector normal = position.subtract(player.getLocation()); + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { + Vector3 normal = position.toVector3().subtract(player.getLocation().toVector()); editSession.makeCircle(position, pattern, size, size, size, false, normal); } - private Vector any90Rotate(Vector normal) { + private Vector3 any90Rotate(Vector3 normal) { normal = normal.normalize(); if (normal.getX() == 1 || normal.getY() == 1 || normal.getZ() == 1) { - return new Vector(normal.getZ(), normal.getX(), normal.getY()); + return new Vector3(normal.getZ(), normal.getX(), normal.getY()); } AffineTransform affine = new AffineTransform(); affine = affine.rotateX(90); affine = affine.rotateY(90); affine = affine.rotateZ(90); - Vector random = affine.apply(normal); + Vector3 random = affine.apply(normal); return random.cross(normal).normalize(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java index 82c59a302..396ba249d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CommandBrush.java @@ -7,12 +7,12 @@ import com.boydti.fawe.wrappers.PlayerWrapper; import com.boydti.fawe.wrappers.SilentPlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.util.Location; import java.util.List; @@ -26,7 +26,7 @@ public class CommandBrush 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 { int radius = (int) size; CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius)); String replaced = command.replace("{x}", position.getBlockX() + "") @@ -41,10 +41,10 @@ public class CommandBrush implements Brush { if (face == null) { position = position.add(0, 1, 1); } else { - position = position.add(face.getDirection()); + position = position.add(face.getDirection().toBlockPoint()); } fp.setSelection(selector); - PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position))); + PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3()))); List cmds = StringMan.split(replaced, ';'); for (String cmd : cmds) { CommandEvent event = new CommandEvent(wePlayer, cmd); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java index db16b9196..a040f6d7a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/CopyPastaBrush.java @@ -10,7 +10,6 @@ import com.boydti.fawe.object.function.mask.AbstractDelegateMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.command.tool.brush.Brush; @@ -22,6 +21,7 @@ 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.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.session.ClipboardHolder; @@ -50,7 +50,7 @@ public class CopyPastaBrush implements Brush, ResettableTool { } @Override - public void build(final EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(final EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { FawePlayer fp = editSession.getPlayer(); ClipboardHolder clipboard = session.getExistingClipboard(); if (clipboard == null) { @@ -66,7 +66,7 @@ public class CopyPastaBrush implements Brush, ResettableTool { final int minY = position.getBlockY(); mask = new AbstractDelegateMask(mask) { @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (super.test(vector) && vector.getBlockY() >= minY) { BlockStateHolder block = editSession.getLazyBlock(vector); if (!block.getBlockType().getMaterial().isAir()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java index ee6a8ef50..c05bce1f1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ErodeBrush.java @@ -7,12 +7,12 @@ import com.boydti.fawe.object.clipboard.FaweClipboard; import com.boydti.fawe.object.clipboard.OffsetFaweClipboard; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.Blocks; import com.sk89q.worldedit.command.tool.brush.Brush; 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.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -23,14 +23,14 @@ public class ErodeBrush implements Brush { private PseudoRandom rand = new PseudoRandom(); - private static final Vector[] FACES_TO_CHECK = {new Vector(0, 0, 1), new Vector(0, 0, -1), new Vector(0, 1, 0), new Vector(0, -1, 0), new Vector(1, 0, 0), new Vector(-1, 0, 0)}; + private static final BlockVector3[] FACES_TO_CHECK = {new BlockVector3(0, 0, 1), new BlockVector3(0, 0, -1), new BlockVector3(0, 1, 0), new BlockVector3(0, -1, 0), new BlockVector3(1, 0, 0), new BlockVector3(-1, 0, 0)}; @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 { this.erosion(editSession, 2, 1, 5, 1, position, size); } - public void erosion(final EditSession es, int erodeFaces, int erodeRec, int fillFaces, int fillRec, Vector target, double size) { + public void erosion(final EditSession es, int erodeFaces, int erodeRec, int fillFaces, int fillRec, BlockVector3 target, double size) { int brushSize = (int) size + 1; int brushSizeSquared = (int) (size * size); int dimension = brushSize * 2 + 1; @@ -98,7 +98,7 @@ public class ErodeBrush implements Brush { } else { Arrays.fill(frequency, 0); } - for (Vector offs : FACES_TO_CHECK) { + for (BlockVector3 offs : FACES_TO_CHECK) { BlockStateHolder next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); if (!next.getBlockType().getMaterial().isMovementBlocker()) { continue; @@ -142,7 +142,7 @@ public class ErodeBrush implements Brush { } else { Arrays.fill(frequency, 0); } - for (Vector offs : FACES_TO_CHECK) { + for (BlockVector3 offs : FACES_TO_CHECK) { BlockStateHolder next = current.getBlock(x + offs.getBlockX(), y + offs.getBlockY(), z + offs.getBlockZ()); if (next.getBlockType().getMaterial().isMovementBlocker()) { continue; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FallingSphere.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FallingSphere.java index e0334ea86..e4506ca6d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FallingSphere.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FallingSphere.java @@ -3,13 +3,13 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; public class FallingSphere 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 { int px = position.getBlockX(); int py = position.getBlockY(); int pz = position.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FlattenBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FlattenBrush.java index d446770a7..de2cbc45a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FlattenBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/FlattenBrush.java @@ -4,11 +4,12 @@ import com.boydti.fawe.object.brush.heightmap.HeightMap; import com.boydti.fawe.object.brush.heightmap.ScalableHeightMap; 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.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; + import java.io.InputStream; public class FlattenBrush extends HeightBrush { @@ -18,7 +19,7 @@ public class FlattenBrush extends HeightBrush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { int size = (int) sizeDouble; Mask mask = editSession.getMask(); if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/HeightBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/HeightBrush.java index c8f73b3a4..a9b364736 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/HeightBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/HeightBrush.java @@ -11,13 +11,15 @@ import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.extent.clipboard.Clipboard; 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.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; + import java.io.IOException; import java.io.InputStream; @@ -68,7 +70,7 @@ public class HeightBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { int size = (int) sizeDouble; HeightMap map = getHeightMap(); map.setSize(size); @@ -83,7 +85,7 @@ public class HeightBrush implements Brush { hmmg.getMetaData().setMeta("PRECISION_HEIGHT", metaHeight = new byte[hmmg.getArea()]); } - Vector origin = hmmg.getOrigin(); + Vector3 origin = hmmg.getOrigin(); int bx = position.getBlockX(); int bz = position.getBlockZ(); @@ -131,14 +133,14 @@ public class HeightBrush implements Brush { } if (smooth) { - Vector2D min = new Vector2D(Math.max(0, bx - size), Math.max(0, bz - size)); - Vector2D max = new Vector2D(Math.min(hmmg.getWidth() - 1, bx + size), Math.min(hmmg.getLength() - 1, bz + size)); + BlockVector2 min = new BlockVector2(Math.max(0, bx - size), Math.max(0, bz - size)); + BlockVector2 max = new BlockVector2(Math.min(hmmg.getWidth() - 1, bx + size), Math.min(hmmg.getLength() - 1, bz + size)); hmmg.smooth(min, max, 8, 1); if (size > 20) { int smoothSize = size + 8; - min = new Vector2D(Math.max(0, bx - smoothSize), Math.max(0, bz - smoothSize)); - max = new Vector2D(Math.min(hmmg.getWidth() - 1, bx + smoothSize), Math.min(hmmg.getLength() - 1, bz + smoothSize)); + min = new BlockVector2(Math.max(0, bx - smoothSize), Math.max(0, bz - smoothSize)); + max = new BlockVector2(Math.min(hmmg.getWidth() - 1, bx + smoothSize), Math.min(hmmg.getLength() - 1, bz + smoothSize)); hmmg.smooth(min, max, 1, 1); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java index 670fb66f0..34007b9f4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ImageBrush.java @@ -6,7 +6,6 @@ import com.boydti.fawe.util.TextureUtil; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.command.tool.brush.Brush; @@ -16,6 +15,9 @@ import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -64,15 +66,15 @@ public class ImageBrush implements Brush { } private interface ColorFunction { - int call(int x1, int z1, int x2, int z2, Extent extent, Vector pos); + int call(int x1, int z1, int x2, int z2, Extent extent, BlockVector3 pos); } private interface BlockFunction { - void apply(int color, Extent extent, Vector pos); + void apply(int color, Extent extent, BlockVector3 pos); } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { TextureUtil texture = session.getTextureUtil(); final int cx = position.getBlockX(); @@ -88,19 +90,19 @@ public class ImageBrush implements Brush { AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX((pitch - 90) % 360).inverse(); RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { - private final Vector mutable = new Vector(); + private final MutableVector mutable = new MutableVector(); @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (solid.test(vector)) { int dx = vector.getBlockX() - cx; int dy = vector.getBlockY() - cy; int dz = vector.getBlockZ() - cz; - Vector pos1 = transform.apply(mutable.setComponents(dx - 0.5, dy - 0.5, dz - 0.5)); + Vector3 pos1 = transform.apply(mutable.setComponents(dx - 0.5, dy - 0.5, dz - 0.5)); int x1 = (int) (pos1.getX() * scale + centerX); int z1 = (int) (pos1.getZ() * scale + centerZ); - Vector pos2 = transform.apply(mutable.setComponents(dx + 0.5, dy + 0.5, dz + 0.5)); + Vector3 pos2 = transform.apply(mutable.setComponents(dx + 0.5, dy + 0.5, dz + 0.5)); int x2 = (int) (pos2.getX() * scale + centerX); int z2 = (int) (pos2.getZ() * scale + centerZ); if (x2 < x1) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java index 143115aa1..c2fd28bae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/InspectBrush.java @@ -13,12 +13,13 @@ import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.DoubleActionTraceTool; 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.math.Vector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -47,7 +48,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { return perform(player, session, true); } - public Vector getTarget(Player player, boolean adjacent) { + public Vector3 getTarget(Player player, boolean adjacent) { Location target = null; int range = this.range > -1 ? getRange() : MAX_RANGE; if (adjacent) { @@ -67,7 +68,7 @@ public class InspectBrush extends BrushTool implements DoubleActionTraceTool { player.print(BBC.getPrefix() + BBC.SETTING_DISABLE.f("history.use-database (Import with /frb #import )")); return false; } - Vector target = getTarget(player, rightClick); + BlockVector3 target = getTarget(player, rightClick).toBlockPoint(); final int x = target.getBlockX(); final int y = target.getBlockY(); final int z = target.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java index 3635a11f1..687cedc63 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LayerBrush.java @@ -6,8 +6,6 @@ import com.boydti.fawe.object.mask.AdjacentAnyMask; import com.boydti.fawe.object.mask.RadiusMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.BlockMask; import com.sk89q.worldedit.function.mask.BlockTypeMask; @@ -17,6 +15,8 @@ import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -34,7 +34,7 @@ public class LayerBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern ignore, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern ignore, double size) throws MaxChangedBlocksException { final FaweQueue queue = editSession.getQueue(); final AdjacentAnyMask adjacent = new AdjacentAnyMask(new BlockTypeMask(editSession, BlockTypes.AIR, BlockTypes.CAVE_AIR, BlockTypes.VOID_AIR)); final SolidBlockMask solid = new SolidBlockMask(editSession); @@ -51,7 +51,7 @@ public class LayerBrush implements Brush { boolean found = false; int previous = layers[depth - 1].getInternalId(); int previous2 = layers[depth - 2].getInternalId(); - for (Vector dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { + for (BlockVector3 dir : BreadthFirstSearch.DEFAULT_DIRECTIONS) { mutable.setComponents(pos.getBlockX() + dir.getBlockX(), pos.getBlockY() + dir.getBlockY(), pos.getBlockZ() + dir.getBlockZ()); if (visitor.isVisited(mutable) && queue.getCachedCombinedId4Data(mutable.getBlockX(), mutable.getBlockY(), mutable.getBlockZ()) == previous) { mutable.setComponents(pos.getBlockX() + dir.getBlockX() * 2, pos.getBlockY() + dir.getBlockY() * 2, pos.getBlockZ() + dir.getBlockZ() * 2); @@ -73,7 +73,7 @@ public class LayerBrush implements Brush { BlockStateHolder currentPattern = layers[depth]; return editSession.setBlock(pos, currentPattern); }, layers.length - 1, editSession); - for (Vector pos : visited) { + for (BlockVector3 pos : visited) { visitor.visit(pos); } Operations.completeBlindly(visitor); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java index cdf6d0dcd..0ed02da3d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/LineBrush.java @@ -4,14 +4,14 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.brush.visualization.VisualExtent; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; public class LineBrush implements Brush, ResettableTool { private final boolean shell, select, flat; - private Vector pos1; + private BlockVector3 pos1; public LineBrush(boolean shell, boolean select, boolean flat) { this.shell = shell; @@ -20,7 +20,7 @@ public class LineBrush implements Brush, ResettableTool { } @Override - public void build(EditSession editSession, Vector position, final Pattern pattern, double size) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, final Pattern pattern, double size) throws MaxChangedBlocksException { boolean visual = (editSession.getExtent() instanceof VisualExtent); if (pos1 == null) { if (!visual) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/PopulateSchem.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/PopulateSchem.java index 3c404e3a8..1f7fe4ed9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/PopulateSchem.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/PopulateSchem.java @@ -2,13 +2,14 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.jnbt.anvil.generator.SchemGen; import com.boydti.fawe.util.MaskTraverser; +import com.intellectualcrafters.plot.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.session.ClipboardHolder; import java.util.List; @@ -27,10 +28,11 @@ public class PopulateSchem 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 { new MaskTraverser(mask).reset(editSession); SchemGen gen = new SchemGen(mask, editSession, clipboards, randomRotate); - CuboidRegion cuboid = new CuboidRegion(editSession.getWorld(), position.subtract(size, size, size), position.add(size, size, size)); + int size1 = MathMan.roundInt(size); + CuboidRegion cuboid = new CuboidRegion(editSession.getWorld(), position.subtract(size1, size1, size1), position.add(size1, size1, size1)); try { editSession.addSchems(cuboid, mask, clipboards, rarity, randomRotate); } catch (WorldEditException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java index 7e7bd283d..4bbb4642a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RaiseBrush.java @@ -2,12 +2,12 @@ package com.boydti.fawe.object.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; public class RaiseBrush extends ErodeBrush { @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 { this.erosion(editSession, 6, 0, 1, 1, position, size); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java index 53a445242..53a053f96 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RecurseBrush.java @@ -4,7 +4,6 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.command.tool.brush.Brush; @@ -14,6 +13,7 @@ import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class RecurseBrush implements Brush { @@ -25,7 +25,7 @@ public class RecurseBrush implements Brush { } @Override - public void build(final EditSession editSession, final Vector position, Pattern to, double size) throws MaxChangedBlocksException { + public void build(final EditSession editSession, final BlockVector3 position, Pattern to, double size) throws MaxChangedBlocksException { Mask mask = editSession.getMask(); if (mask == null) { mask = Masks.alwaysTrue(); @@ -42,7 +42,7 @@ public class RecurseBrush implements Brush { final Mask radMask = new RadiusMask(0, (int) size); DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, replace, Integer.MAX_VALUE, Integer.MAX_VALUE) { @Override - public boolean isVisitable(Vector from, Vector to) { + public boolean isVisitable(BlockVector3 from, BlockVector3 to) { int y = to.getBlockY(); return y >= y && y < maxY && radMask.test(to) && super.isVisitable(from, to); } @@ -52,7 +52,7 @@ public class RecurseBrush implements Brush { } else { RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, radius, editSession) { @Override - public boolean isVisitable(Vector from, Vector to) { + public boolean isVisitable(BlockVector3 from, BlockVector3 to) { int y = to.getBlockY(); return y >= y && y < maxY && super.isVisitable(from, to); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RockBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RockBrush.java index c89d4e2e3..32cf5ba18 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RockBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/RockBrush.java @@ -3,24 +3,26 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.object.random.SimplexNoise; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; + import java.util.concurrent.ThreadLocalRandom; public class RockBrush implements Brush { private final double amplitude; private final double frequency; - private final Vector radius; + private final Vector3 radius; - public RockBrush(Vector radius, double frequency, double amplitude) { + public RockBrush(Vector3 radius, double frequency, double amplitude) { this.frequency = frequency; this.amplitude = amplitude; this.radius = radius; } @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 { double seedX = ThreadLocalRandom.current().nextDouble(); double seedY = ThreadLocalRandom.current().nextDouble(); double seedZ = ThreadLocalRandom.current().nextDouble(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java index 6049ae774..5242b96de 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterBrush.java @@ -8,7 +8,6 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Masks; @@ -16,6 +15,8 @@ import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.Arrays; public class ScatterBrush implements Brush { @@ -39,7 +40,7 @@ public class ScatterBrush 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 { this.mask = editSession.getMask(); if (this.mask == null) { this.mask = Masks.alwaysTrue(); @@ -63,7 +64,7 @@ public class ScatterBrush implements Brush { int maxFails = 1000; for (int i = 0; i < count; i++) { int index = PseudoRandom.random.nextInt(length); - Vector pos = visited.get(index); + BlockVector3 pos = visited.get(index); if (pos != null && canApply(editSession, pos)) { int x = pos.getBlockX(); int y = pos.getBlockY(); @@ -82,18 +83,18 @@ public class ScatterBrush implements Brush { finish(editSession, placed, position, pattern, size); } - public void finish(EditSession editSession, LocalBlockVectorSet placed, Vector pos, Pattern pattern, double size) { + public void finish(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pos, Pattern pattern, double size) { } - public boolean canApply(EditSession editSession, Vector pos) { + public boolean canApply(EditSession editSession, BlockVector3 pos) { return mask.test(pos); } - public Vector getDirection(Vector pt) { + public BlockVector3 getDirection(BlockVector3 pt) { return surface.direction(pt); } - public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { + public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws MaxChangedBlocksException { editSession.setBlock(pt, p); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterCommand.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterCommand.java index 02df4fa84..c7edce44c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterCommand.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterCommand.java @@ -8,11 +8,11 @@ import com.boydti.fawe.wrappers.PlayerWrapper; import com.boydti.fawe.wrappers.SilentPlayerWrapper; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.CommandEvent; import com.sk89q.worldedit.extension.platform.CommandManager; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.selector.CuboidRegionSelector; import com.sk89q.worldedit.util.Location; import java.util.List; @@ -26,7 +26,7 @@ public class ScatterCommand extends ScatterBrush { } @Override - public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector position, Pattern p, double size) throws MaxChangedBlocksException { + public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 position, Pattern p, double size) throws MaxChangedBlocksException { int radius = getDistance(); CuboidRegionSelector selector = new CuboidRegionSelector(editSession.getWorld(), position.subtract(radius, radius, radius), position.add(radius, radius, radius)); String replaced = command.replace("{x}", position.getBlockX() + "") @@ -38,7 +38,7 @@ public class ScatterCommand extends ScatterBrush { FawePlayer fp = editSession.getPlayer(); Player player = fp.getPlayer(); fp.setSelection(selector); - PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position))); + PlayerWrapper wePlayer = new SilentPlayerWrapper(new LocationMaskedPlayerWrapper(player, new Location(player.getExtent(), position.toVector3()))); List cmds = StringMan.split(replaced, ';'); for (String cmd : cmds) { CommandEvent event = new CommandEvent(wePlayer, cmd); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java index fa29ebd8c..9e6f80c0b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ScatterOverlayBrush.java @@ -3,8 +3,8 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.object.collection.LocalBlockVectorSet; 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; public class ScatterOverlayBrush extends ScatterBrush { public ScatterOverlayBrush(int count, int distance) { @@ -12,12 +12,12 @@ public class ScatterOverlayBrush extends ScatterBrush { } @Override - public void apply(EditSession editSession, LocalBlockVectorSet placed, Vector pt, Pattern p, double size) throws MaxChangedBlocksException { + public void apply(EditSession editSession, LocalBlockVectorSet placed, BlockVector3 pt, Pattern p, double size) throws MaxChangedBlocksException { int x = pt.getBlockX(); int y = pt.getBlockY(); int z = pt.getBlockZ(); - Vector dir = getDirection(pt); - dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ()); - editSession.setBlock(dir, p); + BlockVector3 dir = getDirection(pt); +// dir.setComponents(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ()); + editSession.setBlock(x + dir.getBlockX(), y + dir.getBlockY(), z + dir.getBlockZ(), p); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java index 5617826b9..fd22324ff 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/ShatterBrush.java @@ -5,12 +5,12 @@ import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; 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.function.visitor.BreadthFirstSearch; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; public class ShatterBrush extends ScatterBrush { private final MutableBlockVector mutable = new MutableBlockVector(); @@ -20,11 +20,11 @@ public class ShatterBrush extends ScatterBrush { } @Override - public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final Vector position, Pattern p, double size) throws MaxChangedBlocksException { + public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final BlockVector3 position, Pattern p, double size) throws MaxChangedBlocksException { } @Override - public void finish(EditSession editSession, LocalBlockVectorSet placed, final Vector position, Pattern pattern, double size) { + public void finish(EditSession editSession, LocalBlockVectorSet placed, final BlockVector3 position, Pattern pattern, double size) { int radius2 = (int) (size * size); // Keep track of where we've visited LocalBlockVectorSet tmp = new LocalBlockVectorSet(); @@ -34,7 +34,7 @@ public class ShatterBrush extends ScatterBrush { LocalBlockVectorSet[] frontiersVisited = new LocalBlockVectorSet[placed.size()]; // Initiate the frontier with the starting points int i = 0; - for (Vector pos : placed) { + for (BlockVector3 pos : placed) { LocalBlockVectorSet set = new LocalBlockVectorSet(); set.add(pos); frontiers[i] = set; @@ -66,7 +66,7 @@ public class ShatterBrush extends ScatterBrush { return; } for (int i = 0; i < BreadthFirstSearch.DIAGONAL_DIRECTIONS.length; i++) { - Vector direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i]; + BlockVector3 direction = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i]; int x2 = x + direction.getBlockX(); int y2 = y + direction.getBlockY(); int z2 = z + direction.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java index bc1c3c039..e4362abaa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SpikeBrush.java @@ -2,14 +2,14 @@ package com.boydti.fawe.object.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; public class SpikeBrush 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 { } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java index 93a5f756e..7b2e7f3ce 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplatterBrush.java @@ -6,7 +6,6 @@ import com.boydti.fawe.object.mask.SurfaceMask; import com.boydti.fawe.object.pattern.BiomePattern; 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.mask.Mask; @@ -14,6 +13,8 @@ import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.Arrays; public class SplatterBrush extends ScatterBrush { @@ -27,7 +28,7 @@ public class SplatterBrush extends ScatterBrush { } @Override - public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final Vector position, Pattern p, double size) throws MaxChangedBlocksException { + public void apply(final EditSession editSession, final LocalBlockVectorSet placed, final BlockVector3 position, Pattern p, double size) throws MaxChangedBlocksException { final Pattern finalPattern; if (solid) { Pattern tmp; @@ -46,7 +47,7 @@ public class SplatterBrush extends ScatterBrush { RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { double dist = vector.distanceSq(position); if (dist < size2 && !placed.contains(vector) && (PseudoRandom.random.random(5) < 2) && surface.test(vector)) { placed.add(vector); @@ -56,7 +57,7 @@ public class SplatterBrush extends ScatterBrush { } }, new RegionFunction() { @Override - public boolean apply(Vector vector) throws WorldEditException { + public boolean apply(BlockVector3 vector) throws WorldEditException { return editSession.setBlock(vector, finalPattern); } }, recursion, editSession); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java index a8f2ad339..5c6acae47 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SplineBrush.java @@ -8,7 +8,6 @@ import com.boydti.fawe.object.visitor.DFSRecursiveVisitor; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.entity.Player; @@ -17,6 +16,9 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.Node; import java.util.ArrayList; import java.util.Collection; @@ -27,12 +29,12 @@ import java.util.List; public class SplineBrush implements Brush, ResettableTool { public static int MAX_POINTS = 15; - private ArrayList> positionSets; + private ArrayList> positionSets; private int numSplines; private final LocalSession session; private final Player player; - private Vector position; + private BlockVector3 position; public SplineBrush(Player player, LocalSession session) { this.session = session; @@ -50,7 +52,7 @@ public class SplineBrush implements Brush, ResettableTool { } @Override - public void build(EditSession editSession, final Vector position, Pattern pattern, double size) throws WorldEditException { + public void build(EditSession editSession, final BlockVector3 position, Pattern pattern, double size) throws WorldEditException { Mask mask = editSession.getMask(); if (mask == null) { mask = new IdMask(editSession); @@ -68,21 +70,21 @@ public class SplineBrush implements Brush, ResettableTool { if (positionSets.size() >= MAX_POINTS) { throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); } - final ArrayList points = new ArrayList<>(); + final ArrayList points = new ArrayList<>(); if (size > 0) { DFSRecursiveVisitor visitor = new DFSRecursiveVisitor(mask, new RegionFunction() { @Override - public boolean apply(Vector p) { - points.add(new Vector(p)); + public boolean apply(BlockVector3 p) { + points.add(p); return true; } }, (int) size, 1); - List directions = visitor.getDirections(); + List directions = visitor.getDirections(); for (int x = -1; x <= 1; x++) { for (int y = -1; y <= 1; y++) { for (int z = -1; z <= 1; z++) { if (x != 0 || y != 0 || z != 0) { - Vector pos = new Vector(x, y, z); + BlockVector3 pos = new BlockVector3(x, y, z); if (!directions.contains(pos)) { directions.add(pos); } @@ -109,8 +111,8 @@ public class SplineBrush implements Brush, ResettableTool { player.print(BBC.getPrefix() + BBC.BRUSH_SPLINE_SECONDARY_ERROR.s()); return; } - List centroids = new ArrayList<>(); - for (List points : positionSets) { + List centroids = new ArrayList<>(); + for (List points : positionSets) { centroids.add(getCentroid(points)); } @@ -121,7 +123,7 @@ public class SplineBrush implements Brush, ResettableTool { final List nodes = new ArrayList(centroids.size()); - for (final Vector nodevector : centroids) { + for (final Vector3 nodevector : centroids) { final Node n = new Node(nodevector); n.setTension(tension); n.setBias(bias); @@ -130,8 +132,8 @@ public class SplineBrush implements Brush, ResettableTool { } int samples = numSplines; for (int i = 0; i < numSplines; i++) { - List currentSpline = new ArrayList<>(); - for (ArrayList points : positionSets) { + List currentSpline = new ArrayList<>(); + for (ArrayList points : positionSets) { int listSize = points.size(); int index = (int) (i * listSize / (double) (numSplines)); currentSpline.add(points.get(index)); @@ -148,9 +150,9 @@ public class SplineBrush implements Brush, ResettableTool { } } - private Vector getCentroid(Collection points) { - Vector sum = new Vector(); - for (Vector p : points) { + private Vector3 getCentroid(Collection points) { + MutableVector sum = new MutableVector(); + for (BlockVector3 p : points) { sum.mutX(sum.getX() + p.getX()); sum.mutY(sum.getY() + p.getY()); sum.mutZ(sum.getZ() + p.getZ()); @@ -158,7 +160,7 @@ public class SplineBrush implements Brush, ResettableTool { return sum.multiply(1.0 / points.size()); } - private Vector normal(Collection points, Vector centroid) { + private BlockVector3 normal(Collection points, BlockVector3 centroid) { int n = points.size(); switch (n) { case 1: { @@ -177,8 +179,8 @@ public class SplineBrush implements Brush, ResettableTool { double yz = 0.0; double zz = 0.0; - Vector r = new Vector(); - for (Vector p : points) { + MutableVector r = new MutableVector(); + for (BlockVector3 p : points) { r.mutX((p.getX() - centroid.getX())); r.mutY((p.getY() - centroid.getY())); r.mutZ((p.getZ() - centroid.getZ())); @@ -200,19 +202,19 @@ public class SplineBrush implements Brush, ResettableTool { } // Pick path with best conditioning: - Vector dir; + BlockVector3 dir; if (det_max == det_x) { double a = (xz * yz - xy * zz) / det_x; double b = (xy * yz - xz * yy) / det_x; - dir = new Vector(1.0, a, b); + dir = new BlockVector3(1.0, a, b); } else if (det_max == det_y) { double a = (yz * xz - xy * zz) / det_y; double b = (xy * xz - yz * xx) / det_y; - dir = new Vector(a, 1.0, b); + dir = new BlockVector3(a, 1.0, b); } else { double a = (yz * xy - xz * yy) / det_z; double b = (xz * xy - yz * xx) / det_z; - dir = new Vector(a, b, 1.0); + dir = new BlockVector3(a, b, 1.0); } ; return dir.normalize(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java index 4383ab878..00b4e070a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/StencilBrush.java @@ -3,10 +3,9 @@ package com.boydti.fawe.object.brush; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.brush.heightmap.HeightMap; import com.boydti.fawe.object.mask.AdjacentAnyMask; +import com.intellectualcrafters.plot.util.MathMan; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.Mask; @@ -15,6 +14,10 @@ import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.util.Location; import java.io.InputStream; @@ -29,7 +32,7 @@ public class StencilBrush extends HeightBrush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { final int cx = position.getBlockX(); final int cy = position.getBlockY(); final int cz = position.getBlockZ(); @@ -51,7 +54,7 @@ public class StencilBrush extends HeightBrush { Player player = editSession.getPlayer().getPlayer(); - Vector pos = player.getLocation(); +// BlockVector3 pos = player.getLocation().toVector(); @@ -62,17 +65,17 @@ public class StencilBrush extends HeightBrush { RecursiveVisitor visitor = new RecursiveVisitor(new Mask() { - private final MutableBlockVector mutable = new MutableBlockVector(); + private final MutableVector mutable = new MutableVector(); @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (solid.test(vector)) { int dx = vector.getBlockX() - cx; int dy = vector.getBlockY() - cy; int dz = vector.getBlockZ() - cz; - Vector srcPos = transform.apply(mutable.setComponents(dx, dy, dz)); - dx = srcPos.getBlockX(); - dz = srcPos.getBlockZ(); + Vector3 srcPos = transform.apply(mutable.setComponents(dx, dy, dz)); + dx = MathMan.roundInt(srcPos.getX()); + dz = MathMan.roundInt(srcPos.getZ()); int distance = dx * dx + dz * dz; if (distance > size2 || Math.abs(dx) > 256 || Math.abs(dz) > 256) return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java index c3fa7544d..194a43672 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSphereBrush.java @@ -4,18 +4,19 @@ import com.boydti.fawe.object.mask.RadiusMask; import com.boydti.fawe.object.mask.SurfaceMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.Arrays; public class SurfaceSphereBrush 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 { SurfaceMask surface = new SurfaceMask(editSession); final SolidBlockMask solid = new SolidBlockMask(editSession); final RadiusMask radius = new RadiusMask(0, (int) size); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java index 979e29ab0..548eeeaf8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/SurfaceSpline.java @@ -7,6 +7,9 @@ import com.boydti.fawe.util.MathMan; import com.sk89q.worldedit.*; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.interpolation.KochanekBartelsInterpolation; import com.sk89q.worldedit.math.interpolation.Node; import java.util.ArrayList; @@ -22,17 +25,17 @@ public class SurfaceSpline implements Brush { this.quality = quality; } - private ArrayList path = new ArrayList<>(); + private ArrayList path = new ArrayList<>(); @Override - public void build(EditSession editSession, Vector pos, Pattern pattern, double radius) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 pos, Pattern pattern, double radius) throws MaxChangedBlocksException { int maxY = editSession.getMaxY(); boolean vis = editSession.getExtent() instanceof VisualExtent; if (path.isEmpty() || !pos.equals(path.get(path.size() - 1))) { int max = editSession.getNearestSurfaceTerrainBlock(pos.getBlockX(), pos.getBlockZ(), pos.getBlockY(), 0, editSession.getMaxY()); if (max == -1) return; - pos.mutY(max); - path.add(pos); +// pos.mutY(max); + path.add(new Vector3(pos.getBlockX(), max, pos.getBlockZ())); editSession.getPlayer().sendMessage(BBC.getPrefix() + BBC.BRUSH_SPLINE_PRIMARY_2.s()); if (!vis) return; } @@ -40,7 +43,7 @@ public class SurfaceSpline implements Brush { final List nodes = new ArrayList<>(path.size()); final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); - for (final Vector nodevector : path) { + for (final Vector3 nodevector : path) { final Node n = new Node(nodevector); n.setTension(tension); n.setBias(bias); @@ -50,14 +53,14 @@ public class SurfaceSpline implements Brush { interpol.setNodes(nodes); final double splinelength = interpol.arcLength(0, 1); for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { - final Vector tipv = interpol.getPosition(loop); + final Vector3 tipv = interpol.getPosition(loop); final int tipx = MathMan.roundInt(tipv.getX()); final int tipz = (int) tipv.getZ(); int tipy = MathMan.roundInt(tipv.getY()); tipy = editSession.getNearestSurfaceTerrainBlock(tipx, tipz, tipy, 0, maxY); if (tipy == -1) continue; if (radius == 0) { - Vector set = MutableBlockVector.get(tipx, tipy, tipz); + BlockVector3 set = MutableBlockVector.get(tipx, tipy, tipz); try { pattern.apply(editSession, set, set); } catch (WorldEditException e) { @@ -71,7 +74,7 @@ public class SurfaceSpline implements Brush { double radius2 = (radius * radius); LocalBlockVectorSet newSet = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); - for (final Vector v : vset) { + for (final BlockVector3 v : vset) { final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) { for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/HeightMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/HeightMap.java index 61c7a1807..a20256397 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/HeightMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/HeightMap.java @@ -4,9 +4,9 @@ import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.util.MainUtil; 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.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.convolution.GaussianKernel; import com.sk89q.worldedit.math.convolution.HeightMapFilter; import com.sk89q.worldedit.regions.CuboidRegion; @@ -19,19 +19,19 @@ public interface HeightMap { public void setSize(int size); - default void perform(EditSession session, Mask mask, Vector pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException { + default void perform(EditSession session, Mask mask, BlockVector3 pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException { int[][] data = generateHeightData(session, mask, pos, size, rotationMode, yscale, smooth, towards, layers); applyHeightMapData(data, session, mask, pos, size, rotationMode, yscale, smooth, towards, layers); } - default void applyHeightMapData(int[][] data, EditSession session, Mask mask, Vector pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException { - Vector top = session.getMaximumPoint(); + default void applyHeightMapData(int[][] data, EditSession session, Mask mask, BlockVector3 pos, int size, int rotationMode, double yscale, boolean smooth, boolean towards, boolean layers) throws MaxChangedBlocksException { + BlockVector3 top = session.getMaximumPoint(); int maxY = top.getBlockY(); int diameter = 2 * size + 1; int iterations = 1; - Location min = new Location(session.getWorld(), pos.subtract(size, maxY, size)); - Vector max = pos.add(size, maxY, size); - Region region = new CuboidRegion(session.getWorld(), min, max); + Location min = new Location(session.getWorld(), pos.subtract(size, maxY, size).toVector3()); + BlockVector3 max = pos.add(size, maxY, size); + Region region = new CuboidRegion(session.getWorld(), min.toVector().toBlockPoint(), max); com.sk89q.worldedit.math.convolution.HeightMap heightMap = new com.sk89q.worldedit.math.convolution.HeightMap(session, region, data[0], layers); if (smooth) { try { @@ -52,8 +52,8 @@ public interface HeightMap { } } - default int[][] generateHeightData(EditSession session, Mask mask, Vector pos, int size, final int rotationMode, double yscale, boolean smooth, boolean towards, final boolean layers) { - Vector top = session.getMaximumPoint(); + default int[][] generateHeightData(EditSession session, Mask mask, BlockVector3 pos, int size, final int rotationMode, double yscale, boolean smooth, boolean towards, final boolean layers) { + BlockVector3 top = session.getMaximumPoint(); int maxY = top.getBlockY(); int diameter = 2 * size + 1; int centerX = pos.getBlockX(); @@ -67,14 +67,14 @@ public interface HeightMap { centerY <<= 3; maxY <<= 3; } - Vector mutablePos = new Vector(0, 0, 0); +// Vector mutablePos = new Vector(0, 0, 0); if (towards) { double sizePowInv = 1d / Math.pow(size, yscale); int targetY = pos.getBlockY(); int tmpY = targetY; for (int x = -size; x <= size; x++) { int xx = centerX + x; - mutablePos.mutX(xx); +// mutablePos.mutX(xx); for (int z = -size; z <= size; z++) { int index = (z + size) * diameter + (x + size); int zz = centerZ + z; @@ -118,7 +118,7 @@ public interface HeightMap { int height = pos.getBlockY(); for (int x = -size; x <= size; x++) { int xx = centerX + x; - mutablePos.mutX(xx); +// mutablePos.mutX(xx); for (int z = -size; z <= size; z++) { int index = (z + size) * diameter + (x + size); int zz = centerZ + z; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/RotatableHeightMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/RotatableHeightMap.java index d6f1fca69..8569ea195 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/RotatableHeightMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/RotatableHeightMap.java @@ -1,16 +1,16 @@ package com.boydti.fawe.object.brush.heightmap; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableVector; import com.sk89q.worldedit.math.transform.AffineTransform; public class RotatableHeightMap extends AbstractDelegateHeightMap { private AffineTransform transform; - private MutableBlockVector mutable; + private MutableVector mutable; public RotatableHeightMap(HeightMap parent) { super(parent); - mutable = new MutableBlockVector(); + mutable = new MutableVector(); this.transform = new AffineTransform(); } @@ -22,7 +22,7 @@ public class RotatableHeightMap extends AbstractDelegateHeightMap { public double getHeight(int x, int z) { mutable.mutX(x); mutable.mutZ(z); - Vector pos = transform.apply(mutable.setComponents(x, 0, z)); + BlockVector3 pos = transform.apply(mutable.setComponents(x, 0, z)).toBlockPoint(); return super.getHeight(pos.getBlockX(), pos.getBlockZ()); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java index cea5fdff5..8f17679b4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/heightmap/ScalableHeightMap.java @@ -3,10 +3,11 @@ package com.boydti.fawe.object.brush.heightmap; import com.boydti.fawe.object.IntegerPair; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.awt.image.BufferedImage; @@ -60,7 +61,7 @@ public class ScalableHeightMap implements com.boydti.fawe.object.brush.heightmap } public static ScalableHeightMap fromClipboard(Clipboard clipboard) { - Vector dim = clipboard.getDimensions(); + BlockVector3 dim = clipboard.getDimensions(); byte[][] heightArray = new byte[dim.getBlockX()][dim.getBlockZ()]; int minX = clipboard.getMinimumPoint().getBlockX(); int minZ = clipboard.getMinimumPoint().getBlockZ(); @@ -68,7 +69,7 @@ public class ScalableHeightMap implements com.boydti.fawe.object.brush.heightmap int maxY = clipboard.getMaximumPoint().getBlockY(); int clipHeight = maxY - minY + 1; HashSet visited = new HashSet<>(); - for (Vector pos : clipboard.getRegion()) { + for (BlockVector3 pos : clipboard.getRegion()) { IntegerPair pair = new IntegerPair(pos.getBlockX(), pos.getBlockZ()); if (visited.contains(pair)) { continue; @@ -77,9 +78,10 @@ public class ScalableHeightMap implements com.boydti.fawe.object.brush.heightmap int xx = pos.getBlockX(); int zz = pos.getBlockZ(); int highestY = minY; + MutableBlockVector bv = new MutableBlockVector(pos); for (int y = minY; y <= maxY; y++) { - pos.mutY(y); - BlockStateHolder block = clipboard.getBlock(pos); + bv.mutY(y); + BlockStateHolder block = clipboard.getBlock(bv); if (!block.getBlockType().getMaterial().isAir()) { highestY = y + 1; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/ClipboardSpline.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/ClipboardSpline.java index 936338999..4dc8120ae 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/ClipboardSpline.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/ClipboardSpline.java @@ -3,11 +3,11 @@ package com.boydti.fawe.object.brush.sweep; import com.boydti.fawe.object.collection.LocalBlockVectorSet; 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.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.interpolation.Interpolation; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.RoundedTransform; @@ -24,11 +24,11 @@ public class ClipboardSpline extends Spline { private final Transform transform; private ClipboardHolder clipboardHolder; - private Vector originalOrigin; + private BlockVector3 originalOrigin; private Transform originalTransform; - private Vector center; - private Vector centerOffset; + private BlockVector3 center; + private BlockVector3 centerOffset; private LocalBlockVectorSet buffer; /** @@ -70,8 +70,9 @@ public class ClipboardSpline extends Spline { this.originalOrigin = clipboard.getOrigin(); Region region = clipboard.getRegion(); - Vector origin = clipboard.getOrigin(); - center = region.getCenter().setY(origin.getY() - 1); + BlockVector3 origin = clipboard.getOrigin(); +// center = region.getCenter().setY(origin.getY() - 1); + center = region.getCenter().withY(origin.getY() - 1).toBlockPoint(); this.centerOffset = center.subtract(center.round()); this.center = center.subtract(centerOffset); this.transform = transform; @@ -79,7 +80,7 @@ public class ClipboardSpline extends Spline { } @Override - protected int pasteBlocks(Vector target, Vector offset, double angle) throws MaxChangedBlocksException { + protected int pasteBlocks(BlockVector3 target, BlockVector3 offset, double angle) throws MaxChangedBlocksException { RoundedTransform transform = new RoundedTransform(new AffineTransform() .translate(offset) .rotateY(angle)); @@ -95,7 +96,7 @@ public class ClipboardSpline extends Spline { clipboard.setOrigin(center.subtract(centerOffset).round()); clipboardHolder.setTransform(transform); - Vector functionOffset = target.subtract(clipboard.getOrigin()); + BlockVector3 functionOffset = target.subtract(clipboard.getOrigin()); final int offX = functionOffset.getBlockX(); final int offY = functionOffset.getBlockY(); final int offZ = functionOffset.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java index e04eb1933..ee6851ec2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/Spline.java @@ -3,8 +3,10 @@ package com.boydti.fawe.object.brush.sweep; import com.google.common.base.Preconditions; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -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.math.Vector3; import com.sk89q.worldedit.math.interpolation.Interpolation; import java.util.ArrayList; @@ -19,7 +21,7 @@ import java.util.List; */ public abstract class Spline { - private Vector2D direction = new Vector2D(1, 0); + private BlockVector2 direction = new BlockVector2(1, 0); private final int nodeCount; protected EditSession editSession; @@ -77,7 +79,7 @@ public abstract class Spline { * The default direction is a (1;0) vector (pointing in the positive x-direction). * @param direction A normalized vector representing the horizontal forward direction of the clipboard content */ - public void setDirection(Vector2D direction) { + public void setDirection(BlockVector2 direction) { this.direction = direction; } @@ -91,7 +93,7 @@ public abstract class Spline { * The default direction is a (1;0) vector (pointing in the positive x-direction). * @return A vector representing the horizontal forward direction of the clipboard content */ - public Vector2D getDirection() { + public BlockVector2 getDirection() { return direction; } @@ -125,14 +127,14 @@ public abstract class Spline { Preconditions.checkArgument(position <= 1); // Calculate position from spline - Vector target = interpolation.getPosition(position); - Vector offset = target.subtract(target.round()); + BlockVector3 target = interpolation.getPosition(position).toBlockPoint(); + BlockVector3 offset = target.subtract(target.round()); target = target.subtract(offset); // Calculate rotation from spline - Vector deriv = interpolation.get1stDerivative(position); - Vector2D deriv2D = new Vector2D(deriv.getX(), deriv.getZ()).normalize(); + Vector3 deriv = interpolation.get1stDerivative(position); + Vector2 deriv2D = new Vector2(deriv.getX(), deriv.getZ()).normalize(); double angle = Math.toDegrees( Math.atan2(direction.getZ(), direction.getX()) - Math.atan2(deriv2D.getZ(), deriv2D.getX()) ); @@ -140,7 +142,7 @@ public abstract class Spline { return pasteBlocks(target, offset, angle); } - protected abstract int pasteBlocks(Vector target, Vector offset, double angle) throws MaxChangedBlocksException; + protected abstract int pasteBlocks(BlockVector3 target, BlockVector3 offset, double angle) throws MaxChangedBlocksException; private void initSections() { int sectionCount = nodeCount - 1; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java index 60063e6a7..d9825241b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/sweep/SweepBrush.java @@ -9,10 +9,12 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EmptyClipboardException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.brush.Brush; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableVector; +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; @@ -23,8 +25,8 @@ import java.util.List; import java.util.stream.Collectors; public class SweepBrush implements Brush, ResettableTool { - private List positions; - private Vector position; + private List positions; + private BlockVector3 position; private int copies; private static final double tension = 0D; @@ -37,7 +39,7 @@ public class SweepBrush implements Brush, ResettableTool { } @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 { boolean visualization = editSession.getExtent() instanceof VisualExtent; if (visualization && positions.isEmpty()) { return; @@ -59,7 +61,7 @@ public class SweepBrush implements Brush, ResettableTool { Interpolation interpol = new KochanekBartelsInterpolation(); List nodes = positions.stream().map(v -> { - Node n = new Node(v); + Node n = new Node(v.toVector3()); n.setTension(tension); n.setBias(bias); n.setContinuity(continuity); @@ -74,7 +76,7 @@ public class SweepBrush implements Brush, ResettableTool { } Clipboard clipboard = holder.getClipboard(); - Vector dimensions = clipboard.getDimensions(); + BlockVector3 dimensions = clipboard.getDimensions(); AffineTransform transform = new AffineTransform(); if (dimensions.getBlockX() > dimensions.getBlockZ()) { transform = transform.rotateY(90); @@ -93,10 +95,10 @@ public class SweepBrush implements Brush, ResettableTool { double blockDistance = 1d / splineLength; double step = blockDistance / quality; double accumulation = 0; - Vector last = null; + MutableVector last = new MutableVector(0, 0, 0); for (double pos = 0D; pos <= 1D; pos += step) { - Vector gradient = interpol.get1stDerivative(pos); - if (last == null) last = new Vector(interpol.get1stDerivative(pos)); + Vector3 gradient = interpol.get1stDerivative(pos); + if (last == null) last = new MutableVector(interpol.get1stDerivative(pos)); double dist = MathMan.sqrtApprox(last.distanceSq(gradient)); last.mutX(gradient.getX()); last.mutY(gradient.getY()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java index 13b12e9cc..e9b4f188e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/ImmutableVirtualWorld.java @@ -13,6 +13,9 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; 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.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.world.World; @@ -59,7 +62,7 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return FaweCache.getBiome(0); } @@ -185,27 +188,27 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { } @Override - public boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { return setBlock(position, block); } @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 unsupported(); } @Override - public void dropItem(Vector position, BaseItemStack item) { + public void dropItem(Vector3 position, BaseItemStack item) { unsupported(); } @Override - public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { + public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { return unsupported(); } @@ -264,12 +267,12 @@ public abstract class ImmutableVirtualWorld implements VirtualWorld { } @Override - public boolean setBlock(Vector pt, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException { return unsupported(); } @Override - public void simulateBlockMine(Vector position) { + public void simulateBlockMine(BlockVector3 position) { unsupported(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java index 53282be2a..db9be1e55 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VirtualWorld.java @@ -3,11 +3,12 @@ package com.boydti.fawe.object.brush.visualization; import com.boydti.fawe.object.FaweChunk; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.BlockInteractEvent; import com.sk89q.worldedit.event.platform.PlayerInputEvent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.SimpleWorld; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -16,12 +17,12 @@ import java.io.Closeable; import java.io.IOException; public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable { - Vector getOrigin(); + Vector3 getOrigin(); FaweChunk getSnapshot(int chunkX, int chunkZ); @Override - default BlockState getFullBlock(Vector position) { + default BlockState getFullBlock(BlockVector3 position) { return getLazyBlock(position); } @@ -29,15 +30,15 @@ public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable { int getMaxY(); @Override - boolean setBlock(Vector pt, BlockStateHolder block) throws WorldEditException; + boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException; @Override - default Vector getMaximumPoint() { + default BlockVector3 getMaximumPoint() { return FaweQueue.super.getMaximumPoint(); } @Override - default Vector getMinimumPoint() { + default BlockVector3 getMinimumPoint() { return FaweQueue.super.getMinimumPoint(); } @@ -52,7 +53,7 @@ public interface VirtualWorld extends SimpleWorld, FaweQueue, Closeable { void close(boolean update) throws IOException; - default void handleBlockInteract(Player player, Vector pos, BlockInteractEvent event) {} + default void handleBlockInteract(Player player, BlockVector3 pos, BlockInteractEvent event) {} default void handlePlayerInput(Player player, PlayerInputEvent event) {} } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualExtent.java index c3c260366..2711f187e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/brush/visualization/VisualExtent.java @@ -7,13 +7,13 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.visitor.FaweChunkVisitor; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +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; import it.unimi.dsi.fastutil.longs.Long2ObjectMap; @@ -31,7 +31,7 @@ public class VisualExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @@ -62,7 +62,7 @@ public class VisualExtent extends AbstractDelegateExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { // Do nothing return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java index 9aaef3ed4..c950f8bf3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/change/MutableBiomeChange.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.change; -import com.sk89q.worldedit.MutableBlockVector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.history.UndoContext; import com.sk89q.worldedit.history.change.Change; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; public class MutableBiomeChange implements Change { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java index f8b656eda..ab411e890 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/AbstractDelegateChangeSet.java @@ -4,7 +4,6 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.FaweQueue; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.inventory.BlockBag; @@ -12,6 +11,7 @@ import com.sk89q.worldedit.history.change.BlockChange; import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.EntityCreate; import com.sk89q.worldedit.history.change.EntityRemove; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -154,7 +154,7 @@ public class AbstractDelegateChangeSet extends FaweChangeSet { } @Override - public void add(Vector loc, BlockStateHolder from, BlockStateHolder to) { + public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) { parent.add(loc, from, to); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java index 3a8665303..5b092d77d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/BlockBagChangeSet.java @@ -5,11 +5,11 @@ import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBagException; import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -71,7 +71,7 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet { } @Override - public void add(Vector loc, BlockStateHolder from, BlockStateHolder to) { + public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) { int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java index 1d2fe1afb..14c8f284f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/changeset/FaweChangeSet.java @@ -13,9 +13,7 @@ import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.TaskManager; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.inventory.BlockBag; @@ -24,6 +22,7 @@ import com.sk89q.worldedit.history.change.Change; 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.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -197,7 +196,7 @@ public abstract class FaweChangeSet implements ChangeSet { public void add(BlockChange change) { try { - BlockVector loc = change.getPosition(); + BlockVector3 loc = change.getPosition(); BlockStateHolder from = change.getPrevious(); BlockStateHolder to = change.getCurrent(); add(loc, from, to); @@ -206,7 +205,7 @@ public abstract class FaweChangeSet implements ChangeSet { } } - public void add(Vector loc, BlockStateHolder from, BlockStateHolder to) { + public void add(BlockVector3 loc, BlockStateHolder from, BlockStateHolder to) { int x = loc.getBlockX(); int y = loc.getBlockY(); int z = loc.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java index 7ff4bb52c..aee7627fe 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/AbstractDelegateFaweClipboard.java @@ -2,12 +2,12 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.NBTStreamer; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -87,12 +87,12 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard { } @Override - public void setOrigin(Vector offset) { + public void setOrigin(BlockVector3 offset) { parent.setOrigin(offset); } @Override - public void setDimensions(Vector dimensions) { + public void setDimensions(BlockVector3 dimensions) { parent.setDimensions(dimensions); } @@ -107,7 +107,7 @@ public class AbstractDelegateFaweClipboard extends FaweClipboard { } @Override - public Vector getDimensions() { + public BlockVector3 getDimensions() { return parent.getDimensions(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java index e9934cc73..f708e96df 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/CPUOptimizedClipboard.java @@ -8,12 +8,12 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -112,7 +112,7 @@ public class CPUOptimizedClipboard extends FaweClipboard { } @Override - public void setDimensions(Vector dimensions) { + public void setDimensions(BlockVector3 dimensions) { width = dimensions.getBlockX(); height = dimensions.getBlockY(); length = dimensions.getBlockZ(); @@ -125,8 +125,8 @@ public class CPUOptimizedClipboard extends FaweClipboard { } @Override - public Vector getDimensions() { - return new Vector(width, height, length); + public BlockVector3 getDimensions() { + return new BlockVector3(width, height, length); } private int ylast; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java index b74b0e977..bd7bdc4e0 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/DiskOptimizedClipboard.java @@ -11,13 +11,13 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -166,18 +166,18 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } @Override - public Vector getDimensions() { - return new Vector(width, height, length); + public BlockVector3 getDimensions() { + return new BlockVector3(width, height, length); } public BlockArrayClipboard toClipboard() { try { - CuboidRegion region = new CuboidRegion(new Vector(0, 0, 0), new Vector(width - 1, height - 1, length - 1)); + CuboidRegion region = new CuboidRegion(new BlockVector3(0, 0, 0), new BlockVector3(width - 1, height - 1, length - 1)); int ox = mbb.getShort(8); int oy = mbb.getShort(10); int oz = mbb.getShort(12); BlockArrayClipboard clipboard = new BlockArrayClipboard(region, this); - clipboard.setOrigin(new Vector(ox, oy, oz)); + clipboard.setOrigin(new BlockVector3(ox, oy, oz)); return clipboard; } catch (Throwable e) { MainUtil.handleError(e); @@ -223,7 +223,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } @Override - public void setOrigin(Vector offset) { + public void setOrigin(BlockVector3 offset) { try { mbb.putShort(8, (short) offset.getBlockX()); mbb.putShort(10, (short) offset.getBlockY()); @@ -234,7 +234,7 @@ public class DiskOptimizedClipboard extends FaweClipboard implements Closeable { } @Override - public void setDimensions(Vector dimensions) { + public void setDimensions(BlockVector3 dimensions) { try { width = dimensions.getBlockX(); height = dimensions.getBlockY(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java index 1ea6bc0ff..5f23c954e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/EmptyClipboard.java @@ -1,8 +1,6 @@ package com.boydti.fawe.object.clipboard; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -10,6 +8,8 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.operation.Operation; +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.util.Location; @@ -30,31 +30,31 @@ public class EmptyClipboard implements Clipboard { @Override public Region getRegion() { - return new CuboidRegion(Vector.ZERO, Vector.ZERO); + return new CuboidRegion(BlockVector3.ZERO, BlockVector3.ZERO); } @Override - public Vector getDimensions() { - return Vector.ZERO; + public BlockVector3 getDimensions() { + return BlockVector3.ZERO; } @Override - public Vector getOrigin() { - return Vector.ZERO; + public BlockVector3 getOrigin() { + return BlockVector3.ZERO; } @Override - public void setOrigin(Vector origin) { + public void setOrigin(BlockVector3 origin) { } @Override - public Vector getMinimumPoint() { - return Vector.ZERO; + public BlockVector3 getMinimumPoint() { + return BlockVector3.ZERO; } @Override - public Vector getMaximumPoint() { - return Vector.ZERO; + public BlockVector3 getMaximumPoint() { + return BlockVector3.ZERO; } @Override @@ -74,27 +74,27 @@ public class EmptyClipboard implements Clipboard { } @Override - public BlockState getFullBlock(Vector position) { + public BlockState getFullBlock(BlockVector3 position) { return EditSession.nullBlock; } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return EditSession.nullBlock; } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return EditSession.nullBiome; } @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/boydti/fawe/object/clipboard/FaweClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java index c5431a081..04fe83c41 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/FaweClipboard.java @@ -5,12 +5,12 @@ import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; @@ -51,12 +51,12 @@ public abstract class FaweClipboard { public abstract boolean remove(ClipboardEntity clipboardEntity); - public void setOrigin(Vector offset) { + public void setOrigin(BlockVector3 offset) { } // Do nothing - public abstract void setDimensions(Vector dimensions); + public abstract void setDimensions(BlockVector3 dimensions); - public abstract Vector getDimensions(); + public abstract BlockVector3 getDimensions(); /** * The locations provided are relative to the clipboard min diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java index ba81a3b07..67efba2d8 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/MemoryOptimizedClipboard.java @@ -10,12 +10,12 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -159,7 +159,7 @@ public class MemoryOptimizedClipboard extends FaweClipboard { } @Override - public void setDimensions(Vector dimensions) { + public void setDimensions(BlockVector3 dimensions) { width = dimensions.getBlockX(); height = dimensions.getBlockY(); length = dimensions.getBlockZ(); @@ -174,8 +174,8 @@ public class MemoryOptimizedClipboard extends FaweClipboard { } @Override - public Vector getDimensions() { - return new Vector(width, height, length); + public BlockVector3 getDimensions() { + return new BlockVector3(width, height, length); } private int lastI; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java index 7792c9652..9d97af316 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ReadOnlyClipboard.java @@ -3,12 +3,12 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.jnbt.NBTStreamer; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; @@ -36,12 +36,12 @@ public abstract class ReadOnlyClipboard extends FaweClipboard { } @Override - public Vector getDimensions() { + public BlockVector3 getDimensions() { return region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); } @Override - public void setDimensions(Vector dimensions) { + public void setDimensions(BlockVector3 dimensions) { throw new UnsupportedOperationException("Clipboard is immutable"); } @@ -67,7 +67,7 @@ public abstract class ReadOnlyClipboard extends FaweClipboard { @Override public void streamBiomes(NBTStreamer.ByteReader task) { - Vector dim = getDimensions(); + BlockVector3 dim = getDimensions(); int index = 0; for (int z = 0; z <= dim.getBlockZ(); z++) { for (int x = 0; x <= dim.getBlockX(); x++, index++) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java index f50625963..7e7412a56 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/ResizableClipboardBuilder.java @@ -3,12 +3,12 @@ package com.boydti.fawe.object.clipboard; import com.boydti.fawe.object.change.MutableBlockChange; import com.boydti.fawe.object.change.MutableTileChange; import com.boydti.fawe.object.changeset.MemoryOptimizedHistory; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.history.change.Change; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -60,8 +60,8 @@ public class ResizableClipboardBuilder extends MemoryOptimizedHistory { } public Clipboard build() { - Vector pos1 = new Vector(minX, minY, minZ); - Vector pos2 = new Vector(maxX, maxY, maxZ); + BlockVector3 pos1 = new BlockVector3(minX, minY, minZ); + BlockVector3 pos2 = new BlockVector3(maxX, maxY, maxZ); CuboidRegion region = new CuboidRegion(pos1, pos2); BlockArrayClipboard clipboard = new BlockArrayClipboard(region); Iterator iter = getIterator(true); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java index 1c30b0f60..2c570edd3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/WorldCopyClipboard.java @@ -5,8 +5,6 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.world.block.BlockState; @@ -14,6 +12,9 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RegionVisitor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.biome.BaseBiome; @@ -38,7 +39,7 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { super(region); this.hasBiomes = hasBiomes; this.hasEntities = hasEntities; - final Vector origin = region.getMinimumPoint(); + final BlockVector3 origin = region.getMinimumPoint(); this.mx = origin.getBlockX(); this.my = origin.getBlockY(); this.mz = origin.getBlockZ(); @@ -72,15 +73,15 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { @Override public void forEach(BlockReader task, boolean air) { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); - final Vector pos = new Vector(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + MutableBlockVector pos = new MutableBlockVector(); if (region instanceof CuboidRegion) { if (air) { ((CuboidRegion) region).setUseOldIterator(true); RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override - public boolean apply(Vector pos) throws WorldEditException { + public boolean apply(BlockVector3 pos) throws WorldEditException { BlockState block = getBlockAbs(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); int x = pos.getBlockX() - mx; int y = pos.getBlockY() - my; @@ -102,7 +103,7 @@ public class WorldCopyClipboard extends ReadOnlyClipboard { cuboidEquivalent.setUseOldIterator(true); RegionVisitor visitor = new RegionVisitor(cuboidEquivalent, new RegionFunction() { @Override - public boolean apply(Vector pos) throws WorldEditException { + public boolean apply(BlockVector3 pos) throws WorldEditException { int x = pos.getBlockX() - mx; int y = pos.getBlockY() - my; int z = pos.getBlockZ() - mz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java index 31a0bb9e8..5f6dc6b65 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/clipboard/remap/ClipboardRemapper.java @@ -7,7 +7,6 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.intellectualcrafters.plot.util.MathMan; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -15,7 +14,6 @@ import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.regions.Region; -import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.registry.BundledBlockData; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java index fa4054394..cc69c2f8b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/BlockVectorSet.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.collection; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; + import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectIterator; @@ -20,7 +21,7 @@ import java.util.Set; * - All BlockVectors must be a valid world coordinate: y=[0,255],x=[-30000000,30000000],z=[-30000000,30000000] * - This will use ~8 bytes for every 64 BlockVectors (about 800x less than a HashSet) */ -public class BlockVectorSet extends AbstractCollection implements Set { +public class BlockVectorSet extends AbstractCollection implements Set { private Int2ObjectMap localSets = new Int2ObjectOpenHashMap<>(); @Override @@ -32,7 +33,7 @@ public class BlockVectorSet extends AbstractCollection implements Set> iter = localSets.int2ObjectEntrySet().iterator(); while (iter.hasNext()) { @@ -42,7 +43,7 @@ public class BlockVectorSet extends AbstractCollection implements Set index) { int localIndex = index - count; - Vector pos = set.getIndex(localIndex); + MutableBlockVector pos = new MutableBlockVector(set.getIndex(localIndex)); if (pos != null) { int pair = entry.getIntKey(); int cx = MathMan.unpairX(pair); @@ -75,22 +76,22 @@ public class BlockVectorSet extends AbstractCollection implements Set iterator() { + public Iterator iterator() { final ObjectIterator> entries = localSets.int2ObjectEntrySet().iterator(); if (!entries.hasNext()) { - return new ArrayList().iterator(); + return new ArrayList().iterator(); } - return new Iterator() { + return new Iterator() { Int2ObjectMap.Entry entry = entries.next(); - Iterator entryIter = entry.getValue().iterator(); + Iterator entryIter = entry.getValue().iterator(); MutableBlockVector mutable = new MutableBlockVector(); @Override @@ -104,7 +105,7 @@ public class BlockVectorSet extends AbstractCollection implements Set implements Set implements Set implements Set implements Set c) { + public boolean addAll(Collection c) { boolean result = false; - for (Vector v : c) { + for (BlockVector3 v : c) { result |= add(v); } return result; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java index bd0a4b9df..72d483733 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVector2DSet.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.collection; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.MutableBlockVector2D; + import java.util.Collection; import java.util.Iterator; import java.util.Set; @@ -13,7 +13,7 @@ import java.util.Set; * - All Vector2Ds must be within x[0,32768), y[0,32768) * - This will use 8 bytes for every 64 Vector2Ds (about 800x less than a HashSet) */ -public class LocalBlockVector2DSet implements Set { +public class LocalBlockVector2DSet implements Set { private final SparseBitSet set; private final MutableBlockVector2D mutable = new MutableBlockVector2D(); @@ -41,8 +41,8 @@ public class LocalBlockVector2DSet implements Set { @Override public boolean contains(Object o) { - if (o instanceof Vector2D) { - Vector2D v = (Vector2D) o; + if (o instanceof BlockVector2) { + BlockVector2 v = (BlockVector2) o; return contains(v.getBlockX(), v.getBlockZ()); } return false; @@ -90,7 +90,7 @@ public class LocalBlockVector2DSet implements Set { return false; } - public Vector2D getIndex(int getIndex) { + public BlockVector2 getIndex(int getIndex) { int size = size(); if (getIndex > size) { return null; @@ -108,8 +108,8 @@ public class LocalBlockVector2DSet implements Set { } @Override - public Iterator iterator() { - return new Iterator() { + public Iterator iterator() { + return new Iterator() { int index = set.nextSetBit(0); int previous = -1; @@ -124,7 +124,7 @@ public class LocalBlockVector2DSet implements Set { } @Override - public Vector2D next() { + public BlockVector2 next() { if (index != -1) { int x = MathMan.unpairSearchCoordsX(index); int y = MathMan.unpairSearchCoordsY(index); @@ -147,14 +147,14 @@ public class LocalBlockVector2DSet implements Set { public T[] toArray(T[] array) { int size = size(); if (array == null || array.length < size) { - array = (T[]) new BlockVector2D[size]; + array = (T[]) new BlockVector2[size]; } int index = 0; for (int i = 0; i < size; i++) { index = set.nextSetBit(index); int x = MathMan.unpairSearchCoordsX(index); int y = MathMan.unpairSearchCoordsY(index); - array[i] = (T) new BlockVector2D(x, y); + array[i] = (T) new BlockVector2(x, y); index++; } return array; @@ -174,11 +174,11 @@ public class LocalBlockVector2DSet implements Set { } @Override - public boolean add(Vector2D vector) { + public boolean add(BlockVector2 vector) { return add(vector.getBlockX(), vector.getBlockZ()); } - private int getIndex(Vector2D vector) { + private int getIndex(BlockVector2 vector) { return MathMan.pairSearchCoords(vector.getBlockX(), vector.getBlockZ()); } @@ -200,8 +200,8 @@ public class LocalBlockVector2DSet implements Set { @Override public boolean remove(Object o) { - if (o instanceof Vector2D) { - Vector2D v = (Vector2D) o; + if (o instanceof BlockVector2) { + BlockVector2 v = (BlockVector2) o; return remove(v.getBlockX(), v.getBlockZ()); } return false; @@ -218,9 +218,9 @@ public class LocalBlockVector2DSet implements Set { } @Override - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { boolean result = false; - for (Vector2D v : c) { + for (BlockVector2 v : c) { result |= add(v); } return result; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java index 35fab081f..d4aff5660 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/collection/LocalBlockVectorSet.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.collection; import com.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; + import java.util.Collection; import java.util.Iterator; import java.util.Set; @@ -13,7 +13,7 @@ import java.util.Set; * - All vectors must be in a 2048 * 2048 area centered around the first entry * - This will use 8 bytes for every 64 BlockVectors (about 800x less than a HashSet) */ -public class LocalBlockVectorSet implements Set { +public class LocalBlockVectorSet implements Set { private int offsetX, offsetZ; private final SparseBitSet set; @@ -48,8 +48,8 @@ public class LocalBlockVectorSet implements Set { @Override public boolean contains(Object o) { - if (o instanceof Vector) { - Vector v = (Vector) o; + if (o instanceof BlockVector3) { + BlockVector3 v = (BlockVector3) o; return contains(v.getBlockX(), v.getBlockY(), v.getBlockZ()); } return false; @@ -100,7 +100,7 @@ public class LocalBlockVectorSet implements Set { this.offsetZ = z; } - public Vector getIndex(int getIndex) { + public BlockVector3 getIndex(int getIndex) { int size = size(); if (getIndex > size) { return null; @@ -123,8 +123,8 @@ public class LocalBlockVectorSet implements Set { } @Override - public Iterator iterator() { - return new Iterator() { + public Iterator iterator() { + return new Iterator() { int index = set.nextSetBit(0); int previous = -1; MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); @@ -140,7 +140,7 @@ public class LocalBlockVectorSet implements Set { } @Override - public BlockVector next() { + public BlockVector3 next() { if (index != -1) { int b1 = (index & 0xFF); int b2 = ((byte) (index >> 8)) & 0x7F; @@ -167,7 +167,7 @@ public class LocalBlockVectorSet implements Set { public T[] toArray(T[] array) { int size = size(); if (array == null || array.length < size) { - array = (T[]) new BlockVector[size]; + array = (T[]) new BlockVector3[size]; } int index = 0; for (int i = 0; i < size; i++) { @@ -179,7 +179,7 @@ public class LocalBlockVectorSet implements Set { int x = offsetX + (((b3 + ((MathMan.unpair8x(b2)) << 8)) << 21) >> 21); int y = b1; int z = offsetZ + (((b4 + ((MathMan.unpair8y(b2)) << 8)) << 21) >> 21); - array[i] = (T) new BlockVector(x, y, z); + array[i] = (T) new BlockVector3(x, y, z); index++; } return array; @@ -223,11 +223,11 @@ public class LocalBlockVectorSet implements Set { } @Override - public boolean add(Vector vector) { + public boolean add(BlockVector3 vector) { return add(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); } - private int getIndex(Vector vector) { + private int getIndex(BlockVector3 vector) { return MathMan.tripleSearchCoords(vector.getBlockX() - offsetX, vector.getBlockY(), vector.getBlockZ() - offsetZ); } @@ -249,8 +249,8 @@ public class LocalBlockVectorSet implements Set { @Override public boolean remove(Object o) { - if (o instanceof Vector) { - Vector v = (Vector) o; + if (o instanceof BlockVector3) { + BlockVector3 v = (BlockVector3) o; return remove(v.getBlockX(), v.getBlockY(), v.getBlockZ()); } return false; @@ -267,9 +267,9 @@ public class LocalBlockVectorSet implements Set { } @Override - public boolean addAll(Collection c) { + public boolean addAll(Collection c) { boolean result = false; - for (Vector v : c) { + for (BlockVector3 v : c) { result |= add(v); } return result; @@ -280,7 +280,7 @@ public class LocalBlockVectorSet implements Set { boolean result = false; int size = size(); int index = -1; - Vector mVec = MutableBlockVector.get(0, 0, 0); + MutableBlockVector mVec = MutableBlockVector.get(0, 0, 0); for (int i = 0; i < size; i++) { index = set.nextSetBit(index + 1); int b1 = (index & 0xFF); @@ -310,7 +310,7 @@ public class LocalBlockVectorSet implements Set { public void forEach(BlockVectorSetVisitor visitor) { int size = size(); int index = -1; - Vector mVec = MutableBlockVector.get(0, 0, 0); + BlockVector3 mVec = MutableBlockVector.get(0, 0, 0); for (int i = 0; i < size; i++) { index = set.nextSetBit(index + 1); int b1 = (index & 0xFF); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java index 8339719e4..02ea126b3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/BlockTranslateExtent.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -24,7 +24,7 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { mutable.mutX((location.getX() + dx)); mutable.mutY((location.getY() + dy)); mutable.mutZ((location.getZ() + dz)); @@ -40,7 +40,7 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return super.setBiome(position.add(dx, dz), biome); } @@ -50,17 +50,17 @@ public class BlockTranslateExtent extends AbstractDelegateExtent { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return super.getBiome(position.add(dx, dz)); } @Override - public BlockState getBlock(Vector location) { + public BlockState getBlock(BlockVector3 location) { return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } @Override - public BlockState getLazyBlock(Vector location) { + public BlockState getLazyBlock(BlockVector3 location) { return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/EmptyExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/EmptyExtent.java index 1a774746f..90cb84d59 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/EmptyExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/EmptyExtent.java @@ -1,8 +1,6 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -10,6 +8,8 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; 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; @@ -23,12 +23,12 @@ public class EmptyExtent implements Extent { public EmptyExtent() { } - public Vector getMinimumPoint() { - return Vector.ZERO; + public BlockVector3 getMinimumPoint() { + return BlockVector3.ZERO; } - public Vector getMaximumPoint() { - return Vector.ZERO; + public BlockVector3 getMaximumPoint() { + return BlockVector3.ZERO; } public List getEntities(Region region) { @@ -45,27 +45,27 @@ public class EmptyExtent implements Extent { } @Override - public BlockState getFullBlock(Vector position) { + public BlockState getFullBlock(BlockVector3 position) { return EditSession.nullBlock; } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return EditSession.nullBlock; } @Nullable - 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/boydti/fawe/object/extent/FastWorldEditExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java index cc5d2a69e..fbbe39585 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FastWorldEditExtent.java @@ -6,14 +6,14 @@ import com.boydti.fawe.object.HasFaweQueue; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.*; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; +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.World; @@ -106,17 +106,17 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa } @Override - public BaseBiome getBiome(final Vector2D position) { + public BaseBiome getBiome(final BlockVector2 position) { return FaweCache.CACHE_BIOME[queue.getBiomeId(position.getBlockX(), position.getBlockZ())]; } @Override - public boolean setBlock(final Vector location, final BlockStateHolder block) throws WorldEditException { + public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @Override - public BlockState getLazyBlock(Vector location) { + public BlockState getLazyBlock(BlockVector3 location) { return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } @@ -145,12 +145,12 @@ public class FastWorldEditExtent extends AbstractDelegateExtent implements HasFa } @Override - public BlockState getBlock(final Vector position) { + public BlockState getBlock(final BlockVector3 position) { return this.getLazyBlock(position); } @Override - public boolean setBiome(final Vector2D position, final BaseBiome biome) { + public boolean setBiome(final BlockVector2 position, final BaseBiome biome) { queue.setBiome(position.getBlockX(), position.getBlockZ(), biome); return true; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java index 04f8323f3..2d27066f6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/FaweRegionExtent.java @@ -4,14 +4,14 @@ import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.util.WEManager; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +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; @@ -48,16 +48,16 @@ public abstract class FaweRegionExtent extends ResettableExtent { return false; } - public final boolean contains(Vector p) { + public final boolean contains(BlockVector3 p) { return contains(p.getBlockX(), p.getBlockY(), p.getBlockZ()); } - public final boolean contains(Vector2D p) { + public final boolean contains(BlockVector2 p) { return contains(p.getBlockX(), p.getBlockZ()); } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (!contains(location)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); @@ -79,7 +79,7 @@ public abstract class FaweRegionExtent extends ResettableExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { if (!contains(position)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); @@ -101,7 +101,7 @@ public abstract class FaweRegionExtent extends ResettableExtent { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); @@ -112,7 +112,7 @@ public abstract class FaweRegionExtent extends ResettableExtent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); @@ -123,7 +123,7 @@ public abstract class FaweRegionExtent extends ResettableExtent { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { if (!contains(position)) { if (!limit.MAX_FAILS()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java index c0e68f856..6d0efac0b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MemoryCheckingExtent.java @@ -5,12 +5,12 @@ import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.util.MemUtil; import com.boydti.fawe.util.Perm; import com.boydti.fawe.util.WEManager; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; 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; public class MemoryCheckingExtent extends AbstractDelegateExtent { @@ -22,7 +22,7 @@ public class MemoryCheckingExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(final Vector location, final BlockStateHolder block) throws WorldEditException { + public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { if (super.setBlock(location, block)) { if (MemUtil.isMemoryLimited()) { if (this.player != null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java index f5aa12ac1..3ad106eda 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/MultiTransform.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -40,14 +40,14 @@ public class MultiTransform extends RandomTransform { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { boolean result = false; for (AbstractDelegateExtent extent : extents) result |= extent.setBlock(location, block); return result; } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { boolean result = false; for (AbstractDelegateExtent extent : extents) result |= extent.setBiome(position, biome); return result; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java index 610068303..3e4831c67 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/NullExtent.java @@ -3,8 +3,6 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.object.exception.FaweException; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -12,6 +10,8 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; 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; @@ -48,27 +48,27 @@ public class NullExtent extends FaweRegionExtent { } @Override - public BaseBiome getBiome(final Vector2D arg0) { + public BaseBiome getBiome(final BlockVector2 arg0) { throw new FaweException(reason); } @Override - public BaseBlock getBlock(final Vector arg0) { + public BaseBlock getBlock(final BlockVector3 arg0) { throw new FaweException(reason); } @Override - public BaseBlock getLazyBlock(final Vector arg0) { + public BaseBlock getLazyBlock(final BlockVector3 arg0) { throw new FaweException(reason); } @Override - public boolean setBiome(final Vector2D arg0, final BaseBiome arg1) { + public boolean setBiome(final BlockVector2 arg0, final BaseBiome arg1) { throw new FaweException(reason); } @Override - public boolean setBlock(final Vector arg0, final BlockStateHolder arg1) throws WorldEditException { + public boolean setBlock(final BlockVector3 arg0, final BlockStateHolder arg1) throws WorldEditException { throw new FaweException(reason); } @@ -98,13 +98,13 @@ public class NullExtent extends FaweRegionExtent { } @Override - public Vector getMaximumPoint() { - return new Vector(0, 0, 0); + public BlockVector3 getMaximumPoint() { + return new BlockVector3(0, 0, 0); } @Override - public Vector getMinimumPoint() { - return new Vector(0, 0, 0); + public BlockVector3 getMinimumPoint() { + return new BlockVector3(0, 0, 0); } @Override diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java index 7225fe9c0..b652e741f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/OffsetExtent.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -22,7 +22,7 @@ public class OffsetExtent extends ResettableExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return getExtent().setBiome(mutable.setComponents(position.getBlockX() + dx, position.getBlockZ() + dz), biome); } @@ -32,7 +32,7 @@ public class OffsetExtent extends ResettableExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return getExtent().setBlock(location.getBlockX() + dx, location.getBlockY() + dy, location.getBlockZ() + dz, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java index 977db3092..d4ac2e34f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PatternTransform.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class PatternTransform extends ResettableExtent { @@ -17,7 +17,7 @@ public class PatternTransform extends ResettableExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return pattern.apply(getExtent(), location, location); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java index 0b9f69e1a..dbe59d503 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/PositionTransformExtent.java @@ -1,12 +1,14 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -14,7 +16,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; public class PositionTransformExtent extends ResettableExtent { private transient MutableBlockVector mutable = new MutableBlockVector(); - private transient Vector min; + private transient BlockVector3 min; private Transform transform; public PositionTransformExtent(Extent parent, Transform transform) { @@ -29,36 +31,36 @@ public class PositionTransformExtent extends ResettableExtent { return super.setExtent(extent); } - public void setOrigin(Vector pos) { + public void setOrigin(BlockVector3 pos) { this.min = pos; } - private Vector getPos(Vector pos) { + private BlockVector3 getPos(BlockVector3 pos) { if (min == null) { - min = new Vector(pos); + min = pos; } mutable.mutX(((pos.getX() - min.getX()))); mutable.mutY(((pos.getY() - min.getY()))); mutable.mutZ(((pos.getZ() - min.getZ()))); - Vector tmp = transform.apply(mutable); + MutableVector tmp = new MutableVector(transform.apply(mutable.toVector3())); tmp.mutX((tmp.getX() + min.getX())); tmp.mutY((tmp.getY() + min.getY())); tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp; + return tmp.toBlockPoint(); } - private Vector getPos(int x, int y, int z) { + private BlockVector3 getPos(int x, int y, int z) { if (min == null) { - min = new Vector(x, y, z); + min = new BlockVector3(x, y, z); } mutable.mutX(((x - min.getX()))); mutable.mutY(((y - min.getY()))); mutable.mutZ(((z - min.getZ()))); - Vector tmp = transform.apply(mutable); + MutableVector tmp = new MutableVector(transform.apply(mutable.toVector3())); tmp.mutX((tmp.getX() + min.getX())); tmp.mutY((tmp.getY() + min.getY())); tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp; + return tmp.toBlockPoint(); } @Override @@ -67,21 +69,21 @@ public class PositionTransformExtent extends ResettableExtent { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return super.getLazyBlock(getPos(position)); } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return super.getBlock(getPos(position)); } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { mutable.mutX(position.getBlockX()); mutable.mutZ(position.getBlockZ()); mutable.mutY(0); - return super.getBiome(getPos(mutable).toVector2D()); + return super.getBiome(getPos(mutable).toBlockVector2()); } @Override @@ -91,16 +93,16 @@ public class PositionTransformExtent extends ResettableExtent { @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return super.setBlock(getPos(location), block); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { mutable.mutX(position.getBlockX()); mutable.mutZ(position.getBlockZ()); mutable.mutY(0); - return super.setBiome(getPos(mutable).toVector2D(), biome); + return super.setBiome(getPos(mutable).toBlockVector2(), biome); } public void setTransform(Transform transform) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java index 59d7b6ad5..3cf9168fa 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ProcessedWEExtent.java @@ -5,8 +5,6 @@ import com.boydti.fawe.object.FaweLimit; import com.boydti.fawe.util.WEManager; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -14,6 +12,8 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +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; @@ -48,7 +48,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public BaseBiome getBiome(final Vector2D position) { + public BaseBiome getBiome(final BlockVector2 position) { return super.getBiome(position); } @@ -73,12 +73,12 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(final Vector location, final BlockStateHolder block) throws WorldEditException { + public boolean setBlock(final BlockVector3 location, final BlockStateHolder block) throws WorldEditException { return setBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); } @Override - public BlockState getLazyBlock(Vector location) { + public BlockState getLazyBlock(BlockVector3 location) { return getLazyBlock(location.getBlockX(), location.getBlockY(), location.getBlockZ()); } @@ -106,7 +106,7 @@ public class ProcessedWEExtent extends AbstractDelegateExtent { } @Override - public boolean setBiome(final Vector2D position, final BaseBiome biome) { + public boolean setBiome(final BlockVector2 position, final BaseBiome biome) { if (!limit.MAX_CHANGES()) { WEManager.IMP.cancelEditSafe(this, BBC.WORLDEDIT_CANCEL_REASON_MAX_CHANGES); return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java index 17c2d6193..54ab458c6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/RandomOffsetTransform.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -27,14 +27,14 @@ public class RandomOffsetTransform extends ResettableExtent { } @Override - public boolean setBiome(Vector2D pos, BaseBiome biome) { + public boolean setBiome(BlockVector2 pos, BaseBiome biome) { int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx; int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz; return getExtent().setBiome(mutable.setComponents(x, z), biome); } @Override - public boolean setBlock(Vector pos, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 pos, BlockStateHolder block) throws WorldEditException { int x = pos.getBlockX() + random.nextInt(1 + (dx << 1)) - dx; int y = pos.getBlockY() + random.nextInt(1 + (dy << 1)) - dy; int z = pos.getBlockZ() + random.nextInt(1 + (dz << 1)) - dz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java index ac96e0904..bee31b63d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ResettableExtent.java @@ -2,9 +2,9 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.util.ExtentTraverser; import com.boydti.fawe.util.ReflectionUtils; -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.world.World; import java.io.IOException; import java.io.Serializable; @@ -18,7 +18,7 @@ public class ResettableExtent extends AbstractDelegateExtent implements Serializ super(parent); } - public final void init(Vector pos) { + public final void init(BlockVector3 pos) { Extent extent = getExtent(); if (extent instanceof ResettableExtent && extent != this) { ((ResettableExtent) extent).init(pos); @@ -26,7 +26,7 @@ public class ResettableExtent extends AbstractDelegateExtent implements Serializ setOrigin(pos); } - protected void setOrigin(Vector pos) { + protected void setOrigin(BlockVector3 pos) { } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java index 4543a551f..937573404 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/ScaleTransform.java @@ -1,14 +1,14 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -18,7 +18,7 @@ import javax.annotation.Nullable; public class ScaleTransform extends ResettableExtent { private transient MutableBlockVector mutable = new MutableBlockVector(); private transient int maxy; - private transient Vector min; + private transient BlockVector3 min; private final double dx, dy, dz; @@ -39,9 +39,9 @@ public class ScaleTransform extends ResettableExtent { return super.setExtent(extent); } - private Vector getPos(Vector pos) { + private BlockVector3 getPos(BlockVector3 pos) { if (min == null) { - min = new Vector(pos); + min = pos; } mutable.mutX((min.getX() + (pos.getX() - min.getX()) * dx)); mutable.mutY((min.getY() + (pos.getY() - min.getY()) * dy)); @@ -49,9 +49,9 @@ public class ScaleTransform extends ResettableExtent { return mutable; } - private Vector getPos(int x, int y, int z) { + private BlockVector3 getPos(int x, int y, int z) { if (min == null) { - min = new Vector(x, y, z); + min = new BlockVector3(x, y, z); } mutable.mutX((min.getX() + (x - min.getX()) * dx)); mutable.mutY((min.getY() + (y - min.getY()) * dy)); @@ -61,9 +61,9 @@ public class ScaleTransform extends ResettableExtent { @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { boolean result = false; - Vector pos = getPos(location); + MutableBlockVector pos = new MutableBlockVector(getPos(location)); double sx = pos.getX(); double sy = pos.getY(); double sz = pos.getZ(); @@ -81,16 +81,16 @@ public class ScaleTransform extends ResettableExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { boolean result = false; - Vector pos = getPos(position.getBlockX(), 0, position.getBlockZ()); + MutableBlockVector pos = new MutableBlockVector(getPos(position.getBlockX(), 0, position.getBlockZ())); double sx = pos.getX(); double sz = pos.getZ(); double ex = pos.getX() + dx; double ez = pos.getZ() + dz; for (pos.mutZ(sz); pos.getZ() < ez; pos.mutZ(pos.getZ() + 1)) { for (pos.mutX(sx); pos.getX() < ex; pos.mutX(pos.getX() + 1)) { - result |= super.setBiome(pos.toVector2D(), biome); + result |= super.setBiome(pos.toBlockVector2(), biome); } } return result; @@ -99,7 +99,7 @@ public class ScaleTransform extends ResettableExtent { @Override public boolean setBlock(int x1, int y1, int z1, BlockStateHolder block) throws WorldEditException { boolean result = false; - Vector pos = getPos(x1, y1, z1); + MutableBlockVector pos = new MutableBlockVector(getPos(x1, y1, z1)); double sx = pos.getX(); double sy = pos.getY(); double sz = pos.getZ(); @@ -119,7 +119,7 @@ public class ScaleTransform extends ResettableExtent { @Nullable @Override public Entity createEntity(Location location, BaseEntity entity) { - Location newLoc = new Location(location.getExtent(), getPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()), location.getYaw(), location.getPitch()); + Location newLoc = new Location(location.getExtent(), getPos(location.getBlockX(), location.getBlockY(), location.getBlockZ()).toVector3(), location.getYaw(), location.getPitch()); return super.createEntity(newLoc, entity); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java index 543cac3f3..3b46ca433 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SelectTransform.java @@ -1,7 +1,5 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -10,6 +8,8 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -25,11 +25,11 @@ public abstract class SelectTransform extends ResettableExtent { public abstract AbstractDelegateExtent getExtent(int x, int z); - public Extent getExtent(Vector pos) { + public Extent getExtent(BlockVector3 pos) { return getExtent(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); } - public Extent getExtent(Vector2D pos) { + public Extent getExtent(BlockVector2 pos) { return getExtent(pos.getBlockX(), pos.getBlockZ()); } @@ -39,7 +39,7 @@ public abstract class SelectTransform extends ResettableExtent { } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return getExtent(position).setBlock(position, block); } @@ -50,7 +50,7 @@ public abstract class SelectTransform extends ResettableExtent { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return getExtent(position).setBiome(position, biome); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java index 423fd51c5..7f5382d73 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SlowExtent.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.Fawe; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; 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; public class SlowExtent extends AbstractDelegateExtent { @@ -18,7 +18,7 @@ public class SlowExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { if (!Fawe.isMainThread()) try { Thread.sleep(sleep); } catch (InterruptedException e) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java index 7cd046493..53aea79da 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/SourceMaskExtent.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -43,7 +43,7 @@ public class SourceMaskExtent extends TemporalExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { set(location.getBlockX(), location.getBlockY(), location.getBlockZ(), block); return mask.test(location) && super.setBlock(location, block); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java index b2db133a4..835b1d807 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/StripNBTExtent.java @@ -3,7 +3,6 @@ package com.boydti.fawe.object.extent; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.Tag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -11,6 +10,7 @@ import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.NbtValued; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -34,7 +34,7 @@ public class StripNBTExtent extends AbstractDelegateExtent { } @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return super.setBlock(location, stripNBT(block)); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java index 33f0a4170..5ca1792bf 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TemporalExtent.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.extent; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BlockMaterial; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +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; import com.sk89q.worldedit.world.registry.BundledBlockData; @@ -51,7 +51,7 @@ public class TemporalExtent extends AbstractDelegateExtent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { if (position.getX() == x && position.getY() == y && position.getZ() == z) { return block; } @@ -59,7 +59,7 @@ public class TemporalExtent extends AbstractDelegateExtent { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { if (position.getX() == x && position.getY() == y && position.getZ() == z) { return block; } @@ -75,7 +75,7 @@ public class TemporalExtent extends AbstractDelegateExtent { } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { if (position.getX() == bx && position.getZ() == bz) { return biome; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java index a5e32f5fc..e0082d330 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/extent/TransformExtent.java @@ -1,13 +1,14 @@ package com.boydti.fawe.object.extent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.transform.BlockTransformExtent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableVector; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -16,7 +17,7 @@ import com.sk89q.worldedit.world.registry.BlockRegistry; public class TransformExtent extends BlockTransformExtent { private final MutableBlockVector mutable = new MutableBlockVector(); - private Vector min; + private BlockVector3 min; private int maxy; public TransformExtent(Extent parent) { @@ -32,50 +33,50 @@ public class TransformExtent extends BlockTransformExtent { } @Override - public Vector getMinimumPoint() { - Vector pos1 = new MutableBlockVector(getPos(super.getMinimumPoint())); - Vector pos2 = new MutableBlockVector(getPos(super.getMaximumPoint())); - return Vector.getMinimum(pos1, pos2); + public BlockVector3 getMinimumPoint() { + BlockVector3 pos1 = new MutableBlockVector(getPos(super.getMinimumPoint())); + BlockVector3 pos2 = new MutableBlockVector(getPos(super.getMaximumPoint())); + return pos1.getMinimum(pos2); } @Override - public Vector getMaximumPoint() { - Vector pos1 = new MutableBlockVector(getPos(super.getMinimumPoint())); - Vector pos2 = new MutableBlockVector(getPos(super.getMaximumPoint())); - return Vector.getMaximum(pos1, pos2); + public BlockVector3 getMaximumPoint() { + BlockVector3 pos1 = new MutableBlockVector(getPos(super.getMinimumPoint())); + BlockVector3 pos2 = new MutableBlockVector(getPos(super.getMaximumPoint())); + return pos1.getMaximum(pos2); } @Override - public void setOrigin(Vector pos) { + public void setOrigin(BlockVector3 pos) { this.min = pos; } - public Vector getPos(Vector pos) { + public BlockVector3 getPos(BlockVector3 pos) { if (min == null) { - min = new Vector(pos); + min = pos; } mutable.mutX(((pos.getX() - min.getX()))); mutable.mutY(((pos.getY() - min.getY()))); mutable.mutZ(((pos.getZ() - min.getZ()))); - Vector tmp = getTransform().apply(mutable); + MutableVector tmp = new MutableVector(getTransform().apply(mutable.toVector3())); tmp.mutX((tmp.getX() + min.getX())); tmp.mutY((tmp.getY() + min.getY())); tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp; + return tmp.toBlockPoint(); } - public Vector getPos(int x, int y, int z) { + public BlockVector3 getPos(int x, int y, int z) { if (min == null) { - min = new Vector(x, y, z); + min = new BlockVector3(x, y, z); } mutable.mutX(((x - min.getX()))); mutable.mutY(((y - min.getY()))); mutable.mutZ(((z - min.getZ()))); - Vector tmp = getTransform().apply(mutable); + MutableVector tmp = new MutableVector(getTransform().apply(mutable.toVector3())); tmp.mutX((tmp.getX() + min.getX())); tmp.mutY((tmp.getY() + min.getY())); tmp.mutZ((tmp.getZ() + min.getZ())); - return tmp; + return tmp.toBlockPoint(); } @Override @@ -84,21 +85,21 @@ public class TransformExtent extends BlockTransformExtent { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return transformFast(super.getLazyBlock(getPos(position))); } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return transformFast(super.getBlock(getPos(position))); } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { mutable.mutX(position.getBlockX()); mutable.mutZ(position.getBlockZ()); mutable.mutY(0); - return super.getBiome(getPos(mutable).toVector2D()); + return super.getBiome(getPos(mutable).toBlockVector2()); } @Override @@ -108,15 +109,15 @@ public class TransformExtent extends BlockTransformExtent { @Override - public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { return super.setBlock(getPos(location), transformFastInverse((BlockState) block)); } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { mutable.mutX(position.getBlockX()); mutable.mutZ(position.getBlockZ()); mutable.mutY(0); - return super.setBiome(getPos(mutable).toVector2D(), biome); + return super.setBiome(getPos(mutable).toBlockVector2(), biome); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/NullRegionFunction.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/NullRegionFunction.java index 2bed14216..48db35e5c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/NullRegionFunction.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/NullRegionFunction.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.function; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; public class NullRegionFunction implements RegionFunction { @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return false; } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/SurfaceRegionFunction.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/SurfaceRegionFunction.java index 8858d302f..ddaf51d58 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/SurfaceRegionFunction.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/SurfaceRegionFunction.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.function; -import com.sk89q.worldedit.MutableBlockVector; -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.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.MutableBlockVector; public class SurfaceRegionFunction implements FlatRegionFunction { private final Extent extent; @@ -24,7 +24,7 @@ public class SurfaceRegionFunction implements FlatRegionFunction { } @Override - public boolean apply(Vector2D position) throws WorldEditException { + public boolean apply(BlockVector2 position) throws WorldEditException { int x = position.getBlockX(); int z = position.getBlockZ(); int layer = extent.getNearestSurfaceTerrainBlock(x, z, lastY, minY, maxY, false); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java index 8ffdb6de3..ddd216369 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/BiomeCopy.java @@ -1,10 +1,10 @@ package com.boydti.fawe.object.function.block; -import com.sk89q.worldedit.MutableBlockVector2D; -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.math.MutableBlockVector2D; public class BiomeCopy implements RegionFunction { protected final Extent source; @@ -19,7 +19,7 @@ public class BiomeCopy implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { int x = position.getBlockX(); int z = position.getBlockZ(); if (x != mPos2d.getBlockX() || z != mPos2d.getBlockZ()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java index cdb30b465..2d08f6dec 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/CombinedBlockCopy.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.function.block; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class CombinedBlockCopy implements RegionFunction { @@ -21,7 +21,7 @@ public class CombinedBlockCopy implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { BlockStateHolder block = source.getBlock(position); function.apply(position); return destination.setBlock(position, block); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java index a50c3c2af..c1c6dd200 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/block/SimpleBlockCopy.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.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; public class SimpleBlockCopy implements RegionFunction { @@ -16,7 +16,7 @@ public class SimpleBlockCopy implements RegionFunction { } @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return destination.setBlock(position, source.getBlock(position)); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java index 6adcc0a05..fd6e472fe 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/function/mask/AbstractDelegateMask.java @@ -1,9 +1,10 @@ package com.boydti.fawe.object.function.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class AbstractDelegateMask extends AbstractMask { @@ -19,7 +20,7 @@ public class AbstractDelegateMask extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return mask.test(vector); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java index 0996fac9d..a3fa905e6 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentAnyMask.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; /** * Just an optimized version of the Adjacent Mask for single adjacency @@ -28,7 +28,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(Vector v) { + public boolean test(BlockVector3 v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); @@ -53,7 +53,7 @@ public class AdjacentAnyMask extends AbstractMask implements ResettableMask { return false; } - public Vector direction(Vector v) { + public BlockVector3 direction(BlockVector3 v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java index eca8d4faf..851915978 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AdjacentMask.java @@ -1,21 +1,25 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; public class AdjacentMask extends AbstractMask { private final int min, max; private final Mask mask; + private MutableBlockVector v; public AdjacentMask(Mask mask, int requiredMin, int requiredMax) { this.mask = mask; this.min = requiredMin; this.max = requiredMax; + this.v = new MutableBlockVector(); } @Override - public boolean test(Vector v) { + public boolean test(BlockVector3 bv) { + v.setComponents(bv); int count = 0; double x = v.getX(); double y = v.getY(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java index 872732b8a..adc768cd5 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/AngleMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.SolidBlockMask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; + import java.util.Arrays; import javax.annotation.Nullable; @@ -112,7 +113,7 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { } } - public boolean adjacentAir(Vector v) { + public boolean adjacentAir(BlockVector3 v) { int x = v.getBlockX(); int y = v.getBlockY(); int z = v.getBlockZ(); @@ -138,7 +139,7 @@ public class AngleMask extends SolidBlockMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { int x = vector.getBlockX(); int y = vector.getBlockY(); int z = vector.getBlockZ(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java index 424b78823..679c15735 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BiomeMask.java @@ -1,10 +1,10 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; public class BiomeMask extends AbstractExtentMask implements ResettableMask { @@ -22,8 +22,8 @@ public class BiomeMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(Vector vector) { - Vector2D pos = mutable.setComponents(vector.getBlockX(), vector.getBlockZ()); + public boolean test(BlockVector3 vector) { + BlockVector2 pos = mutable.setComponents(vector.getBlockX(), vector.getBlockZ()); return getExtent().getBiome(pos).getId() == biome.getId(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java index fb217d5b7..dfab059a2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BlockLightMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class BlockLightMask extends AbstractExtentMask { @@ -18,7 +19,7 @@ public class BlockLightMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); if (extent instanceof LightingExtent) { int light = ((LightingExtent) extent).getBlockLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java index 1153aad21..099a47b2f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/BrightnessMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class BrightnessMask extends AbstractExtentMask { @@ -18,7 +19,7 @@ public class BrightnessMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); if (extent instanceof LightingExtent) { int light = ((LightingExtent) extent).getBrightness(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java index 05da2402c..b5ee4a811 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/CachedMask.java @@ -2,9 +2,9 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.object.function.mask.AbstractDelegateMask; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; public class CachedMask extends AbstractDelegateMask implements ResettableMask { @@ -41,7 +41,7 @@ public class CachedMask extends AbstractDelegateMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return test(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java index b0bd2254e..01afbac85 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/DataMask.java @@ -1,9 +1,10 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class DataMask extends AbstractExtentMask implements ResettableMask { @@ -15,7 +16,7 @@ public class DataMask extends AbstractExtentMask implements ResettableMask { private transient int data = -1; @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); if (data != -1) { return extent.getLazyBlock(vector).getInternalPropertiesId() == data; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java index 35d23c15f..7b7705172 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdDataMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.FaweCache; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class IdDataMask extends AbstractExtentMask implements ResettableMask { @@ -15,7 +16,7 @@ public class IdDataMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); if (combined != -1) { return extent.getLazyBlock(vector).getInternalId() == combined; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java index 0f8ff0f3b..e9b36b365 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/IdMask.java @@ -1,9 +1,10 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class IdMask extends AbstractExtentMask implements ResettableMask { @@ -15,7 +16,7 @@ public class IdMask extends AbstractExtentMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { Extent extent = getExtent(); if (id != -1) { return extent.getLazyBlock(vector).getInternalBlockTypeId() == id; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java index 703a0b398..1ebbfbce1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/LightMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class LightMask extends AbstractExtentMask { @@ -18,7 +19,7 @@ public class LightMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (getExtent() instanceof LightingExtent) { int light = ((LightingExtent) getExtent()).getLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java index 06d47f22b..ed9210eca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/MaskedTargetBlock.java @@ -21,7 +21,7 @@ public class MaskedTargetBlock extends TargetBlock { Location lastBlock = null; while (getNextBlock() != null) { Location current = getCurrentBlock(); - if (!mask.test(current.toVector())) { + if (!mask.test(current.toVector().toBlockPoint())) { if (searchForLastBlock) { lastBlock = current; if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java index a9411a34e..7279b8b1a 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/OpacityMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class OpacityMask extends AbstractExtentMask { @@ -18,7 +19,7 @@ public class OpacityMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (getExtent() instanceof LightingExtent) { int light = ((LightingExtent) getExtent()).getOpacity(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java index 011b3ce7d..f0f9c3fe1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/PlaneMask.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; /** @@ -14,7 +15,7 @@ public class PlaneMask extends AbstractMask implements ResettableMask { private transient int originX = Integer.MAX_VALUE, originY = Integer.MAX_VALUE, originZ = Integer.MAX_VALUE; @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { switch (mode) { case -1: originX = vector.getBlockX(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java index e7b791e18..5759aabba 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RadiusMask.java @@ -1,14 +1,14 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class RadiusMask extends AbstractMask implements ResettableMask { - private transient Vector pos; + private transient BlockVector3 pos; private final int minSqr, maxSqr; public RadiusMask(int min, int max) { @@ -22,9 +22,9 @@ public class RadiusMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(Vector to) { + public boolean test(BlockVector3 to) { if (pos == null) { - pos = new MutableBlockVector(to); + pos = to; } int dx = pos.getBlockX() - to.getBlockX(); int d = dx * dx; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java index e7cf15492..265184db9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/RandomMask.java @@ -1,7 +1,8 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.SplittableRandom; public class RandomMask extends AbstractMask implements ResettableMask { @@ -14,7 +15,7 @@ public class RandomMask extends AbstractMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { return random.nextInt() <= threshold; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java index ea62394ae..9358552ca 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SimplexMask.java @@ -1,8 +1,8 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.random.SimplexNoise; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; +import com.sk89q.worldedit.math.BlockVector3; public class SimplexMask extends AbstractMask { private final double min, max, scale; @@ -14,7 +14,7 @@ public class SimplexMask extends AbstractMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { double value = SimplexNoise.noise(vector.getBlockX() * scale, vector.getBlockY() * scale, vector.getBlockZ() * scale); return value >= min && value <= max; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java index dbb2985d5..8b796d3ac 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SkyLightMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.AbstractExtentMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; public class SkyLightMask extends AbstractExtentMask { @@ -18,7 +19,7 @@ public class SkyLightMask extends AbstractExtentMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (getExtent() instanceof LightingExtent) { int light = ((LightingExtent) getExtent()).getSkyLight(vector.getBlockX(), vector.getBlockY(), vector.getBlockZ()); return light >= min && light <= max; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java index 4baeb9a2d..aae0022b1 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SolidPlaneMask.java @@ -1,10 +1,11 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask2D; import com.sk89q.worldedit.function.mask.SolidBlockMask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; + import javax.annotation.Nullable; /** @@ -22,7 +23,7 @@ public class SolidPlaneMask extends SolidBlockMask implements ResettableMask { } @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { switch (mode) { case -1: if (!super.test(vector)) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java index 5330d8ceb..cd740f93f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/SurfaceMask.java @@ -1,9 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockTypes; public class SurfaceMask extends AdjacentAnyMask { @@ -22,7 +22,7 @@ public class SurfaceMask extends AdjacentAnyMask { } @Override - public boolean test(Vector v) { + public boolean test(BlockVector3 v) { return !getParentMask().test(v.getBlockX(), v.getBlockY(), v.getBlockZ()) && super.test(v); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java index 5975be2d5..9776acfe7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/WallMask.java @@ -1,21 +1,25 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; public class WallMask extends AbstractMask { private final int min, max; private final Mask mask; + private MutableBlockVector v; public WallMask(Mask mask, int requiredMin, int requiredMax) { this.mask = mask; this.min = requiredMin; this.max = requiredMax; + this.v = new MutableBlockVector(); } @Override - public boolean test(Vector v) { + public boolean test(BlockVector3 bv) { + v.setComponents(bv); int count = 0; double x = v.getX(); double y = v.getY(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java index b74b970b6..44e1a3263 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/XAxisMask.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; /** @@ -13,7 +14,7 @@ public class XAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockX(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java index cd4746363..2d333cb5f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/YAxisMask.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; /** @@ -13,7 +14,7 @@ public class YAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockY(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java index 15215e157..15dd3cb36 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/mask/ZAxisMask.java @@ -1,8 +1,9 @@ package com.boydti.fawe.object.mask; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.mask.AbstractMask; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector3; + import javax.annotation.Nullable; /** @@ -13,7 +14,7 @@ public class ZAxisMask extends AbstractMask implements ResettableMask { private transient int layer = -1; @Override - public boolean test(Vector vector) { + public boolean test(BlockVector3 vector) { if (layer == -1) { layer = vector.getBlockZ(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java index d377a706c..0467a26f9 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AngleColorPattern.java @@ -4,11 +4,11 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.DataAnglePattern; import com.boydti.fawe.util.TextureHolder; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -32,7 +32,7 @@ public class AngleColorPattern extends DataAnglePattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder block = extent.getBlock(position); int slope = getSlope(block, position); if (slope == -1) return block; @@ -43,7 +43,7 @@ public class AngleColorPattern extends DataAnglePattern { } @Override - public int getSlope(BlockStateHolder block, Vector vector) { + public int getSlope(BlockStateHolder block, BlockVector3 vector) { int slope = super.getSlope(block, vector); if (slope != -1) { int x = vector.getBlockX(); @@ -61,7 +61,7 @@ public class AngleColorPattern extends DataAnglePattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { BlockStateHolder block = extent.getBlock(getPosition); int slope = getSlope(block, getPosition); if (slope == -1) return false; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java index fee5e8187..95f59a2d3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/AverageColorPattern.java @@ -3,11 +3,11 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -26,7 +26,7 @@ public class AverageColorPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder block = getExtent().getBlock(position); TextureUtil util = holder.getTextureUtil(); int currentColor = util.getColor(block.getBlockType()); @@ -35,7 +35,7 @@ public class AverageColorPattern extends AbstractExtentPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { BlockType blockType = extent.getBlockType(getPosition); TextureUtil util = holder.getTextureUtil(); int currentColor = util.getColor(blockType); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java index dbfbf85bd..478ed737d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BiomePattern.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; import java.io.IOException; @@ -19,12 +19,12 @@ public class BiomePattern extends ExistingPattern { } @Override - public BaseBlock apply(Vector position) { + public BaseBlock apply(BlockVector3 position) { throw new BiomePatternException(); } @Override - public boolean apply(Extent extent, Vector set, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 getPosition) throws WorldEditException { return extent.setBiome(set.getBlockX(), set.getBlockY(), set.getBlockZ(), biome); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java index bb0a9900e..c0d89838c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern.java @@ -4,13 +4,13 @@ import com.boydti.fawe.Fawe; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.boydti.fawe.util.FaweTimer; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -33,12 +33,12 @@ public class BufferedPattern extends AbstractPattern implements ResettablePatter } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { return pattern.apply(position); } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { long now = timer.getTick(); try { if (!set(setPosition)) { @@ -50,7 +50,7 @@ public class BufferedPattern extends AbstractPattern implements ResettablePatter return false; } - public boolean set(Vector pos) { + public boolean set(BlockVector3 pos) { return set.add(pos); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern2D.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern2D.java index 359388c1c..154538ee4 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern2D.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/BufferedPattern2D.java @@ -1,8 +1,8 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.object.FawePlayer; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; public class BufferedPattern2D extends BufferedPattern { @@ -11,7 +11,7 @@ public class BufferedPattern2D extends BufferedPattern { } @Override - public boolean set(Vector pos) { + public boolean set(BlockVector3 pos) { return set.add(pos.getBlockX(), 0, pos.getBlockY()); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java index 609696538..23f474c86 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DataPattern.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.FaweCache; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; 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; @@ -22,7 +22,7 @@ public class DataPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder oldBlock = getExtent().getBlock(position); BlockStateHolder newBlock = pattern.apply(position); return oldBlock.withPropertyId(newBlock.getInternalPropertiesId()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java index 3b18e4056..ea8d92fe2 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/DesaturatePattern.java @@ -3,12 +3,12 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -26,7 +26,7 @@ public class DesaturatePattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockType block = extent.getBlockType(position); TextureUtil util = holder.getTextureUtil(); int color = util.getColor(block); @@ -43,7 +43,7 @@ public class DesaturatePattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { BlockType block = extent.getBlockType(getPosition); TextureUtil util = holder.getTextureUtil(); int color = util.getColor(block); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java index 2acb45d6c..7394db862 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExistingPattern.java @@ -1,10 +1,10 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -14,12 +14,12 @@ public class ExistingPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { return getExtent().getBlock(position); } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { if (set.equals(get)) { return false; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java index 8109513c8..3df96a01b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ExpressionPattern.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.pattern; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.function.pattern.AbstractPattern; 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 com.sk89q.worldedit.world.block.BlockStateHolder; @@ -49,10 +49,10 @@ public class ExpressionPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector vector) { + public BlockStateHolder apply(BlockVector3 vector) { try { if (expression.getEnvironment() instanceof WorldEditExpressionEnvironment) { - ((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector); + ((WorldEditExpressionEnvironment) expression.getEnvironment()).setCurrentBlock(vector.toVector3()); } double combined = expression.evaluate(vector.getX(), vector.getY(), vector.getZ()); return BlockState.getFromInternalId((int) combined); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java index c90284863..e2667bd8b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/FullClipboardPattern.java @@ -1,7 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -10,6 +8,8 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.regions.Region; import java.io.IOException; import java.io.NotSerializableException; @@ -36,7 +36,7 @@ public class FullClipboardPattern extends AbstractExtentPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { Region region = clipboard.getRegion(); ForwardExtentCopy copy = new ForwardExtentCopy(clipboard, clipboard.getRegion(), clipboard.getOrigin(), extent, setPosition); copy.setSourceMask(new ExistingBlockMask(clipboard)); @@ -45,7 +45,7 @@ public class FullClipboardPattern extends AbstractExtentPattern { } @Override - public BaseBlock apply(Vector position) { + public BaseBlock apply(BlockVector3 position) { throw new IllegalStateException("Incorrect use. This pattern can only be applied to an extent!"); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java index e1b52d3a4..c7a7579fc 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdDataMaskPattern.java @@ -1,11 +1,11 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.FaweCache; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; 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; @@ -21,7 +21,7 @@ public class IdDataMaskPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder oldBlock = getExtent().getBlock(position); BlockStateHolder newBlock = pattern.apply(position); int oldData = oldBlock.getInternalPropertiesId(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdPattern.java index 9634eb862..29d4d0f1c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/IdPattern.java @@ -1,8 +1,8 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import static com.google.common.base.Preconditions.checkNotNull; @@ -17,7 +17,7 @@ public class IdPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockStateHolder oldBlock = getExtent().getBlock(position); BlockStateHolder newBlock = pattern.apply(position); return newBlock.withPropertyId(oldBlock.getInternalPropertiesId()); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java index e8610191a..941a0e8fd 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear2DBlockPattern.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class Linear2DBlockPattern extends AbstractPattern { @@ -18,7 +18,7 @@ public class Linear2DBlockPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { int index = (position.getBlockX() + position.getBlockZ()) % patternsArray.length; if (index < 0) { index += patternsArray.length; @@ -27,7 +27,7 @@ public class Linear2DBlockPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { int index = (get.getBlockX() + get.getBlockZ()) % patternsArray.length; if (index < 0) { index += patternsArray.length; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java index d9332a994..8fb81ca66 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/Linear3DBlockPattern.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class Linear3DBlockPattern extends AbstractPattern { @@ -18,7 +18,7 @@ public class Linear3DBlockPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { int index = (position.getBlockX() + position.getBlockY() + position.getBlockZ()) % patternsArray.length; if (index < 0) { index += patternsArray.length; @@ -27,7 +27,7 @@ public class Linear3DBlockPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { int index = (get.getBlockX() + get.getBlockY() + get.getBlockZ()) % patternsArray.length; if (index < 0) { index += patternsArray.length; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java index 65e94e68d..63de5b392 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/LinearBlockPattern.java @@ -1,12 +1,12 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class LinearBlockPattern extends AbstractPattern implements ResettablePattern { @@ -19,7 +19,7 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { if (index == patternsArray.length) { index = 0; } @@ -27,7 +27,7 @@ public class LinearBlockPattern extends AbstractPattern implements ResettablePat } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { if (index == patternsArray.length) { index = 0; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java index 6f2712685..9751fe514 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/MaskedPattern.java @@ -1,6 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -8,6 +7,7 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; public class MaskedPattern extends AbstractPattern { @@ -24,7 +24,7 @@ public class MaskedPattern extends AbstractPattern { @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { patternExtent.setTarget(position); if (mask.test(position)) { return patternExtent.getAndResetTarget(); @@ -33,7 +33,7 @@ public class MaskedPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { patternExtent.setTarget(get); if (mask.test(get)) { return patternExtent.getAndResetTarget(extent, set, get); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java index 4147a90fb..cb71d055c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoXPattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -22,14 +22,14 @@ public class NoXPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector pos) { + public BlockStateHolder apply(BlockVector3 pos) { mutable.mutY((pos.getY())); mutable.mutZ((pos.getZ())); return pattern.apply(mutable); } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutY((get.getY())); mutable.mutZ((get.getZ())); return pattern.apply(extent, set, mutable); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java index 38caadf7a..451a17a59 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoYPattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -23,14 +23,14 @@ public class NoYPattern extends AbstractPattern { private transient MutableBlockVector mutable = new MutableBlockVector(); @Override - public BlockStateHolder apply(Vector pos) { + public BlockStateHolder apply(BlockVector3 pos) { mutable.mutX((pos.getX())); mutable.mutZ((pos.getZ())); return pattern.apply(mutable); } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutX((get.getX())); mutable.mutZ((get.getZ())); return pattern.apply(extent, set, mutable); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java index e81f9a5a1..fa45fc95e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/NoZPattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -23,14 +23,14 @@ public class NoZPattern extends AbstractPattern { private transient MutableBlockVector mutable = new MutableBlockVector(); @Override - public BlockStateHolder apply(Vector pos) { + public BlockStateHolder apply(BlockVector3 pos) { mutable.mutX((pos.getX())); mutable.mutY((pos.getY())); return pattern.apply(mutable); } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutX((get.getX())); mutable.mutY((get.getY())); return pattern.apply(extent, set, mutable); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java index 5886f35d8..c557ca686 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/OffsetPattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -26,7 +26,7 @@ public class OffsetPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { mutable.mutX((position.getX() + dx)); mutable.mutY((position.getY() + dy)); mutable.mutZ((position.getZ() + dz)); @@ -34,7 +34,7 @@ public class OffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutX((get.getX() + dx)); mutable.mutY((get.getY() + dy)); mutable.mutZ((get.getZ() + dz)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java index 31a8369e1..bf1036e1b 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PatternExtent.java @@ -1,7 +1,5 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -11,6 +9,8 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +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; @@ -24,7 +24,7 @@ import javax.annotation.Nullable; public class PatternExtent extends AbstractPattern implements Extent { private final Pattern pattern; private transient BlockStateHolder block; - private transient Vector target = new Vector(); + private transient BlockVector3 target = new BlockVector3(0, 0, 0); public PatternExtent(Pattern pattern) { this.pattern = pattern; @@ -32,17 +32,17 @@ public class PatternExtent extends AbstractPattern implements Extent { private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { stream.defaultReadObject(); - target = new Vector(); + target = new BlockVector3(0, 0, 0); } @Override - public Vector getMinimumPoint() { - return new Vector(Integer.MIN_VALUE, 0, Integer.MIN_VALUE); + public BlockVector3 getMinimumPoint() { + return new BlockVector3(Integer.MIN_VALUE, 0, Integer.MIN_VALUE); } @Override - public Vector getMaximumPoint() { - return new Vector(Integer.MAX_VALUE, 255, Integer.MAX_VALUE); + public BlockVector3 getMaximumPoint() { + return new BlockVector3(Integer.MAX_VALUE, 255, Integer.MAX_VALUE); } @Override @@ -62,7 +62,7 @@ public class PatternExtent extends AbstractPattern implements Extent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { BlockStateHolder tmp = pattern.apply(position); if (position == target || (position.getX() == target.getX() && position.getY() == target.getY() && position.getZ() == target.getZ())) { block = tmp; @@ -72,11 +72,11 @@ public class PatternExtent extends AbstractPattern implements Extent { return (BlockState) tmp; } - public void setTarget(Vector vector) { + public void setTarget(BlockVector3 vector) { this.target = vector; } - public boolean getAndResetTarget(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean getAndResetTarget(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { BlockStateHolder result = block; if (result != null) { block = null; @@ -97,22 +97,22 @@ public class PatternExtent extends AbstractPattern implements Extent { } @Override - public BlockState getFullBlock(Vector position) { + public BlockState getFullBlock(BlockVector3 position) { return getBlock(position); } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return new BaseBiome(0); } @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; } @@ -123,12 +123,12 @@ public class PatternExtent extends AbstractPattern implements Extent { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { return pattern.apply(position); } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { return pattern.apply(extent, set, get); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java index 2a0888640..5815feb4c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/PropertyPattern.java @@ -4,10 +4,10 @@ import com.boydti.fawe.object.string.MutableCharSequence; import com.boydti.fawe.util.MathMan; import com.boydti.fawe.util.StringMan; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.IntegerProperty; import com.sk89q.worldedit.registry.state.Property; @@ -191,7 +191,7 @@ public class PropertyPattern extends AbstractExtentPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockState block = getExtent().getBlock(position); return apply(block, block); } @@ -208,7 +208,7 @@ public class PropertyPattern extends AbstractExtentPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { BlockState block = getExtent().getBlock(get); block = apply(block, null); if (block != null) { diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java index 4a0059635..f1505bff7 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomFullClipboardPattern.java @@ -2,14 +2,15 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.object.PseudoRandom; import com.boydti.fawe.object.schematic.Schematic; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.session.ClipboardHolder; @@ -35,7 +36,7 @@ public class RandomFullClipboardPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { ClipboardHolder holder = clipboards.get(PseudoRandom.random.random(clipboards.size())); AffineTransform transform = new AffineTransform(); if (randomRotate) { @@ -43,7 +44,7 @@ public class RandomFullClipboardPattern extends AbstractPattern { holder.setTransform(new AffineTransform().rotateY(PseudoRandom.random.random(4) * 90)); } if (randomFlip) { - transform = transform.scale(new Vector(1, 0, 0).multiply(-2).add(1, 1, 1)); + transform = transform.scale(new Vector3(1, 0, 0).multiply(-2).add(1, 1, 1)); } if (!transform.isIdentity()) { holder.setTransform(transform); @@ -60,7 +61,7 @@ public class RandomFullClipboardPattern extends AbstractPattern { } @Override - public BaseBlock apply(Vector position) { + public BaseBlock apply(BlockVector3 position) { throw new IllegalStateException("Incorrect use. This pattern can only be applied to an extent!"); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java index b292a9351..952d26d0c 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RandomOffsetPattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -34,7 +34,7 @@ public class RandomOffsetPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); @@ -42,7 +42,7 @@ public class RandomOffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutX((get.getX() + r.nextInt(dx2) - dx)); mutable.mutY((get.getY() + r.nextInt(dy2) - dy)); mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java index db7a8d786..dce3c993d 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/RelativePattern.java @@ -1,13 +1,13 @@ package com.boydti.fawe.object.pattern; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -15,7 +15,7 @@ import java.io.IOException; public class RelativePattern extends AbstractPattern implements ResettablePattern { private final Pattern pattern; - private transient Vector origin; + private transient BlockVector3 origin; private transient MutableBlockVector mutable = new MutableBlockVector(); public RelativePattern(Pattern pattern) { @@ -23,9 +23,9 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter } @Override - public BlockStateHolder apply(Vector pos) { + public BlockStateHolder apply(BlockVector3 pos) { if (origin == null) { - origin = new Vector(pos); + origin = pos; } mutable.mutX((pos.getX() - origin.getX())); mutable.mutY((pos.getY() - origin.getY())); @@ -34,9 +34,9 @@ public class RelativePattern extends AbstractPattern implements ResettablePatter } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { if (origin == null) { - origin = new Vector(get); + origin = get; } mutable.mutX((get.getX() - origin.getX())); mutable.mutY((get.getY() - origin.getY())); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java index ea5208de6..fb5601f87 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SaturatePattern.java @@ -3,12 +3,12 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureHolder; import com.boydti.fawe.util.TextureUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -28,7 +28,7 @@ public class SaturatePattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockType block = extent.getBlockType(position); TextureUtil util = holder.getTextureUtil(); int currentColor = util.getColor(block); @@ -37,7 +37,7 @@ public class SaturatePattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector setPosition, Vector getPosition) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 setPosition, BlockVector3 getPosition) throws WorldEditException { BlockType block = extent.getBlockType(getPosition); TextureUtil util = holder.getTextureUtil(); int currentColor = util.getColor(block); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ShadePattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ShadePattern.java index e68cbb6a4..709f883bb 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ShadePattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/ShadePattern.java @@ -2,11 +2,11 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.Fawe; import com.boydti.fawe.util.TextureUtil; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.pattern.AbstractPattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -28,7 +28,7 @@ public class ShadePattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { BlockType block = extent.getBlockType(position); return (darken ? util.getDarkerBlock(block) : util.getLighterBlock(block)).getDefaultState(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java index b0589232e..845ec1d86 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SolidRandomOffsetPattern.java @@ -1,8 +1,6 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.FaweCache; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -11,6 +9,8 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.SolidBlockMask; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -44,7 +44,7 @@ public class SolidRandomOffsetPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { mutable.mutX((position.getX() + r.nextInt(dx2) - dx)); mutable.mutY((position.getY() + r.nextInt(dy2) - dy)); mutable.mutZ((position.getZ() + r.nextInt(dz2) - dz)); @@ -57,7 +57,7 @@ public class SolidRandomOffsetPattern extends AbstractPattern { } @Override - public boolean apply(Extent extent, Vector set, Vector get) throws WorldEditException { + public boolean apply(Extent extent, BlockVector3 set, BlockVector3 get) throws WorldEditException { mutable.mutX((get.getX() + r.nextInt(dx2) - dx)); mutable.mutY((get.getY() + r.nextInt(dy2) - dy)); mutable.mutZ((get.getZ() + r.nextInt(dz2) - dz)); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java index ea44edb1d..7d6fab7ea 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/pattern/SurfaceRandomOffsetPattern.java @@ -2,13 +2,13 @@ package com.boydti.fawe.object.pattern; import com.boydti.fawe.FaweCache; import com.boydti.fawe.object.PseudoRandom; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.function.pattern.AbstractPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.BreadthFirstSearch; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.world.block.BlockStateHolder; import java.io.IOException; @@ -38,17 +38,17 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { } @Override - public BlockStateHolder apply(Vector position) { + public BlockStateHolder apply(BlockVector3 position) { return pattern.apply(travel(position)); } - private Vector travel(Vector pos) { + private BlockVector3 travel(BlockVector3 pos) { cur.setComponents(pos); for (int move = 0; move < moves; move++) { int index = 0; for (int i = 0; i < allowed.length; i++) { next = buffer[i]; - Vector dir = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i]; + BlockVector3 dir = BreadthFirstSearch.DIAGONAL_DIRECTIONS[i]; next.setComponents(cur.getBlockX() + dir.getBlockX(), cur.getBlockY() + dir.getBlockY(), cur.getBlockZ() + dir.getBlockZ()); if (allowed(next)) { allowed[index++] = next; @@ -63,7 +63,8 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { return cur; } - private boolean allowed(Vector v) { + private boolean allowed(BlockVector3 bv) { + MutableBlockVector v = new MutableBlockVector(bv); BlockStateHolder block = pattern.apply(v); if (!block.getBlockType().getMaterial().isMovementBlocker()) { return false; @@ -107,7 +108,7 @@ public class SurfaceRandomOffsetPattern extends AbstractPattern { return false; } - private boolean canPassthrough(Vector v) { + private boolean canPassthrough(BlockVector3 v) { BlockStateHolder block = pattern.apply(v); return !block.getBlockType().getMaterial().isMovementBlocker(); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java index d3455cf64..4a0f361f3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/FaweQueueDelegateExtent.java @@ -3,12 +3,12 @@ package com.boydti.fawe.object.queue; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.exception.FaweException; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -62,22 +62,22 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue { } @Override - public boolean setBiome(Vector2D position, BaseBiome biome) { + public boolean setBiome(BlockVector2 position, BaseBiome biome) { return parentExtent.setBiome(position, biome); } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return parentExtent.getBlock(position); } @Override - public BaseBiome getBiome(Vector2D position) { + public BaseBiome getBiome(BlockVector2 position) { return parentExtent.getBiome(position); } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return parentExtent.setBlock(position, block); } @@ -87,7 +87,7 @@ public class FaweQueueDelegateExtent extends DelegateFaweQueue { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return parentExtent.getLazyBlock(position); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java index 84dfc08da..83ac287c3 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/IDelegateFaweQueue.java @@ -13,8 +13,6 @@ import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.SetQueue; import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -23,6 +21,8 @@ import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.Pattern; +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.session.ClipboardHolder; @@ -51,12 +51,12 @@ public interface IDelegateFaweQueue extends FaweQueue { } @Override - default Vector getMinimumPoint() { + default BlockVector3 getMinimumPoint() { return getQueue().getMinimumPoint(); } @Override - default Vector getMaximumPoint() { + default BlockVector3 getMaximumPoint() { return getQueue().getMaximumPoint(); } @@ -71,22 +71,22 @@ public interface IDelegateFaweQueue extends FaweQueue { } @Override - default BlockState getBlock(Vector position) { + default BlockState getBlock(BlockVector3 position) { return getQueue().getBlock(position); } @Override - default BaseBiome getBiome(Vector2D position) { + default BaseBiome getBiome(BlockVector2 position) { return getQueue().getBiome(position); } @Override - default boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { + default boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { return getQueue().setBlock(position, block); } @Override - default boolean setBiome(Vector2D position, BaseBiome biome) { + default boolean setBiome(BlockVector2 position, BaseBiome biome) { return getQueue().setBiome(position, biome); } @@ -261,12 +261,12 @@ public interface IDelegateFaweQueue extends FaweQueue { } @Override - default void forEachBlockInChunk(int cx, int cz, RunnableVal2 onEach) { + default void forEachBlockInChunk(int cx, int cz, RunnableVal2 onEach) { getQueue().forEachBlockInChunk(cx, cz, onEach); } @Override - default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { + default void forEachTileInChunk(int cx, int cz, RunnableVal2 onEach) { getQueue().forEachTileInChunk(cx, cz, onEach); } @@ -459,7 +459,7 @@ public interface IDelegateFaweQueue extends FaweQueue { } @Override - default BlockState getLazyBlock(Vector position) { + default BlockState getLazyBlock(BlockVector3 position) { return getQueue().getLazyBlock(position); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java index 41576b36e..154bc92da 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/queue/NullFaweQueue.java @@ -7,7 +7,7 @@ import com.boydti.fawe.object.RunnableVal2; import com.boydti.fawe.object.exception.FaweException; import com.boydti.fawe.util.SetQueue; import com.sk89q.jnbt.CompoundTag; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; @@ -188,7 +188,7 @@ public class NullFaweQueue implements FaweQueue { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return state; } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java index 5e1771cfe..f79627448 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/regions/FuzzyRegion.java @@ -2,15 +2,14 @@ package com.boydti.fawe.object.regions; import com.boydti.fawe.object.HasFaweQueue; import com.boydti.fawe.object.collection.BlockVectorSet; -import com.sk89q.worldedit.BlockVector; 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.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.AbstractRegion; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.world.World; @@ -48,18 +47,18 @@ public class FuzzyRegion extends AbstractRegion { public void select(int x, int y, int z) { RecursiveVisitor search = new RecursiveVisitor(mask, new RegionFunction() { @Override - public boolean apply(Vector p) throws WorldEditException { + public boolean apply(BlockVector3 p) throws WorldEditException { setMinMax(p.getBlockX(), p.getBlockY(), p.getBlockZ()); return true; } }, 256, extent instanceof HasFaweQueue ? (HasFaweQueue) extent : null); search.setVisited(set); - search.visit(new Vector(x, y, z)); + search.visit(new BlockVector3(x, y, z)); Operations.completeBlindly(search); } @Override - public Iterator iterator() { + public Iterator iterator() { return (Iterator) set.iterator(); } @@ -94,32 +93,32 @@ public class FuzzyRegion extends AbstractRegion { } @Override - public Vector getMinimumPoint() { - return new Vector(minX, minY, minZ); + public BlockVector3 getMinimumPoint() { + return new BlockVector3(minX, minY, minZ); } @Override - public Vector getMaximumPoint() { - return new Vector(maxX, maxY, maxZ); + public BlockVector3 getMaximumPoint() { + return new BlockVector3(maxX, maxY, maxZ); } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Selection cannot expand"); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { throw new RegionOperationException("Selection cannot contract"); } @Override - public boolean contains(Vector position) { + public boolean contains(BlockVector3 position) { return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { throw new RegionOperationException("Selection cannot be shifted"); } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java index 46268ff1b..1bd435f19 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/schematic/Schematic.java @@ -7,8 +7,6 @@ import com.boydti.fawe.util.EditSessionBuilder; import com.boydti.fawe.util.MaskTraverser; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.MutableBlockVector2D; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.entity.Entity; @@ -24,6 +22,8 @@ import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RegionVisitor; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; @@ -73,7 +73,7 @@ public class Schematic { * @param to * @return */ - public EditSession paste(World world, Vector to) { + public EditSession paste(World world, BlockVector3 to) { return paste(world, to, true, true, null); } @@ -105,7 +105,7 @@ public class Schematic { } } - public EditSession paste(World world, Vector to, boolean allowUndo, boolean pasteAir, @Nullable Transform transform) { + public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, @Nullable Transform transform) { return paste(world, to, allowUndo, pasteAir, true, transform); } @@ -119,7 +119,7 @@ public class Schematic { * @param transform * @return */ - public EditSession paste(World world, Vector to, boolean allowUndo, boolean pasteAir, boolean copyEntities, @Nullable Transform transform) { + public EditSession paste(World world, BlockVector3 to, boolean allowUndo, boolean pasteAir, boolean copyEntities, @Nullable Transform transform) { checkNotNull(world); checkNotNull(to); Region region = clipboard.getRegion(); @@ -165,7 +165,7 @@ public class Schematic { return editSession; } - public void paste(Extent extent, Vector to, boolean pasteAir, Transform transform) { + public void paste(Extent extent, BlockVector3 to, boolean pasteAir, Transform transform) { checkNotNull(transform); Region region = clipboard.getRegion(); Extent source = clipboard; @@ -192,11 +192,11 @@ public class Schematic { Operations.completeBlindly(copy); } - public void paste(Extent extent, Vector to, final boolean pasteAir) { + public void paste(Extent extent, BlockVector3 to, final boolean pasteAir) { Region region = clipboard.getRegion().clone(); final int maxY = extent.getMaximumPoint().getBlockY(); - final Vector bot = clipboard.getMinimumPoint(); - final Vector origin = clipboard.getOrigin(); + final BlockVector3 bot = clipboard.getMinimumPoint(); + final BlockVector3 origin = clipboard.getOrigin(); final boolean copyBiomes = !(clipboard instanceof BlockArrayClipboard) || ((BlockArrayClipboard) clipboard).IMP.hasBiomes(); @@ -251,7 +251,7 @@ public class Schematic { mpos2d.setComponents(Integer.MIN_VALUE, Integer.MIN_VALUE); } @Override - public boolean apply(Vector mutable) throws WorldEditException { + public boolean apply(BlockVector3 mutable) throws WorldEditException { BlockStateHolder block = clipboard.getBlock(mutable); int xx = mutable.getBlockX() + relx; int zz = mutable.getBlockZ() + relz; diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java index a9ec075a9..1ed62df9e 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSRecursiveVisitor.java @@ -1,10 +1,9 @@ package com.boydti.fawe.object.visitor; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; - +import com.sk89q.worldedit.math.BlockVector3; import static com.google.common.base.Preconditions.checkNotNull; @@ -33,7 +32,7 @@ public class DFSRecursiveVisitor extends DFSVisitor { } @Override - public boolean isVisitable(final Vector from, final Vector to) { + public boolean isVisitable(final BlockVector3 from, final BlockVector3 to) { return this.mask.test(to); } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java index c9201d61d..f7ea5eb28 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/object/visitor/DFSVisitor.java @@ -2,12 +2,13 @@ package com.boydti.fawe.object.visitor; import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.IntegerTrio; -import com.sk89q.worldedit.MutableBlockVector; -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.math.MutableBlockVector; + import java.util.ArrayDeque; import java.util.ArrayList; import java.util.HashSet; @@ -20,7 +21,7 @@ import java.util.concurrent.atomic.AtomicInteger; public abstract class DFSVisitor implements Operation { private final RegionFunction function; - private final List directions = new ArrayList<>(); + private final List directions = new ArrayList<>(); private final Map visited; private final ArrayDeque queue; private final HashSet hashQueue; @@ -37,32 +38,32 @@ public abstract class DFSVisitor implements Operation { this.hashQueue = new LinkedHashSet<>(); this.visited = new LinkedHashMap<>(); this.function = function; - this.directions.add(new Vector(0, -1, 0)); - this.directions.add(new Vector(0, 1, 0)); - this.directions.add(new Vector(-1, 0, 0)); - this.directions.add(new Vector(1, 0, 0)); - this.directions.add(new Vector(0, 0, -1)); - this.directions.add(new Vector(0, 0, 1)); + this.directions.add(new BlockVector3(0, -1, 0)); + this.directions.add(new BlockVector3(0, 1, 0)); + this.directions.add(new BlockVector3(-1, 0, 0)); + this.directions.add(new BlockVector3(1, 0, 0)); + this.directions.add(new BlockVector3(0, 0, -1)); + this.directions.add(new BlockVector3(0, 0, 1)); this.maxDepth = maxDepth; this.maxBranch = maxBranching; } - public abstract boolean isVisitable(Vector from, Vector to); + public abstract boolean isVisitable(BlockVector3 from, BlockVector3 to); - public List getDirections() { + public List getDirections() { return this.directions; } private IntegerTrio[] getIntDirections() { IntegerTrio[] array = new IntegerTrio[directions.size()]; for (int i = 0; i < array.length; i++) { - Vector dir = directions.get(i); + BlockVector3 dir = directions.get(i); array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); } return array; } - public void visit(final Vector pos) { + public void visit(final BlockVector3 pos) { Node node = new Node(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()); if (!this.hashQueue.contains(node)) { isVisitable(pos, pos); // Ignore this, just to initialize mask on this point @@ -77,7 +78,7 @@ public abstract class DFSVisitor implements Operation { Node from; Node adjacent; MutableBlockVector mutable = new MutableBlockVector(); - Vector mutable2 = new Vector(); + MutableBlockVector mutable2 = new MutableBlockVector(); int countAdd, countAttempt; IntegerTrio[] dirs = getIntDirections(); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/FaweMask.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/FaweMask.java index 99e9aa4b8..2714da0db 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/FaweMask.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/FaweMask.java @@ -1,7 +1,7 @@ package com.boydti.fawe.regions; import com.boydti.fawe.object.FawePlayer; -import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.IDelegateRegion; import com.sk89q.worldedit.regions.Region; @@ -11,12 +11,12 @@ public class FaweMask implements IDelegateRegion { private String description = null; @Deprecated - public FaweMask(final BlockVector pos1, final BlockVector pos2, final String id) { + public FaweMask(final BlockVector3 pos1, final BlockVector3 pos2, final String id) { this(new CuboidRegion(pos1, pos2), id); } @Deprecated - public FaweMask(final BlockVector pos1, final BlockVector pos2) { + public FaweMask(final BlockVector3 pos1, final BlockVector3 pos2) { this(pos1, pos2, null); if ((pos1 == null) || (pos2 == null)) { throw new IllegalArgumentException("BlockVectors cannot be null!"); diff --git a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/CuboidRegionFilter.java b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/CuboidRegionFilter.java index 832482033..b3bfcd820 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/regions/general/CuboidRegionFilter.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/regions/general/CuboidRegionFilter.java @@ -1,7 +1,7 @@ package com.boydti.fawe.regions.general; import com.boydti.fawe.object.collection.LongHashSet; -import com.sk89q.worldedit.Vector2D; +import com.sk89q.worldedit.math.BlockVector2; public abstract class CuboidRegionFilter implements RegionFilter { @@ -18,7 +18,7 @@ public abstract class CuboidRegionFilter implements RegionFilter { */ public abstract void calculateRegions(); - public void add(Vector2D pos1, Vector2D pos2) { + public void add(BlockVector2 pos1, BlockVector2 pos2) { int ccx1 = pos1.getBlockX() >> 9; int ccz1 = pos1.getBlockZ() >> 9; int ccx2 = pos2.getBlockX() >> 9; 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 84a8a0a5b..24581fe10 100644 --- a/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/jnbt/NBTUtils.java @@ -19,7 +19,9 @@ package com.sk89q.jnbt; -import com.sk89q.worldedit.Vector; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.world.storage.InvalidFormatException; import java.util.Map; @@ -167,9 +169,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 db61b1dd0..0a98bd7aa 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 javax.annotation.Nullable; import java.util.ArrayList; @@ -110,9 +110,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()); @@ -200,7 +200,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; @@ -214,7 +214,7 @@ public class YAMLNode { return null; } - return new Vector(x, y, z); + return new Vector3(x, y, z); } /** @@ -225,7 +225,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; @@ -238,7 +238,7 @@ public class YAMLNode { return null; } - return new Vector2D(x, z); + return new Vector2(x, z); } /** @@ -250,8 +250,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; @@ -557,9 +557,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"); @@ -570,7 +570,7 @@ public class YAMLNode { continue; } - list.add(new Vector(x, y, z)); + list.add(new Vector3(x, y, z)); } return list; @@ -587,10 +587,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"); @@ -600,7 +600,7 @@ public class YAMLNode { continue; } - list.add(new Vector2D(x, z)); + list.add(new Vector2(x, z)); } return list; @@ -617,10 +617,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"); @@ -630,7 +630,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 04b600967..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/BlockVector.java +++ /dev/null @@ -1,120 +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 java.io.IOException; - -/** - * 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) { - this(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - } - - /** - * 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) { - this((int) x, (int) y, (int) 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) { - this((int) x, (int) y, (int) z); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector)) { - return false; - } - Vector other = (Vector) obj; - return (int) other.getX() == (int) this.getX() && (int) other.getY() == (int) this.getY() - && (int) other.getZ() == (int) this.getZ(); - - } - - public boolean equals(BlockVector obj) { - return obj.getBlockX() == this.getBlockX() && obj.getBlockY() == this.getBlockY() && obj.getBlockZ() == this.getBlockZ(); - } - - @Override - public int hashCode() { - return ((int) getX() ^ ((int) getZ() << 16)) ^ ((int) getY() << 30); - } - - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - if (!(this instanceof MutableBlockVector)) { - stream.writeInt(getBlockX()); - stream.writeInt(getBlockY()); - stream.writeInt(getBlockZ()); - } - } - - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - if (this instanceof MutableBlockVector) return; - this.setComponents(stream.readInt(), stream.readInt(), stream.readInt()); - } - - @Override - public BlockVector toBlockVector() { - return this; - } - - @Override - public String toString() { - return "(" + getBlockX() + ", " + getBlockY() + ", " + getBlockZ() + ")"; - } -} 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 cdf0cb36a..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) { - this(position.getBlockX(), position.getBlockZ()); - } - - /** - * 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) { - this((int) x, (int) z); - } - - /** - * Construct a new instance. - * - * @param x the X coordinate - * @param z the Z coordinate - */ - public BlockVector2D(double x, double z) { - this((int) x, (int) 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 c14ff2337..71856a092 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -47,6 +47,12 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.function.mask.*; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItemStack; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +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.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.event.extent.EditSessionEvent; @@ -60,6 +66,7 @@ import com.sk89q.worldedit.extent.world.SurvivalModeExtent; import com.sk89q.worldedit.function.GroundFunction; import com.sk89q.worldedit.function.RegionFunction; 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.Naturalizer; import com.sk89q.worldedit.function.generator.GardenPatchGenerator; @@ -77,6 +84,16 @@ 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.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.MutableBlockVector; +import com.sk89q.worldedit.math.MutableBlockVector2D; +import com.sk89q.worldedit.math.MutableVector; +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; import com.sk89q.worldedit.math.noise.RandomNoise; @@ -87,7 +104,9 @@ import com.sk89q.worldedit.regions.shape.ArbitraryShape; import com.sk89q.worldedit.regions.shape.RegionShape; import com.sk89q.worldedit.regions.shape.WorldEditExpressionEnvironment; import com.sk89q.worldedit.util.Countable; +import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.util.collection.DoubleArrayList; import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.world.SimpleWorld; import com.sk89q.worldedit.world.World; @@ -101,8 +120,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; @@ -133,6 +150,7 @@ import static com.sk89q.worldedit.regions.Regions.minimumBlockY; */ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, SimpleWorld { /** + * Used by {@link EditSession#setBlock(BlockVector3, BlockStateHolder, Stage)} to * determine which {@link Extent}s should be bypassed. */ public enum Stage { @@ -153,7 +171,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, private FawePlayer player; private FaweChangeSet changeTask; - private MutableBlockVector mutable = new MutableBlockVector(); + private MutableBlockVector mutablebv = new MutableBlockVector(); + private MutableVector mutablev = new MutableVector(); private int changes = 0; private BlockBag blockBag; @@ -163,13 +182,6 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public static final UUID CONSOLE = UUID.fromString("1-1-3-3-7"); public static final BaseBiome nullBiome = new BaseBiome(0); public static final BlockState nullBlock = BlockTypes.AIR.getDefaultState(); - private static final Vector[] recurseDirections = { - PlayerDirection.NORTH.vector(), - PlayerDirection.EAST.vector(), - PlayerDirection.SOUTH.vector(), - PlayerDirection.WEST.vector(), - PlayerDirection.UP.vector(), - PlayerDirection.DOWN.vector(),}; @Deprecated public EditSession(@Nonnull World world, @Nullable FaweQueue queue, @Nullable FawePlayer player, @Nullable FaweLimit limit, @Nullable FaweChangeSet changeSet, @Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue, @Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages, @Nullable BlockBag blockBag, @Nullable EventBus bus, @Nullable EditSessionEvent event) { @@ -908,12 +920,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Override - public BaseBiome getBiome(final Vector2D position) { + public BaseBiome getBiome(final BlockVector2 position) { return this.extent.getBiome(position); } @Override - public boolean setBiome(final Vector2D position, final BaseBiome biome) { + public boolean setBiome(final BlockVector2 position, final BaseBiome biome) { this.changes++; return this.extent.setBiome(position, biome); } @@ -950,7 +962,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Override - public BlockState getLazyBlock(final Vector position) { + public BlockState getLazyBlock(final BlockVector3 position) { return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } @@ -963,8 +975,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Override - public BlockState getBlock(final Vector position) { - return getLazyBlock(position.getBlockX(), position.getBlockY(), position.getBlockZ()); + public BlockState getBlock(BlockVector3 position) { + return world.getBlock(position); + } + + @Override + public BlockState getFullBlock(BlockVector3 position) { + return world.getFullBlock(position); } /** @@ -972,13 +989,24 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * * @param position the position * @return the block type - * @deprecated Use {@link #getLazyBlock(Vector)} or {@link #getBlock(Vector)} + * @deprecated Use {@link #getLazyBlock(BlockVector3)} or {@link #getBlock(BlockVector3)} */ @Deprecated - public BlockType getBlockType(final Vector position) { + public BlockType getBlockType(final BlockVector3 position) { return getBlockType(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } + public int getHighestTerrainBlock(int x, int z, int minY, int maxY) { + for (int y = maxY; y >= minY; --y) { + BlockVector3 pt = new BlockVector3(x, y, z); + BlockState block = getBlock(pt); + if (block.getBlockType().getMaterial().isMovementBlocker()) { + return y; + } + } + return minY; + } + public BlockType getBlockType(int x, int y, int z) { if (!limit.MAX_CHECKS()) { throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_MAX_CHECKS); @@ -996,7 +1024,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return whether the block changed * @throws WorldEditException thrown on a set error */ - public boolean setBlock(final Vector position, final BaseBlock block, final Stage stage) throws WorldEditException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block, Stage stage) throws WorldEditException { this.changes++; switch (stage) { case BEFORE_HISTORY: @@ -1010,24 +1038,31 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, throw new RuntimeException("New enum entry added that is unhandled here"); } - /** - * Set a block, bypassing history but still utilizing block re-ordering. - * - * @param position the position to set the block at - * @param block the block - * @return whether the block changed - */ - public boolean smartSetBlock(final Vector position, final BlockStateHolder block) { - this.changes++; + public boolean rawSetBlock(BlockVector3 position, BlockStateHolder block) { try { return this.bypassAll.setBlock(position, block); } catch (final WorldEditException e) { throw new RuntimeException("Unexpected exception", e); } } + + /** + * Set a block, bypassing history but still utilizing block re-ordering. + * + * @param position the position to set the block at + * @param block the block + * @return whether the block changed + */ + public boolean smartSetBlock(BlockVector3 position, BlockStateHolder block) { + try { + return setBlock(position, block, Stage.BEFORE_REORDER); + } catch (WorldEditException e) { + throw new RuntimeException("Unexpected exception", e); + } + } @Override - public boolean setBlock(Vector position, BlockStateHolder block) throws MaxChangedBlocksException { + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws MaxChangedBlocksException { this.changes++; try { return this.extent.setBlock(position, block); @@ -1050,20 +1085,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public boolean setBlock(int x, int y, int z, Pattern pattern) { this.changes++; try { - mutable.setComponents(x, y, z); - return pattern.apply(extent, mutable, mutable); + mutablebv.setComponents(x, y, z); + return pattern.apply(extent, mutablebv, mutablebv); } catch (WorldEditException e) { throw new RuntimeException("Unexpected exception", e); } } - + @Deprecated public boolean setBlock(int x, int y, int z, com.sk89q.worldedit.patterns.Pattern pattern) { return setBlock(x, y, z, (Pattern) pattern); } @Deprecated - public boolean setBlock(Vector position, com.sk89q.worldedit.patterns.Pattern pattern) { + public boolean setBlock(BlockVector3 position, com.sk89q.worldedit.patterns.Pattern pattern) { return setBlock(position, (Pattern) pattern); } @@ -1073,12 +1108,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Deprecated - public boolean setBlock(Vector position, BaseBlock block) throws MaxChangedBlocksException { + public boolean setBlock(BlockVector3 position, BaseBlock block) throws MaxChangedBlocksException { return setBlock(position, (BlockState) block); } @SuppressWarnings("deprecation") - public boolean setBlock(final Vector position, final Pattern pattern) { + public boolean setBlock(final BlockVector3 position, final Pattern pattern) { this.changes++; try { return pattern.apply(this.extent, position, position); @@ -1088,7 +1123,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @SuppressWarnings("deprecation") - public int setBlocks(final Set vset, final Pattern pattern) { + public int setBlocks(final Set vset, final Pattern pattern) { RegionVisitor visitor = new RegionVisitor(vset, new BlockReplace(extent, pattern), this); Operations.completeBlindly(visitor); changes += visitor.getAffected(); @@ -1105,7 +1140,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return whether a block was changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public boolean setChanceBlockIfAir(final Vector position, final BaseBlock block, final double probability) throws MaxChangedBlocksException { + public boolean setChanceBlockIfAir(final BlockVector3 position, final BaseBlock block, final double probability) throws MaxChangedBlocksException { return (ThreadLocalRandom.current().nextInt(65536) <= (probability * 65536)) && this.setBlockIfAir(position, block); } @@ -1119,9 +1154,16 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @deprecated Use your own method */ @Deprecated - public boolean setBlockIfAir(final Vector position, final BlockStateHolder block) throws MaxChangedBlocksException { + public boolean setBlockIfAir(final BlockVector3 position, final BlockStateHolder block) throws MaxChangedBlocksException { return this.getBlock(position).getBlockType().getMaterial().isAir() && this.setBlock(position, block); } +// private int setBlocks(Set vset, Pattern pattern) throws MaxChangedBlocksException { +// int affected = 0; +// for (BlockVector3 v : vset) { +// affected += setBlock(v, pattern) ? 1 : 0; +// } +// return affected; +// } @Override @Nullable @@ -1139,10 +1181,10 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @deprecated Get the change set with {@link #getChangeSet()} and add the change with that */ @Deprecated - public void rememberChange(final Vector position, final BaseBlock existing, final BaseBlock block) { + public void rememberChange(final BlockVector3 position, final BaseBlock existing, final BaseBlock block) { ChangeSet changeSet = getChangeSet(); if (changeSet != null) { - changeSet.add(new BlockChange(position.toBlockVector(), existing, block)); + changeSet.add(new BlockChange(position, existing, block)); } } @@ -1199,20 +1241,20 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { if (extent != null) { return this.extent.getMinimumPoint(); } else { - return new Vector(-30000000, 0, -30000000); + return new BlockVector3(-30000000, 0, -30000000); } } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { if (extent != null) { return this.extent.getMaximumPoint(); } else { - return new Vector(30000000, 255, 30000000); + return new BlockVector3(30000000, 255, 30000000); } } @@ -1278,7 +1320,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final BlockType id = searchIDs.iterator().next(); RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return getBlockType(position) == id; } }, this); @@ -1295,7 +1337,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public int countBlock(final Region region, final boolean[] ids) { RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return ids[getBlockType(position).getInternalId()]; } }, this); @@ -1306,7 +1348,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public int countBlock(final Region region, final Mask mask) { RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return mask.test(position); } }, this); @@ -1325,7 +1367,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final Mask mask = new BlockMaskBuilder().addBlocks(searchBlocks).build(extent); RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { return mask.test(position); } }, this); @@ -1340,7 +1382,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final int endY = region.getMaximumPoint().getBlockY(); RegionVisitor visitor = new RegionVisitor(flat, new RegionFunction() { @Override - public boolean apply(Vector pos) throws WorldEditException { + public boolean apply(BlockVector3 pos) throws WorldEditException { int x = pos.getBlockX(); int z = pos.getBlockZ(); int freeSpot = startCheckY; @@ -1378,15 +1420,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fillDirection(final Vector origin, final Pattern pattern, final double radius, final int depth, Vector direction) { + public int fillDirection(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, BlockVector3 direction) { checkNotNull(origin); checkNotNull(pattern); checkArgument(radius >= 0, "radius >= 0"); checkArgument(depth >= 1, "depth >= 1"); - if (direction.equals(new Vector(0, -1, 0))) { + if (direction.equals(new BlockVector3(0, -1, 0))) { return fillXZ(origin, pattern, radius, depth, false); } - final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))); + final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), Masks.negate(new ExistingBlockMask(EditSession.this))); // Want to replace blocks final BlockReplace replace = new BlockReplace(EditSession.this, pattern); @@ -1414,10 +1456,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ @SuppressWarnings("deprecation") - public int fillXZ(final Vector origin, final BaseBlock block, final double radius, final int depth, final boolean recursive) { + public int fillXZ(final BlockVector3 origin, final BaseBlock block, final double radius, final int depth, final boolean recursive) { return this.fillXZ(origin, (Pattern) block, radius, depth, recursive); } - /** * Fills an area recursively in the X/Z directions. * @@ -1430,13 +1471,19 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ @SuppressWarnings("deprecation") - public int fillXZ(final Vector origin, final Pattern pattern, final double radius, final int depth, final boolean recursive) { + public int fillXZ(final BlockVector3 origin, final Pattern pattern, final double radius, final int depth, final boolean recursive) { checkNotNull(origin); checkNotNull(pattern); checkArgument(radius >= 0, "radius >= 0"); checkArgument(depth >= 1, "depth >= 1"); - final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), new BoundedHeightMask(Math.max( + final MaskIntersection mask = new MaskIntersection(new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), new BoundedHeightMask(Math.max( (origin.getBlockY() - depth) + 1, getMinimumPoint().getBlockY()), Math.min(getMaximumPoint().getBlockY(), origin.getBlockY())), Masks.negate(new ExistingBlockMask(EditSession.this))); +// MaskIntersection mask = new MaskIntersection( +// 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())), +// Masks.negate(new ExistingBlockMask(this))); // Want to replace blocks final BlockReplace replace = new BlockReplace(EditSession.this, pattern); @@ -1466,8 +1513,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - @SuppressWarnings("deprecation") - public int removeAbove(final Vector position, final int apothem, final int height) { + public int removeAbove(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(height >= 1, "height >= 1"); @@ -1487,8 +1533,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - @SuppressWarnings("deprecation") - public int removeBelow(final Vector position, final int apothem, final int height) { + public int removeBelow(BlockVector3 position, int apothem, int height) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); checkArgument(height >= 1, "height >= 1"); @@ -1509,11 +1554,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ @SuppressWarnings("deprecation") - public int removeNear(final Vector position, Mask mask, final int apothem) { + public int removeNear(final BlockVector3 position, Mask mask, final int apothem) { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); - final Vector adjustment = new Vector(1, 1, 1).multiply(apothem - 1); + final BlockVector3 adjustment = new BlockVector3(1, 1, 1).multiply(apothem - 1); final Region region = new CuboidRegion(this.getWorld(), // Causes clamping of Y range position.add(adjustment.multiply(-1)), position.add(adjustment)); final Pattern pattern = BlockTypes.AIR.getDefaultState(); @@ -1527,8 +1572,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (!(region instanceof CuboidRegion)) return false; if (regionExtent != null) { if (!(region instanceof CuboidRegion)) return false; - Vector pos1 = region.getMinimumPoint(); - Vector pos2 = region.getMaximumPoint(); + BlockVector3 pos1 = region.getMinimumPoint(); + BlockVector3 pos2 = region.getMaximumPoint(); boolean contains = false; for (Region current : regionExtent.getRegions()) { if (current.contains((int) pos1.getX(), pos1.getBlockY(), pos1.getBlockZ()) && current.contains(pos2.getBlockX(), pos2.getBlockY(), pos2.getBlockZ())) { @@ -1551,6 +1596,19 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, public boolean hasExtraExtents() { return wrapped || getMask() != null || getSourceMask() != null || history != null; } + public int removeNear(BlockVector3 position, BlockType blockType, int apothem) throws MaxChangedBlocksException { + checkNotNull(position); + checkArgument(apothem >= 1, "apothem >= 1"); + + Mask mask = new BlockTypeMask(this, blockType); + BlockVector3 adjustment = BlockVector3.ONE.multiply(apothem - 1); + Region region = new CuboidRegion( + getWorld(), // Causes clamping of Y range + position.add(adjustment.multiply(-1)), + position.add(adjustment)); + Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); + return replaceBlocks(region, mask, pattern); + } /** * Sets all the blocks inside a region to a given block type. @@ -1573,7 +1631,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, Operations.completeBlindly(visitor); this.changes += visitor.getAffected(); } else { - Iterator iter = region.iterator(); + Iterator iter = region.iterator(); while (iter.hasNext()) { if (this.extent.setBlock(iter.next(), block)) { changes++; @@ -1676,10 +1734,17 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, checkNotNull(region); checkNotNull(pattern); - final Vector center = region.getCenter(); + final BlockVector3 center = region.getCenter().toBlockPoint(); final Region centerRegion = new CuboidRegion(this.getWorld(), // Causes clamping of Y range center.floor(), center.ceil()); return this.setBlocks(centerRegion, pattern); +// Vector3 center = region.getCenter(); +// Region centerRegion = new CuboidRegion( +// getWorld(), // Causes clamping of Y range +// 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); } /** @@ -1786,7 +1851,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (region instanceof CuboidRegion) { return this.makeCuboidWalls(region, pattern); } else { - for (BlockVector position : region) { + for (BlockVector3 position : region) { int x = position.getBlockX(); int y = position.getBlockY(); int z = position.getBlockZ(); @@ -1826,13 +1891,19 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, checkNotNull(region); checkNotNull(pattern); final BlockReplace replace = new BlockReplace(EditSession.this, pattern); - final RegionOffset offset = new RegionOffset(new Vector(0, 1, 0), replace); + final RegionOffset offset = new RegionOffset(new BlockVector3(0, 1, 0), replace); int minY = region.getMinimumPoint().getBlockY(); int maxY = Math.min(getMaximumPoint().getBlockY(), region.getMaximumPoint().getBlockY() + 1); SurfaceRegionFunction surface = new SurfaceRegionFunction(this, offset, minY, maxY); FlatRegionVisitor visitor = new FlatRegionVisitor(asFlatRegion(region), surface, this); Operations.completeBlindly(visitor); return this.changes = visitor.getAffected(); +// BlockReplace replace = new BlockReplace(this, pattern); +// 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); +// return ground.getAffected(); } /** @@ -1852,7 +1923,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return this.changes = naturalizer.getAffected(); } - public int stackCuboidRegion(final Region region, final Vector dir, final int count, final boolean copyAir) { + public int stackCuboidRegion(final Region region, final BlockVector3 dir, final int count, final boolean copyAir) { return stackCuboidRegion(region, dir, count, copyAir, true, false); } @@ -1866,15 +1937,23 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int stackCuboidRegion(final Region region, final Vector dir, final int count, final boolean copyAir, boolean copyEntities, boolean copyBiomes) { + public int stackCuboidRegion(final Region region, final BlockVector3 dir, final int count, final boolean copyAir, boolean copyEntities, boolean copyBiomes) { checkNotNull(region); checkNotNull(dir); checkArgument(count >= 1, "count >= 1 required"); - final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); - final Vector to = region.getMinimumPoint(); + final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); + final BlockVector3 to = region.getMinimumPoint(); final ForwardExtentCopy copy = new ForwardExtentCopy(EditSession.this, region, EditSession.this, to); copy.setCopyingEntities(copyEntities); copy.setCopyBiomes(copyBiomes); +// public int stackCuboidRegion(Region region, BlockVector3 dir, int count, boolean copyAir) throws MaxChangedBlocksException { +// checkNotNull(region); +// checkNotNull(dir); +// checkArgument(count >= 1, "count >= 1 required"); +// +// 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))); Mask sourceMask = getSourceMask(); @@ -1901,24 +1980,24 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks moved * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int moveRegion(final Region region, final Vector dir, final int distance, final boolean copyAir, final BlockStateHolder replacement) { + public int moveRegion(final Region region, final BlockVector3 dir, final int distance, final boolean copyAir, final BlockStateHolder replacement) { return moveRegion(region, dir, distance, copyAir, true, false, replacement); } - public int moveRegion(final Region region, final Vector dir, final int distance, final boolean copyAir, final boolean copyEntities, final boolean copyBiomes, BlockStateHolder replacement) { + public int moveRegion(final Region region, final BlockVector3 dir, final int distance, final boolean copyAir, final boolean copyEntities, final boolean copyBiomes, BlockStateHolder replacement) { return moveRegion(region, dir, distance, copyAir, copyEntities, copyBiomes, (Pattern) replacement); } - public int moveRegion(final Region region, final Vector dir, final int distance, final boolean copyAir, final boolean copyEntities, final boolean copyBiomes, Pattern replacement) { + public int moveRegion(final Region region, final BlockVector3 dir, final int distance, final boolean copyAir, final boolean copyEntities, final boolean copyBiomes, Pattern replacement) { checkNotNull(region); checkNotNull(dir); checkArgument(distance >= 1, "distance >= 1 required"); - final Vector displace = dir.multiply(distance); + final BlockVector3 displace = dir.multiply(distance); - final Vector size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); - final Vector to = region.getMinimumPoint().add(dir.multiply(distance)); + final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1); + final BlockVector3 to = region.getMinimumPoint().add(dir.multiply(distance)); - Vector disAbs = displace.positive(); + BlockVector3 disAbs = displace.abs(); if (disAbs.getBlockX() < size.getBlockX() && disAbs.getBlockY() < size.getBlockY() && disAbs.getBlockZ() < size.getBlockZ()) { // Buffer if overlapping @@ -1958,7 +2037,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks moved * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int moveCuboidRegion(final Region region, final Vector dir, final int distance, final boolean copyAir, final BlockStateHolder replacement) { + public int moveCuboidRegion(final Region region, final BlockVector3 dir, final int distance, final boolean copyAir, final BlockStateHolder replacement) { return this.moveRegion(region, dir, distance, copyAir, replacement); } @@ -1970,7 +2049,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drainArea(final Vector origin, final double radius) { + public int drainArea(final BlockVector3 origin, final double radius) { checkNotNull(origin); checkArgument(radius >= 0, "radius >= 0 required"); Mask liquidMask; @@ -1986,13 +2065,27 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, new BoundedHeightMask(0, EditSession.this.getMaximumPoint().getBlockY()), new RegionMask( new EllipsoidRegion(null, origin, - new Vector(radius, radius, radius))), liquidMask); + new Vector3(radius, radius, radius))), liquidMask); final BlockReplace replace = new BlockReplace(EditSession.this, BlockTypes.AIR.getDefaultState()); final RecursiveVisitor visitor = new RecursiveVisitor(mask, replace, (int) (radius * 2 + 1), this); // Around the origin in a 3x3 block - for (final BlockVector position : CuboidRegion.fromCenter(origin, 1)) { + for (final BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { +// 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 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 (BlockVector3 position : CuboidRegion.fromCenter(origin, 1)) { if (mask.test(position)) { visitor.visit(position); } @@ -2010,21 +2103,21 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int fixLiquid(final Vector origin, final double radius, Mask liquidMask, Pattern pattern) { + public int fixLiquid(final BlockVector3 origin, final double radius, Mask liquidMask, Pattern pattern) { checkNotNull(origin); checkArgument(radius >= 0, "radius >= 0 required"); // There are boundaries that the routine needs to stay in MaskIntersection mask = new MaskIntersection( new BoundedHeightMask(0, Math.min(origin.getBlockY(), getMaximumPoint().getBlockY())), - new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), + new RegionMask(new EllipsoidRegion(null, origin, new Vector3(radius, radius, radius))), liquidMask); BlockReplace replace = new BlockReplace(this, pattern); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace, (int) (radius * 2 + 1), this); // 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); } @@ -2045,7 +2138,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCylinder(final Vector pos, final Pattern block, final double radius, final int height, final boolean filled) { + public int makeCylinder(final BlockVector3 pos, final Pattern block, final double radius, final int height, final boolean filled) { return this.makeCylinder(pos, block, radius, radius, height, filled); } @@ -2061,37 +2154,37 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeCylinder(Vector pos, final Pattern block, double radiusX, double radiusZ, int height, final boolean filled) { + public int makeCylinder(BlockVector3 pos, final Pattern block, double radiusX, double radiusZ, int height, final boolean filled) { return makeCylinder(pos, block, radiusX, radiusZ, height, 0, filled); } - public int makeHollowCylinder(Vector pos, final Pattern block, double radiusX, double radiusZ, int height, double thickness) { + public int makeHollowCylinder(BlockVector3 pos, final Pattern block, double radiusX, double radiusZ, int height, double thickness) { return makeCylinder(pos, block, radiusX, radiusZ, height, thickness, false); } - private int makeCylinder(Vector pos, final Pattern block, double radiusX, double radiusZ, int height, double thickness, final boolean filled) { + private int makeCylinder(BlockVector3 pos, final Pattern block, double radiusX, double radiusZ, int height, double thickness, final boolean filled) { radiusX += 0.5; radiusZ += 0.5; - + MutableBlockVector posv = new MutableBlockVector(pos); if (height == 0) { return this.changes; } else if (height < 0) { height = -height; - pos.mutY(pos.getY() - height); + posv.mutY(posv.getY() - height); } - if (pos.getBlockY() < 0) { - pos.mutY(0); - } else if (((pos.getBlockY() + height) - 1) > maxY) { - height = (maxY - pos.getBlockY()) + 1; + if (posv.getBlockY() < 0) { + posv.mutY(0); + } else if (((posv.getBlockY() + height) - 1) > maxY) { + height = (maxY - posv.getBlockY()) + 1; } final double invRadiusX = 1 / (radiusX); final double invRadiusZ = 1 / (radiusZ); - int px = pos.getBlockX(); - int py = pos.getBlockY(); - int pz = pos.getBlockZ(); + int px = posv.getBlockX(); + int py = posv.getBlockY(); + int pz = posv.getBlockZ(); MutableBlockVector mutable = new MutableBlockVector(); final int ceilRadiusX = (int) Math.ceil(radiusX); @@ -2178,7 +2271,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return this.changes; } - public int makeCircle(Vector pos, final Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled, Vector normal) { + public int makeCircle(BlockVector3 pos, final Pattern block, double radiusX, double radiusY, double radiusZ, boolean filled, Vector3 normal) { radiusX += 0.5; radiusY += 0.5; radiusZ += 0.5; @@ -2275,7 +2368,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeSphere(final Vector pos, final Pattern block, final double radius, final boolean filled) { + public int makeSphere(final BlockVector3 pos, final Pattern block, final double radius, final boolean filled) { return this.makeSphere(pos, block, radius, radius, radius, filled); } @@ -2291,7 +2384,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeSphere(final Vector pos, final Pattern block, double radiusX, double radiusY, double radiusZ, final boolean filled) { + public int makeSphere(final BlockVector3 pos, final Pattern block, double radiusX, double radiusY, double radiusZ, final boolean filled) { radiusX += 0.5; radiusY += 0.5; radiusZ += 0.5; @@ -2370,7 +2463,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks changed * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePyramid(final Vector position, final Pattern block, int size, final boolean filled) { + public int makePyramid(final BlockVector3 position, final Pattern block, int size, final boolean filled) { final int height = size; for (int y = 0; y <= height; ++y) { @@ -2398,13 +2491,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int thaw(final Vector position, final double radius) { - final double radiusSq = radius * radius; + public int thaw(BlockVector3 position, final double radius) + throws MaxChangedBlocksException { + int affected = 0; + double radiusSq = radius * radius; final int ox = position.getBlockX(); final int oy = position.getBlockY(); final int oz = position.getBlockZ(); - final int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= (ox + ceilRadius); ++x) { int dx = x - ox; @@ -2430,6 +2524,27 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, continue; default: break; +// 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 BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { +// continue; +// } +// +// for (int y = world.getMaxY(); y >= 1; --y) { +// BlockVector3 pt = new BlockVector3(x, y, z); +// BlockType id = getBlock(pt).getBlockType(); +// +// if (id == BlockTypes.ICE) { +// if (setBlock(pt, water)) { +// ++affected; +// } +// } else if (id == BlockTypes.SNOW) { +// if (setBlock(pt, air)) { +// ++affected; +// } +// } else if (id.getMaterial().isAir()) { +// continue; } break; } @@ -2447,7 +2562,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int simulateSnow(final Vector position, final double radius) { + public int simulateSnow(final BlockVector3 position, final double radius) { final double radiusSq = radius * radius; @@ -2482,6 +2597,33 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, case JUNGLE_LEAVES: case OAK_LEAVES: case SPRUCE_LEAVES: +// 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 BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { +// continue; +// } +// +// for (int y = world.getMaxY(); y >= 1; --y) { +// BlockVector3 pt = new BlockVector3(x, y, z); +// BlockType id = getBlock(pt).getBlockType(); +// +// if (id.getMaterial().isAir()) { +// continue; +// } +// +// // Ice! +// if (id == BlockTypes.WATER) { +// if (setBlock(pt, ice)) { +// ++affected; +// } +// break; +// } +// +// // Snow should not cover these blocks +// if (id.getMaterial().isTranslucent()) { +// // Add snow on leaves +// if (!BlockCategories.LEAVES.contains(id)) { break; default: if (type.getMaterial().isTranslucent()) { @@ -2512,7 +2654,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int green(final Vector position, final double radius) { + public int green(final BlockVector3 position, final double radius) { + return this.green(position, radius, false); +} + public int green(BlockVector3 position, double radius, boolean onlyNormalDirt) + throws MaxChangedBlocksException { + int affected = 0; final double radiusSq = radius * radius; final int ox = position.getBlockX(); @@ -2543,6 +2690,26 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (block.getMaterial().isMovementBlocker()) { break loop; } +// for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { +// for (int z = oz - ceilRadius; z <= oz + ceilRadius; ++z) { +// if ((new BlockVector3(x, oy, z)).distanceSq(position) > radiusSq) { +// continue; +// } +// +// for (int y = world.getMaxY(); y >= 1; --y) { +// final BlockVector3 pt = new BlockVector3(x, y, z); +// final BlockState block = getBlock(pt); +// +// if (block.getBlockType() == BlockTypes.DIRT || +// (!onlyNormalDirt && block.getBlockType() == BlockTypes.COARSE_DIRT)) { +// if (setBlock(pt, grass)) { +// ++affected; +// } +// break; +// } else if (block.getBlockType() == BlockTypes.WATER || block.getBlockType() == BlockTypes.LAVA) { +// break; +// } else if (block.getBlockType().getMaterial().isMovementBlocker()) { +// break; } } } @@ -2559,7 +2726,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of patches created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePumpkinPatches(final Vector position, final int apothem) { + public int makePumpkinPatches(final BlockVector3 position, final int apothem) { return makePumpkinPatches(position, apothem, 0.02); } @@ -2571,7 +2738,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of patches created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makePumpkinPatches(final Vector position, final int apothem, double density) { + public int makePumpkinPatches(final BlockVector3 position, final int apothem, double density) { // We want to generate pumpkins final GardenPatchGenerator generator = new GardenPatchGenerator(EditSession.this); generator.setPlant(GardenPatchGenerator.getPumpkinPattern()); @@ -2597,7 +2764,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of trees created * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int makeForest(final Vector basePosition, final int size, final double density, TreeGenerator.TreeType treeType) { + public int makeForest(final BlockVector3 basePosition, final int size, final double density, TreeGenerator.TreeType treeType) { try { for (int x = basePosition.getBlockX() - size; x <= (basePosition.getBlockX() + size); ++x) { for (int z = basePosition.getBlockZ() - size; z <= (basePosition.getBlockZ() + size); ++z) { @@ -2615,11 +2782,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, switch (type.getTypeEnum()) { case GRASS: case DIRT: - treeType.generate(this, new Vector(x, y + 1, z)); + treeType.generate(this, new BlockVector3(x, y + 1, z)); this.changes++; break; case SNOW: - setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState()); + setBlock(new BlockVector3(x, y, z), BlockTypes.AIR.getDefaultState()); break; case AIR: case CAVE_AIR: @@ -2628,6 +2795,33 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, default: break; } +// 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() +// + size; ++x) { +// for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ() +// + size; ++z) { +// // Don't want to be in the ground +// if (!getBlock(new BlockVector3(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) { +// continue; +// } +// // The gods don't want a tree here +// if (Math.random() >= density) { +// continue; +// } // def 0.05 +// +// for (int y = basePosition.getBlockY(); y >= basePosition.getBlockY() - 10; --y) { +// // Check if we hit the ground +// BlockType t = getBlock(new BlockVector3(x, y, z)).getBlockType(); +// if (t == BlockTypes.GRASS_BLOCK || t == BlockTypes.DIRT) { +// treeType.generate(this, new BlockVector3(x, y + 1, z)); +// ++affected; +// break; +// } else if (t == BlockTypes.SNOW) { +// setBlock(new BlockVector3(x, y, z), BlockTypes.AIR.getDefaultState()); +// } else if (!t.getMaterial().isAir()) { // Trees won't grow on this! +// break; } } } @@ -2647,8 +2841,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (region instanceof CuboidRegion) { // Doing this for speed - 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(); @@ -2667,7 +2861,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } } else { - for (final Vector pt : region) { + for (final BlockVector3 pt : region) { BlockType type = getBlockType(pt); counter[type.getInternalId()]++; } @@ -2694,8 +2888,8 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, if (region instanceof CuboidRegion) { // Doing this for speed - 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(); @@ -2718,7 +2912,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } } else { - for (final Vector pt : region) { + for (final BlockVector3 pt : region) { BlockStateHolder blk = this.getBlock(pt); BlockType type = blk.getBlockType(); int[] stateCounter = counter[type.getInternalId()]; @@ -2747,7 +2941,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return distribution; } - public int makeShape(final Region region, final Vector zero, final Vector unit, final Pattern pattern, final String expressionString, final boolean hollow) throws ExpressionException, + 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(); @@ -2762,9 +2956,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, @Override public BlockStateHolder getMaterial(final int x, final int y, final int z, final BlockStateHolder defaultMaterial) { //TODO Optimize - avoid vector creation (math) - final Vector current = mutable.setComponents(x, y, z); + final Vector3 current = mutablev.setComponents(x, y, z); +// protected BlockStateHolder getMaterial(int x, int y, int z, BlockStateHolder defaultMaterial) { +// 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().getInternalId(), defaultMaterial.getInternalPropertiesId()) <= 0) { @@ -2787,7 +2983,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } - 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(); final RValue x = expression.getVariable("x", false).optimize(); @@ -2795,14 +2991,24 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final RValue z = expression.getVariable("z", false).optimize(); final WorldEditExpressionEnvironment environment = new WorldEditExpressionEnvironment(this, unit, zero); expression.setEnvironment(environment); - final Vector zero2 = zero.add(0.5, 0.5, 0.5); + final Vector3 zero2 = zero.add(0.5, 0.5, 0.5); RegionVisitor visitor = new RegionVisitor(region, new RegionFunction() { +// final DoubleArrayList queue = new DoubleArrayList<>(false); +// +// for (BlockVector3 position : region) { +// // offset, scale +// final Vector3 scaled = position.toVector3().subtract(zero).divide(unit); +// +// // transform +// expression.evaluate(scaled.getX(), scaled.getY(), scaled.getZ()); +// +// final BlockVector3 sourcePosition = environment.toWorld(x.getValue(), y.getValue(), z.getValue()); private MutableBlockVector mutable = new MutableBlockVector(); @Override - public boolean apply(Vector position) throws WorldEditException { + public boolean apply(BlockVector3 position) throws WorldEditException { try { // offset, scale double sx = (position.getX() - zero.getX()) / unit.getX(); @@ -2818,6 +3024,18 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } catch (EvaluationException e) { throw new RuntimeException(e); } +// // queue operation +// queue.put(position, material); +// } +// +// int affected = 0; +// for (Map.Entry entry : queue) { +// BlockVector3 position = entry.getKey(); +// BaseBlock material = entry.getValue(); +// +// // set at new position +// if (setBlock(position, material)) { +// ++affected; } }, this); Operations.completeBlindly(visitor); @@ -2835,12 +3053,11 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public int hollowOutRegion(final Region region, final int thickness, final Pattern pattern) { - - + try { final Set outside = new LocalBlockVectorSet(); - 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(); @@ -2851,32 +3068,30 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, for (int x = minX; x <= maxX; ++x) { for (int y = minY; y <= maxY; ++y) { - this.recurseHollow(region, new BlockVector(x, y, minZ), outside); - this.recurseHollow(region, new BlockVector(x, y, maxZ), outside); + this.recurseHollow(region, new BlockVector3(x, y, minZ), outside); + this.recurseHollow(region, new BlockVector3(x, y, maxZ), outside); } } for (int y = minY; y <= maxY; ++y) { for (int z = minZ; z <= maxZ; ++z) { - this.recurseHollow(region, new BlockVector(minX, y, z), outside); - this.recurseHollow(region, new BlockVector(maxX, y, z), outside); + this.recurseHollow(region, new BlockVector3(minX, y, z), outside); + this.recurseHollow(region, new BlockVector3(maxX, y, z), outside); } } for (int z = minZ; z <= maxZ; ++z) { for (int x = minX; x <= maxX; ++x) { - this.recurseHollow(region, new BlockVector(x, minY, z), outside); - this.recurseHollow(region, new BlockVector(x, maxY, z), outside); + this.recurseHollow(region, new BlockVector3(x, minY, z), outside); + this.recurseHollow(region, new BlockVector3(x, maxY, z), outside); } } for (int i = 1; i < thickness; ++i) { final Set newOutside = new LocalBlockVectorSet(); - outer: - for (final BlockVector position : region) { - for (final Vector recurseDirection : this.recurseDirections) { - final BlockVector neighbor = position.add(recurseDirection).toBlockVector(); - + outer: for (BlockVector3 position : region) { + for (BlockVector3 recurseDirection : recurseDirections) { + BlockVector3 neighbor = position.add(recurseDirection); if (outside.contains(neighbor)) { newOutside.add(position); continue outer; @@ -2886,12 +3101,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, outside.addAll(newOutside); } - try { - outer: - for (final BlockVector position : region) { - for (final Vector recurseDirection : this.recurseDirections) { - final 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; } @@ -2906,7 +3118,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return changes; } - public int drawLine(final Pattern pattern, final Vector pos1, final Vector pos2, final double radius, final boolean filled) { + public int drawLine(final Pattern pattern, final BlockVector3 pos1, final BlockVector3 pos2, final double radius, final boolean filled) { return drawLine(pattern, pos1, pos2, radius, filled, false); } @@ -2921,7 +3133,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drawLine(final Pattern pattern, final Vector pos1, final Vector pos2, final double radius, final boolean filled, boolean flat) { + public int drawLine(final Pattern pattern, final BlockVector3 pos1, final BlockVector3 pos2, final double radius, final boolean filled, boolean flat) { LocalBlockVectorSet vset = new LocalBlockVectorSet(); boolean notdrawn = true; @@ -2965,7 +3177,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, vset.add(tipx, tipy, tipz); } } - Set newVset; + Set newVset; if (flat) { newVset = this.getStretched(vset, radius); if (!filled) { @@ -2994,14 +3206,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int drawSpline(final Pattern pattern, final List nodevectors, final double tension, final double bias, final double continuity, final double quality, final double radius, final boolean filled) throws WorldEditException { + public int drawSpline(final Pattern pattern, final List nodevectors, final double tension, final double bias, final double continuity, final double quality, final double radius, final boolean filled) throws WorldEditException { LocalBlockVectorSet vset = new LocalBlockVectorSet(); final List nodes = new ArrayList(nodevectors.size()); final KochanekBartelsInterpolation interpol = new KochanekBartelsInterpolation(); - - for (final Vector nodevector : nodevectors) { - final Node n = new Node(nodevector); + for (BlockVector3 nodevector : nodevectors) { + Node n = new Node(nodevector.toVector3()); n.setTension(tension); n.setBias(bias); n.setContinuity(continuity); @@ -3011,14 +3222,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, interpol.setNodes(nodes); final double splinelength = interpol.arcLength(0, 1); for (double loop = 0; loop <= 1; loop += 1D / splinelength / quality) { - final Vector tipv = interpol.getPosition(loop); + final BlockVector3 tipv = interpol.getPosition(loop).toBlockPoint(); if (radius == 0) { pattern.apply(this, tipv, tipv); } else { vset.add(tipv); } } - Set newVset; + Set newVset; if (radius != 0) { newVset = this.getBallooned(vset, radius); if (!filled) { @@ -3029,13 +3240,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return changes; } - private Set getBallooned(final Set vset, final double radius) { + private Set getBallooned(final Set vset, final double radius) { if (radius < 1) { return vset; } final LocalBlockVectorSet returnset = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); - for (final Vector v : vset) { + for (final BlockVector3 v : vset) { final 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++) { @@ -3050,13 +3261,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return returnset; } - public Set getStretched(final Set vset, final double radius) { + public Set getStretched(final Set vset, final double radius) { if (radius < 1) { return vset; } final LocalBlockVectorSet returnset = new LocalBlockVectorSet(); final int ceilrad = (int) Math.ceil(radius); - for (final Vector v : vset) { + for (final BlockVector3 v : vset) { final int tipx = v.getBlockX(), tipy = v.getBlockY(), tipz = v.getBlockZ(); for (int loopx = tipx - ceilrad; loopx <= (tipx + ceilrad); loopx++) { for (int loopz = tipz - ceilrad; loopz <= (tipz + ceilrad); loopz++) { @@ -3069,43 +3280,45 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return returnset; } - public Set getOutline(final Set vset) { - // TODO optimize - vset instanceof LocalBlockVectorSet -> avoid Vector creation + public Set getOutline(final Set vset) { final LocalBlockVectorSet returnset = new LocalBlockVectorSet(); - for (final Vector v : vset) { - final 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, z + 1)) && vset.contains(new Vector(x, y, z - 1)))) { + final LocalBlockVectorSet newset = new LocalBlockVectorSet(); + newset.addAll(vset); + for (final BlockVector3 v : newset) { + final int x = v.getX(), y = v.getY(), z = v.getZ(); + if (!(newset.contains(x + 1, y, z) + && newset.contains(x - 1, y, z) + && newset.contains(x, y, z + 1) && newset.contains(x, y, z - 1))) { returnset.add(v); } } return returnset; } - public Set getHollowed(final Set vset) { - //TODO Optimize - avoid vector creation + public Set getHollowed(final Set vset) { final Set returnset = new LocalBlockVectorSet(); - for (final Vector v : vset) { - final 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)))) { + final LocalBlockVectorSet newset = new LocalBlockVectorSet(); + newset.addAll(vset); + for (final BlockVector3 v : newset) { + final int x = v.getX(), y = v.getY(), z = v.getZ(); + if (!(newset.contains(x + 1, y, z) + && newset.contains(x - 1, y, z) + && newset.contains(x, y + 1, z) + && newset.contains(x, y - 1, z) + && newset.contains(x, y, z + 1) && newset.contains(x, y, z - 1))) { returnset.add(v); } } return returnset; } - public void recurseHollow(final Region region, final BlockVector origin, final Set outside) { + public void recurseHollow(final Region region, final BlockVector3 origin, final Set outside) { //TODO FIXME Optimize - avoid vector creation - final ArrayDeque queue = new ArrayDeque(); + final ArrayDeque queue = new ArrayDeque(); queue.addLast(origin); while (!queue.isEmpty()) { - final BlockVector current = queue.removeFirst(); + final BlockVector3 current = queue.removeFirst(); if (this.getBlockType(current).getMaterial().isMovementBlocker()) { continue; } @@ -3118,15 +3331,15 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, continue; } - for (final Vector recurseDirection : this.recurseDirections) { - queue.addLast(current.add(recurseDirection).toBlockVector()); + for (BlockVector3 recurseDirection : recurseDirections) { + queue.addLast(current.add(recurseDirection)); } } } - public int makeBiomeShape(final Region region, final Vector zero, final Vector unit, final BaseBiome biomeType, final String expressionString, final boolean hollow) throws ExpressionException { - 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(); @@ -3138,9 +3351,9 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final ArbitraryBiomeShape shape = new ArbitraryBiomeShape(region) { @Override protected BaseBiome getBiome(final int x, final int z, final 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) { @@ -3157,7 +3370,14 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return shape.generate(this, biomeType, hollow); } - + private static final BlockVector3[] recurseDirections = { + Direction.NORTH.toBlockVector(), + Direction.EAST.toBlockVector(), + Direction.SOUTH.toBlockVector(), + Direction.WEST.toBlockVector(), + Direction.UP.toBlockVector(), + Direction.DOWN.toBlockVector(), + }; private double lengthSq(final double x, final double y, final double z) { return (x * x) + (y * y) + (z * z); } @@ -3173,12 +3393,12 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } @Override - public int getBlockLightLevel(Vector position) { + public int getBlockLightLevel(BlockVector3 position) { return queue.getEmmittedLight(position.getBlockX(), position.getBlockY(), position.getBlockZ()); } @Override - public boolean clearContainerBlockContents(Vector pos) { + public boolean clearContainerBlockContents(BlockVector3 pos) { BlockStateHolder block = getFullBlock(pos); CompoundTag nbt = block.getNbtData(); if (nbt != null) { @@ -3199,7 +3419,7 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return session.regenerate(region, null, null); } - private void setExistingBlocks(Vector pos1, Vector pos2) { + private void setExistingBlocks(BlockVector3 pos1, BlockVector3 pos2) { for (int x = (int) pos1.getX(); x <= (int) pos2.getX(); x++) { for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { for (int y = (int) pos1.getY(); y <= (int) pos2.getY(); y++) { @@ -3224,22 +3444,22 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, final FaweRegionExtent fe = this.getRegionExtent(); final boolean cuboid = region instanceof CuboidRegion; if (fe != null && cuboid) { - Vector max = region.getMaximumPoint(); - Vector min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); if (!fe.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ()) && !fe.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ())) { throw new FaweException(BBC.WORLDEDIT_CANCEL_REASON_OUTSIDE_REGION); } } - final Set chunks = region.getChunks(); + final Set chunks = region.getChunks(); MutableBlockVector mutable = new MutableBlockVector(); MutableBlockVector2D mutable2D = new MutableBlockVector2D(); - for (Vector2D chunk : chunks) { + for (BlockVector2 chunk : chunks) { final int cx = chunk.getBlockX(); final int cz = chunk.getBlockZ(); final int bx = cx << 4; final int bz = cz << 4; - final Vector cmin = new Vector(bx, 0, bz); - final Vector cmax = cmin.add(15, getMaxY(), 15); + final BlockVector3 cmin = new BlockVector3(bx, 0, bz); + final BlockVector3 cmax = cmin.add(15, getMaxY(), 15); final boolean containsBot1 = (fe == null || fe.contains(cmin.getBlockX(), cmin.getBlockY(), cmin.getBlockZ())); final boolean containsBot2 = region.contains(cmin); final boolean containsTop1 = (fe == null || fe.contains(cmax.getBlockX(), cmax.getBlockY(), cmax.getBlockZ())); @@ -3266,13 +3486,13 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, } } else { if (!conNextX) { - setExistingBlocks(new Vector(bx + 16, 0, bz), new Vector(bx + 31, getMaxY(), bz + 15)); + setExistingBlocks(new BlockVector3(bx + 16, 0, bz), new BlockVector3(bx + 31, getMaxY(), bz + 15)); } if (!conNextZ) { - setExistingBlocks(new Vector(bx, 0, bz + 16), new Vector(bx + 15, getMaxY(), bz + 31)); + setExistingBlocks(new BlockVector3(bx, 0, bz + 16), new BlockVector3(bx + 15, getMaxY(), bz + 31)); } if (!chunks.contains(mutable2D.setComponents(cx + 1, cz + 1)) && !conNextX && !conNextZ) { - setExistingBlocks(new Vector(bx + 16, 0, bz + 16), new Vector(bx + 31, getMaxY(), bz + 31)); + setExistingBlocks(new BlockVector3(bx + 16, 0, bz + 16), new BlockVector3(bx + 31, getMaxY(), bz + 31)); } for (int x = 0; x < 16; x++) { int xx = x + bx; @@ -3320,27 +3540,26 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, return false; } - @Override - public void dropItem(Vector position, BaseItemStack item) { - if (getWorld() != null) { - getWorld().dropItem(position, item); - } - } +// public void dropItem(BlockVector3 position, BaseItemStack item) { +// if (getWorld() != null) { +// getWorld().dropItem(position, item); +// } +// } @Override - public void simulateBlockMine(Vector position) { + public void simulateBlockMine(BlockVector3 position) { TaskManager.IMP.sync((Supplier) () -> { world.simulateBlockMine(position); return null; }); } - public boolean generateTree(TreeGenerator.TreeType type, Vector position) { + public boolean generateTree(TreeGenerator.TreeType type, BlockVector3 position) { return generateTree(type, this, position); } @Override - public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) { + public boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) { if (getWorld() != null) { try { return getWorld().generateTree(type, editSession, position); @@ -3371,5 +3590,17 @@ public class EditSession extends AbstractDelegateExtent implements HasFaweQueue, world.setWeather(weatherType, duration); } + @Override + public void dropItem(Vector3 position, BaseItemStack item) { + // TODO Auto-generated method stub + + } + + @Override + public boolean playEffect(Vector3 position, int type, int data) { + // TODO Auto-generated method stub + return false; + } + } 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 0666d2de1..a1292f9e2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -55,6 +55,8 @@ import com.sk89q.worldedit.history.changeset.ChangeSet; 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; @@ -128,12 +130,12 @@ public class LocalSession implements TextureHolder { private transient TextureUtil texture; private transient ResettableExtent transform = null; private transient TimeZone timezone = TimeZone.getDefault(); - private transient World currentWorld; private transient UUID uuid; private transient volatile long historySize = 0; private transient VirtualWorld virtual; + private transient BlockVector3 cuiTemporaryBlock; // Saved properties private String lastScript; @@ -870,10 +872,10 @@ public class LocalSession implements TextureHolder { * @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(); + return player.getBlockIn().toVector().toBlockPoint(); } return selector.getPrimaryPosition(); @@ -1105,6 +1107,60 @@ public class LocalSession implements TextureHolder { public void tellVersion(Actor player) { } + + public boolean shouldUseServerCUI() { + return this.useServerCUI; + } + + public void setUseServerCUI(boolean useServerCUI) { + this.useServerCUI = useServerCUI; + setDirty(); + } + + /** + * Update server-side WorldEdit CUI. + * + * @param actor The player + */ + public void updateServerCUI(Actor actor) { + if (!actor.isPlayer()) { + return; // This is for players only. + } + + if (!config.serverSideCUI) { + return; // Disabled in config. + } + + Player player = (Player) actor; + + if (!useServerCUI || hasCUISupport) { + if (cuiTemporaryBlock != null) { + player.sendFakeBlock(cuiTemporaryBlock, null); + cuiTemporaryBlock = null; + } + return; // If it's not enabled, ignore this. + } + + // Remove the old block. + if (cuiTemporaryBlock != null) { + player.sendFakeBlock(cuiTemporaryBlock, null); + cuiTemporaryBlock = null; + } + + BaseBlock block = ServerCUIHandler.createStructureBlock(player); + 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 BlockVector3( + ((IntTag) tags.get("x")).getValue(), + ((IntTag) tags.get("y")).getValue(), + ((IntTag) tags.get("z")).getValue() + ); + + player.sendFakeBlock(cuiTemporaryBlock, block); + } + } + /** * Dispatch a CUI event but only if the actor has CUI support. * 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 45eb24dba..0c3aa122c 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 8ce05ce2d..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector.java +++ /dev/null @@ -1,915 +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.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.math.transform.AffineTransform; -import java.io.IOException; -import java.io.Serializable; -import javax.annotation.Nullable; - -/** - * An immutable 3-dimensional vector. - */ -public class Vector extends Vector2D implements Comparable, Serializable { - - 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); - - private transient double y; - - /** - * 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.mutX(x); - this.mutY(y); - this.mutZ(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.mutX(x); - this.mutY(y); - this.mutZ(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.mutX(x); - this.mutY(y); - this.mutZ(z); - } - - /** - * Copy another vector. - * - * @param other another vector to make a copy of - */ - public Vector(Vector other) { - this.mutX(other.getX()); - this.mutY(other.getY()); - this.mutZ(other.getZ()); - } - - public Vector(double[] arr) { - this.mutX(arr[0]); - this.mutY(arr[1]); - this.mutZ(arr[2]); - } - - /** - * 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.mutX(0); - this.mutY(0); - this.mutZ(0); - } - - public Vector setComponents(int x, int y, int z) { - this.mutX(x); - this.mutY(y); - this.mutZ(z); - return this; - } - - public Vector setComponents(double x, double y, double z) { - this.mutX(x); - this.mutY(y); - this.mutZ(z); - return this; - } - - public void mutX(int x) { - this.x = x; - } - - public void mutY(int y) { - this.y = y; - } - - public void mutZ(int z) { - this.z = z; - } - - public void mutX(double x) { - this.x = x; - } - - public void mutY(double y) { - this.y = y; - } - - public void mutZ(double z) { - this.z = z; - } - - /** - * 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 MathMan.roundInt(getX()); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector setX(double x) { - return new Vector(x, getY(), getZ()); - } - - /** - * Set the X coordinate. - * - * @param x the X coordinate - * @return new vector - */ - public Vector setX(int x) { - return new Vector(x, getY(), getZ()); - } - - /** - * 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 MathMan.roundInt(getY()); - } - - /** - * Set the Y coordinate. - * - * @param y the new Y - * @return a new vector - */ - public Vector setY(double y) { - return new Vector(getX(), y, getZ()); - } - - /** - * Set the Y coordinate. - * - * @param y the new Y - * @return a new vector - */ - public Vector setY(int y) { - return new Vector(getX(), y, getZ()); - } - - /** - * 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 MathMan.roundInt(getZ()); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector setZ(double z) { - return new Vector(getX(), getY(), z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector setZ(int z) { - return new Vector(getX(), getY(), 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(getX() + other.getX(), getY() + other.getY(), getZ() + other.getZ()); - } - - /** - * 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.getX() + x, this.getY() + y, this.getZ() + 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.getX() + x, this.getY() + y, this.getZ() + 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 = getX(), newY = getY(), newZ = getZ(); - - for (Vector other : others) { - newX += other.getX(); - newY += other.getY(); - newZ += other.getZ(); - } - - 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(getX() - other.getX(), getY() - other.getY(), getZ() - other.getZ()); - } - - /** - * 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.getX() - x, this.getY() - y, this.getZ() - 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.getX() - x, this.getY() - y, this.getZ() - 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 = getX(), newY = getY(), newZ = getZ(); - - for (Vector other : others) { - newX -= other.getX(); - newY -= other.getY(); - newZ -= other.getZ(); - } - - 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(getX() * other.getX(), getY() * other.getY(), getZ() * other.getZ()); - } - - /** - * 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.getX() * x, this.getY() * y, this.getZ() * 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.getX() * x, this.getY() * y, this.getZ() * 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 = getX(), newY = getY(), newZ = getZ(); - - for (Vector other : others) { - newX *= other.getX(); - newY *= other.getY(); - newZ *= other.getZ(); - } - - 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.getX() * n, this.getY() * n, this.getZ() * 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.getX() * n, this.getY() * n, this.getZ() * 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.getX() * n, this.getY() * n, this.getZ() * 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(getX() / other.getX(), getY() / other.getY(), getZ() / other.getZ()); - } - - /** - * 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.getX() / x, this.getY() / y, this.getZ() / 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.getX() / x, this.getY() / y, this.getZ() / 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(getX() / n, getY() / n, getZ() / 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(getX() / n, getY() / n, getZ() / 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(getX() / n, getY() / n, getZ() / n); - } - - /** - * Get the length of the vector. - * - * @return length - */ - public double length() { - return Math.sqrt(getX() * getX() + getY() * getY() + getZ() * getZ()); - } - - /** - * Get the length, squared, of the vector. - * - * @return length, squared - */ - public double lengthSq() { - return getX() * getX() + getY() * getY() + getZ() * getZ(); - } - - public double volume() { - return getX() * getY() * getZ(); - } - - /** - * 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.getX() - getX(), 2) + - Math.pow(other.getY() - getY(), 2) + - Math.pow(other.getZ() - getZ(), 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.getX() - getX(), 2) + - Math.pow(other.getY() - getY(), 2) + - Math.pow(other.getZ() - getZ(), 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 getX() * other.getX() + getY() * other.getY() + getZ() * other.getZ(); - } - - /** - * 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( - getY() * other.getZ() - getZ() * other.getY(), - getZ() * other.getX() - getX() * other.getZ(), - getX() * other.getY() - getY() * other.getX() - ); - } - - /** - * 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 getX() >= min.getX() && getX() <= max.getX() && getY() >= min.getY() && getY() <= max.getY() && getZ() >= min.getZ() && getZ() <= max.getZ(); - } - - /** - * 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(getX(), Math.max(min, Math.min(max, getY())), getZ()); - } - - /** - * Floors the values of all components. - * - * @return a new vector - */ - public Vector floor() { - return new Vector(Math.floor(getX()), Math.floor(getY()), Math.floor(getZ())); - } - - /** - * Rounds all components up. - * - * @return a new vector - */ - public Vector ceil() { - return new Vector(Math.ceil(getX()), Math.ceil(getY()), Math.ceil(getZ())); - } - - /** - * 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(getX() + 0.5), Math.floor(getY() + 0.5), Math.floor(getZ() + 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(getX()), Math.abs(getY()), Math.abs(getZ())); - } - - /** - * 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.getX() - aboutX; - double z = this.getZ() - 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, - getY(), - 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 (getX() == 0 && getY() == 0 && getZ() == 0) { - // this is a zero vector - return true; - } - - final double otherX = other.getX(); - final double otherY = other.getY(); - final double otherZ = other.getZ(); - - if (otherX == 0 && otherY == 0 && otherZ == 0) { - // other is a zero vector - return true; - } - - if ((getX() == 0) != (otherX == 0)) return false; - if ((getY() == 0) != (otherY == 0)) return false; - if ((getZ() == 0) != (otherZ == 0)) return false; - - final double quotientX = otherX / getX(); - if (!Double.isNaN(quotientX)) { - return other.equals(multiply(quotientX)); - } - - final double quotientY = otherY / getY(); - if (!Double.isNaN(quotientY)) { - return other.equals(multiply(quotientY)); - } - - final double quotientZ = otherZ / getZ(); - 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(getX()), - Math.floor(getY()), - Math.floor(getZ()) - ); - } - - /** - * Create a new {@code BlockVector} from this vector. - * - * @return a new {@code BlockVector} - */ - public BlockVector toBlockVector() { - return new BlockVector(this); - } - - /** - * Creates a 2D vector by dropping the Y component from this vector. - * - * @return a new {@code Vector2D} - */ - public Vector2D toVector2D() { - return new Vector2D(getX(), getZ()); - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof Vector)) { - return false; - } - - Vector other = (Vector) obj; - return other.getX() == this.getX() && other.getZ() == this.getZ() && other.getY() == this.getY(); - } - - @Override - public int compareTo(@Nullable Vector other) { - if (other == null) { - throw new IllegalArgumentException("null not supported"); - } - if (getY() != other.getY()) return Double.compare(getY(), other.getY()); - if (getZ() != other.getZ()) return Double.compare(getZ(), other.getZ()); - if (getX() != other.getX()) return Double.compare(getX(), other.getX()); - return 0; - } - - @Override - public int hashCode() { - return ((int) getX() ^ ((int) getZ() << 16)) ^ ((int) getY() << 30); - } - - @Override - public String toString() { - String x = (getX() == getBlockX() ? "" + getBlockX() : "" + getX()); - String y = (getY() == getBlockY() ? "" + getBlockY() : "" + getY()); - String z = (getZ() == getBlockZ() ? "" + getBlockZ() : "" + getZ()); - 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.getX(), v2.getX()), - Math.min(v1.getY(), v2.getY()), - Math.min(v1.getZ(), v2.getZ()) - ); - } - - /** - * 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.getX(), v2.getX()), - Math.max(v1.getY(), v2.getY()), - Math.max(v1.getZ(), v2.getZ()) - ); - } - - /** - * 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.getX() + v2.getX()) / 2, - (v1.getY() + v2.getY()) / 2, - (v1.getZ() + v2.getZ()) / 2 - ); - } - - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - if (!(this instanceof MutableBlockVector)) { - stream.writeDouble(x); - stream.writeDouble(y); - stream.writeDouble(z); - } - } - - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - if (this instanceof MutableBlockVector) return; - this.x = stream.readDouble(); - this.y = stream.readDouble(); - this.z = stream.readDouble(); - } - - -} 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 be32c1e21..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/Vector2D.java +++ /dev/null @@ -1,681 +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.boydti.fawe.util.MathMan; -import com.sk89q.worldedit.math.transform.AffineTransform; -import java.io.IOException; -import java.io.Serializable; - -/** - * An immutable 2-dimensional vector. - */ -public class Vector2D implements Serializable { - 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); - - public transient 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.getX(); - this.z = other.getZ(); - } - - /** - * 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 MathMan.roundInt(getX()); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector2D setX(double x) { - return new Vector2D(x, getZ()); - } - - /** - * Set the X coordinate. - * - * @param x the new X - * @return a new vector - */ - public Vector2D setX(int x) { - return new Vector2D(x, getZ()); - } - - /** - * 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 MathMan.roundInt(getZ()); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector2D setZ(double z) { - return new Vector2D(getX(), z); - } - - /** - * Set the Z coordinate. - * - * @param z the new Z - * @return a new vector - */ - public Vector2D setZ(int z) { - return new Vector2D(getX(), 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(getX() + other.getX(), getZ() + other.getZ()); - } - - /** - * 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.getX() + x, this.getZ() + 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.getX() + x, this.getZ() + 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 = getX(), newZ = getZ(); - - for (Vector2D other : others) { - newX += other.getX(); - newZ += other.getZ(); - } - - 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(getX() - other.getX(), getZ() - other.getZ()); - } - - /** - * 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.getX() - x, this.getZ() - 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.getX() - x, this.getZ() - 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 = getX(), newZ = getZ(); - - for (Vector2D other : others) { - newX -= other.getX(); - newZ -= other.getZ(); - } - - 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(getX() * other.getX(), getZ() * other.getZ()); - } - - /** - * 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.getX() * x, this.getZ() * 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.getX() * x, this.getZ() * 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 = getX(), newZ = getZ(); - - for (Vector2D other : others) { - newX *= other.getX(); - newZ *= other.getZ(); - } - - 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.getX() * n, this.getZ() * 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.getX() * n, this.getZ() * 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.getX() * n, this.getZ() * 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(getX() / other.getX(), getZ() / other.getZ()); - } - - /** - * 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.getX() / x, this.getZ() / 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.getX() / x, this.getZ() / 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(getX() / n, getZ() / 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(getX() / n, getZ() / 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(getX() / n, getZ() / n); - } - - /** - * Get the length of the vector. - * - * @return length - */ - public double length() { - return Math.sqrt(getX() * getX() + getZ() * getZ()); - } - - /** - * Get the length, squared, of the vector. - * - * @return length, squared - */ - public double lengthSq() { - return getX() * getX() + getZ() * getZ(); - } - - /** - * 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.getX() - getX(), 2) + Math.pow(other.getZ() - getZ(), 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.getX() - getX(), 2) + - Math.pow(other.getZ() - getZ(), 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 getX() * other.getX() + getZ() * other.getZ(); - } - - /** - * 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 getX() >= min.getX() && getX() <= max.getX() - && getZ() >= min.getZ() && getZ() <= max.getZ(); - } - - /** - * 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(getX()), Math.floor(getZ())); - } - - /** - * Rounds all components up. - * - * @return a new vector - */ - public Vector2D ceil() { - return new Vector2D(Math.ceil(getX()), Math.ceil(getZ())); - } - - /** - * 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(getX() + 0.5), Math.floor(getZ() + 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(getX()), Math.abs(getZ())); - } - - /** - * 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.getX() - aboutX; - double z = this.getZ() - 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 (getX() == 0 && getZ() == 0) { - // this is a zero vector - return true; - } - - final double otherX = other.getX(); - final double otherZ = other.getZ(); - - if (otherX == 0 && otherZ == 0) { - // other is a zero vector - return true; - } - - if ((getX() == 0) != (otherX == 0)) return false; - if ((getZ() == 0) != (otherZ == 0)) return false; - - final double quotientX = otherX / getX(); - if (!Double.isNaN(quotientX)) { - return other.equals(multiply(quotientX)); - } - - final double quotientZ = otherZ / getZ(); - 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(getX(), 0, getZ()); - } - - /** - * 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(getX(), y, getZ()); - } - - @Override - public boolean equals(Object obj) { - if (!(obj instanceof Vector2D)) { - return false; - } - - Vector2D other = (Vector2D) obj; - return other.getX() == this.getX() && other.getZ() == this.getZ(); - - } - - @Override - public int hashCode() { - return ((new Double(getX())).hashCode() >> 13) ^ - (new Double(getZ())).hashCode(); - } - - @Override - public String toString() { - return "(" + getX() + ", " + getZ() + ")"; - } - - /** - * 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.getX(), v2.getX()), - Math.min(v1.getZ(), v2.getZ()) - ); - } - - /** - * 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.getX(), v2.getX()), - Math.max(v1.getZ(), v2.getZ()) - ); - } - - private void writeObject(java.io.ObjectOutputStream stream) throws IOException { - if (this instanceof MutableBlockVector2D) return; - stream.writeDouble(x); - stream.writeDouble(z); - } - - private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { - if (this instanceof MutableBlockVector2D) return; - this.x = stream.readDouble(); - this.z = stream.readDouble(); - } -} 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 653e866ba..f7544189b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -38,6 +38,8 @@ import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.internal.expression.Expression; import com.sk89q.worldedit.internal.expression.runtime.Constant; import com.sk89q.worldedit.internal.expression.runtime.RValue; +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; @@ -378,7 +380,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); @@ -390,7 +392,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 3f91f0a56..d7411fe79 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 @@ -30,8 +30,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; @@ -44,7 +42,12 @@ 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; +<<<<<<< HEAD import com.sk89q.worldedit.function.visitor.RegionVisitor; +======= +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.FlatRegion; import com.sk89q.worldedit.regions.Region; @@ -150,6 +153,7 @@ public class BiomeCommands extends MethodCommands { return; } +<<<<<<< HEAD BaseBiome biome = player.getWorld().getBiome(blockPosition.toVector().toVector2D()); biomes[biome.getId()]++; size = 1; @@ -157,11 +161,23 @@ public class BiomeCommands extends MethodCommands { BaseBiome biome = player.getWorld().getBiome(player.getLocation().toVector().toVector2D()); biomes[biome.getId()]++; size = 1; +======= + 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().toBlockPoint().toBlockVector2()); + biomes.add(biome); + + qualifier = "at your position"; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } else { World world = player.getWorld(); Region region = session.getSelection(world); if (region instanceof FlatRegion) { +<<<<<<< HEAD for (Vector2D pt : new Fast2DIterator(((FlatRegion) region).asFlatRegion(), editSession)) { biomes[editSession.getBiome(pt).getId()]++; size++; @@ -176,6 +192,15 @@ public class BiomeCommands extends MethodCommands { }, editSession); Operations.completeBlindly(visitor); size += visitor.getAffected(); +======= + for (BlockVector2 pt : ((FlatRegion) region).asFlatRegion()) { + biomes.add(world.getBiome(pt)); + } + } else { + for (BlockVector3 pt : region) { + biomes.add(world.getBiome(pt.toBlockVector2())); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } @@ -219,7 +244,7 @@ public class BiomeCommands extends MethodCommands { 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 9af1ef1aa..143865310 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 @@ -39,6 +39,19 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Step; import com.sk89q.worldedit.*; import com.sk89q.worldedit.command.tool.brush.*; +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.command.tool.brush.ButcherBrush; +import com.sk89q.worldedit.command.tool.brush.ClipboardBrush; +import com.sk89q.worldedit.command.tool.brush.CylinderBrush; +import com.sk89q.worldedit.command.tool.brush.GravityBrush; +import com.sk89q.worldedit.command.tool.brush.HollowCylinderBrush; +import com.sk89q.worldedit.command.tool.brush.HollowSphereBrush; +import com.sk89q.worldedit.command.tool.brush.SmoothBrush; +import com.sk89q.worldedit.command.tool.brush.SphereBrush; import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.ParserContext; @@ -47,9 +60,10 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.SingleBlockTypeMask; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.expression.Expression; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.command.InvalidUsageException; import com.sk89q.worldedit.util.command.binding.Range; @@ -63,9 +77,6 @@ import java.awt.*; import java.awt.image.BufferedImage; import java.io.*; import java.net.URI; -import java.net.URL; -import java.nio.channels.Channels; -import java.nio.channels.ReadableByteChannel; import java.util.ArrayList; import java.util.List; @@ -268,8 +279,8 @@ public class BrushCommands extends BrushProcessor { max = 5 ) @CommandPermissions("worldedit.brush.rock") - public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("10") Vector radius, @Optional("100") double sphericity, @Optional("30") double frequency, @Optional("50") double amplitude, CommandContext context) throws WorldEditException { - double max = MathMan.max(radius.getBlockX(), radius.getBlockY(), radius.getBlockZ()); + public BrushSettings blobBrush(Player player, EditSession editSession, LocalSession session, Pattern fill, @Optional("10") Vector3 radius, @Optional("100") double sphericity, @Optional("30") double frequency, @Optional("50") double amplitude, CommandContext context) throws WorldEditException { + double max = MathMan.max(radius.getX(), radius.getY(), radius.getZ()); getWorldEdit().checkMaxBrushRadius(max); Brush brush = new BlobBrush(radius.divide(max), frequency / 100, amplitude / 100, sphericity / 100); return set(session, context, @@ -600,7 +611,7 @@ public class BrushCommands extends BrushProcessor { ClipboardHolder holder = session.getClipboard(); Clipboard clipboard = holder.getClipboard(); - Vector size = clipboard.getDimensions(); + BlockVector3 size = clipboard.getDimensions(); getWorldEdit().checkMaxBrushRadius(size.getBlockX()); getWorldEdit().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 26d5a6f39..1b9122a05 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 @@ -26,11 +26,15 @@ import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -75,10 +79,17 @@ public class ChunkCommands { String filename = "c." + Integer.toString(chunkX, 36) + "." + Integer.toString(chunkZ, 36) + ".dat"; +<<<<<<< HEAD player.print(BBC.getPrefix() + "Chunk: " + chunkX + ", " + chunkZ); player.print(BBC.getPrefix() + "Old format: " + folder1 + "/" + folder2 + "/" + filename); player.print(BBC.getPrefix() + "McRegion: region/" + McRegionChunkStore.getFilename( new Vector2D(chunkX, chunkZ))); +======= + player.print("Chunk: " + chunkX + ", " + chunkZ); + player.print("Old format: " + folder1 + "/" + folder2 + "/" + filename); + player.print("McRegion: region/" + McRegionChunkStore.getFilename( + new BlockVector2(chunkX, chunkZ))); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -89,11 +100,19 @@ public class ChunkCommands { max = 0 ) @CommandPermissions("worldedit.listchunks") +<<<<<<< HEAD public void listChunks(Player player, LocalSession session, CommandContext args) throws WorldEditException { Set chunks = session.getSelection(player.getWorld()).getChunks(); for (Vector2D chunk : chunks) { player.print(BBC.getPrefix() + LegacyChunkStore.getFilename(chunk)); +======= + public void listChunks(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + Set chunks = session.getSelection(player.getWorld()).getChunks(); + + for (BlockVector2 chunk : chunks) { + player.print(LegacyChunkStore.getFilename(chunk)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } @@ -110,7 +129,7 @@ public class ChunkCommands { player.print(BBC.getPrefix() + "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) { @@ -127,7 +146,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"); @@ -159,7 +178,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 798eb9577..1d465742d 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command; +<<<<<<< HEAD import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; import com.boydti.fawe.config.BBC; @@ -40,6 +41,19 @@ import com.boydti.fawe.util.gui.FormBuilder; import com.boydti.fawe.wrappers.FakePlayer; import com.sk89q.minecraft.util.commands.*; import com.sk89q.worldedit.*; +======= +import static com.google.common.base.Preconditions.checkNotNull; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; +import static com.sk89q.minecraft.util.commands.Logging.LogMode.REGION; + +import com.sk89q.minecraft.util.commands.Command; +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.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.extent.PasteEvent; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; @@ -55,6 +69,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.math.transform.Transform; import com.sk89q.worldedit.regions.Region; @@ -465,9 +481,14 @@ public class ClipboardCommands extends MethodCommands { } Clipboard clipboard = holder.getClipboard(); Region region = clipboard.getRegion(); +<<<<<<< HEAD Vector to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); checkPaste(player, editSession, to, holder, clipboard); +======= + + BlockVector3 to = atOrigin ? clipboard.getOrigin() : session.getPlacementPosition(player); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner Operation operation = holder .createPaste(editSession) .to(to) @@ -478,10 +499,17 @@ public class ClipboardCommands extends MethodCommands { Operations.completeLegacy(operation); if (selectPasted) { +<<<<<<< HEAD Vector clipboardOffset = clipboard.getRegion().getMinimumPoint().subtract(clipboard.getOrigin()); Vector realTo = to.add(new Vector(holder.getTransform().apply(clipboardOffset))); Vector max = realTo.add(new Vector(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()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.setRegionSelector(player.getWorld(), selector); selector.learnChanges(); selector.explainRegionAdjust(player, session); @@ -577,14 +605,24 @@ public class ClipboardCommands extends MethodCommands { max = 1 ) @CommandPermissions("worldedit.clipboard.flip") +<<<<<<< HEAD public void flip(Player player, LocalSession session, @Optional(Direction.AIM) @Direction Vector direction) throws WorldEditException { +======= + public void flip(Player player, LocalSession session, EditSession editSession, + @Optional(Direction.AIM) @Direction BlockVector3 direction) throws WorldEditException { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner ClipboardHolder holder = session.getClipboard(); - Clipboard clipboard = holder.getClipboard(); AffineTransform transform = new AffineTransform(); +<<<<<<< HEAD transform = transform.scale(direction.positive().multiply(-2).add(1, 1, 1)); holder.setTransform(transform.combine(holder.getTransform())); BBC.COMMAND_FLIPPED.send(player); +======= + 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."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Deprecated // See SchematicCommands#clear 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 c22b3d4c1..7eb486f05 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 @@ -19,12 +19,18 @@ package com.sk89q.worldedit.command; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -67,8 +73,8 @@ public 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( @@ -76,6 +82,7 @@ public class FlattenedClipboardTransform { transform, new AffineTransform().translate(original.getOrigin())); +<<<<<<< HEAD // new Vector(minimum.getX(), minimum.getY(), minimum.getZ()) // new Vector(maximum.getX(), maximum.getY(), maximum.getZ()) Vector[] corners = new Vector[]{ @@ -87,26 +94,44 @@ public class FlattenedClipboardTransform { new Vector(minimum.getX(), maximum.getY(), maximum.getZ()), new Vector(maximum.getX(), minimum.getY(), maximum.getZ()), new Vector(maximum.getX(), maximum.getY(), minimum.getZ())}; +======= + Vector3[] corners = new Vector3[] { + minimum, + maximum, + minimum.withX(maximum.getX()), + minimum.withY(maximum.getY()), + minimum.withZ(maximum.getZ()), + maximum.withX(minimum.getX()), + maximum.withY(minimum.getY()), + maximum.withZ(minimum.getZ()) }; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner for (int i = 0; i < corners.length; i++) { corners[i] = transformAround.apply(new Vector(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 +<<<<<<< HEAD newMinimum.mutX(Math.ceil(Math.floor(newMinimum.getX()))); newMinimum.mutY(Math.ceil(Math.floor(newMinimum.getY()))); newMinimum.mutZ(Math.ceil(Math.floor(newMinimum.getZ()))); return new CuboidRegion(newMinimum, newMaximum); +======= + newMinimum = newMinimum.floor(); + newMaximum = newMaximum.ceil(); + + return new CuboidRegion(newMinimum.toBlockPoint(), newMaximum.toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** 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 27f80ed27..cea409929 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 @@ -31,9 +31,16 @@ import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; +<<<<<<< HEAD import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; @@ -42,7 +49,12 @@ import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.visitor.RegionVisitor; import com.sk89q.worldedit.internal.annotation.Selection; import com.sk89q.worldedit.internal.expression.ExpressionException; +<<<<<<< HEAD import com.sk89q.worldedit.regions.CuboidRegion; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator.TreeType; @@ -201,6 +213,7 @@ public class GenerationCommands extends MethodCommands { }, getArguments(context), (int) max, context); } +<<<<<<< HEAD @Command( aliases = {"/cyl"}, usage = " [,] [height]", @@ -224,6 +237,11 @@ public class GenerationCommands extends MethodCommands { int affected = editSession.makeCylinder(pos, pattern, radius.getX(), radius.getZ(), Math.min(256, height), !hollow); BBC.VISITOR_BLOCK.send(fp, affected); }, getArguments(context), (int) max, context); +======= + BlockVector3 pos = session.getPlacementPosition(player); + int affected = editSession.makeCylinder(pos, pattern, radiusX, radiusZ, height, !hollow); + player.print(affected + " block(s) have been created."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -259,6 +277,7 @@ public class GenerationCommands extends MethodCommands { ) @CommandPermissions("worldedit.generation.sphere") @Logging(PLACEMENT) +<<<<<<< HEAD public void sphere(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, Vector radius, @Optional("false") boolean raised, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException, ParameterException { double max = MathMan.max(radius.getBlockX(), radius.getBlockY(), radius.getBlockZ()); worldEdit.checkMaxRadius(max); @@ -269,6 +288,39 @@ public class GenerationCommands extends MethodCommands { player.findFreePosition(); BBC.VISITOR_BLOCK.send(fp, affected); }, getArguments(context), (int) max, context); +======= + public void sphere(Player player, LocalSession session, EditSession editSession, Pattern pattern, String radiusString, @Optional("false") boolean raised, @Switch('h') boolean hollow) throws WorldEditException { + String[] radii = radiusString.split(","); + final double radiusX, radiusY, radiusZ; + switch (radii.length) { + case 1: + radiusX = radiusY = radiusZ = Math.max(1, Double.parseDouble(radii[0])); + break; + + case 3: + radiusX = Math.max(1, Double.parseDouble(radii[0])); + radiusY = Math.max(1, Double.parseDouble(radii[1])); + radiusZ = Math.max(1, Double.parseDouble(radii[2])); + break; + + default: + player.printError("You must either specify 1 or 3 radius values."); + return; + } + + worldEdit.checkMaxRadius(radiusX); + worldEdit.checkMaxRadius(radiusY); + worldEdit.checkMaxRadius(radiusZ); + + BlockVector3 pos = session.getPlacementPosition(player); + if (raised) { + pos = pos.add(0, (int) radiusY, 0); + } + + int affected = editSession.makeSphere(pos, pattern, radiusX, radiusY, radiusZ, !hollow); + player.findFreePosition(); + player.print(affected + " block(s) have been created."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -324,7 +376,12 @@ public class GenerationCommands extends MethodCommands { ) @CommandPermissions("worldedit.generation.pyramid") @Logging(PLACEMENT) +<<<<<<< HEAD public void pyramid(FawePlayer fp, Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow, CommandContext context) throws WorldEditException, ParameterException { +======= + public void pyramid(Player player, LocalSession session, EditSession editSession, Pattern pattern, @Range(min = 1) int size, @Switch('h') boolean hollow) throws WorldEditException { + BlockVector3 pos = session.getPlacementPosition(player); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner worldEdit.checkMaxRadius(size); Vector pos = session.getPlacementPosition(player); fp.checkConfirmationRadius(() -> { @@ -362,33 +419,46 @@ public class GenerationCommands extends MethodCommands { @Switch('h') boolean hollow, @Switch('r') boolean useRawCoords, @Switch('o') boolean offset, +<<<<<<< HEAD @Switch('c') boolean offsetCenter, CommandContext context) throws WorldEditException, ParameterException { final Vector zero; Vector unit; +======= + @Switch('c') boolean offsetCenter) throws WorldEditException { + + final Vector3 zero; + Vector3 unit; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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); +<<<<<<< HEAD if (unit.getX() == 0) unit.mutX(1); if (unit.getY() == 0) unit.mutY(1); if (unit.getZ() == 0) unit.mutZ(1); +======= + 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); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } fp.checkConfirmationRegion(() -> { @@ -430,33 +500,53 @@ public class GenerationCommands extends MethodCommands { @Switch('h') boolean hollow, @Switch('r') boolean useRawCoords, @Switch('o') boolean offset, +<<<<<<< HEAD @Switch('c') boolean offsetCenter, CommandContext context) throws WorldEditException, ParameterException { final Vector zero; Vector unit; +======= + @Switch('c') boolean offsetCenter) throws WorldEditException { + final Vector3 zero; + Vector3 unit; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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); +<<<<<<< HEAD if (unit.getX() == 0) unit.mutX(1); if (unit.getY() == 0) unit.mutY(1); if (unit.getZ() == 0) unit.mutZ(1); +======= + 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 { + final int affected = editSession.makeBiomeShape(region, zero, unit, target, expression, hollow); + player.findFreePosition(); + player.print("" + affected + " columns affected."); + } catch (ExpressionException e) { + player.printError(e.getMessage()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } fp.checkConfirmationRegion(() -> { 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 7dab9b06c..2a846e11a 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 @@ -34,9 +34,16 @@ import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; import com.sk89q.minecraft.util.commands.Logging; +<<<<<<< HEAD import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.function.GroundFunction; @@ -51,6 +58,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; @@ -247,8 +256,8 @@ public class RegionCommands extends MethodCommands { } 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); BBC.VISITOR_BLOCK.send(player, blocksChanged); @@ -281,9 +290,14 @@ public class RegionCommands extends MethodCommands { } worldEdit.checkMaxRadius(thickness); +<<<<<<< HEAD player.checkConfirmationRegion(() -> { ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region; List vectors = new ArrayList(cpregion.getVertices()); +======= + ConvexPolyhedralRegion cpregion = (ConvexPolyhedralRegion) region; + List vectors = new ArrayList<>(cpregion.getVertices()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int blocksChanged = editSession.drawSpline(pattern, vectors, 0, 0, 0, 10, thickness, !shell); @@ -537,6 +551,7 @@ public class RegionCommands extends MethodCommands { public void move(FawePlayer player, LocalSession session, EditSession editSession, @Selection Region region, @Optional("1") @Range(min = 1) int count, +<<<<<<< HEAD @Optional(Direction.AIM) @Direction Vector direction, @Optional("air") Pattern replace, @Switch('b') boolean copyBiomes, @@ -556,6 +571,22 @@ public class RegionCommands extends MethodCommands { } catch (RegionOperationException e) { player.sendMessage(BBC.getPrefix() + e.getMessage()); } +======= + @Optional(Direction.AIM) @Direction BlockVector3 direction, + @Optional("air") BlockStateHolder replace, + @Switch('s') boolean moveSelection) throws WorldEditException { + + int affected = editSession.moveRegion(region, direction, count, true, replace); + + if (moveSelection) { + try { + region.shift(direction.multiply(count)); + + session.getRegionSelector(player.getWorld()).learnChanges(); + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); + } catch (RegionOperationException e) { + player.printError(e.getMessage()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } BBC.VISITOR_BLOCK.send(player, affected); @@ -604,8 +635,9 @@ public class RegionCommands extends MethodCommands { public void stack(FawePlayer player, LocalSession session, EditSession editSession, @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, +<<<<<<< HEAD @Switch('b') boolean copyBiomes, @Switch('e') boolean skipEntities, @Switch('a') boolean ignoreAirBlocks, @Switch('m') Mask sourceMask, CommandContext context) throws WorldEditException { @@ -626,6 +658,22 @@ public class RegionCommands extends MethodCommands { } catch (RegionOperationException e) { player.sendMessage(BBC.getPrefix() + e.getMessage()); } +======= + @Switch('a') boolean ignoreAirBlocks) throws WorldEditException { + int affected = editSession.stackCuboidRegion(region, direction, count, !ignoreAirBlocks); + + if (moveSelection) { + try { + final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()); + + final BlockVector3 shiftVector = direction.toVector3().multiply(count * (Math.abs(direction.dot(size)) + 1)).toBlockPoint(); + region.shift(shiftVector); + + session.getRegionSelector(player.getWorld()).learnChanges(); + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); + } catch (RegionOperationException e) { + player.printError(e.getMessage()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } BBC.VISITOR_BLOCK.send(player, affected); @@ -651,27 +699,39 @@ public class RegionCommands extends MethodCommands { @Selection Region region, @Text String expression, @Switch('r') boolean useRawCoords, +<<<<<<< HEAD @Switch('o') boolean offset, CommandContext context) throws WorldEditException { final Vector zero; Vector unit; +======= + @Switch('o') boolean offset) throws WorldEditException { + final Vector3 zero; + Vector3 unit; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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); +<<<<<<< HEAD if (unit.getX() == 0) unit.mutX(1); if (unit.getY() == 0) unit.mutY(1); if (unit.getZ() == 0) unit.mutZ(1); +======= + 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); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } fp.checkConfirmationRegion(() -> { 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 e9b5efc5a..114a5e971 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 @@ -32,8 +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.Vector2D; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; @@ -45,7 +43,12 @@ import com.sk89q.worldedit.extension.input.ParserContext; import com.sk89q.worldedit.extension.platform.permission.ActorSelectorLimits; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.clipboard.Clipboard; +<<<<<<< HEAD import com.sk89q.worldedit.function.mask.Mask; +======= +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; import com.sk89q.worldedit.regions.RegionSelector; @@ -66,7 +69,10 @@ 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; +<<<<<<< HEAD import com.sk89q.worldedit.world.block.BlockState; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; import java.io.File; @@ -117,6 +123,7 @@ public class SelectionCommands { } else { pos = player.getBlockIn().toVector(); } +<<<<<<< HEAD pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY()); if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) { BBC.SELECTOR_ALREADY_SET.send(player); @@ -124,6 +131,16 @@ public class SelectionCommands { } session.getRegionSelector(player.getWorld()).explainPrimarySelection(player, session, pos); +======= + + 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().toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -150,14 +167,24 @@ public class SelectionCommands { } else { pos = player.getBlockIn().toVector(); } +<<<<<<< HEAD pos = pos.clampY(0, player.getWorld().getMaximumPoint().getBlockY()); if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) { BBC.SELECTOR_ALREADY_SET.send(player); +======= + + if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { + player.printError("Position already set."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return; } session.getRegionSelector(player.getWorld()) +<<<<<<< HEAD .explainSecondarySelection(player, session, pos); +======= + .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -172,13 +199,22 @@ public class SelectionCommands { Vector pos = player.getBlockTrace(300).toVector(); if (pos != null) { +<<<<<<< HEAD if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos, ActorSelectorLimits.forActor(player))) { BBC.SELECTOR_ALREADY_SET.send(player); +======= + if (!session.getRegionSelector(player.getWorld()).selectPrimary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { + player.printError("Position already set."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return; } session.getRegionSelector(player.getWorld()) +<<<<<<< HEAD .explainPrimarySelection(player, session, pos); +======= + .explainPrimarySelection(player, session, pos.toVector().toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } else { player.printError("No block in sight!"); } @@ -196,13 +232,22 @@ public class SelectionCommands { Vector pos = player.getBlockTrace(300).toVector(); if (pos != null) { +<<<<<<< HEAD if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos, ActorSelectorLimits.forActor(player))) { BBC.SELECTOR_ALREADY_SET.send(player); +======= + if (!session.getRegionSelector(player.getWorld()).selectSecondary(pos.toVector().toBlockPoint(), ActorSelectorLimits.forActor(player))) { + player.printError("Position already set."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return; } session.getRegionSelector(player.getWorld()) +<<<<<<< HEAD .explainSecondarySelection(player, session, pos); +======= + .explainSecondarySelection(player, session, pos.toVector().toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } else { player.printError("No block in sight!"); } @@ -226,22 +271,28 @@ public class SelectionCommands { ) @Logging(POSITION) @CommandPermissions("worldedit.selection.chunk") +<<<<<<< HEAD public void chunk(Player player, LocalSession session, CommandContext args) throws WorldEditException { final Vector min; final Vector max; +======= + public void chunk(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + final BlockVector3 min; + final BlockVector3 max; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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); BBC.SELECTION_CHUNKS.send(player, 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(","); @@ -250,14 +301,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); BBC.SELECTION_CHUNK.send(player, min2D.getBlockX() + ", " + min2D.getBlockZ()); @@ -327,8 +378,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); @@ -340,7 +391,11 @@ public class SelectionCommands { return; } +<<<<<<< HEAD List dirs = new ArrayList(); +======= + List dirs = new ArrayList<>(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int change = args.getInteger(0); int reverseChange = 0; @@ -385,11 +440,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)); } } @@ -410,8 +465,14 @@ public class SelectionCommands { ) @Logging(REGION) @CommandPermissions("worldedit.selection.contract") +<<<<<<< HEAD public void contract(Player player, LocalSession session, CommandContext args) throws WorldEditException { List dirs = new ArrayList(); +======= + public void contract(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + + List dirs = new ArrayList<>(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int change = args.getInteger(0); int reverseChange = 0; @@ -455,11 +516,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,8 +544,14 @@ public class SelectionCommands { ) @Logging(REGION) @CommandPermissions("worldedit.selection.shift") +<<<<<<< HEAD public void shift(Player player, LocalSession session, CommandContext args) throws WorldEditException { List dirs = new ArrayList(); +======= + public void shift(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + + List dirs = new ArrayList<>(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int change = args.getInteger(0); if (args.argsLength() == 2) { if (args.getString(1).contains(",")) { @@ -501,7 +568,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 +627,28 @@ public class SelectionCommands { BBC.SELECTION_INSET.send(player); } +<<<<<<< HEAD private Vector[] getChangesForEachDir(CommandContext args) { List changes = new ArrayList(6); +======= + private BlockVector3[] getChangesForEachDir(CommandContext args) { + List changes = new ArrayList<>(6); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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( @@ -588,6 +660,7 @@ public class SelectionCommands { max = 0 ) @CommandPermissions("worldedit.selection.size") +<<<<<<< HEAD public void size(Player player, LocalSession session, CommandContext args) throws WorldEditException { if (args.hasFlag('c')) { ClipboardHolder root = session.getClipboard(); @@ -628,15 +701,33 @@ public class SelectionCommands { // player.print(BBC.getPrefix() + "Offset: " + origin); // player.print(BBC.getPrefix() + "Cuboid distance: " + size.distance(Vector.ONE)); // player.print(BBC.getPrefix() + "# of blocks: " + (int) (size.getX() * size.getY() * size.getZ())); +======= + 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(); + 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(BlockVector3.ONE)); + player.print("# of blocks: " + (int) (size.getX() * size.getY() * size.getZ())); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return; } Region region = session.getSelection(player.getWorld()); - Vector size = region.getMaximumPoint() + BlockVector3 size = region.getMaximumPoint() .subtract(region.getMinimumPoint()) .add(1, 1, 1); +<<<<<<< HEAD player.print(BBC.getPrefix() + "Type: " + session.getRegionSelector(player.getWorld()) +======= + player.print("Type: " + session.getRegionSelector(player.getWorld()) +>>>>>>> 399e0ad5... Refactor vector system to be cleaner .getTypeName()); for (String line : session.getRegionSelector(player.getWorld()) @@ -644,9 +735,15 @@ public class SelectionCommands { player.print(BBC.getPrefix() + line); } +<<<<<<< HEAD player.print(BBC.getPrefix() + "Size: " + size); player.print(BBC.getPrefix() + "Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint())); player.print(BBC.getPrefix() + "# of blocks: " + region.getArea()); +======= + player.print("Size: " + size); + player.print("Cuboid distance: " + region.getMaximumPoint().distance(region.getMinimumPoint())); + player.print("# of blocks: " + region.getArea()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 b4caa5208..38984f420 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command; +<<<<<<< HEAD import com.boydti.fawe.Fawe; import com.boydti.fawe.FaweAPI; import com.boydti.fawe.command.FaweParser; @@ -42,6 +43,21 @@ import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import static com.sk89q.minecraft.util.commands.Logging.LogMode.PLACEMENT; + +import com.google.common.base.Joiner; +import com.sk89q.minecraft.util.commands.Command; +import com.sk89q.minecraft.util.commands.CommandContext; +import com.sk89q.minecraft.util.commands.CommandException; +import com.sk89q.minecraft.util.commands.CommandPermissions; +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.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.command.util.CreatureButcher; import com.sk89q.worldedit.command.util.EntityRemover; import com.sk89q.worldedit.entity.Entity; @@ -64,6 +80,7 @@ import com.sk89q.worldedit.internal.annotation.Direction; 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; @@ -243,6 +260,7 @@ public class UtilityCommands extends MethodCommands { BBC.WORLDEDIT_CANCEL_COUNT.send(player, cancelled); } +<<<<<<< HEAD @Command( aliases = {"/fill"}, usage = " [depth] [direction]", @@ -258,6 +276,11 @@ public class UtilityCommands extends MethodCommands { int affected; affected = editSession.fillDirection(pos, pattern, radius, (int) depth, direction); player.print(BBC.getPrefix() + affected + " block(s) have been created."); +======= + BlockVector3 pos = session.getPlacementPosition(player); + int affected = editSession.fillXZ(pos, pattern, radius, depth, false); + player.print(affected + " block(s) have been created."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -269,12 +292,35 @@ public class UtilityCommands extends MethodCommands { ) @CommandPermissions("worldedit.fill.recursive") @Logging(PLACEMENT) +<<<<<<< HEAD public void fillr(Player player, LocalSession session, EditSession editSession, Pattern pattern, double radius, @Optional("-1") double depth) throws WorldEditException { worldEdit.checkMaxRadius(radius); Vector pos = session.getPlacementPosition(player); if (depth == -1) depth = Integer.MAX_VALUE; int affected = editSession.fillXZ(pos, pattern, radius, (int) depth, true); player.print(BBC.getPrefix() + affected + " block(s) have been created."); +======= + public void fillr(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { + + ParserContext context = new ParserContext(); + context.setActor(player); + context.setWorld(player.getWorld()); + context.setSession(session); + Pattern pattern = we.getPatternFactory().parseFromInput(args.getString(0), context); + + double radius = Math.max(1, args.getDouble(1)); + we.checkMaxRadius(radius); + int depth = args.argsLength() > 2 ? Math.max(1, args.getInteger(2)) : Integer.MAX_VALUE; + + BlockVector3 pos = session.getPlacementPosition(player); + int affected = 0; + if (pattern instanceof BlockPattern) { + affected = editSession.fillXZ(pos, ((BlockPattern) pattern).getBlock(), radius, depth, true); + } else { + affected = editSession.fillXZ(pos, pattern, radius, depth, true); + } + player.print(affected + " block(s) have been created."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Command( @@ -384,9 +430,16 @@ public class UtilityCommands extends MethodCommands { if (from == null) { from = new ExistingBlockMask(editSession); } +<<<<<<< HEAD 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); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner Region region = new CuboidRegion(player.getWorld(), min, max); int affected = editSession.replaceBlocks(region, from, to); @@ -521,8 +574,13 @@ public class UtilityCommands extends MethodCommands { EditSession editSession = null; if (player != null) { +<<<<<<< HEAD session = worldEdit.getSessionManager().get(player); Vector center = session.getPlacementPosition(player); +======= + session = we.getSessionManager().get(player); + BlockVector3 center = session.getPlacementPosition(player); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner editSession = session.createEditSession(player); List entities; if (radius >= 0) { @@ -581,8 +639,13 @@ public class UtilityCommands extends MethodCommands { EditSession editSession = null; if (player != null) { +<<<<<<< HEAD session = worldEdit.getSessionManager().get(player); Vector center = session.getPlacementPosition(player); +======= + session = we.getSessionManager().get(player); + BlockVector3 center = session.getPlacementPosition(player); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 a93a6f62c..ff102e56a 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 @@ -3,9 +3,18 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; +<<<<<<< HEAD import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Platform; +======= +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -30,7 +39,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; @@ -40,6 +49,7 @@ public class AreaPickaxe implements BlockTool { return true; } +<<<<<<< HEAD EditSession editSession = session.createEditSession(player); editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); @@ -48,6 +58,24 @@ public class AreaPickaxe implements BlockTool { for (int y = oy + range; y >= oy - range; --y) { if (initialType.equals(editSession.getLazyBlock(x, y, z))) { continue; +======= + try (EditSession editSession = session.createEditSession(player)) { + editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); + + try { + 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) { + BlockVector3 pos = new BlockVector3(x, y, z); + if (editSession.getBlock(pos).getBlockType() != initialType) { + continue; + } + + ((World) clicked.getExtent()).queueBlockBreakEffect(server, pos, initialType, clicked.toVector().toBlockPoint().distanceSq(pos)); + + editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } editSession.setBlock(x, y, z, 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 f7437ea76..53b954caa 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 @@ -26,6 +26,11 @@ 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; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.registry.state.Property; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -45,7 +50,12 @@ public class BlockDataCyler implements DoubleActionBlockTool { World world = (World) clicked.getExtent(); +<<<<<<< HEAD BlockStateHolder block = world.getBlock(clicked.toVector()); +======= + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + BlockState block = world.getBlock(blockPoint); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!config.allowedDataCycleBlocks.isEmpty() && !player.hasPermission("worldedit.override.data-cycler") @@ -57,6 +67,7 @@ public class BlockDataCyler implements DoubleActionBlockTool { if (block.getBlockType().getProperties().isEmpty()) { player.printError("That block's data cannot be cycled!"); } else { +<<<<<<< HEAD BlockStateHolder newBlock = block; // TODO Forward = cycle value, Backward = Next property @@ -70,6 +81,40 @@ public class BlockDataCyler implements DoubleActionBlockTool { player.printError("Max blocks change limit reached."); } finally { session.remember(editSession); +======= + Property currentProperty = selectedProperties.get(player.getUniqueId()); + + if (currentProperty == null || (forward && block.getState(currentProperty) == null)) { + currentProperty = block.getStates().keySet().stream().findFirst().get(); + selectedProperties.put(player.getUniqueId(), currentProperty); + } + + if (forward) { + block.getState(currentProperty); + int index = currentProperty.getValues().indexOf(block.getState(currentProperty)); + index = (index + 1) % currentProperty.getValues().size(); + BlockState newBlock = block.with(currentProperty, currentProperty.getValues().get(index)); + + try (EditSession editSession = session.createEditSession(player)) { + editSession.disableBuffering(); + + try { + 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."); + } finally { + session.remember(editSession); + } + } + } else { + List> properties = Lists.newArrayList(block.getStates().keySet()); + int index = properties.indexOf(currentProperty); + index = (index + 1) % properties.size(); + currentProperty = properties.get(index); + selectedProperties.put(player.getUniqueId(), currentProperty); + player.print("Now cycling " + currentProperty.getName()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } 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 e7f71a915..174f21921 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 @@ -29,13 +29,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; /** @@ -58,10 +58,22 @@ public class BlockReplacer implements DoubleActionBlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { BlockBag bag = session.getBlockBag(player); +<<<<<<< HEAD EditSession editSession = session.createEditSession(player); try { editSession.setBlock(clicked.toVector(), pattern); +======= + try (EditSession editSession = session.createEditSession(player)) { + try { + editSession.disableBuffering(); + BlockVector3 position = clicked.toVector().toBlockPoint(); + editSession.setBlock(position, pattern.apply(position)); + } catch (MaxChangedBlocksException ignored) { + } finally { + session.remember(editSession); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } finally { if (bag != null) { bag.flushChanges(); @@ -75,9 +87,13 @@ public class BlockReplacer implements DoubleActionBlockTool { @Override public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session, com.sk89q.worldedit.util.Location clicked) { +<<<<<<< HEAD EditSession editSession = session.createEditSession(player); BlockStateHolder targetBlock = (editSession).getBlock(clicked.toVector()); BlockType type = targetBlock.getBlockType(); +======= + BlockStateHolder targetBlock = player.getWorld().getBlock(clicked.toVector().toBlockPoint()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (type != null) { this.pattern = 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 ab88340e2..5ab140b8a 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 @@ -432,6 +432,7 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool }); } +<<<<<<< HEAD public boolean act(BrushAction action, Platform server, LocalConfiguration config, Player player, LocalSession session) { switch (action) { case PRIMARY: @@ -474,6 +475,14 @@ public class BrushTool implements DoubleActionTraceTool, ScrollTool, MovableTool MaskIntersection newMask = new MaskIntersection(existingMask); newMask.add(mask); editSession.setMask(newMask); +======= + try { + brush.build(editSession, target.toVector().toBlockPoint(), material, size); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } Mask sourceMask = current.getSourceMask(); 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 a1b51e256..4f0160070 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 @@ -24,6 +24,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; @@ -48,8 +49,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; @@ -65,8 +67,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 43a840cf6..53a0d0b4b 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,13 +69,14 @@ 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."); return true; } +<<<<<<< HEAD final EditSession editSession = session.createEditSession(player); try { @@ -89,6 +90,21 @@ public class FloatingTreeRemover implements BlockTool { final BlockState otherState = editSession.getBlock(blockVector); if (isTreeBlock(otherState.getBlockType())) { editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); +======= + try (EditSession editSession = session.createEditSession(player)) { + try { + final Set blockSet = bfs(world, clicked.toVector().toBlockPoint()); + if (blockSet == null) { + player.printError("That's not a floating tree."); + return true; + } + + for (BlockVector3 blockVector : blockSet) { + final BlockState otherState = editSession.getBlock(blockVector); + if (isTreeBlock(otherState.getBlockType())) { + editSession.setBlock(blockVector, BlockTypes.AIR.getDefaultState()); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } } catch (MaxChangedBlocksException e) { @@ -100,13 +116,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 +132,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 37644f77f..e7f663119 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,11 +19,19 @@ package com.sk89q.worldedit.command.tool; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -54,7 +62,12 @@ public class FloodFillTool implements BlockTool { public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session, Location clicked) { World world = (World) clicked.getExtent(); +<<<<<<< HEAD BlockType initialType = world.getBlockType(clicked.toVector()); +======= + BlockVector3 origin = clicked.toVector().toBlockPoint(); + BlockType initialType = world.getBlock(origin).getBlockType(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (initialType.getMaterial().isAir()) { return true; @@ -64,7 +77,19 @@ public class FloodFillTool implements BlockTool { return true; } +<<<<<<< HEAD EditSession editSession = session.createEditSession(player); +======= + try (EditSession editSession = session.createEditSession(player)) { + try { + recurse(editSession, origin, origin, range, initialType, new HashSet<>()); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } finally { + session.remember(editSession); + } + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner try { recurse(editSession, clicked.toVector().toBlockVector(), @@ -77,8 +102,13 @@ public class FloodFillTool implements BlockTool { return true; } +<<<<<<< HEAD private void recurse(EditSession editSession, BlockVector pos, Vector origin, int size, BlockType initialType, Set visited) throws WorldEditException { +======= + private void recurse(EditSession editSession, BlockVector3 pos, BlockVector3 origin, int size, BlockType initialType, + Set visited) throws MaxChangedBlocksException { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (origin.distance(pos) > size || visited.contains(pos)) { return; @@ -92,17 +122,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 789055d72..7da08e369 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 @@ -28,6 +28,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.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -55,7 +56,24 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo public boolean actSecondary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); if (pos == null) return false; +<<<<<<< HEAD EditSession eS = session.createEditSession(player); +======= + try (EditSession eS = session.createEditSession(player)) { + eS.disableBuffering(); + BlockVector3 blockPoint = pos.toVector().toBlockPoint(); + BlockStateHolder applied = secondary.apply(blockPoint); + if (applied.getBlockType().getMaterial().isAir()) { + eS.setBlock(blockPoint, secondary); + } else { + eS.setBlock(pos.getDirection().toBlockPoint(), secondary); + } + return true; + } catch (MaxChangedBlocksException e) { + // one block? eat it + } + return false; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner BlockStateHolder applied = secondary.apply(pos.toVector()); if (applied.getBlockType().getMaterial().isAir()) { @@ -70,12 +88,27 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo public boolean actPrimary(Platform server, LocalConfiguration config, Player player, LocalSession session) { Location pos = getTargetFace(player); if (pos == null) return false; +<<<<<<< HEAD EditSession eS = session.createEditSession(player); BlockStateHolder applied = primary.apply(pos.toVector()); if (applied.getBlockType().getMaterial().isAir()) { eS.setBlock(pos.toVector(), primary); } else { eS.setBlock(pos.add(pos.getDirection()), primary); +======= + try (EditSession eS = session.createEditSession(player)) { + eS.disableBuffering(); + BlockVector3 blockPoint = pos.toVector().toBlockPoint(); + BlockStateHolder applied = primary.apply(blockPoint); + if (applied.getBlockType().getMaterial().isAir()) { + eS.setBlock(blockPoint, primary); + } else { + eS.setBlock(pos.getDirection().toBlockPoint(), primary); + } + return true; + } catch (MaxChangedBlocksException e) { + // one block? eat it +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } return true; } 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 5a8f6165e..be89294d7 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 @@ -27,6 +27,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; 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; /** @@ -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 edfefdd06..22dca7ef1 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 @@ -1,5 +1,6 @@ package com.sk89q.worldedit.command.tool; +<<<<<<< HEAD import com.boydti.fawe.object.mask.IdMask; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalConfiguration; @@ -12,6 +13,16 @@ import com.sk89q.worldedit.function.block.BlockReplace; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.visitor.RecursiveVisitor; +======= +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -37,7 +48,12 @@ public class RecursivePickaxe implements BlockTool { World world = (World) clicked.getExtent(); final Vector pos = clicked.toVector(); +<<<<<<< HEAD EditSession editSession = session.createEditSession(player); +======= + BlockVector3 origin = clicked.toVector().toBlockPoint(); + BlockType initialType = world.getBlock(origin).getBlockType(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner BlockStateHolder block = editSession.getBlock(pos); if (block.getBlockType().getMaterial().isAir()) { @@ -50,6 +66,7 @@ public class RecursivePickaxe implements BlockTool { editSession.getSurvivalExtent().setToolUse(config.superPickaxeManyDrop); +<<<<<<< HEAD final int radius = (int) range; final BlockReplace replace = new BlockReplace(editSession, (editSession.nullBlock)); editSession.setMask((Mask) null); @@ -59,9 +76,54 @@ public class RecursivePickaxe implements BlockTool { editSession.flushQueue(); session.remember(editSession); +======= + try { + 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 { + session.remember(editSession); + } + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return true; } +<<<<<<< HEAD +======= + 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)) { + return; + } + + visited.add(pos); + + if (editSession.getBlock(pos).getBlockType() != initialType) { + return; + } + + world.queueBlockBreakEffect(server, pos, initialType, distanceSq); + + editSession.setBlock(pos, BlockTypes.AIR.getDefaultState()); + + recurse(server, editSession, world, pos.add(1, 0, 0), + origin, size, initialType, visited); + recurse(server, editSession, world, pos.add(-1, 0, 0), + origin, size, initialType, visited); + recurse(server, editSession, world, pos.add(0, 0, 1), + origin, size, initialType, visited); + recurse(server, editSession, world, pos.add(0, 0, -1), + origin, size, initialType, visited); + recurse(server, editSession, world, pos.add(0, 1, 0), + origin, size, initialType, visited); + recurse(server, editSession, world, pos.add(0, -1, 0), + origin, size, initialType, visited); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } \ No newline at end of file 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 21176deb7..bc53b0e37 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 @@ -25,6 +25,7 @@ import com.sk89q.worldedit.LocalSession; 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; @@ -42,6 +43,7 @@ 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(); +<<<<<<< HEAD final BlockType blockType = world.getLazyBlock(clicked.toVector()).getBlockType(); if (blockType == BlockTypes.BEDROCK && !player.canDestroyBedrock()) { return true; @@ -49,6 +51,21 @@ public class SinglePickaxe implements BlockTool { EditSession editSession = session.createEditSession(player); editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); +======= + BlockVector3 blockPoint = clicked.toVector().toBlockPoint(); + final BlockType blockType = world.getBlock(blockPoint).getBlockType(); + if (blockType == BlockTypes.BEDROCK + && !player.canDestroyBedrock()) { + return true; + } + + try (EditSession editSession = session.createEditSession(player)) { + editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); + editSession.setBlock(blockPoint, BlockTypes.AIR.getDefaultState()); + } catch (MaxChangedBlocksException e) { + player.printError("Max blocks change limit reached."); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner try { if (editSession.setBlock(clicked.getBlockX(), clicked.getBlockY(), clicked.getBlockZ(), EditSession.nullBlock)) { 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 436d42104..c36f0d691 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 @@ -50,6 +50,7 @@ public class TreePlanter implements BlockTool { EditSession editSession = session.createEditSession(player); +<<<<<<< HEAD try { boolean successful = false; @@ -57,6 +58,13 @@ public class TreePlanter implements BlockTool { if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0))) { successful = true; break; +======= + for (int i = 0; i < 10; i++) { + if (treeType.generate(editSession, clicked.toVector().add(0, 1, 0).toBlockPoint())) { + successful = true; + break; + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } 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 97a07e700..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,9 +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.WorldEditException; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; /** * A brush is a long-range build tool. @@ -39,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 WorldEditException; + 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 3aa52262c..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,10 +21,10 @@ 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.world.block.BlockTypes; 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 0e21d43e0..14eeb62c5 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,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.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; 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.world.block.BlockStateHolder; public class GravityBrush implements Brush { @@ -38,7 +38,7 @@ public class GravityBrush implements Brush { } @Override - public void build(EditSession editSession, Vector position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { + public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double sizeDouble) throws MaxChangedBlocksException { Mask mask = editSession.getMask(); if (mask == Masks.alwaysTrue() || mask == Masks.alwaysTrue2D()) { mask = null; @@ -47,12 +47,23 @@ public class GravityBrush implements Brush { int endY = position.getBlockY() + size; int startPerformY = Math.max(0, position.getBlockY() - size); int startCheckY = fullHeight ? 0 : startPerformY; - Vector mutablePos = new Vector(0, 0, 0); +// Vector mutablePos = new Vector(0, 0, 0); for (int x = position.getBlockX() + size; x > position.getBlockX() - size; --x) { for (int z = position.getBlockZ() + size; z > position.getBlockZ() - size; --z) { int freeSpot = startCheckY; for (int y = startCheckY; y <= endY; y++) { BlockStateHolder block = editSession.getLazyBlock(x, y, z); +//======= +// 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 BlockVector3 pt = new BlockVector3(x, y, z); +// final BlockStateHolder block = editSession.getBlock(pt); +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!block.getBlockType().getMaterial().isAir()) { if (y != freeSpot) { editSession.setBlock(x, y, z, EditSession.nullBlock); @@ -61,6 +72,17 @@ public class GravityBrush implements Brush { freeSpot = y + 1; } } +//<<<<<<< HEAD +//======= +// BlockVector3 pt = new BlockVector3(x, y, z); +// Collections.reverse(blockTypes); +// for (int i = 0; i < blockTypes.size();) { +// if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) { +// editSession.setBlock(pt, blockTypes.get(i++)); +// } +// pt = pt.add(0, 1, 0); +// } +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } } 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 5955531bf..be47971b7 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,12 +21,10 @@ 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.blocks.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; 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 { @@ -37,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 = 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 6c689652c..42a300048 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,17 +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.blocks.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; 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 = 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 d52ebbd4b..a187f9df9 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 @@ -23,7 +23,9 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.convolution.HeightMap; 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.HeightMapFilter; import com.sk89q.worldedit.regions.CuboidRegion; @@ -39,10 +41,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 cfcaa91e5..828e6a032 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,17 +21,16 @@ 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.blocks.BaseBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockTypes; 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(new BaseBlock(BlockTypes.COBBLESTONE)); } 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 4b0543043..a41c47d98 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 @@ -19,17 +19,20 @@ package com.sk89q.worldedit.entity; +import javax.annotation.Nullable; + import com.sk89q.worldedit.PlayerDirection; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; 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.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; /** @@ -254,13 +257,24 @@ 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. + * + *

+ * This block isn't real. + *

+ * + * @param pos The position of the block + * @param block The block to send, null to reset + */ + 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 07fdec002..eb69ef189 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 @@ -20,13 +20,17 @@ package com.sk89q.worldedit.event.extent; import com.sk89q.worldedit.EditSession; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.event.Cancellable; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 javax.annotation.Nullable; @@ -55,7 +59,11 @@ import static com.sk89q.worldedit.EditSession.Stage; * 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 +<<<<<<< HEAD * {@link EditSession#rawSetBlock(Vector, BaseBlock)} will skip your +======= + * {@link EditSession#rawSetBlock(BlockVector3, BlockStateHolder)} will skip your +>>>>>>> 399e0ad5... Refactor vector system to be cleaner * 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 39ff01699..af4533d0d 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,6 +19,7 @@ package com.sk89q.worldedit.extension.factory; +<<<<<<< HEAD import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.jnbt.JSON2NBT; import com.boydti.fawe.jnbt.NBTException; @@ -30,6 +31,13 @@ import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BaseItem; +======= +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.NotABlockException; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.world.block.BaseBlock; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.blocks.MobSpawnerBlock; import com.sk89q.worldedit.blocks.SignBlock; import com.sk89q.worldedit.blocks.SkullBlock; @@ -44,6 +52,11 @@ import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.SlottableBlockBag; import com.sk89q.worldedit.internal.registry.InputParser; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.registry.state.Property; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -198,7 +211,11 @@ public class DefaultBlockParser extends InputParser { int index = Integer.parseInt(typeString.replaceAll("[a-z]+", "")); // Get the block type from the "primary position" final World world = context.requireWorld(); +<<<<<<< HEAD final Vector primaryPosition; +======= + final BlockVector3 primaryPosition; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner try { primaryPosition = context.requireSession().getRegionSelector(world).getVerticies().get(index - 1); } 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 95248cd5b..9fd0152c4 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 @@ -1,11 +1,15 @@ package com.sk89q.worldedit.extension.factory; +<<<<<<< HEAD import com.boydti.fawe.command.FaweParser; import com.boydti.fawe.command.SuggestInputParseException; import com.boydti.fawe.config.BBC; import com.boydti.fawe.util.StringMan; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.CommandLocals; +======= +import com.sk89q.worldedit.IncompleteRegionException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.MaskCommands; import com.sk89q.worldedit.extension.input.InputParseException; @@ -16,9 +20,24 @@ import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.function.mask.BlockMaskBuilder; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.MaskIntersection; +<<<<<<< HEAD import com.sk89q.worldedit.function.mask.MaskUnion; import com.sk89q.worldedit.internal.command.ActorAuthorizer; import com.sk89q.worldedit.internal.command.WorldEditBinding; +======= +import com.sk89q.worldedit.function.mask.Masks; +import com.sk89q.worldedit.function.mask.NoiseFilter; +import com.sk89q.worldedit.function.mask.OffsetMask; +import com.sk89q.worldedit.function.mask.RegionMask; +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.session.request.Request; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.SimpleDispatcher; @@ -150,6 +169,7 @@ public class DefaultMaskParser extends FaweParser { } } } else { +<<<<<<< HEAD List args = entry.getValue(); String cmdArgs = ((args.isEmpty()) ? "" : " " + StringMan.join(args, " ")); try { @@ -178,10 +198,55 @@ public class DefaultMaskParser extends FaweParser { throw new InputParseException(e2.getMessage()); } }); +======= + throw new NoMatchException("Unrecognized mask '" + component + '\''); + } + + case '>': + case '<': + Mask submask; + if (component.length() > 1) { + submask = getBlockMaskComponent(masks, component.substring(1), context); + } else { + submask = new ExistingBlockMask(extent); + } + OffsetMask offsetMask = new OffsetMask(submask, new BlockVector3(0, firstChar == '>' ? -1 : 1, 0)); + return new MaskIntersection(offsetMask, Masks.negate(submask)); + + case '$': + Set biomes = new HashSet<>(); + String[] biomesList = component.substring(1).split(","); + BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() + .queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); + List knownBiomes = biomeRegistry.getBiomes(); + for (String biomeName : biomesList) { + BaseBiome biome = Biomes.findBiomeByName(knownBiomes, biomeName, biomeRegistry); + if (biome == null) { + throw new InputParseException("Unknown biome '" + biomeName + '\''); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } +<<<<<<< HEAD if (pe.and) { masks.add(new ArrayList<>()); +======= + + return Masks.asMask(new BiomeMask2D(context.requireExtent(), biomes)); + + case '%': + int i = Integer.parseInt(component.substring(1)); + return new NoiseFilter(new RandomNoise(), ((double) i) / 100); + + case '=': + try { + Expression exp = Expression.compile(component.substring(1), "x", "y", "z"); + WorldEditExpressionEnvironment env = new WorldEditExpressionEnvironment( + Request.request().getEditSession(), Vector3.ONE, Vector3.ZERO); + exp.setEnvironment(env); + return new ExpressionMask(exp); + } catch (ExpressionException e) { + throw new InputParseException("Invalid expression: " + e.getMessage()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } masks.get(masks.size() - 1).add(mask); } 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 e214d2e5f..4ee50469a 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,10 +21,22 @@ 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; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.BlockMaterial; +======= +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -107,7 +119,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; @@ -115,9 +127,13 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (free == 2) { if (y - 1 != origY) { +<<<<<<< HEAD final Vector pos = new Vector(x, y - 2, z); final BlockStateHolder state = world.getBlock(pos); setPosition(new Vector(x + 0.5, y - 2 + BlockType.centralTopLimit(state), z + 0.5)); +======= + setPosition(new Vector3(x + 0.5, y - 2 + 1, z + 0.5)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } return; @@ -135,10 +151,17 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { int z = searchPos.getBlockZ(); while (y >= 0) { +<<<<<<< HEAD final Vector pos = new Vector(x, y, z); final BlockStateHolder id = world.getBlock(pos); if (id.getBlockType().getMaterial().isMovementBlocker()) { setPosition(new Vector(x + 0.5, y + BlockType.centralTopLimit(id), z + 0.5)); +======= + final BlockVector3 pos = new BlockVector3(x, y, z); + final BlockState id = world.getBlock(pos); + if (id.getBlockType().getMaterial().isMovementBlocker()) { + setPosition(new Vector3(x + 0.5, y + 1, z + 0.5)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return; } @@ -162,6 +185,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { int maxY = world.getMaxY(); if (y >= maxY) return false; +<<<<<<< HEAD BlockMaterial initialMaterial = world.getBlockType(new Vector(x, y, z)).getMaterial(); boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube(); @@ -180,6 +204,29 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { if (!lastState) { lastState = BlockType.centralBottomLimit(state) != 1; continue; +======= + while (y <= world.getMaximumPoint().getY() + 2) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + ++free; + } else { + free = 0; + } + + if (free == 2) { + ++spots; + if (spots == 2) { + 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(); + + // Don't get put in lava! + if (type == BlockTypes.LAVA) { + return false; + } + + setPosition(platform.toVector3().add(0.5, 1, 0.5)); + return true; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } if (freeStart == -1) { freeStart = level + BlockType.centralTopLimit(state); @@ -213,6 +260,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { BlockMaterial initialMaterial = world.getBlockType(new Vector(x, y, z)).getMaterial(); +<<<<<<< HEAD boolean lastState = initialMaterial.isMovementBlocker() && initialMaterial.isFullCube(); double height = 1.85; @@ -241,6 +289,28 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { double space = freeEnd - freeStart; if (space >= height) { setPosition(new Vector(x + 0.5, freeStart, z + 0.5)); +======= + while (y >= 1) { + if (!world.getBlock(new BlockVector3(x, y, z)).getBlockType().getMaterial().isMovementBlocker()) { + ++free; + } else { + free = 0; + } + + if (free == 2) { + // So we've found a spot, but we have to drop the player + // lightly and also check to see if there's something to + // stand upon + while (y >= 0) { + 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.toVector3().add(0.5, 1, 0.5)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return true; } // Not enough room, reset the free position @@ -271,13 +341,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; @@ -305,7 +375,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; @@ -322,26 +392,41 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { +<<<<<<< HEAD Vector spot = new Vector(x, y - 1, z); if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { try { getLocation().getExtent().setBlock(new Vector(x, y - 1, z), BlockTypes.GLASS.getDefaultState()); } catch (WorldEditException e) { e.printStackTrace(); +======= + try { + BlockVector3 spot = new BlockVector3(x, y - 1, z); + if (!getLocation().getExtent().getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) { + getLocation().getExtent().setBlock(spot, BlockTypes.GLASS.getDefaultState()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } - setPosition(new Vector(x + 0.5, y, z + 0.5)); + setPosition(new Vector3(x + 0.5, y, z + 0.5)); } @Override public Location getBlockIn() { +<<<<<<< HEAD Location loc = getLocation(); return new Location(loc.getExtent(), loc.toBlockVector(), loc.getDirection()); +======= + return getLocation().setPosition(getLocation().toVector().floor()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Override public Location getBlockOn() { +<<<<<<< HEAD return getLocation().setY(getLocation().getY() - 1); +======= + return getLocation().setPosition(getLocation().setY(getLocation().getY() - 1).toVector().floor()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Override @@ -416,7 +501,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; @@ -450,7 +535,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()); } @@ -522,4 +607,12 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { return false; } -} \ No newline at end of file +<<<<<<< HEAD +} +======= + @Override + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { + + } +} +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 53bbe3bb3..ec952810e 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extension.platform; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.boydti.fawe.object.FawePlayer; import com.boydti.fawe.object.brush.visualization.VirtualWorld; @@ -31,9 +32,23 @@ import com.boydti.fawe.wrappers.WorldWrapper; import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.tool.*; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.LocalConfiguration; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +import com.sk89q.worldedit.command.tool.BlockTool; +import com.sk89q.worldedit.command.tool.DoubleActionBlockTool; +import com.sk89q.worldedit.command.tool.DoubleActionTraceTool; +import com.sk89q.worldedit.command.tool.Tool; +import com.sk89q.worldedit.command.tool.TraceTool; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.event.platform.*; 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.session.request.Request; import com.sk89q.worldedit.util.HandSide; @@ -290,6 +305,7 @@ public class PlatformManager { public void handleBlockInteract(BlockInteractEvent event) { // Create a proxy actor with a potentially different world for // making changes to the world +<<<<<<< HEAD Request.reset(); final Actor actor = createProxyActor(event.getCause()); try { @@ -306,6 +322,12 @@ public class PlatformManager { virtual.handleBlockInteract(playerActor, vector, event); if (event.isCancelled()) return; } +======= + Actor actor = createProxyActor(event.getCause()); + + Location location = event.getLocation(); + Vector3 vector = location.toVector(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (event.getType() == Interaction.HIT) { if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().wandItem)) { @@ -342,6 +364,7 @@ public class PlatformManager { return; } } +<<<<<<< HEAD final Tool tool = session.getTool(playerActor); if (tool != null && tool instanceof DoubleActionBlockTool) { if (tool.canUse(playerActor)) { @@ -356,6 +379,14 @@ public class PlatformManager { event.setCancelled(true); return; } +======= + + RegionSelector selector = session.getRegionSelector(player.getWorld()); + + BlockVector3 blockPoint = vector.toBlockPoint(); + if (selector.selectPrimary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainPrimarySelection(actor, session, blockPoint); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } else if (event.getType() == Interaction.OPEN) { if (session.isToolControlEnabled() && playerActor.getItemInHand(HandSide.MAIN_HAND).getType().equals(getConfiguration().wandItem)) { @@ -379,6 +410,7 @@ public class PlatformManager { return; } +<<<<<<< HEAD final Tool tool = session.getTool(playerActor); if (tool != null && tool instanceof BlockTool) { if (tool.canUse(playerActor)) { @@ -399,6 +431,23 @@ public class PlatformManager { return; } } +======= + RegionSelector selector = session.getRegionSelector(player.getWorld()); + BlockVector3 blockPoint = vector.toBlockPoint(); + if (selector.selectSecondary(blockPoint, ActorSelectorLimits.forActor(player))) { + selector.explainSecondarySelection(actor, session, blockPoint); + } + + event.setCancelled(true); + return; + } + + Tool tool = session.getTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); + if (tool instanceof BlockTool) { + if (tool.canUse(player)) { + ((BlockTool) tool).actPrimary(queryCapability(Capability.WORLD_EDITING), getConfiguration(), player, session, location); + event.setCancelled(true); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } } 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 dfc18b3ec..22295d01c 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 @@ -19,15 +19,20 @@ package com.sk89q.worldedit.extension.platform; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockStateHolder; + +import static com.google.common.base.Preconditions.checkNotNull; + 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; @@ -46,7 +51,7 @@ public class PlayerProxy extends AbstractPlayerActor { private final Actor permActor; private final Actor cuiActor; private final World world; - private Vector offset = Vector.ZERO; + private Vector3 offset = Vector3.ZERO; public PlayerProxy(Player basePlayer, Actor permActor, Actor cuiActor, World world) { checkNotNull(basePlayer); @@ -59,7 +64,7 @@ public class PlayerProxy extends AbstractPlayerActor { this.world = world; } - public void setOffset(Vector position) { + public void setOffset(Vector3 position) { this.offset = position; } @@ -106,7 +111,7 @@ public 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); } @@ -170,4 +175,10 @@ public class PlayerProxy extends AbstractPlayerActor { public void setGameMode(GameMode gameMode) { basePlayer.setGameMode(gameMode); } -} \ No newline at end of file + + @Override + 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 43ed8caed..4da1c5a86 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 @@ -22,32 +22,29 @@ package com.sk89q.worldedit.extent; import com.boydti.fawe.jnbt.anvil.generator.GenBase; import com.boydti.fawe.jnbt.anvil.generator.Resource; import com.boydti.fawe.object.extent.LightingExtent; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BlockMaterial; +import static com.google.common.base.Preconditions.checkNotNull; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; 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.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.registry.BundledBlockData; import java.util.List; import javax.annotation.Nullable; - -import static com.google.common.base.Preconditions.checkNotNull; - /** * A base class for {@link Extent}s that merely passes extents onto another. */ @@ -79,12 +76,12 @@ public class AbstractDelegateExtent implements LightingExtent { } @Override - public BlockType getBlockType(Vector position) { + public BlockType getBlockType(BlockVector3 position) { return extent.getBlockType(position); } @Override - public BlockState getFullBlock(Vector position) { + public BlockState getFullBlock(BlockVector3 position) { return extent.getFullBlock(position); } @@ -127,11 +124,6 @@ public class AbstractDelegateExtent implements LightingExtent { return extent; } - @Override - public BlockState getBlock(Vector position) { - return extent.getLazyBlock(position); - } - @Override public BlockState getLazyBlock(int x, int y, int z) { mutable.mutX(x); @@ -141,7 +133,7 @@ public class AbstractDelegateExtent implements LightingExtent { } @Override - public BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return extent.getLazyBlock(position); } @@ -152,9 +144,13 @@ public class AbstractDelegateExtent implements LightingExtent { mutable.mutZ(z); return setBlock(mutable, block); } + + public BlockState getBlock(BlockVector3 position) { + return extent.getBlock(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); } @@ -175,12 +171,12 @@ public class AbstractDelegateExtent implements LightingExtent { } @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); } @@ -195,12 +191,12 @@ public class AbstractDelegateExtent implements LightingExtent { } @Override - public Vector getMinimumPoint() { + public BlockVector3 getMinimumPoint() { return extent.getMinimumPoint(); } @Override - public Vector getMaximumPoint() { + public BlockVector3 getMaximumPoint() { return extent.getMaximumPoint(); } @@ -254,7 +250,7 @@ public class AbstractDelegateExtent implements LightingExtent { } @Override - public boolean contains(Vector pt) { + public boolean contains(BlockVector3 pt) { return extent.contains(pt); } 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 602eff780..083369b1d 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 @@ -19,20 +19,32 @@ package com.sk89q.worldedit.extent; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; +<<<<<<< HEAD import javax.annotation.Nullable; +======= +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockStateHolder; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.ArrayList; import java.util.List; @@ -59,9 +71,15 @@ public class ChangeSetExtent extends AbstractDelegateExtent { } @Override +<<<<<<< HEAD public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { BlockStateHolder previous = getBlock(location); changeSet.add(new BlockChange(location.toBlockVector(), previous, block)); +======= + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + BaseBlock previous = getFullBlock(location); + changeSet.add(new BlockChange(location, previous, block)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 ae697294b..caf69d24b 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 @@ -35,8 +35,11 @@ import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.registry.state.PropertyGroup; import com.sk89q.worldedit.session.ClipboardHolder; -import com.sk89q.worldedit.util.Location; +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.world.biome.BaseBiome; import com.sk89q.worldedit.world.block.BlockState; @@ -63,7 +66,7 @@ public interface Extent extends InputExtent, OutputExtent { * * @return the minimum point */ - Vector getMinimumPoint(); + BlockVector3 getMinimumPoint(); /** * Get the maximum point in the extent. @@ -73,7 +76,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. @@ -114,25 +117,25 @@ public interface Extent extends InputExtent, OutputExtent { } @Override - default BlockState getBlock(Vector position) { + default BlockState getBlock(BlockVector3 position) { return getFullBlock(position); } @Override - default BlockState getLazyBlock(Vector position) { + default BlockState getLazyBlock(BlockVector3 position) { return getFullBlock(position); } default BlockState getLazyBlock(int x, int y, int z) { - return getLazyBlock(MutableBlockVector.get(x, y, z)); + return getLazyBlock(new BlockVector3(x, y, z)); } default boolean setBlock(int x, int y, int z, BlockStateHolder state) throws WorldEditException { - return setBlock(MutableBlockVector.get(x, y, z), state); + return setBlock(new BlockVector3(x, y, z), state); } default boolean setBiome(int x, int y, int z, BaseBiome biome) { - return setBiome(MutableBlockVector2D.get(x, z), biome); + return setBiome(new BlockVector2(x, z), biome); } default int getHighestTerrainBlock(final int x, final int z, int minY, int maxY) { @@ -252,7 +255,7 @@ public interface Extent extends InputExtent, OutputExtent { } default void generate(Region region, GenBase gen) throws WorldEditException { - for (Vector2D chunkPos : region.getChunks()) { + for (BlockVector2 chunkPos : region.getChunks()) { gen.generate(chunkPos, this); } } @@ -263,7 +266,7 @@ public interface Extent extends InputExtent, OutputExtent { default void spawnResource(Region region, Resource gen, int rarity, int frequency) throws WorldEditException { ThreadLocalRandom random = ThreadLocalRandom.current(); - for (Vector2D chunkPos : region.getChunks()) { + for (BlockVector2 chunkPos : region.getChunks()) { for (int i = 0; i < frequency; i++) { if (random.nextInt(100) > rarity) { continue; @@ -275,9 +278,9 @@ public interface Extent extends InputExtent, OutputExtent { } } - default boolean contains(Vector pt) { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + default boolean contains(BlockVector3 pt) { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); return (pt.containedWithin(min, max)); } @@ -309,7 +312,7 @@ public interface Extent extends InputExtent, OutputExtent { default List> getBlockDistribution(final Region region) { int[] counter = new int[BlockTypes.size()]; - for (final Vector pt : region) { + for (final BlockVector3 pt : region) { BlockType type = getBlockType(pt); counter[type.getInternalId()]++; } @@ -333,7 +336,7 @@ public interface Extent extends InputExtent, OutputExtent { default List> getBlockDistributionWithData(final Region region) { int[][] counter = new int[BlockTypes.size()][]; - for (final Vector pt : region) { + for (final BlockVector3 pt : region) { BlockStateHolder blk = this.getBlock(pt); BlockType type = blk.getBlockType(); int[] stateCounter = counter[type.getInternalId()]; 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 2a2c97a0c..07f6a7f2b 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,14 +19,10 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.blocks.LazyBlock; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; 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.BlockType; @@ -49,9 +45,9 @@ public interface InputExtent { * @param position position of the block * @return the block */ - BlockState getBlock(Vector position); + BlockState getBlock(BlockVector3 position); - default BlockType getBlockType(Vector position) { + default BlockType getBlockType(BlockVector3 position) { return getBlock(position).getBlockType(); } @@ -76,7 +72,7 @@ public interface InputExtent { * @param position position of the block * @return the block */ - BlockState getLazyBlock(Vector position); + BlockState getLazyBlock(BlockVector3 position); /** * Get a immutable snapshot of the block at the given location. @@ -84,7 +80,7 @@ public interface InputExtent { * @param position position of the block * @return the block */ - BlockState getFullBlock(Vector position); + BlockState getFullBlock(BlockVector3 position); /** * Get the biome at the given location. @@ -95,6 +91,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 a3d745c47..0c6c2c622 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 @@ -19,14 +19,23 @@ package com.sk89q.worldedit.extent; +<<<<<<< HEAD import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.function.mask.Mask; +<<<<<<< HEAD import com.sk89q.worldedit.world.biome.BaseBiome; +======= +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -72,7 +81,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 538bde2a2..97a9f377a 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,9 +19,8 @@ package com.sk89q.worldedit.extent; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.LazyBlock; @@ -32,9 +31,24 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.function.operation.Operation; +======= +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.biome.BaseBiome; +<<<<<<< HEAD +======= +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; import java.util.Collections; @@ -46,18 +60,21 @@ import java.util.List; */ public class NullExtent implements Extent { +<<<<<<< HEAD private final Vector nullPoint = new Vector(0, 0, 0); public static final NullExtent INSTANCE = new NullExtent(); +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner @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 @@ -77,11 +94,12 @@ public class NullExtent implements Extent { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); } @Override +<<<<<<< HEAD public BlockState getLazyBlock(Vector position) { return BlockTypes.AIR.getDefaultState(); } @@ -89,21 +107,25 @@ public class NullExtent implements Extent { @Override public BlockState getFullBlock(Vector position) { return new BaseBlock(getBlock(position)); +======= + public BaseBlock getFullBlock(BlockVector3 position) { + return getBlock(position).toBaseBlock(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @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 fe1ac4936..5ecd2cca0 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,12 +19,12 @@ 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.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; 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 javax.annotation.Nullable; @@ -51,7 +51,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. @@ -60,7 +60,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 9ea2e1fd6..5538f822d 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,8 +21,6 @@ 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.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; @@ -32,6 +30,8 @@ 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; @@ -45,19 +45,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()); @@ -67,7 +67,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) { @@ -78,22 +78,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; @@ -103,8 +103,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 { @@ -120,32 +120,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 851cb192b..b13a76c4d 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 f4031bc5e..08ee58487 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.extent.clipboard; +<<<<<<< HEAD import com.boydti.fawe.config.Settings; import com.boydti.fawe.object.clipboard.DiskOptimizedClipboard; import com.boydti.fawe.object.clipboard.FaweClipboard; @@ -32,12 +33,24 @@ import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.world.block.BaseBlock; +import com.sk89q.worldedit.world.block.BlockState; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import java.io.Closeable; @@ -56,6 +69,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable { +<<<<<<< HEAD private Region region; public FaweClipboard IMP; private Vector size; @@ -75,6 +89,12 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.my = origin.getBlockY(); this.mz = origin.getBlockZ(); } +======= + private final Region region; + private BlockVector3 origin; + private final BlockStateHolder[][][] blocks; + private final List entities = new ArrayList<>(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Create a new instance. @@ -94,6 +114,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable this.mz = origin.getBlockZ(); } +<<<<<<< HEAD public BlockArrayClipboard(Region region, FaweClipboard clipboard) { checkNotNull(region); this.region = region.clone(); @@ -125,6 +146,10 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable @Override public void close() { IMP.close(); +======= + BlockVector3 dimensions = getDimensions(); + blocks = new BlockStateHolder[dimensions.getBlockX()][dimensions.getBlockY()][dimensions.getBlockZ()]; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Override @@ -137,36 +162,42 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable } @Override - public Vector getOrigin() { + public BlockVector3 getOrigin() { return origin; } @Override - public void setOrigin(Vector origin) { + public void setOrigin(BlockVector3 origin) { this.origin = origin; IMP.setOrigin(origin.subtract(region.getMinimumPoint())); } @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(); } @Override public List getEntities(Region region) { +<<<<<<< HEAD List filtered = new ArrayList(); for (Entity entity : getEntities()) { if (region.contains(entity.getLocation().toVector())) { +======= + List filtered = new ArrayList<>(); + for (Entity entity : entities) { + if (region.contains(entity.getLocation().toVector().toBlockPoint())) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner filtered.add(entity); } } @@ -185,12 +216,20 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { if (region.contains(position)) { +<<<<<<< HEAD int x = position.getBlockX() - mx; int y = position.getBlockY() - my; int z = position.getBlockZ() - mz; return IMP.getBlock(x, y, z); +======= + BlockVector3 v = position.subtract(region.getMinimumPoint()); + BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()]; + if (block != null) { + return block.toImmutableState(); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } return EditSession.nullBlock; } @@ -200,9 +239,20 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable } @Override +<<<<<<< HEAD public BlockState getLazyBlock(Vector position) { return getBlock(position); } +======= + public BaseBlock getFullBlock(BlockVector3 position) { + if (region.contains(position)) { + BlockVector3 v = position.subtract(region.getMinimumPoint()); + BlockStateHolder block = blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()]; + if (block != null) { + return block.toBaseBlock(); + } + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner @Override public BlockState getFullBlock(Vector position) { @@ -210,12 +260,22 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable } @Override +<<<<<<< HEAD public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { if (region.contains(location)) { final int x = location.getBlockX(); final int y = location.getBlockY(); final int z = location.getBlockZ(); return setBlock(x, y, z, block); +======= + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + if (region.contains(position)) { + BlockVector3 v = position.subtract(region.getMinimumPoint()); + blocks[v.getBlockX()][v.getBlockY()][v.getBlockZ()] = block; + return true; + } else { + return false; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } return false; } @@ -236,6 +296,7 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable } @Override +<<<<<<< HEAD public BaseBiome getBiome(Vector2D position) { int x = position.getBlockX() - mx; int z = position.getBlockZ() - mz; @@ -248,6 +309,15 @@ public class BlockArrayClipboard implements Clipboard, LightingExtent, Closeable int z = position.getBlockZ() - mz; IMP.setBiome(x, z, biome.getId()); return true; +======= + public BaseBiome getBiome(BlockVector2 position) { + return new BaseBiome(0); + } + + @Override + public boolean setBiome(BlockVector2 position, BaseBiome biome) { + return false; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Nullable 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 new file mode 100644 index 000000000..f278595a0 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/clipboard/io/MCEditSchematicReader.java @@ -0,0 +1,316 @@ +/* + * 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.extent.clipboard.io; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.jnbt.ByteArrayTag; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.ListTag; +import com.sk89q.jnbt.NBTInputStream; +import com.sk89q.jnbt.NamedTag; +import com.sk89q.jnbt.ShortTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; +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; +import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.entity.EntityType; +import com.sk89q.worldedit.world.entity.EntityTypes; +import com.sk89q.worldedit.world.registry.LegacyMapper; +import com.sk89q.worldedit.world.storage.NBTConversions; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Reads schematic files that are compatible with MCEdit and other editors. + */ +public class MCEditSchematicReader extends NBTSchematicReader { + + private static final List COMPATIBILITY_HANDLERS = new ArrayList<>(); + + static { + COMPATIBILITY_HANDLERS.add(new SignCompatibilityHandler()); + // TODO Add a handler for skulls, flower pots, note blocks, etc. + } + + private static final Logger log = Logger.getLogger(MCEditSchematicReader.class.getCanonicalName()); + private final NBTInputStream inputStream; + + /** + * Create a new instance. + * + * @param inputStream the input stream to read from + */ + public MCEditSchematicReader(NBTInputStream inputStream) { + checkNotNull(inputStream); + this.inputStream = inputStream; + } + + @Override + public Clipboard read() throws IOException { + // Schematic tag + NamedTag rootTag = inputStream.readNamedTag(); + if (!rootTag.getName().equals("Schematic")) { + throw new IOException("Tag 'Schematic' does not exist or is not first"); + } + CompoundTag schematicTag = (CompoundTag) rootTag.getTag(); + + // Check + Map schematic = schematicTag.getValue(); + if (!schematic.containsKey("Blocks")) { + throw new IOException("Schematic file is missing a 'Blocks' tag"); + } + + // Check type of Schematic + String materials = requireTag(schematic, "Materials", StringTag.class).getValue(); + if (!materials.equals("Alpha")) { + throw new IOException("Schematic file is not an Alpha schematic"); + } + + // ==================================================================== + // Metadata + // ==================================================================== + + BlockVector3 origin; + Region region; + + // Get information + short width = requireTag(schematic, "Width", ShortTag.class).getValue(); + short height = requireTag(schematic, "Height", ShortTag.class).getValue(); + short length = requireTag(schematic, "Length", ShortTag.class).getValue(); + + try { + int originX = requireTag(schematic, "WEOriginX", IntTag.class).getValue(); + int originY = requireTag(schematic, "WEOriginY", IntTag.class).getValue(); + int originZ = requireTag(schematic, "WEOriginZ", IntTag.class).getValue(); + 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(); + BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ); + + origin = min.subtract(offset); + region = new CuboidRegion(min, min.add(width, height, length).subtract(BlockVector3.ONE)); + } catch (IOException ignored) { + origin = BlockVector3.ZERO; + region = new CuboidRegion(origin, origin.add(width, height, length).subtract(BlockVector3.ONE)); + } + + // ==================================================================== + // Blocks + // ==================================================================== + + // Get blocks + byte[] blockId = requireTag(schematic, "Blocks", ByteArrayTag.class).getValue(); + byte[] blockData = requireTag(schematic, "Data", ByteArrayTag.class).getValue(); + byte[] addId = new byte[0]; + short[] blocks = new short[blockId.length]; // Have to later combine IDs + + // We support 4096 block IDs using the same method as vanilla Minecraft, where + // the highest 4 bits are stored in a separate byte array. + if (schematic.containsKey("AddBlocks")) { + addId = requireTag(schematic, "AddBlocks", ByteArrayTag.class).getValue(); + } + + // Combine the AddBlocks data with the first 8-bit block ID + for (int index = 0; index < blockId.length; index++) { + if ((index >> 1) >= addId.length) { // No corresponding AddBlocks index + blocks[index] = (short) (blockId[index] & 0xFF); + } else { + if ((index & 1) == 0) { + blocks[index] = (short) (((addId[index >> 1] & 0x0F) << 8) + (blockId[index] & 0xFF)); + } else { + blocks[index] = (short) (((addId[index >> 1] & 0xF0) << 4) + (blockId[index] & 0xFF)); + } + } + } + + // Need to pull out tile entities + List tileEntities = requireTag(schematic, "TileEntities", ListTag.class).getValue(); + Map> tileEntitiesMap = new HashMap<>(); + + for (Tag tag : tileEntities) { + if (!(tag instanceof CompoundTag)) continue; + CompoundTag t = (CompoundTag) tag; + + int x = 0; + int y = 0; + int z = 0; + + Map values = new HashMap<>(); + + for (Map.Entry entry : t.getValue().entrySet()) { + switch (entry.getKey()) { + case "x": + if (entry.getValue() instanceof IntTag) { + x = ((IntTag) entry.getValue()).getValue(); + } + break; + case "y": + if (entry.getValue() instanceof IntTag) { + y = ((IntTag) entry.getValue()).getValue(); + } + break; + case "z": + if (entry.getValue() instanceof IntTag) { + z = ((IntTag) entry.getValue()).getValue(); + } + break; + } + + values.put(entry.getKey(), entry.getValue()); + } + + int index = y * width * length + z * width + x; + BlockState block = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]); + if (block != null) { + for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) { + if (handler.isAffectedBlock(block)) { + handler.updateNBT(block, values); + } + } + } + + BlockVector3 vec = new BlockVector3(x, y, z); + tileEntitiesMap.put(vec, values); + } + + BlockArrayClipboard clipboard = new BlockArrayClipboard(region); + clipboard.setOrigin(origin); + + // Don't log a torrent of errors + int failedBlockSets = 0; + + for (int x = 0; x < width; ++x) { + for (int y = 0; y < height; ++y) { + for (int z = 0; z < length; ++z) { + int index = y * width * length + z * width + x; + BlockVector3 pt = new BlockVector3(x, y, z); + BlockState state = LegacyMapper.getInstance().getBlockFromLegacy(blocks[index], blockData[index]); + + try { + if (state != null) { + if (tileEntitiesMap.containsKey(pt)) { + clipboard.setBlock(region.getMinimumPoint().add(pt), state.toBaseBlock(new CompoundTag(tileEntitiesMap.get(pt)))); + } else { + clipboard.setBlock(region.getMinimumPoint().add(pt), state); + } + } else { + log.warning("Unknown block when pasting schematic: " + blocks[index] + ":" + blockData[index] + ". Please report this issue."); + } + } catch (WorldEditException e) { + switch (failedBlockSets) { + case 0: + log.log(Level.WARNING, "Failed to set block on a Clipboard", e); + break; + case 1: + log.log(Level.WARNING, "Failed to set block on a Clipboard (again) -- no more messages will be logged", e); + break; + default: + } + + failedBlockSets++; + } + } + } + } + + // ==================================================================== + // Entities + // ==================================================================== + + try { + List entityTags = requireTag(schematic, "Entities", ListTag.class).getValue(); + + for (Tag tag : entityTags) { + if (tag instanceof CompoundTag) { + CompoundTag compound = (CompoundTag) tag; + String id = convertEntityId(compound.getString("id")); + Location location = NBTConversions.toLocation(clipboard, compound.getListTag("Pos"), compound.getListTag("Rotation")); + + if (!id.isEmpty()) { + EntityType entityType = EntityTypes.get(id.toLowerCase()); + if (entityType != null) { + BaseEntity state = new BaseEntity(entityType, compound); + clipboard.createEntity(location, state); + } else { + log.warning("Unknown entity when pasting schematic: " + id.toLowerCase()); + } + } + } + } + } catch (IOException ignored) { // No entities? No problem + } + + return clipboard; + } + + private String convertEntityId(String id) { + switch(id) { + case "xp_orb": + return "experience_orb"; + case "xp_bottle": + return "experience_bottle"; + case "eye_of_ender_signal": + return "eye_of_ender"; + case "ender_crystal": + return "end_crystal"; + case "fireworks_rocket": + return "firework_rocket"; + case "commandblock_minecart": + return "command_block_minecart"; + case "snowman": + return "snow_golem"; + case "villager_golem": + return "iron_golem"; + case "evocation_fangs": + return "evoker_fangs"; + case "evocation_illager": + return "evoker"; + case "vindication_illager": + return "vindicator"; + case "illusion_illager": + return "illusioner"; + } + return id; + } + + @Override + public void close() throws IOException { + inputStream.close(); + } +} 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 4c54af4e8..6fb964435 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 @@ -42,8 +42,12 @@ import com.sk89q.jnbt.NamedTag; import com.sk89q.jnbt.ShortTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.WorldEdit; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.entity.BaseEntity; @@ -51,6 +55,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; @@ -103,10 +108,18 @@ public class SpongeSchematicReader extends NBTSchematicReader { return read(UUID.randomUUID()); } +<<<<<<< HEAD @Override public Clipboard read(UUID uuid) throws IOException { return readVersion1(uuid); } +======= + private Clipboard readVersion1(Map schematic) throws IOException { + BlockVector3 origin; + Region region; + + Map metadata = requireTag(schematic, "Metadata", CompoundTag.class).getValue(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner private int width, height, length; private int offsetX, offsetY, offsetZ; @@ -121,12 +134,35 @@ public class SpongeSchematicReader extends NBTSchematicReader { } return fc; } +<<<<<<< HEAD if (Settings.IMP.CLIPBOARD.USE_DISK) { return fc = new DiskOptimizedClipboard(size, 1, 1, uuid); } else if (Settings.IMP.CLIPBOARD.COMPRESSION_LEVEL == 0) { return fc = new CPUOptimizedClipboard(size, 1, 1); } else { return fc = new MemoryOptimizedClipboard(size, 1, 1); +======= + + 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(); + BlockVector3 offset = new BlockVector3(offsetX, offsetY, offsetZ); + origin = min.subtract(offset); + 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(BlockVector3.ONE)); + } + + int paletteMax = requireTag(schematic, "PaletteMax", IntTag.class).getValue(); + Map paletteObject = requireTag(schematic, "Palette", CompoundTag.class).getValue(); + if (paletteObject.size() != paletteMax) { + throw new IOException("Differing given palette size to actual size"); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } @@ -152,6 +188,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { int index = ((IntTag) entry.getValue()).getValue(); palette[index] = (char) state.getOrdinal(); } +<<<<<<< HEAD }); streamer.addReader("Schematic.BlockData.#", new NBTStreamer.LazyReader() { @Override @@ -161,6 +198,23 @@ public class SpongeSchematicReader extends NBTSchematicReader { } catch (IOException e) { e.printStackTrace(); } +======= + palette.put(id, state); + } + + byte[] blocks = requireTag(schematic, "BlockData", ByteArrayTag.class).getValue(); + + Map> tileEntitiesMap = new HashMap<>(); + try { + List> tileEntityTags = requireTag(schematic, "TileEntities", ListTag.class).getValue().stream() + .map(tag -> (CompoundTag) tag) + .map(CompoundTag::getValue) + .collect(Collectors.toList()); + + for (Map tileEntity : tileEntityTags) { + int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue(); + tileEntitiesMap.put(new BlockVector3(pos[0], pos[1], pos[2]), tileEntity); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } }); streamer.addReader("Schematic.Biomes.#", new NBTStreamer.LazyReader() { @@ -207,6 +261,7 @@ public class SpongeSchematicReader extends NBTSchematicReader { Fawe.debug("Invalid entity: " + id); } } +<<<<<<< HEAD }); streamer.readFully(); if (fc == null) setupClipboard(length * width * height, uuid); @@ -225,6 +280,21 @@ public class SpongeSchematicReader extends NBTSchematicReader { for (int index = 0; index < volume; index++) { BlockState state = BlockTypes.states[palette[fis.read()]]; fc.setBlock(index, state); +======= + // index = (y * length + z) * width + x + int y = index / (width * length); + int z = (index % (width * length)) / width; + int x = (index % (width * length)) % width; + BlockState state = palette.get(value); + BlockVector3 pt = new BlockVector3(x, y, z); + try { + if (tileEntitiesMap.containsKey(pt)) { + Map values = Maps.newHashMap(tileEntitiesMap.get(pt)); + for (NBTCompatibilityHandler handler : COMPATIBILITY_HANDLERS) { + if (handler.isAffectedBlock(state)) { + handler.updateNBT(state, values); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } else { for (int index = 0; index < volume; index++) { 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 9956b9dbe..8a4a3345b 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 @@ -27,15 +27,23 @@ import com.sk89q.jnbt.NBTConstants; import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; +<<<<<<< HEAD import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; import net.jpountz.lz4.LZ4BlockInputStream; import net.jpountz.lz4.LZ4BlockOutputStream; +======= +import com.sk89q.worldedit.world.block.BaseBlock; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -75,9 +83,15 @@ public class SpongeSchematicWriter implements ClipboardWriter { public void write1(Clipboard clipboard) throws IOException { // metadata Region region = clipboard.getRegion(); +<<<<<<< HEAD Vector origin = clipboard.getOrigin(); BlockVector min = region.getMinimumPoint().toBlockVector(); Vector offset = min.subtract(origin); +======= + BlockVector3 origin = clipboard.getOrigin(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 offset = min.subtract(origin); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int width = region.getWidth(); int height = region.getHeight(); int length = region.getLength(); @@ -90,6 +104,7 @@ public class SpongeSchematicWriter implements ClipboardWriter { if (length > MAX_SIZE) { throw new IllegalArgumentException("Length of region too large for a .schematic"); } +<<<<<<< HEAD // output final DataOutput rawStream = outputStream.getOutputStream(); outputStream.writeLazyCompoundTag("Schematic", out -> { @@ -142,6 +157,49 @@ public class SpongeSchematicWriter implements ClipboardWriter { })); numTiles[0]++; tilesOut.writeTagPayload(tile); +======= + + Map schematic = new HashMap<>(); + schematic.put("Version", new IntTag(1)); + + Map metadata = new HashMap<>(); + metadata.put("WEOffsetX", new IntTag(offset.getBlockX())); + metadata.put("WEOffsetY", new IntTag(offset.getBlockY())); + metadata.put("WEOffsetZ", new IntTag(offset.getBlockZ())); + + schematic.put("Metadata", new CompoundTag(metadata)); + + schematic.put("Width", new ShortTag((short) width)); + schematic.put("Height", new ShortTag((short) height)); + schematic.put("Length", new ShortTag((short) length)); + + // The Sponge format Offset refers to the 'min' points location in the world. That's our 'Origin' + schematic.put("Offset", new IntArrayTag(new int[]{ + min.getBlockX(), + min.getBlockY(), + min.getBlockZ(), + })); + + int paletteMax = 0; + Map palette = new HashMap<>(); + + List tileEntities = new ArrayList<>(); + + ByteArrayOutputStream buffer = new ByteArrayOutputStream(width * height * length); + + for (int y = 0; y < height; y++) { + int y0 = min.getBlockY() + y; + for (int z = 0; z < length; z++) { + int z0 = min.getBlockZ() + z; + for (int x = 0; x < width; x++) { + int x0 = min.getBlockX() + x; + BlockVector3 point = new BlockVector3(x0, y0, z0); + BaseBlock block = clipboard.getFullBlock(point); + if (block.getNbtData() != null) { + Map values = new HashMap<>(); + for (Map.Entry entry : block.getNbtData().getValue().entrySet()) { + values.put(entry.getKey(), entry.getValue()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } int ordinal = block.getOrdinal(); char value = palette[ordinal]; 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 85bbe66a5..68b19e927 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 @@ -1,10 +1,18 @@ package com.sk89q.worldedit.extent.inventory; +<<<<<<< HEAD import com.boydti.fawe.object.exception.FaweException; 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.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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -82,9 +90,15 @@ public class BlockBagExtent extends AbstractDelegateExtent { } @Override +<<<<<<< HEAD public boolean setBlock(Vector pos, BlockStateHolder block) throws WorldEditException { return setBlock(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), block); } +======= + public boolean setBlock(BlockVector3 position, BlockStateHolder block) throws WorldEditException { + if (blockBag != null) { + BlockState existing = getExtent().getBlock(position); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner @Override public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { 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 new file mode 100644 index 000000000..92a3b6188 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/reorder/ChunkBatchingExtent.java @@ -0,0 +1,118 @@ +/* + * 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.extent.reorder; + +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; + +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.SortedMap; +import java.util.TreeMap; + +/** + * A special extent that batches changes into Minecraft chunks. This helps + * improve the speed of setting the blocks, since chunks do not need to be + * loaded repeatedly, however it does take more memory due to caching the + * blocks. + */ +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((BlockVector2 vec) -> vec.divide(32), BlockVector2.COMPARING_GRID_ARRANGEMENT) + .thenComparing(BlockVector2.COMPARING_GRID_ARRANGEMENT); + + private final SortedMap batches = new TreeMap<>(REGION_OPTIMIZED_SORT); + private boolean enabled; + + public ChunkBatchingExtent(Extent extent) { + this(extent, true); + } + + public ChunkBatchingExtent(Extent extent, boolean enabled) { + super(extent); + this.enabled = enabled; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + @Override + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + if (!enabled) { + return getExtent().setBlock(location, block); + } + BlockVector2 chunkPos = new BlockVector2(location.getBlockX() >> 4, location.getBlockZ() >> 4); + batches.computeIfAbsent(chunkPos, k -> new LocatedBlockList()).add(location, block); + return true; + } + + @Override + protected Operation commitBefore() { + if (!enabled) { + return null; + } + return new Operation() { + + // we get modified between create/resume -- only create this on resume to prevent CME + private Iterator batchIterator; + + @Override + public Operation resume(RunContext run) throws WorldEditException { + if (batchIterator == null) { + batchIterator = batches.values().iterator(); + } + if (!batchIterator.hasNext()) { + return null; + } + new SetLocatedBlocks(getExtent(), batchIterator.next()).resume(run); + batchIterator.remove(); + return this; + } + + @Override + public void cancel() { + } + + @Override + public void addStatusMessages(List messages) { + } + }; + } + +} 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 3c0a1c8fc..ba0d77070 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 @@ -19,9 +19,13 @@ package com.sk89q.worldedit.extent.reorder; +<<<<<<< HEAD import com.google.common.collect.Iterators; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; +======= +import com.google.common.collect.Iterables; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.Blocks; import com.sk89q.worldedit.extent.AbstractDelegateExtent; @@ -30,6 +34,11 @@ import com.sk89q.worldedit.function.operation.BlockMapEntryPlacer; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.operation.RunContext; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.function.operation.SetLocatedBlocks; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.util.collection.TupleArrayList; import com.sk89q.worldedit.world.block.BlockCategories; @@ -94,8 +103,13 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder } @Override +<<<<<<< HEAD public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { BlockStateHolder existing = getBlock(location); +======= + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + BlockState existing = getBlock(location); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!enabled) { return super.setBlock(location, block); @@ -103,18 +117,30 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder if (Blocks.shouldPlaceLast(block.getBlockType())) { // Place torches, etc. last +<<<<<<< HEAD stage2.put(location.toBlockVector(), block); return !existing.equalsFuzzy(block); } else if (Blocks.shouldPlaceFinal(block.getBlockType())) { // Place signs, reed, etc even later stage3.put(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, block); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 { +<<<<<<< HEAD stage1.put(location.toBlockVector(), block); +======= + stage1.add(location, block); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return !existing.equalsFuzzy(block); } } @@ -134,21 +160,28 @@ public class MultiStageReorder extends AbstractDelegateExtent implements Reorder public Operation resume(RunContext run) throws WorldEditException { Extent extent = getExtent(); +<<<<<<< HEAD final Set blocks = new HashSet<>(); final Map blockTypes = new HashMap<>(); for (Map.Entry entry : stage3) { final BlockVector pt = entry.getKey(); +======= + final Set blocks = new HashSet<>(); + final Map blockTypes = new HashMap<>(); + for (LocatedBlock entry : stage3) { + final BlockVector3 pt = entry.getLocation(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner blocks.add(pt); blockTypes.put(pt, entry.getValue()); } 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); @@ -161,13 +194,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); } @@ -191,7 +224,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 30cfb8034..82db00bd2 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 @@ -1,5 +1,6 @@ package com.sk89q.worldedit.extent.transform; +<<<<<<< HEAD import com.boydti.fawe.object.extent.ResettableExtent; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.ByteTag; @@ -14,9 +15,25 @@ import com.sk89q.worldedit.internal.helper.MCDirections; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.registry.state.AbstractProperty; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.Sets; +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.math.Vector3; +import com.sk89q.worldedit.math.transform.Transform; +import com.sk89q.worldedit.registry.state.BooleanProperty; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.registry.state.DirectionalProperty; import com.sk89q.worldedit.util.Direction; +<<<<<<< HEAD import com.sk89q.worldedit.world.biome.BaseBiome; +======= +import com.sk89q.worldedit.world.block.BaseBlock; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -60,11 +77,70 @@ public class BlockTransformExtent extends ResettableExtent { case ROTATION: +<<<<<<< HEAD case AXIS: case FACING: case SHAPE: +======= + @Override + public BlockState getBlock(BlockVector3 position) { + return transformBlock(super.getBlock(position), false); + } + + @Override + public BaseBlock getFullBlock(BlockVector3 position) { + return transformBlock(super.getFullBlock(position), false); + } + + @Override + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException { + return super.setBlock(location, transformBlock(block, true)); + } + + + /** + * Transform the given block using the given transform. + * + *

The provided block is modified.

+ * + * @param block the block + * @param transform the transform + * @return the same block + */ + public static T transform(T block, Transform transform) { + return transform(block, transform, block); + } + + private static final Set directionNames = Sets.newHashSet("north", "south", "east", "west"); + + /** + * Transform the given block using the given transform. + * + * @param block the block + * @param transform the transform + * @param changedBlock the block to change + * @return the changed block + */ + private static T transform(T block, Transform transform, T changedBlock) { + checkNotNull(block); + checkNotNull(transform); + + List properties = block.getBlockType().getProperties(); + + for (Property property : properties) { + if (property instanceof DirectionalProperty) { + Direction value = (Direction) block.getState(property); + if (value != null) { + Vector3 newValue = getNewStateValue((DirectionalProperty) property, transform, value.toVector()); + if (newValue != null) { + changedBlock = (T) changedBlock.with(property, Direction.findClosest(newValue, Direction.Flag.ALL)); + } + } + } + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner case NORTH: case EAST: @@ -76,12 +152,19 @@ public class BlockTransformExtent extends ResettableExtent { } @Nullable +<<<<<<< HEAD private static Integer getNewStateIndex(Transform transform, List directions, int oldIndex) { Direction oldDirection = directions.get(oldIndex); Vector oldVector = oldDirection.toVector(); Vector newVector = transform.apply(oldVector).subtract(transform.apply(Vector.ZERO)).normalize(); int newIndex = oldIndex; double closest = oldVector.toVector().normalize().dot(newVector); +======= + 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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner boolean found = false; for (int i = 0; i < directions.size(); i++) { 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 da0fd9ecc..0589c1508 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 @@ -20,14 +20,18 @@ package com.sk89q.worldedit.extent.validation; import com.sk89q.worldedit.MaxChangedBlocksException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.AbstractDelegateExtent; import com.sk89q.worldedit.extent.Extent; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkArgument; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockStateHolder; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Limits the number of blocks that can be changed before a @@ -78,7 +82,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 43c40429a..c2c84e2c3 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 @@ -19,13 +19,19 @@ package com.sk89q.worldedit.extent.validation; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; 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 static com.google.common.base.Preconditions.checkNotNull; @@ -50,7 +56,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 d98ba4172..9bb136469 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,8 +21,14 @@ package com.sk89q.worldedit.extent.world; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.World; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -52,7 +58,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 6a2179099..aec39eaa2 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 @@ -19,12 +19,18 @@ package com.sk89q.worldedit.extent.world; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; 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 static com.google.common.base.Preconditions.checkNotNull; @@ -62,7 +68,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 00af5970f..339a049ef 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 @@ -19,14 +19,21 @@ package com.sk89q.worldedit.extent.world; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; 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 java.util.HashSet; @@ -41,7 +48,7 @@ import static com.google.common.base.Preconditions.checkNotNull; 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; /** @@ -85,9 +92,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 85a2eccdd..bfb3db93b 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 @@ -19,11 +19,17 @@ package com.sk89q.worldedit.extent.world; +<<<<<<< HEAD import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -80,7 +86,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 be8602416..d266025b2 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 @@ -19,8 +19,10 @@ package com.sk89q.worldedit.function; -import com.sk89q.worldedit.Vector; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.math.BlockVector3; import java.util.*; @@ -95,7 +97,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 35a9802e4..d909779b6 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 @@ -19,14 +19,20 @@ package com.sk89q.worldedit.function; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask2D; +import com.sk89q.worldedit.math.BlockVector2; import static com.google.common.base.Preconditions.checkNotNull; /** - * 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 +56,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 f45c5694d..cbd607f04 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 @@ -19,9 +19,15 @@ package com.sk89q.worldedit.function; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import static com.google.common.base.Preconditions.checkNotNull; @@ -77,12 +83,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 1f773a188..954fda239 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 @@ -19,14 +19,20 @@ package com.sk89q.worldedit.function; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import static com.google.common.base.Preconditions.checkNotNull; /** - * 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 +55,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 f877adce5..88d616ef6 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 @@ -19,10 +19,16 @@ package com.sk89q.worldedit.function.biome; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; import static com.google.common.base.Preconditions.checkNotNull; @@ -49,7 +55,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 new file mode 100644 index 000000000..258e02871 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/block/BlockDistributionCounter.java @@ -0,0 +1,77 @@ +/* + * 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.function.block; + +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; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class BlockDistributionCounter implements RegionFunction { + + private Extent extent; + private boolean fuzzy; + + private List> distribution = new ArrayList<>(); + private Map> map = new HashMap<>(); + + public BlockDistributionCounter(Extent extent, boolean fuzzy) { + this.extent = extent; + this.fuzzy = fuzzy; + } + + @Override + public boolean apply(BlockVector3 position) throws WorldEditException { + BlockStateHolder blk = extent.getBlock(position); + if (fuzzy) { + blk = ((BlockState) blk).toFuzzy(); + } + + if (map.containsKey(blk)) { + map.get(blk).increment(); + } else { + Countable c = new Countable<>(blk, 1); + map.put(blk, c); + distribution.add(c); + } + + return true; + } + + /** + * Gets the distribution list. + * + * @return The distribution + */ + public List> getDistribution() { + Collections.sort(distribution); + Collections.reverse(distribution); + return this.distribution; + } +} 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 6a21edc94..8bcac8efb 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 @@ -19,11 +19,17 @@ package com.sk89q.worldedit.function.block; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; import static com.google.common.base.Preconditions.checkNotNull; @@ -50,8 +56,13 @@ public class BlockReplace implements RegionFunction { } @Override +<<<<<<< HEAD public boolean apply(Vector position) throws WorldEditException { return pattern.apply(extent, position, position); +======= + public boolean apply(BlockVector3 position) throws WorldEditException { + return extent.setBlock(position, pattern.apply(position)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 2ec5af6be..629cb310f 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 @@ -22,23 +22,34 @@ package com.sk89q.worldedit.function.block; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; +<<<<<<< HEAD import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import com.sk89q.jnbt.CompoundTagBuilder; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; +<<<<<<< HEAD import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.Map; import static com.google.common.base.Preconditions.checkNotNull; +======= +import com.sk89q.worldedit.world.block.BaseBlock; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Copies blocks from one extent to another. @@ -47,8 +58,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; /** @@ -60,7 +71,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); @@ -74,9 +85,16 @@ public class ExtentBlockCopy implements RegionFunction { } @Override +<<<<<<< HEAD public boolean apply(Vector position) throws WorldEditException { Vector orig = position.subtract(from); Vector transformed = transform.apply(orig); +======= + public boolean apply(BlockVector3 position) throws WorldEditException { + BaseBlock block = source.getFullBlock(position); + BlockVector3 orig = position.subtract(from); + BlockVector3 transformed = transform.apply(orig.toVector3()).toBlockPoint(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner // Apply transformations to NBT data if necessary BlockStateHolder block = transformNbtData(source.getBlock(position)); @@ -101,11 +119,16 @@ public class ExtentBlockCopy implements RegionFunction { Direction direction = MCDirections.fromRotation(rot); if (direction != null) { +<<<<<<< HEAD Vector applyAbsolute = transform.apply(direction.toVector()); Vector applyOrigin = transform.apply(Vector.ZERO); applyAbsolute.mutX(applyAbsolute.getX() - applyOrigin.getX()); applyAbsolute.mutY(applyAbsolute.getY() - applyOrigin.getY()); applyAbsolute.mutZ(applyAbsolute.getZ() - applyOrigin.getZ()); +======= + Vector3 vector = transform.apply(direction.toVector()).subtract(transform.apply(Vector3.ZERO)).normalize(); + Direction newDirection = Direction.findClosest(vector, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner Direction newDirection = Direction.findClosest(applyAbsolute, Flag.CARDINAL | Flag.ORDINAL | Flag.SECONDARY_ORDINAL); 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 62997afab..d348f7b23 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 @@ -21,7 +21,6 @@ package com.sk89q.worldedit.function.block; import com.google.common.collect.Sets; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -30,8 +29,13 @@ import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.function.LayerFunction; import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.Mask; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkNotNull; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockTypes; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Makes a layer of grass on top, three layers of dirt below, and smooth stone @@ -65,12 +69,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 e49c3c142..6960e81dd 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 @@ -22,17 +22,23 @@ package com.sk89q.worldedit.function.entity; import com.boydti.fawe.util.ReflectionUtils; import com.sk89q.jnbt.ByteTag; import com.sk89q.jnbt.CompoundTag; +<<<<<<< HEAD import com.sk89q.jnbt.FloatTag; import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.Vector; +======= +import com.sk89q.jnbt.CompoundTagBuilder; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -50,8 +56,8 @@ import static com.google.common.base.Preconditions.checkNotNull; 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; @@ -63,7 +69,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); @@ -99,6 +105,7 @@ public class ExtentEntityCopy implements EntityFunction { Location newLocation; Location location = entity.getLocation(); +<<<<<<< HEAD Vector pivot = from.round().add(0.5, 0.5, 0.5); Vector newPosition = transform.apply(location.toVector().subtract(pivot)); Vector newDirection; @@ -110,6 +117,19 @@ public class ExtentEntityCopy implements EntityFunction { newLocation = new Location(destination, newPosition.add(to.round().add(0.5, 0.5, 0.5)), newDirection); state = transformNbtData(state); } +======= + 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(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 + state = transformNbtData(state); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner boolean success = destination.createEntity(newLocation, state) != null; @@ -147,9 +167,14 @@ public class ExtentEntityCopy implements EntityFunction { boolean hasFacing = tag.containsKey("Facing"); if (hasTilePosition) { +<<<<<<< HEAD changed = true; 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(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner values.put("TileX", new IntTag(newTilePosition.getBlockX())); values.put("TileY", new IntTag(newTilePosition.getBlockY())); @@ -168,7 +193,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 f255050b7..58919f9fd 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 @@ -20,7 +20,6 @@ package com.sk89q.worldedit.function.factory; 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; @@ -29,6 +28,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 2729f8506..2bed641d2 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,7 +20,6 @@ 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.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; @@ -28,6 +27,12 @@ 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; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldedit.world.block.BlockTypes; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Generates flora (which may include tall grass, flowers, etc.). @@ -103,7 +108,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 a043e156a..85800201e 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,8 +20,13 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.TreeGenerator; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -49,7 +54,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 d6377db25..5bc169486 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,15 @@ 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; +<<<<<<< HEAD +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockState; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -84,12 +88,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 +106,7 @@ public class GardenPatchGenerator implements RegionFunction { int t = random.nextInt(4); int h = random.nextInt(3) - 1; - Vector p; + BlockVector3 p; BlockStateHolder log = BlockTypes.OAK_LOG.getDefaultState(); @@ -158,7 +162,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 +202,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 b1d8be833..ba25165b7 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 @@ -19,8 +19,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +96,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 f3fa24a92..5eb276c53 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 @@ -1,5 +1,6 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.boydti.fawe.object.collection.FastBitSet; import com.boydti.fawe.util.MainUtil; import com.boydti.fawe.util.StringMan; @@ -10,6 +11,12 @@ import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.registry.state.AbstractProperty; import com.sk89q.worldedit.registry.state.Property; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -75,6 +82,7 @@ public class BlockMask extends AbstractExtentMask { } @Override +<<<<<<< HEAD public Mask optimize() { Map states = new HashMap<>(); int indexFound = -1; @@ -94,6 +102,13 @@ public class BlockMask extends AbstractExtentMask { } else { return this; } +======= + public boolean test(BlockVector3 vector) { + BlockStateHolder block = getExtent().getBlock(vector); + for (BlockStateHolder testBlock : blocks) { + if (testBlock.equalsFuzzy(block)) { + return true; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } // Only types, no states if (indexFound == -1) { 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 bc69a9846..58c4890dc 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 @@ -1,7 +1,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.block.BlockTypes; @@ -75,7 +81,18 @@ public class BlockTypeMask extends AbstractExtentMask { } @Override +<<<<<<< HEAD public boolean test(Vector vector) { return types[getExtent().getBlockType(vector).getInternalId()]; +======= + public boolean test(BlockVector3 vector) { + return blocks.contains(getExtent().getBlock(vector).getBlockType()); + } + + @Nullable + @Override + public Mask2D toMask2D() { + return null; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } 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 fe35ff1ef..5ba97737e 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 @@ -19,7 +19,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkArgument; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; @@ -47,7 +53,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 3c48fb770..54e434209 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 @@ -20,7 +20,11 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.worldedit.extent.Extent; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; @@ -40,8 +44,13 @@ public class ExistingBlockMask extends AbstractExtentMask { } @Override +<<<<<<< HEAD public boolean test(Vector vector) { return !getExtent().getBlock(vector).getMaterial().isAir(); +======= + public boolean test(BlockVector3 vector) { + return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Nullable 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 d1d1e374b..54969e71e 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 @@ -19,10 +19,16 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +67,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 52fc28c57..f86bfdc44 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 @@ -19,10 +19,16 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; import static com.google.common.base.Preconditions.checkNotNull; @@ -52,7 +58,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 81c5385fc..38b3783b1 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 @@ -20,8 +20,8 @@ package com.sk89q.worldedit.function.mask; import com.sk89q.minecraft.util.commands.Link; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.command.UtilityCommands; +import com.sk89q.worldedit.math.BlockVector3; import javax.annotation.Nullable; @@ -40,7 +40,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 e9173e349..80e258e62 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 @@ -19,8 +19,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.google.common.base.Function; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; import java.util.*; @@ -166,8 +172,17 @@ public class MaskIntersection extends AbstractMask { } @Override +<<<<<<< HEAD public boolean test(Vector vector) { for (Mask mask : masksArray) { +======= + public boolean test(BlockVector3 vector) { + if (masks.isEmpty()) { + return false; + } + + for (Mask mask : masks) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!mask.test(vector)) { 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 75905f49f..f4dea45eb 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 @@ -19,7 +19,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.Arrays; import java.util.Collection; @@ -83,7 +89,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 aa0141cb4..9cfaef8dd 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,8 +19,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.google.common.base.Function; import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.math.BlockVector3; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -53,9 +58,14 @@ public class MaskUnion extends MaskIntersection { } @Override +<<<<<<< HEAD public Function, Mask> pairingFunction() { return input -> input.getKey().or(input.getValue()); } +======= + public boolean test(BlockVector3 vector) { + Collection masks = getMasks(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner @Override public boolean test(Vector vector) { 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 c51da2073..9bd01639a 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 @@ -1,7 +1,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; @@ -50,8 +57,36 @@ public final class Masks { * @param finalMask the mask * @return a new mask */ +<<<<<<< HEAD public static Mask negate(final Mask finalMask) { return finalMask.inverse(); +======= + public static Mask negate(final Mask mask) { + if (mask instanceof AlwaysTrue) { + return ALWAYS_FALSE; + } else if (mask instanceof AlwaysFalse) { + return ALWAYS_TRUE; + } + + checkNotNull(mask); + return new AbstractMask() { + @Override + public boolean test(BlockVector3 vector) { + return !mask.test(vector); + } + + @Nullable + @Override + public Mask2D toMask2D() { + Mask2D mask2d = mask.toMask2D(); + if (mask2d != null) { + return negate(mask2d); + } else { + return null; + } + } + }; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** @@ -70,7 +105,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); } }; @@ -85,8 +120,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 @@ -99,12 +134,12 @@ public final class Masks { protected 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; } @@ -127,12 +162,12 @@ public final class Masks { protected 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 61dd7b73a..e79300f1b 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 @@ -19,7 +19,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.math.noise.NoiseGenerator; import javax.annotation.Nullable; @@ -85,8 +92,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 6a2146c58..0bfdd59ad 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 @@ -19,7 +19,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.math.noise.NoiseGenerator; import static com.google.common.base.Preconditions.checkArgument; @@ -83,8 +90,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 96d50a8a7..c6b70f4e6 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 @@ -1,7 +1,14 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import javax.annotation.Nullable; @@ -14,8 +21,12 @@ import static com.google.common.base.Preconditions.checkNotNull; public class OffsetMask extends AbstractMask { private Mask mask; +<<<<<<< HEAD private Vector offset; private MutableBlockVector mutable = new MutableBlockVector(); +======= + private BlockVector3 offset; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Create a new instance. @@ -23,7 +34,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; @@ -54,7 +65,7 @@ public class OffsetMask extends AbstractMask { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -63,17 +74,22 @@ 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 +<<<<<<< HEAD public boolean test(Vector vector) { mutable.mutX((vector.getX() + offset.getX())); mutable.mutY((vector.getY() + offset.getY())); mutable.mutZ((vector.getZ() + offset.getZ())); return getMask().test(mutable); +======= + public boolean test(BlockVector3 vector) { + return getMask().test(vector.add(offset)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Nullable @@ -81,7 +97,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 50d2835ba..5086beafe 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 @@ -19,7 +19,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import static com.google.common.base.Preconditions.checkNotNull; @@ -30,7 +36,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class OffsetMask2D extends AbstractMask2D { private Mask2D mask; - private Vector2D offset; + private BlockVector2 offset; /** * Create a new instance. @@ -38,7 +44,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 +75,7 @@ public class OffsetMask2D extends AbstractMask2D { * * @return the offset */ - public Vector2D getOffset() { + public BlockVector2 getOffset() { return offset; } @@ -78,13 +84,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 1ddf891fe..074632762 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 @@ -19,7 +19,13 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.Region; import javax.annotation.Nullable; @@ -62,7 +68,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 67b30b9cd..428aab881 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 @@ -1,6 +1,11 @@ package com.sk89q.worldedit.function.mask; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; +======= +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.blocks.BlockType; import com.sk89q.worldedit.extent.Extent; @@ -18,8 +23,16 @@ public class SolidBlockMask extends BlockTypeMask { return types; } +<<<<<<< HEAD public SolidBlockMask(Extent extent) { super(extent, getTypes()); +======= + @Override + public boolean test(BlockVector3 vector) { + Extent extent = getExtent(); + BlockState block = extent.getBlock(vector); + return block.getBlockType().getMaterial().isMovementBlocker(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Nullable 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 2ebaacb39..df6f6f414 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.function.operation; +<<<<<<< HEAD import com.boydti.fawe.example.MappedFaweQueue; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.extent.BlockTranslateExtent; @@ -30,6 +31,12 @@ import com.boydti.fawe.util.MaskTraverser; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.Lists; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.extent.Extent; @@ -44,7 +51,12 @@ import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.visitor.EntityVisitor; import com.sk89q.worldedit.function.visitor.IntersectRegionFunction; import com.sk89q.worldedit.function.visitor.RegionVisitor; +<<<<<<< HEAD import com.sk89q.worldedit.math.transform.AffineTransform; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.regions.Region; @@ -67,8 +79,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; @@ -87,10 +99,15 @@ public class ForwardExtentCopy implements Operation { * @param source the source extent * @param region the region to copy * @param destination the destination extent +<<<<<<< HEAD * @param to the destination position * @see #ForwardExtentCopy(Extent, Region, Vector, Extent, Vector) the main constructor +======= + * @param to the destination position + * @see #ForwardExtentCopy(Extent, Region, BlockVector3, Extent, BlockVector3) the main constructor +>>>>>>> 399e0ad5... Refactor vector system to be cleaner */ - 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); } @@ -103,7 +120,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); @@ -313,6 +330,7 @@ public class ForwardExtentCopy implements Operation { int y = translation.getBlockY(); int z = translation.getBlockZ(); +<<<<<<< HEAD maskFunc = position -> { mutable.setComponents(position.getBlockX() + x, position.getBlockY() + y, position.getBlockZ() + z); if (region.contains(mutable)) { @@ -354,6 +372,10 @@ public class ForwardExtentCopy implements Operation { if (!entities.isEmpty()) { ExtentEntityCopy entityCopy = new ExtentEntityCopy(from, destination, to, currentTransform); +======= + if (copyingEntities) { + ExtentEntityCopy entityCopy = new ExtentEntityCopy(from.toVector3(), destination, to.toVector3(), currentTransform); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner entityCopy.setRemoving(removingEntities); EntityVisitor entityVisitor = new EntityVisitor(entities.iterator(), entityCopy); Operations.completeBlindly(entityVisitor); 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 6d2804125..d5ce9f3d3 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 @@ -1,10 +1,17 @@ package com.sk89q.worldedit.function.pattern; +<<<<<<< HEAD import com.boydti.fawe.FaweCache; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BaseBlock; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -45,4 +52,13 @@ public class BlockPattern implements Pattern { checkNotNull(block); this.block = block; } +<<<<<<< HEAD +======= + + @Override + public BlockStateHolder apply(BlockVector3 position) { + return block; + } + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 632fe21c6..7bbf74cef 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 @@ -1,10 +1,16 @@ package com.sk89q.worldedit.function.pattern; +<<<<<<< HEAD import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.extent.clipboard.Clipboard; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -16,9 +22,13 @@ import static com.google.common.base.Preconditions.checkNotNull; public class ClipboardPattern extends AbstractPattern { private final Clipboard clipboard; +<<<<<<< HEAD private final int sx, sy, sz; private final Vector min; private MutableBlockVector mutable = new MutableBlockVector(); +======= + private final BlockVector3 size; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Create a new clipboard pattern. @@ -36,6 +46,7 @@ public class ClipboardPattern extends AbstractPattern { } @Override +<<<<<<< HEAD public BlockStateHolder apply(Vector position) { int xp = position.getBlockX() % sx; int yp = position.getBlockY() % sy; @@ -47,6 +58,14 @@ public class ClipboardPattern extends AbstractPattern { mutable.mutY((min.getY() + yp)); mutable.mutZ((min.getZ() + zp)); return clipboard.getBlock(mutable); +======= + 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(xp, yp, zp)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 9d416ff56..73acb9bc1 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 @@ -20,8 +20,6 @@ package com.sk89q.worldedit.function.pattern; import com.sk89q.minecraft.util.commands.Link; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -29,6 +27,7 @@ import com.sk89q.worldedit.command.UtilityCommands; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.NullExtent; import com.sk89q.worldedit.internal.expression.runtime.Return; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; @@ -41,13 +40,13 @@ import com.sk89q.worldedit.world.block.BlockState; public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{ @Override - default BaseBlock next(Vector position) { + default BaseBlock next(BlockVector3 position) { return new BaseBlock(apply(position)); } @Override default BaseBlock next(int x, int y, int z) { - return new BaseBlock(apply(new Vector(x, y, z))); + return new BaseBlock(apply(new BlockVector3(x, y, z))); } /** @@ -56,10 +55,9 @@ public interface Pattern extends com.sk89q.worldedit.patterns.Pattern{ * @param position the position * @return a block */ - @Deprecated - BlockStateHolder apply(Vector position); + BlockStateHolder apply(BlockVector3 position); - default boolean apply(Extent extent, Vector get, Vector set) throws WorldEditException { + default boolean apply(Extent extent, BlockVector3 get, BlockVector3 set) throws WorldEditException { return extent.setBlock(set, apply(get)); } } \ No newline at end of file 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 edd624fa1..73e19e91f 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 @@ -1,5 +1,6 @@ package com.sk89q.worldedit.function.pattern; +<<<<<<< HEAD import com.boydti.fawe.object.collection.RandomCollection; import com.boydti.fawe.object.random.SimpleRandom; import com.boydti.fawe.object.random.TrueRandom; @@ -8,6 +9,11 @@ import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import java.util.HashMap; @@ -54,8 +60,24 @@ public class RandomPattern extends AbstractPattern { this.patterns.add(pattern); } +<<<<<<< HEAD public Set getPatterns() { return patterns; +======= + @Override + public BlockStateHolder apply(BlockVector3 position) { + double r = random.nextDouble(); + double offset = 0; + + for (Chance chance : patterns) { + if (r <= (offset + chance.getChance()) / max) { + return chance.getPattern().apply(position); + } + offset += chance.getChance(); + } + + throw new RuntimeException("ProportionalFillPattern"); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } public RandomCollection getCollection() { 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 70f3f81d4..2f987d602 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 @@ -19,7 +19,14 @@ package com.sk89q.worldedit.function.pattern; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; @@ -32,7 +39,7 @@ import static com.google.common.base.Preconditions.checkNotNull; public class RepeatingExtentPattern extends AbstractPattern { private Extent extent; - private Vector offset; + private BlockVector3 offset; /** * Create a new instance. @@ -40,7 +47,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); } @@ -69,7 +76,7 @@ public class RepeatingExtentPattern extends AbstractPattern { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -78,18 +85,22 @@ 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(); +<<<<<<< HEAD return extent.getBlock(new Vector(x, y, z)); +======= + return extent.getFullBlock(new BlockVector3(x, y, z)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } 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 c01e9bc9d..544c79405 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 @@ -19,9 +19,15 @@ package com.sk89q.worldedit.function.util; +<<<<<<< HEAD import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.FlatRegionFunction; +import com.sk89q.worldedit.math.BlockVector2; import static com.google.common.base.Preconditions.checkNotNull; @@ -30,7 +36,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class FlatRegionOffset implements FlatRegionFunction { - private Vector2D offset; + private BlockVector2 offset; private final FlatRegionFunction function; /** @@ -39,7 +45,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 +56,7 @@ public class FlatRegionOffset implements FlatRegionFunction { * * @return the offset */ - public Vector2D getOffset() { + public BlockVector2 getOffset() { return offset; } @@ -59,13 +65,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 4d5338eaf..b30cd00d2 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 @@ -19,9 +19,15 @@ package com.sk89q.worldedit.function.util; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.math.BlockVector3; import static com.google.common.base.Preconditions.checkNotNull; @@ -30,7 +36,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class RegionOffset implements RegionFunction { - private Vector offset; + private BlockVector3 offset; private final RegionFunction function; /** @@ -39,7 +45,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 +56,7 @@ public class RegionOffset implements RegionFunction { * * @return the offset */ - public Vector getOffset() { + public BlockVector3 getOffset() { return offset; } @@ -59,13 +65,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 e371e4ff5..10b8a6a1f 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 @@ -7,23 +7,41 @@ import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.HasFaweQueue; import com.boydti.fawe.object.IntegerTrio; import com.boydti.fawe.object.collection.BlockVectorSet; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; +import static com.google.common.base.Preconditions.checkNotNull; + 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.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector3; + +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Queue; +import java.util.Set; +/** + * Performs a breadth-first search starting from points added with + * {@link #visit(BlockVector3)}. The search continues + * to a certain adjacent point provided that the method + * {@link #isVisitable(BlockVector3, BlockVector3)} + * returns true for that point. + * + *

As an abstract implementation, this class can be used to implement + * functionality that starts at certain points and extends outward from + * those points.

+ */ public abstract class BreadthFirstSearch implements Operation { - public static final Vector[] DEFAULT_DIRECTIONS = new Vector[6]; - public static final Vector[] DIAGONAL_DIRECTIONS; + public static final BlockVector3[] DEFAULT_DIRECTIONS = new BlockVector3[6]; + public static final BlockVector3[] DIAGONAL_DIRECTIONS; static { DEFAULT_DIRECTIONS[0] = (new MutableBlockVector(0, -1, 0)); @@ -45,17 +63,17 @@ public abstract class BreadthFirstSearch implements Operation { } } } - Collections.sort(list, new Comparator() { + Collections.sort(list, new Comparator() { @Override - public int compare(Vector o1, Vector o2) { + public int compare(BlockVector3 o1, BlockVector3 o2) { return (int) Math.signum(o1.lengthSq() - o2.lengthSq()); } }); - DIAGONAL_DIRECTIONS = list.toArray(new Vector[list.size()]); + DIAGONAL_DIRECTIONS = list.toArray(new BlockVector3[list.size()]); } private final RegionFunction function; - private List directions = new ArrayList<>(); + private List directions = new ArrayList<>(); private BlockVectorSet visited; private final MappedFaweQueue mFaweQueue; private BlockVectorSet queue; @@ -82,26 +100,24 @@ public abstract class BreadthFirstSearch implements Operation { this.maxDepth = maxDepth; } - public abstract boolean isVisitable(Vector from, Vector to); - - public Collection getDirections() { + public Collection getDirections() { return this.directions; } - public void setDirections(List directions) { + public void setDirections(List directions) { this.directions = directions; } private IntegerTrio[] getIntDirections() { IntegerTrio[] array = new IntegerTrio[directions.size()]; for (int i = 0; i < array.length; i++) { - Vector dir = directions.get(i); + BlockVector3 dir = directions.get(i); array[i] = new IntegerTrio(dir.getBlockX(), dir.getBlockY(), dir.getBlockZ()); } return array; } - public void visit(final Vector pos) { + public void visit(final BlockVector3 pos) { if (!isVisited(pos)) { isVisitable(pos, pos); // Ignore this, just to initialize mask on this point queue.add(pos); @@ -123,13 +139,47 @@ public abstract class BreadthFirstSearch implements Operation { return visited; } - public boolean isVisited(Vector pos) { + public boolean isVisited(BlockVector3 pos) { return visited.contains(pos); } public void setMaxBranch(int maxBranch) { this.maxBranch = maxBranch; } + /** + * Try to visit the given 'to' location. + * + * @param from the origin block + * @param to the block under question + */ + private void visit(BlockVector3 from, BlockVector3 to) { + BlockVector3 blockVector = to; + if (!visited.contains(blockVector)) { + visited.add(blockVector); + if (isVisitable(from, to)) { + queue.add(blockVector); + } + } + } + + /** + * Return whether the given 'to' block should be visited, starting from the + * 'from' block. + * + * @param from the origin block + * @param to the block under question + * @return true if the 'to' block should be visited + */ + protected abstract boolean isVisitable(BlockVector3 from, BlockVector3 to); + + /** + * Get the number of affected objects. + * + * @return the number of affected + */ + public int getAffected() { + return affected; + } @Override public Operation resume(RunContext run) throws WorldEditException { @@ -143,7 +193,7 @@ public abstract class BreadthFirstSearch implements Operation { if (mFaweQueue != null && Settings.IMP.QUEUE.PRELOAD_CHUNKS > 1) { int cx = Integer.MIN_VALUE; int cz = Integer.MIN_VALUE; - for (Vector from : queue) { + for (BlockVector3 from : queue) { for (IntegerTrio direction : dirs) { int x = from.getBlockX() + direction.x; int z = from.getBlockZ() + direction.z; @@ -158,11 +208,11 @@ public abstract class BreadthFirstSearch implements Operation { } } } - for (Vector chunk : chunkLoadSet) { + for (BlockVector3 chunk : chunkLoadSet) { mFaweQueue.queueChunkLoad(chunk.getBlockX(), chunk.getBlockZ()); } } - for (Vector from : queue) { + for (BlockVector3 from : queue) { if (function.apply(from)) affected++; for (int i = 0, j = 0; i < dirs.length && j < maxBranch; i++) { IntegerTrio direction = dirs[i]; @@ -183,6 +233,17 @@ public abstract class BreadthFirstSearch implements Operation { } } } +//======= +// BlockVector3 position; +// +// while ((position = queue.poll()) != null) { +// if (function.apply(position)) { +// affected++; +// } +// +// for (BlockVector3 dir : directions) { +// visit(position, position.add(dir)); +//>>>>>>> 399e0ad5... Refactor vector system to be cleaner } if (currentDepth == maxDepth) { break; @@ -207,10 +268,6 @@ public abstract class BreadthFirstSearch implements Operation { messages.add(BBC.VISITOR_BLOCK.format(getAffected())); } - public int getAffected() { - return this.affected; - } - @Override public void cancel() { } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DirectionalVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DirectionalVisitor.java index ecdcbb690..7aa209756 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DirectionalVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/DirectionalVisitor.java @@ -20,10 +20,11 @@ package com.sk89q.worldedit.function.visitor; import com.boydti.fawe.object.HasFaweQueue; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.MutableBlockVector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; + import java.util.Collection; @@ -38,30 +39,30 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class DirectionalVisitor extends RecursiveVisitor { - private final Vector origin; - private final Vector dirVec; + private final BlockVector3 origin; + private final BlockVector3 dirVec; - public DirectionalVisitor(Mask mask, RegionFunction function, Vector origin, Vector direction) { + public DirectionalVisitor(Mask mask, RegionFunction function, BlockVector3 origin, BlockVector3 direction) { this(mask, function, origin, direction, Integer.MAX_VALUE, null); } - public DirectionalVisitor(Mask mask, RegionFunction function, Vector origin, Vector direction, int distance, HasFaweQueue hasFaweQueue) { + public DirectionalVisitor(Mask mask, RegionFunction function, BlockVector3 origin, BlockVector3 direction, int distance, HasFaweQueue hasFaweQueue) { super(mask, function, distance, hasFaweQueue); checkNotNull(mask); this.origin = origin; this.dirVec = new MutableBlockVector(direction); - final Collection directions = this.getDirections(); + final Collection directions = this.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 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)); + directions.add(new BlockVector3(0, 1, 0)); } @Override - public boolean isVisitable(final Vector from, final Vector to) { + public boolean isVisitable(final BlockVector3 from, final BlockVector3 to) { int dx = to.getBlockX() - from.getBlockX(); int dz = to.getBlockZ() - from.getBlockZ(); int dy = to.getBlockY() - from.getBlockY(); 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 7d91069d7..a902c2ba2 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 @@ -19,10 +19,19 @@ package com.sk89q.worldedit.function.visitor; +<<<<<<< HEAD import com.boydti.fawe.object.HasFaweQueue; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.Collection; @@ -54,19 +63,30 @@ public class DownwardVisitor extends RecursiveVisitor { super(mask, function, depth, hasFaweQueue); checkNotNull(mask); this.baseY = baseY; +<<<<<<< HEAD final Collection directions = this.getDirections(); +======= + + Collection directions = getDirections(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +<<<<<<< HEAD public boolean isVisitable(final Vector from, final Vector to) { final int fromY = from.getBlockY(); return ((fromY == this.baseY) || (to.getBlockY() - from.getBlockY() < 0)) && super.isVisitable(from, to); +======= + protected boolean isVisitable(BlockVector3 from, BlockVector3 to) { + int fromY = from.getBlockY(); + return (fromY == baseY || to.subtract(from).getBlockY() < 0) && super.isVisitable(from, to); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 6a36fcdac..82777b06e 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 @@ -19,17 +19,23 @@ package com.sk89q.worldedit.function.visitor; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.boydti.fawe.example.MappedFaweQueue; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.HasFaweQueue; import com.boydti.fawe.object.visitor.Fast2DIterator; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.regions.FlatRegion; import java.util.List; @@ -78,6 +84,7 @@ public class FlatRegionVisitor implements Operation { } @Override +<<<<<<< HEAD public Operation resume(final RunContext run) throws WorldEditException { if (this.queue != null) { for (final Vector2D pt : new Fast2DIterator(this.iterator, queue)) { @@ -86,6 +93,12 @@ public class FlatRegionVisitor implements Operation { } else { for (final Vector2D pt : this.iterator) { if (this.function.apply(pt)) affected++; +======= + public Operation resume(RunContext run) throws WorldEditException { + for (BlockVector2 pt : flatRegion.asFlatRegion()) { + if (function.apply(pt)) { + affected++; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } } return null; 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 ee0a1d67a..de59b9ccf 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 @@ -19,8 +19,14 @@ package com.sk89q.worldedit.function.visitor; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.LayerFunction; import com.sk89q.worldedit.function.mask.Mask2D; @@ -28,6 +34,8 @@ import com.sk89q.worldedit.function.mask.Masks; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; 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,21 +100,36 @@ public class LayerVisitor implements Operation { } @Override +<<<<<<< HEAD public Operation resume(final RunContext run) throws WorldEditException { for (final Vector2D column : this.iterator) { if (!this.mask.test(column)) { +======= + public Operation resume(RunContext run) throws WorldEditException { + for (BlockVector2 column : flatRegion.asFlatRegion()) { + if (!mask.test(column)) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner continue; } // Abort if we are underground +<<<<<<< HEAD if (this.function.isGround(column.toVector(this.maxY + 1))) { +======= + if (function.isGround(column.toBlockVector3(maxY + 1))) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return null; } boolean found = false; int groundY = 0; +<<<<<<< HEAD for (int y = this.maxY; y >= this.minY; --y) { final Vector test = column.toVector(y); +======= + for (int y = maxY; y >= minY; --y) { + BlockVector3 test = column.toBlockVector3(y); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (!found) { if (this.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 31eae2177..268467a54 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,10 +19,17 @@ package com.sk89q.worldedit.function.visitor; +<<<<<<< HEAD import com.boydti.fawe.object.HasFaweQueue; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +======= +import com.sk89q.worldedit.function.RegionFunction; +import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.Collection; /** @@ -38,18 +45,23 @@ public class NonRisingVisitor extends RecursiveVisitor { */ public NonRisingVisitor(Mask mask, RegionFunction function) { +<<<<<<< HEAD this(mask, function, Integer.MAX_VALUE, null); } public NonRisingVisitor(Mask mask, RegionFunction function, int depth, HasFaweQueue hasFaweQueue) { super(mask, function, depth, hasFaweQueue); final Collection directions = this.getDirections(); +======= + super(mask, function); + Collection directions = getDirections(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 ba45fbf7c..f0ee91a36 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 @@ -19,10 +19,16 @@ package com.sk89q.worldedit.function.visitor; +<<<<<<< HEAD import com.boydti.fawe.object.HasFaweQueue; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.function.RegionFunction; import com.sk89q.worldedit.function.mask.Mask; +import com.sk89q.worldedit.math.BlockVector3; import static com.google.common.base.Preconditions.checkNotNull; @@ -56,8 +62,13 @@ public class RecursiveVisitor extends BreadthFirstSearch { } @Override +<<<<<<< HEAD public boolean isVisitable(final Vector from, final Vector to) { return this.mask.test(to); +======= + protected boolean isVisitable(BlockVector3 from, BlockVector3 to) { + return mask.test(to); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 11895274f..484e12734 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 @@ -25,14 +25,13 @@ import com.boydti.fawe.example.MappedFaweQueue; import com.boydti.fawe.object.FaweQueue; import com.boydti.fawe.object.HasFaweQueue; import com.boydti.fawe.object.exception.FaweException; -import com.sk89q.worldedit.BlockVector; 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.operation.Operation; import com.sk89q.worldedit.function.operation.Operations; import com.sk89q.worldedit.function.operation.RunContext; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; import java.util.Iterator; import java.util.List; @@ -43,7 +42,7 @@ import java.util.List; public class RegionVisitor implements Operation { public final Region region; - public final Iterable iterable; + public final Iterable iterable; public final RegionFunction function; private final MappedFaweQueue queue; private boolean useCuboidIterator = false; @@ -65,10 +64,10 @@ public class RegionVisitor implements Operation { } public RegionVisitor(Region region, RegionFunction function, FaweQueue queue) { - this((Iterable) region, function, queue); + this((Iterable) region, function, queue); } - public RegionVisitor(Iterable iterable, RegionFunction function, HasFaweQueue hasQueue) { + public RegionVisitor(Iterable iterable, RegionFunction function, HasFaweQueue hasQueue) { region = (iterable instanceof Region) ? (Region) iterable : null; this.iterable = iterable; this.function = function; @@ -94,8 +93,8 @@ public class RegionVisitor implements Operation { * - Stop iteration on exception instead of hasNext * - Do not calculate the stacktrace as it is expensive */ - Iterator trailIter = iterable.iterator(); - Iterator leadIter = iterable.iterator(); + Iterator trailIter = iterable.iterator(); + Iterator leadIter = iterable.iterator(); int lastTrailChunkX = Integer.MIN_VALUE; int lastTrailChunkZ = Integer.MIN_VALUE; int lastLeadChunkX = Integer.MIN_VALUE; @@ -103,7 +102,7 @@ public class RegionVisitor implements Operation { int loadingTarget = Settings.IMP.QUEUE.PRELOAD_CHUNKS; try { for (; ; ) { - Vector pt = trailIter.next(); + BlockVector3 pt = trailIter.next(); apply(pt); int cx = pt.getBlockX() >> 4; int cz = pt.getBlockZ() >> 4; @@ -119,7 +118,7 @@ public class RegionVisitor implements Operation { amount = 1; } for (int count = 0; count < amount; ) { - Vector v = leadIter.next(); + BlockVector3 v = leadIter.next(); int vcx = v.getBlockX() >> 4; int vcz = v.getBlockZ() >> 4; if (vcx != lastLeadChunkX || vcz != lastLeadChunkZ) { @@ -176,14 +175,14 @@ public class RegionVisitor implements Operation { } catch (Throwable ignore) { } } else { - for (Vector pt : iterable) { + for (BlockVector3 pt : iterable) { apply(pt); } } return null; } - private void apply(Vector pt) throws WorldEditException { + private void apply(BlockVector3 pt) throws WorldEditException { 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 a7534e8db..7b1c32c9a 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 @@ -19,14 +19,24 @@ package com.sk89q.worldedit.history.change; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.history.UndoContext; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkNotNull; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockStateHolder; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Represents a block change that may be undone or replayed. @@ -37,7 +47,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class BlockChange implements Change { - private final BlockVector position; + private final BlockVector3 position; private final BlockStateHolder previous; private final BlockStateHolder current; @@ -48,7 +58,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); @@ -62,7 +72,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 new file mode 100644 index 000000000..9c9ad2a85 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/history/changeset/BlockOptimizedHistory.java @@ -0,0 +1,83 @@ +/* + * 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.history.changeset; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.google.common.collect.Iterators; +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; + +import java.util.ArrayList; +import java.util.Iterator; + +/** + * An extension of {@link ArrayListHistory} that stores {@link BlockChange}s + * separately in two {@link ArrayList}s. + * + *

Whether this is a good idea or not is highly questionable, but this class + * exists because this is how history was implemented in WorldEdit for + * many years.

+ */ +public class BlockOptimizedHistory extends ArrayListHistory { + + private static Change createChange(LocatedBlock block) { + return new BlockChange(block.getLocation(), block.getBlock(), block.getBlock()); + } + + private final LocatedBlockList previous = new LocatedBlockList(); + private final LocatedBlockList current = new LocatedBlockList(); + + @Override + public void add(Change change) { + checkNotNull(change); + + if (change instanceof BlockChange) { + BlockChange blockChange = (BlockChange) change; + BlockVector3 position = blockChange.getPosition(); + previous.add(position, blockChange.getPrevious()); + current.add(position, blockChange.getCurrent()); + } else { + super.add(change); + } + } + + @Override + public Iterator forwardIterator() { + return Iterators.concat( + super.forwardIterator(), + Iterators.transform(current.iterator(), BlockOptimizedHistory::createChange)); + } + + @Override + public Iterator backwardIterator() { + return Iterators.concat( + super.backwardIterator(), + Iterators.transform(previous.reverseIterator(), BlockOptimizedHistory::createChange)); + } + + @Override + 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 6a8d96ccf..5564b8245 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 @@ -20,7 +20,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; @@ -28,7 +28,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 71c9751e7..fd537fde8 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 @@ -22,9 +22,16 @@ package com.sk89q.worldedit.internal.command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandException; import com.sk89q.minecraft.util.commands.Logging; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.WorldEdit; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -99,13 +106,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 89c850826..27e2461c7 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 @@ -26,11 +26,13 @@ import com.sk89q.worldedit.IncompleteRegionException; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.PlayerDirection; import com.sk89q.worldedit.UnknownDirectionException; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.extension.input.NoMatchException; @@ -42,6 +44,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; @@ -53,6 +56,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.block.BlockType; @@ -306,10 +310,17 @@ public class WorldEditBinding extends BindingHelper { * @throws UnknownDirectionException on an unknown direction */ @BindingMatch(classifier = Direction.class, +<<<<<<< HEAD type = Vector.class, behavior = BindingBehavior.CONSUMES, consumedCount = 1) public Vector getDirection(ArgumentStack context, Direction direction) +======= + type = BlockVector3.class, + behavior = BindingBehavior.CONSUMES, + consumedCount = 1) + public BlockVector3 getDirection(ArgumentStack context, Direction direction) +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 new file mode 100644 index 000000000..eafcb1728 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/cui/ServerCUIHandler.java @@ -0,0 +1,155 @@ +/* + * 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.internal.cui; + +import com.sk89q.jnbt.ByteTag; +import com.sk89q.jnbt.CompoundTag; +import com.sk89q.jnbt.IntTag; +import com.sk89q.jnbt.StringTag; +import com.sk89q.jnbt.Tag; +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +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; +import com.sk89q.worldedit.world.block.BlockTypes; + +import java.util.HashMap; +import java.util.Map; + +import javax.annotation.Nullable; + +/** + * Handles creation of server-side CUI systems. + */ +public class ServerCUIHandler { + + private ServerCUIHandler() { + } + + /** + * Creates a structure block that shows the region. + * + *

+ * Null symbolises removal of the CUI. + *

+ * + * @param player The player to create the structure block for. + * @return The structure block, or null + */ + @Nullable + public static com.sk89q.worldedit.blocks.BaseBlock createStructureBlock(Player player) { + LocalSession session = WorldEdit.getInstance().getSessionManager().get(player); + RegionSelector regionSelector = session.getRegionSelector(player.getWorld()); + + int posX, posY, posZ; + int width, height, length; + + if (regionSelector instanceof CuboidRegionSelector) { + if (regionSelector.isDefined()) { + try { + CuboidRegion region = ((CuboidRegionSelector) regionSelector).getRegion(); + + posX = region.getMinimumPoint().getBlockX(); + posY = region.getMinimumPoint().getBlockY(); + posZ = region.getMinimumPoint().getBlockZ(); + + width = region.getWidth(); + height = region.getHeight(); + length = region.getLength(); + } catch (IncompleteRegionException e) { + // This will never happen. + e.printStackTrace(); + return null; + } + } else { + CuboidRegion region = ((CuboidRegionSelector) regionSelector).getIncompleteRegion(); + BlockVector3 point; + if (region.getPos1() != null) { + point = region.getPos1(); + } else if (region.getPos2() != null) { + point = region.getPos2(); + } else { + // No more selection + return null; + } + + // Just select the point. + posX = point.getBlockX(); + posY = point.getBlockY(); + posZ = point.getBlockZ(); + width = 1; + height = 1; + length = 1; + } + } else { + // We only support cuboid regions right now. + return null; + } + + if (width > 32 || length > 32 || height > 32) { + // Structure blocks have a limit of 32x32x32 + return null; + } + + // Borrowed this math from FAWE + double rotX = player.getLocation().getYaw(); + double rotY = player.getLocation().getPitch(); + double xz = Math.cos(Math.toRadians(rotY)); + int x = (int) (player.getLocation().getX() - (-xz * Math.sin(Math.toRadians(rotX))) * 12); + int z = (int) (player.getLocation().getZ() - (xz * Math.cos(Math.toRadians(rotX))) * 12); + int y = Math.max(0, Math.min(Math.min(255, posY + 32), posY + 3)); + + Map structureTag = new HashMap<>(); + + posX -= x; + posY -= y; + posZ -= z; + + if (Math.abs(posX) > 32 || Math.abs(posY) > 32 || Math.abs(posZ) > 32) { + // Structure blocks have a limit + return null; + } + + structureTag.put("name", new StringTag("worldedit:" + player.getName())); + structureTag.put("author", new StringTag(player.getName())); + structureTag.put("metadata", new StringTag("")); + structureTag.put("x", new IntTag(x)); + structureTag.put("y", new IntTag(y)); + structureTag.put("z", new IntTag(z)); + structureTag.put("posX", new IntTag(posX)); + structureTag.put("posY", new IntTag(posY)); + structureTag.put("posZ", new IntTag(posZ)); + structureTag.put("sizeX", new IntTag(width)); + structureTag.put("sizeY", new IntTag(height)); + structureTag.put("sizeZ", new IntTag(length)); + structureTag.put("rotation", new StringTag("NONE")); + structureTag.put("mirror", new StringTag("NONE")); + structureTag.put("mode", new StringTag("SAVE")); + structureTag.put("ignoreEntities", new ByteTag((byte) 1)); + structureTag.put("showboundingbox", new ByteTag((byte) 1)); + structureTag.put("id", new StringTag(BlockTypes.STRUCTURE_BLOCK.getId())); + + return BlockTypes.STRUCTURE_BLOCK.getDefaultState().toBaseBlock(new CompoundTag(structureTag)); + } +} 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 612709ff7..87191eed9 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,11 +19,15 @@ package com.sk89q.worldedit.internal.expression.runtime; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -397,7 +401,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); @@ -410,7 +414,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); @@ -424,7 +428,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..ab9b74064 --- /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 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..d3c6e1be5 --- /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 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/MathUtils.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java index 3bc9d6f5b..8bcea6509 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MathUtils.java @@ -117,4 +117,34 @@ public final class MathUtils { public static double roundHalfUp(double value) { return Math.signum(value) * Math.round(Math.abs(value)); } + + /** + * Returns the midpoint Vector3 of the two given Vector3's. + * + * @param first Vector3 + * @param second Vector3 + * @return midpoint Vector3 + */ + public static Vector3 midpoint(Vector3 v1, Vector3 v2) { + return new Vector3( + (v1.getX() + v2.getX()) / 2, + (v1.getY() + v2.getY()) / 2, + (v1.getZ() + v2.getZ()) / 2 + ); + } + + /** + * Returns the midpoint BlockVector3 of the two given BlockVector3's. + * + * @param first BlockVector3 + * @param second BlockVector3 + * @return midpoint BlockVector3 + */ + public static BlockVector3 midpoint(BlockVector3 v1, BlockVector3 v2) { + return new BlockVector3( + (v1.getBlockX() + v2.getBlockX()) / 2, + (v1.getBlockY() + v2.getBlockY()) / 2, + (v1.getBlockZ() + v2.getBlockZ()) / 2 + ); + } } \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector.java similarity index 84% rename from worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector.java index afb087087..4aead808c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector.java @@ -1,10 +1,10 @@ -package com.sk89q.worldedit; +package com.sk89q.worldedit.math; import com.boydti.fawe.util.MathMan; import java.io.IOException; import java.io.Serializable; -public class MutableBlockVector extends BlockVector implements Serializable { +public class MutableBlockVector extends BlockVector3 implements Serializable { private transient int x, y, z; private static ThreadLocal MUTABLE_CACHE = new ThreadLocal() { @@ -18,7 +18,7 @@ public class MutableBlockVector extends BlockVector implements Serializable { return MUTABLE_CACHE.get().setComponents(x, y, z); } - public MutableBlockVector(Vector v) { + public MutableBlockVector(BlockVector3 v) { this(v.getBlockX(), v.getBlockY(), v.getBlockZ()); } @@ -33,16 +33,16 @@ public class MutableBlockVector extends BlockVector implements Serializable { super(0, 0, 0); } - public MutableBlockVector setComponents(Vector other) { + public MutableBlockVector setComponents(BlockVector3 other) { return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ()); } - @Override +// @Override public MutableBlockVector setComponents(double x, double y, double z) { return this.setComponents((int) x, (int) y, (int) z); } - @Override +// @Override public MutableBlockVector setComponents(int x, int y, int z) { this.mutX(x); this.mutY(y); @@ -50,48 +50,48 @@ public class MutableBlockVector extends BlockVector implements Serializable { return this; } - @Override +// @Override public final void mutX(double x) { this.x = MathMan.roundInt(x); } - @Override +// @Override public final void mutY(double y) { this.y = MathMan.roundInt(y); } - @Override +// @Override public final void mutZ(double z) { this.z = MathMan.roundInt(z); } - @Override +// @Override public final void mutX(int x) { this.x = x; } - @Override +// @Override public final void mutY(int y) { this.y = y; } - @Override +// @Override public final void mutZ(int z) { this.z = z; } @Override - public final double getX() { + public final int getX() { return x; } @Override - public final double getY() { + public final int getY() { return y; } @Override - public final double getZ() { + public final int getZ() { return z; } @@ -121,4 +121,4 @@ public class MutableBlockVector extends BlockVector implements Serializable { this.y = stream.readByte() & 0xFF; this.z = stream.readInt(); } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector2D.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2D.java similarity index 92% rename from worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector2D.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2D.java index 4141fd6ba..29aee156e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/MutableBlockVector2D.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableBlockVector2D.java @@ -1,9 +1,9 @@ -package com.sk89q.worldedit; +package com.sk89q.worldedit.math; import java.io.IOException; import java.io.Serializable; -public final class MutableBlockVector2D extends BlockVector2D implements Serializable { +public final class MutableBlockVector2D extends BlockVector2 implements Serializable { private static ThreadLocal MUTABLE_CACHE = new ThreadLocal() { @Override protected MutableBlockVector2D initialValue() { @@ -23,13 +23,13 @@ public final class MutableBlockVector2D extends BlockVector2D implements Seriali this.z = 0; } - @Override - public double getX() { +// @Override + public int getX() { return x; } - @Override - public double getZ() { +// @Override + public int getZ() { return z; } @@ -107,4 +107,4 @@ public final class MutableBlockVector2D extends BlockVector2D implements Seriali return setComponents(x + 1, z); } } -} +} \ No newline at end of file diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector.java new file mode 100644 index 000000000..77d1b0175 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/math/MutableVector.java @@ -0,0 +1,109 @@ +package com.sk89q.worldedit.math; + +import com.boydti.fawe.util.MathMan; +import java.io.IOException; +import java.io.Serializable; + +public class MutableVector extends Vector3 implements Serializable { + private transient double x, y, z; + + private static ThreadLocal MUTABLE_CACHE = new ThreadLocal() { + @Override + protected MutableVector initialValue() { + return new MutableVector(); + } + }; + + public static MutableVector get(int x, int y, int z) { + return MUTABLE_CACHE.get().setComponents(x, y, z); + } + + public MutableVector(Vector3 v) { + this(v.getX(), v.getY(), v.getZ()); + } + + public MutableVector(double x, double y, double z) { + super(0, 0, 0); + this.x = x; + this.y = y; + this.z = z; + } + + public MutableVector() { + super(0, 0, 0); + } + + public MutableVector setComponents(BlockVector3 other) { + return setComponents(other.getBlockX(), other.getBlockY(), other.getBlockZ()); + } + +// @Override + public MutableVector setComponents(int x, int y, int z) { + return this.setComponents((double) x, (double) y, (double) z); + } + +// @Override + public MutableVector setComponents(double x, double y, double z) { + this.mutX(x); + this.mutY(y); + this.mutZ(z); + return this; + } + +// @Override + public final void mutX(double x) { + this.x = y; + } + +// @Override + public final void mutY(double y) { + this.y =y; + } + +// @Override + public final void mutZ(double z) { + this.z = y; + } + +// @Override + public final void mutX(int x) { + this.x = (double)x; + } + +// @Override + public final void mutY(int y) { + this.y = (double)y; + } + +// @Override + public final void mutZ(int z) { + this.z = (double)z; + } + + @Override + public final double getX() { + return x; + } + + @Override + public final double getY() { + return y; + } + + @Override + public final double getZ() { + return z; + } + + private void writeObject(java.io.ObjectOutputStream stream) throws IOException { + stream.writeDouble(x); + stream.writeByte((byte) y); + stream.writeDouble(z); + } + + private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException { + this.x = stream.readDouble(); + this.y = stream.readByte() & 0xFF; + this.z = stream.readDouble(); + } +} \ 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..9995b06e9 --- /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 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 bf9533de7..1bb3fd1ad 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 @@ -3,10 +3,15 @@ package com.sk89q.worldedit.math.convolution; import com.boydti.fawe.object.visitor.Fast2DIterator; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +<<<<<<< HEAD import com.sk89q.worldedit.MutableBlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.blocks.BaseBlock; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Regions; @@ -152,7 +157,7 @@ public class HeightMap { public int applyLayers(int[] data) { checkNotNull(data); - Vector minY = region.getMinimumPoint(); + BlockVector3 minY = region.getMinimumPoint(); int originX = minY.getBlockX(); int originY = minY.getBlockY(); int originZ = minY.getBlockZ(); @@ -181,6 +186,7 @@ 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) +<<<<<<< HEAD BlockStateHolder existing = session.getBlock(xr, curBlock, zr); // Skip water/lava @@ -200,13 +206,33 @@ public class HeightMap { } else { existing = PropertyGroup.LEVEL.set(existing, 15); session.setBlock(xr, newBlock, zr, existing); +======= + BlockState existing = session.getBlock(new BlockVector3(xr, curHeight, zr)); + + // Skip water/lava + if (existing.getBlockType() != BlockTypes.WATER && existing.getBlockType() != BlockTypes.LAVA) { + 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 BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr))); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner ++blocksChanged; } } } else if (curHeight > newHeight) { +<<<<<<< HEAD // Fill rest with air for (int y = newBlock + 1; y <= ((curHeight + 15) >> 4); ++y) { session.setBlock(xr, y, zr, fillerAir); +======= + // Shrink -- start from bottom + for (int y = 0; y < newHeight - originY; ++y) { + int copyFrom = (int) (y * scale); + session.setBlock(new BlockVector3(xr, originY + y, zr), session.getBlock(new BlockVector3(xr, originY + copyFrom, zr))); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner ++blocksChanged; } // Set the top block of the column to be the same type @@ -274,12 +300,20 @@ public class HeightMap { } else if (curHeight > newHeight) { // Set the top block of the column to be the same type // (this could otherwise go wrong with rounding) +<<<<<<< HEAD session.setBlock(xr, newHeight, zr, session.getBlock(xr, curHeight, zr)); +======= + session.setBlock(new BlockVector3(xr, newHeight, zr), session.getBlock(new BlockVector3(xr, curHeight, zr))); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner ++blocksChanged; // Fill rest with air for (int y = newHeight + 1; y <= curHeight; ++y) { +<<<<<<< HEAD session.setBlock(xr, y, zr, fillerAir); +======= + session.setBlock(new BlockVector3(xr, y, zr), fillerAir); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner ++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 ac58612ca..e8e79f676 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 @@ -21,7 +21,11 @@ package com.sk89q.worldedit.math.interpolation; -import com.sk89q.worldedit.Vector; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector3; + import java.util.Collections; import java.util.List; @@ -37,10 +41,10 @@ import static com.google.common.base.Preconditions.checkNotNull; 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 +61,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,12 +111,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 +125,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,14 +135,14 @@ public class KochanekBartelsInterpolation implements Interpolation { return fastRetrieve(index); } - private Vector fastRetrieve(int index) { + private Vector3 fastRetrieve(int index) { return nodes.get(index).getPosition(); } - private Vector mutable = new Vector(); + private MutableBlockVector mutable = new MutableBlockVector(); @Override - public Vector getPosition(double position) { + public Vector3 getPosition(double position) { if (coeffA == null) throw new IllegalStateException("Must call setNodes first."); @@ -151,21 +154,21 @@ 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]; double r2 = remainder * remainder; double r3 = r2 * remainder; mutable.mutX((a.getX() * r3 + b.getX() * r2 + c.getX() * remainder + d.getX())); mutable.mutY((a.getY() * r3 + b.getY() * r2 + c.getY() * remainder + d.getY())); mutable.mutZ((a.getZ() * r3 + b.getZ() * r2 + c.getZ() * remainder + d.getZ())); - return mutable; + return mutable.toVector3(); } @Override - public Vector get1stDerivative(double position) { + public Vector3 get1stDerivative(double position) { if (coeffA == null) throw new IllegalStateException("Must call setNodes first."); @@ -177,9 +180,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); } @@ -226,9 +229,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 00fa7c12f..795a5bcf9 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 @@ -21,7 +21,13 @@ package com.sk89q.worldedit.math.interpolation; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.List; @@ -42,7 +48,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 +60,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 +82,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 +93,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 +141,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 7b67c6a86..b99ddbce5 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 @@ -21,7 +21,13 @@ package com.sk89q.worldedit.math.interpolation; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.List; import java.util.Map.Entry; @@ -65,7 +71,7 @@ public class ReparametrisingInterpolation implements Interpolation { } @Override - public Vector getPosition(double position) { + public Vector3 getPosition(double position) { if (position > 1) return null; @@ -73,7 +79,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 2bb5a63f5..7e10b4d6e 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 @@ -1,11 +1,13 @@ package com.sk89q.worldedit.math.transform; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.math.MathUtils; import java.io.IOException; import java.io.Serializable; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MathUtils; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.Vector3; + /** * An affine transform. *

@@ -234,7 +236,11 @@ public class AffineTransform implements Transform, Serializable { 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()); } @@ -280,16 +286,13 @@ public class AffineTransform implements Transform, Serializable { 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) { - // 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 - 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 46cd72177..fcb752d53 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 @@ -19,7 +19,13 @@ package com.sk89q.worldedit.math.transform; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import java.util.ArrayList; import java.util.Arrays; @@ -66,7 +72,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/patterns/Pattern.java b/worldedit-core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java index 812c85029..634b748af 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/patterns/Pattern.java @@ -2,6 +2,7 @@ package com.sk89q.worldedit.patterns; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; /** @@ -17,7 +18,7 @@ public interface Pattern { * @param position the position where a block is needed * @return a block */ - public BaseBlock next(Vector position); + public BaseBlock next(BlockVector3 position); /** * Get a block for a position. This return value of this method does 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 9bc7159f6..8b0b84350 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,8 +19,14 @@ package com.sk89q.worldedit.regions; +<<<<<<< HEAD import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.iterator.RegionIterator; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -36,8 +42,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); } /** @@ -46,7 +52,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); } @@ -61,7 +67,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); } @@ -76,20 +82,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; } @@ -101,12 +107,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); } /** @@ -116,10 +122,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; } /** @@ -129,10 +135,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; } /** @@ -142,10 +148,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; } /** @@ -154,21 +160,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 )); @@ -179,20 +185,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 69b7de440..e2b3b92c4 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 @@ -24,10 +24,18 @@ import com.boydti.fawe.object.collection.LocalBlockVectorSet; import com.sk89q.worldedit.*; import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.util.Location; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.MutableBlockVector; +import com.sk89q.worldedit.math.MutableBlockVector2D; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.ChunkStore; import java.util.AbstractSet; +import java.util.HashSet; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; @@ -40,10 +48,11 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class CuboidRegion extends AbstractRegion implements FlatRegion { - private Vector pos1; - private Vector pos2; + private boolean useOldIterator; private int minX, minY, minZ, maxX, maxY, maxZ; + private BlockVector3 pos1; + private BlockVector3 pos2; /** * Construct a new instance of this cuboid using two corners of the cuboid. @@ -51,7 +60,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); } @@ -62,19 +71,12 @@ 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); this.pos1 = pos1; this.pos2 = pos2; - if (pos1 instanceof Location) { - Extent extent = ((Location) pos1).getExtent(); - if (extent instanceof World) setWorld((World) extent); - } else if (pos2 instanceof Location) { - Extent extent = ((Location) pos2).getExtent(); - if (extent instanceof World) setWorld((World) extent); - } recalculate(); } @@ -87,7 +89,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @return a position */ - public Vector getPos1() { + public BlockVector3 getPos1() { return pos1; } @@ -96,7 +98,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; recalculate(); } @@ -106,7 +108,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { * * @return a position */ - public Vector getPos2() { + public BlockVector3 getPos2() { return pos2; } @@ -115,7 +117,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; recalculate(); } @@ -129,8 +131,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } pos1 = pos1.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY()); pos2 = pos2.clampY(world == null ? Integer.MIN_VALUE : 0, world == null ? Integer.MAX_VALUE : world.getMaxY()); - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); minX = min.getBlockX(); minY = min.getBlockY(); minZ = min.getBlockZ(); @@ -145,21 +147,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(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())), - new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())), + 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(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())), - new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), 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(new Vector(pos1.getX(), min.getY(), pos1.getZ()), new Vector(pos2.getX(), min.getY(), pos2.getZ())), - new CuboidRegion(new Vector(pos1.getX(), max.getY(), pos1.getZ()), new Vector(pos2.getX(), max.getY(), pos2.getZ()))); + new CuboidRegion(pos1.withY(min.getY()), pos2.withY(min.getY())), + new CuboidRegion(pos1.withY(max.getY()), pos2.withY(max.getY()))); } /** @@ -169,31 +171,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(new Vector(min.getX(), pos1.getY(), pos1.getZ()), new Vector(min.getX(), pos2.getY(), pos2.getZ())), - new CuboidRegion(new Vector(max.getX(), pos1.getY(), pos1.getZ()), new Vector(max.getX(), pos2.getY(), pos2.getZ())), + 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(new Vector(pos1.getX(), pos1.getY(), min.getZ()), new Vector(pos2.getX(), pos2.getY(), min.getZ())), - new CuboidRegion(new Vector(pos1.getX(), pos1.getY(), max.getZ()), new Vector(pos2.getX(), pos2.getY(), 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 @@ -207,49 +205,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()); } } } @@ -258,49 +256,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()); } } } @@ -309,19 +307,19 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Set getChunks() { - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + public Set getChunks() { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); final int maxX = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; final int minX = min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; final int maxZ = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; final int minZ = min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; final int size = (maxX - minX + 1) * (maxZ - minZ + 1); - return new AbstractSet() { + return new AbstractSet() { @Override - public Iterator iterator() { - return new Iterator() { + public Iterator iterator() { + return new Iterator() { private MutableBlockVector2D pos = new MutableBlockVector2D().setComponents(maxX + 1, maxZ); @Override @@ -330,8 +328,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Vector2D next() { - Vector2D result = pos; + public BlockVector2 next() { + BlockVector2 result = pos; // calc next pos.setComponents(pos.getX() - 1, pos.getZ()); if (pos.getX() <= minX) { @@ -358,8 +356,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { @Override public boolean contains(Object o) { - if (o instanceof Vector2D) { - Vector2D cv = (Vector2D) o; + if (o instanceof BlockVector2) { + BlockVector2 cv = (BlockVector2) o; return cv.getX() >= minX && cv.getX() <= maxX && cv.getZ() >= minZ && cv.getZ() <= maxZ; } else { return false; @@ -367,26 +365,23 @@ 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); recalculate(); } - @Override - public Set getChunkCubes() { - Set chunks = new LocalBlockVectorSet(); + public Set getChunkCubes() { + Set chunks = new HashSet<>(); - Vector min = getMinimumPoint(); - Vector max = getMaximumPoint(); + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); - for (int x = max.getBlockX() >> ChunkStore.CHUNK_SHIFTS; x >= min.getBlockX() >> ChunkStore.CHUNK_SHIFTS; --x) { - for (int z = max.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; z >= min.getBlockZ() >> ChunkStore.CHUNK_SHIFTS; --z) { - for (int y = max.getBlockY() >> ChunkStore.CHUNK_SHIFTS; y >= min.getBlockY() >> ChunkStore.CHUNK_SHIFTS; --y) { - chunks.add(new Vector(x, y, z)); + 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 BlockVector3(x, y, z)); } } } @@ -394,10 +389,6 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { return chunks; } - @Override - public boolean contains(Vector position) { - return contains(position.getBlockX(), position.getBlockY(), position.getBlockZ()); - } // private int ly = Integer.MIN_VALUE; // private int lz = Integer.MIN_VALUE; @@ -426,16 +417,22 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { public boolean contains(int x, int z) { return x >= this.minX && x <= this.maxX && z >= this.minZ && z <= this.maxZ; } + @Override + public boolean contains(BlockVector3 position) { + BlockVector3 min = getMinimumPoint(); + BlockVector3 max = getMaximumPoint(); + return position.containedWithin(min, max); + } @Override - public Iterator iterator() { + public Iterator iterator() { if (Settings.IMP.HISTORY.COMPRESSION_LEVEL >= 9 || useOldIterator) { return iterator_old(); } - return new Iterator() { + return new Iterator() { final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); + private BlockVector3 min = getMinimumPoint(); + private BlockVector3 max = getMaximumPoint(); int bx = min.getBlockX(); int by = min.getBlockY(); @@ -458,13 +455,14 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { public boolean hasNext = true; + @Override public boolean hasNext() { return hasNext; } @Override - public BlockVector next() { + public BlockVector3 next() { mutable.mutX(x); mutable.mutY(y); mutable.mutZ(z); @@ -507,19 +505,15 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } return mutable; } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } }; } - public Iterator iterator_old() { + public Iterator iterator_old() { final MutableBlockVector mutable = new MutableBlockVector(0, 0, 0); - return new Iterator() { - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); + 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(); @@ -531,7 +525,7 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public BlockVector next() { + public BlockVector3 next() { mutable.mutX(nextX); mutable.mutY(nextY); mutable.mutZ(nextZ); @@ -557,23 +551,18 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } return mutable; } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } }; } @Override - public Iterable asFlatRegion() { - return new Iterable() { + public Iterable asFlatRegion() { + return new Iterable() { @Override - public Iterator iterator() { + public Iterator iterator() { MutableBlockVector2D mutable = new MutableBlockVector2D(); - return new Iterator() { - private Vector min = getMinimumPoint(); - private Vector max = getMaximumPoint(); + return new Iterator() { + private BlockVector3 min = getMinimumPoint(); + private BlockVector3 max = getMaximumPoint(); private int nextX = min.getBlockX(); private int nextZ = min.getBlockZ(); @@ -583,9 +572,9 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } @Override - public Vector2D next() { + public BlockVector2 next() { if (!hasNext()) throw new java.util.NoSuchElementException(); - Vector2D answer = mutable.setComponents(nextX, nextZ); + BlockVector2 answer = mutable.setComponents(nextX, nextZ); if (++nextX > max.getBlockX()) { nextX = min.getBlockX(); if (++nextZ > max.getBlockZ()) { @@ -636,8 +625,8 @@ public class CuboidRegion extends AbstractRegion implements FlatRegion { } public static boolean contains(CuboidRegion region) { - Vector min = region.getMinimumPoint(); - Vector max = region.getMaximumPoint(); + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); return region.contains(min.getBlockX(), min.getBlockY(), min.getBlockZ()) && region.contains(max.getBlockX(), max.getBlockY(), max.getBlockZ()); } @@ -648,10 +637,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 afe7a7367..a7408266e 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 @@ -19,11 +19,20 @@ package com.sk89q.worldedit.regions; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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,9 +48,14 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class CylinderRegion extends AbstractRegion implements FlatRegion { +<<<<<<< HEAD private BlockVector2D center; private BlockVector2D radius; private Vector2D radiusInverse; +======= + private BlockVector2 center; + private Vector2 radius; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner private int minY; private int maxY; private boolean hasY = false; @@ -59,7 +73,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; } @@ -72,9 +86,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; @@ -89,9 +103,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; @@ -99,11 +113,12 @@ 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 +<<<<<<< HEAD public Vector getCenter() { return center.toVector((getMaximumY() + getMinimumY()) / 2); } @@ -116,6 +131,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { @Deprecated public void setCenter(Vector center) { setCenter(center.toVector2D()); +======= + public Vector3 getCenter() { + return center.toVector3((maxY + minY) / 2); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** @@ -123,8 +142,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @param center the center point */ +<<<<<<< HEAD public void setCenter(Vector2D center) { this.center = new BlockVector2D(center); +======= + public void setCenter(BlockVector2 center) { + this.center = center; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** @@ -132,7 +156,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); } @@ -141,9 +165,14 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * * @param radius the radius along the X and Z axes */ +<<<<<<< HEAD public void setRadius(Vector2D radius) { this.radius = radius.add(0.5, 0.5).toBlockVector2D(); this.radiusInverse = Vector2D.ONE.divide(radius); +======= + public void setRadius(Vector2 radius) { + this.radius = radius.add(0.5, 0.5); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** @@ -151,8 +180,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())); } /** @@ -176,6 +205,7 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override +<<<<<<< HEAD public Vector getMinimumPoint() { return center.subtract(getRadius()).toVector(getMinimumY()); } @@ -183,6 +213,15 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { @Override public Vector getMaximumPoint() { return center.add(getRadius()).toVector(getMaximumY()); +======= + public BlockVector3 getMinimumPoint() { + return center.toVector2().subtract(getRadius()).toVector3(minY).toBlockPoint(); + } + + @Override + public BlockVector3 getMaximumPoint() { + return center.toVector2().add(getRadius()).toVector3(maxY).toBlockPoint(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Override @@ -222,10 +261,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) { @@ -235,10 +274,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(); @@ -252,11 +291,18 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @throws RegionOperationException */ @Override +<<<<<<< HEAD public void expand(Vector... changes) throws RegionOperationException { center = center.add(calculateDiff2D(changes)).toBlockVector2D(); radius = radius.add(calculateChanges2D(changes)).toBlockVector2D(); this.radiusInverse = Vector2D.ONE.divide(radius); for (Vector change : changes) { +======= + public void expand(BlockVector3... changes) throws RegionOperationException { + center = center.add(calculateDiff2D(changes)); + radius = radius.add(calculateChanges2D(changes).toVector2()); + for (BlockVector3 change : changes) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int changeY = change.getBlockY(); if (changeY > 0) { maxY += changeY; @@ -273,12 +319,20 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * @throws RegionOperationException */ @Override +<<<<<<< HEAD public void contract(Vector... changes) throws RegionOperationException { center = center.subtract(calculateDiff2D(changes)).toBlockVector2D(); Vector2D newRadius = radius.subtract(calculateChanges2D(changes)); radius = Vector2D.getMaximum(new Vector2D(1.5, 1.5), newRadius).toBlockVector2D(); this.radiusInverse = Vector2D.ONE.divide(radius); for (Vector change : changes) { +======= + public void contract(BlockVector3... changes) throws RegionOperationException { + center = center.subtract(calculateDiff2D(changes)); + Vector2 newRadius = radius.subtract(calculateChanges2D(changes).toVector2()); + radius = new Vector2(1.5, 1.5).getMaximum(newRadius); + for (BlockVector3 change : changes) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int height = maxY - minY; int changeY = change.getBlockY(); if (changeY > 0) { @@ -290,8 +344,13 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override +<<<<<<< HEAD public void shift(Vector change) throws RegionOperationException { center = center.add(change.toVector2D()).toBlockVector2D(); +======= + public void shift(BlockVector3 change) throws RegionOperationException { + center = center.add(change.toBlockVector2()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int changeY = change.getBlockY(); maxY += changeY; @@ -302,9 +361,15 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { * Checks to see if a point is inside this region. */ @Override +<<<<<<< HEAD public boolean contains(Vector position) { final int pt = position.getBlockY(); if (pt < getMinimumY() || pt > getMaximumY()) { +======= + public boolean contains(BlockVector3 position) { + final int blockY = position.getBlockY(); + if (blockY < minY || blockY > maxY) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return false; } int px = position.getBlockX(); @@ -313,7 +378,11 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { double dx = Math.abs(px - center.getBlockX()) * radiusInverse.getX(); double dz = Math.abs(pz - center.getBlockZ()) * radiusInverse.getZ(); +<<<<<<< HEAD return dx * dx + dz * dz <= 1; +======= + return position.toBlockVector2().subtract(center).toVector2().divide(radius).lengthSq() <= 1; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @@ -341,11 +410,12 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { } @Override - public Iterator iterator() { + public Iterator iterator() { return new FlatRegion3DIterator(this); } @Override +<<<<<<< HEAD public Iterable asFlatRegion() { return new Iterable() { @Override @@ -353,6 +423,10 @@ public class CylinderRegion extends AbstractRegion implements FlatRegion { return new FlatRegionIterator(CylinderRegion.this); } }; +======= + public Iterable asFlatRegion() { + return () -> new FlatRegionIterator(CylinderRegion.this); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } /** @@ -372,7 +446,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); } @@ -386,10 +460,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 a35614bc5..b335f3448 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,11 +19,11 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.BlockVector2D; -import com.sk89q.worldedit.MutableBlockVector; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.Vector2D; + +import com.sk89q.worldedit.math.MutableBlockVector; +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; import java.util.HashSet; @@ -53,7 +53,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); } @@ -65,10 +65,10 @@ 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 = new MutableBlockVector(center); - setRadius(radius); + setRadius(radius.toBlockPoint()); } public EllipsoidRegion(EllipsoidRegion ellipsoidRegion) { @@ -76,13 +76,13 @@ public class EllipsoidRegion extends AbstractRegion { } @Override - public Vector getMinimumPoint() { - return center.subtract(getRadius()).clampY(0, 255); + public BlockVector3 getMinimumPoint() { + return center.toVector3().subtract(getRadius()).toBlockPoint(); } @Override - public Vector getMaximumPoint() { - return center.add(getRadius()).clampY(0, 255); + public BlockVector3 getMaximumPoint() { + return center.toVector3().add(getRadius()).toBlockPoint(); } @Override @@ -106,8 +106,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( @@ -117,30 +117,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 BlockVector3 calculateChanges(BlockVector3... changes) { + BlockVector3 total = BlockVector3.ZERO; + for (BlockVector3 change : changes) { + total = total.add(change.abs()); } return total.divide(2).floor(); } @Override - public void expand(Vector... changes) throws RegionOperationException { + public void expand(BlockVector3... changes) throws RegionOperationException { center = new MutableBlockVector(center.add(calculateDiff(changes))); setRadius(radius.add(calculateChanges(changes))); } @Override - public void contract(Vector... changes) throws RegionOperationException { + public void contract(BlockVector3... changes) throws RegionOperationException { center = new MutableBlockVector(center.subtract(calculateDiff(changes))); - Vector newRadius = radius.subtract(calculateChanges(changes)); - setRadius(Vector.getMaximum(new Vector(1.5, 1.5, 1.5), newRadius)); + BlockVector3 newRadius = radius.subtract(calculateChanges(changes)); + setRadius(new BlockVector3(1.5, 1.5, 1.5).getMaximum(newRadius)); } @Override - public void shift(Vector change) throws RegionOperationException { + public void shift(BlockVector3 change) throws RegionOperationException { center = new MutableBlockVector(center.add(change)); } @@ -150,8 +150,8 @@ public class EllipsoidRegion extends AbstractRegion { * @return center */ @Override - public Vector getCenter() { - return center; + public Vector3 getCenter() { + return center.toVector3(); } /** @@ -159,7 +159,7 @@ public class EllipsoidRegion extends AbstractRegion { * * @param center the center */ - public void setCenter(Vector center) { + public void setCenter(BlockVector3 center) { this.center = new MutableBlockVector(center); } @@ -168,9 +168,9 @@ public class EllipsoidRegion extends AbstractRegion { * * @return radii */ - public Vector getRadius() { + public Vector3 getRadius() { if (radius == null) return null; - return radius.subtract(0.5, 0.5, 0.5); + return radius.toVector3().subtract(0.5, 0.5, 0.5); } /** @@ -178,11 +178,11 @@ public class EllipsoidRegion extends AbstractRegion { * * @param radius the radius */ - public void setRadius(Vector radius) { - this.radius = new MutableBlockVector(radius.add(0.5, 0.5, 0.5)); + public void setRadius(BlockVector3 radius) { + this.radius = new MutableBlockVector(radius); radiusSqr = new MutableBlockVector(radius.multiply(radius)); radiusLengthSqr = radiusSqr.getBlockX(); - if (radius.getBlockY() == radius.getBlockX() && radius.getBlockX() == radius.getBlockZ()) { + if (radius.getY() == radius.getX() && radius.getX() == radius.getZ()) { this.sphere = true; } else { this.sphere = false; @@ -190,22 +190,22 @@ public class EllipsoidRegion extends AbstractRegion { } @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( - x >> ChunkStore.CHUNK_SHIFTS, - z >> ChunkStore.CHUNK_SHIFTS + chunks.add(new BlockVector2( + x >> ChunkStore.CHUNK_SHIFTS, + z >> ChunkStore.CHUNK_SHIFTS )); } } @@ -214,29 +214,31 @@ public class EllipsoidRegion extends AbstractRegion { } @Override - public boolean contains(Vector position) { - int cx = position.getBlockX() - center.getBlockX(); - int cx2 = cx * cx; - if (cx2 > radiusSqr.getBlockX()) { - return false; - } - int cz = position.getBlockZ() - center.getBlockZ(); - int cz2 = cz * cz; - if (cz2 > radiusSqr.getBlockZ()) { - return false; - } - int cy = position.getBlockY() - center.getBlockY(); - int cy2 = cy * cy; - if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) { - return false; - } - if (sphere) { - return cx2 + cy2 + cz2 <= radiusLengthSqr; - } - double cxd = (double) cx / radius.getBlockX(); - double cyd = (double) cy / radius.getBlockY(); - double czd = (double) cz / radius.getBlockZ(); - return cxd * cxd + cyd * cyd + czd * czd <= 1; +// public boolean contains(Vector position) { +// int cx = position.getBlockX() - center.getBlockX(); +// int cx2 = cx * cx; +// if (cx2 > radiusSqr.getBlockX()) { +// return false; +// } +// int cz = position.getBlockZ() - center.getBlockZ(); +// int cz2 = cz * cz; +// if (cz2 > radiusSqr.getBlockZ()) { +// return false; +// } +// int cy = position.getBlockY() - center.getBlockY(); +// int cy2 = cy * cy; +// if (radiusSqr.getBlockY() < 255 && cy2 > radiusSqr.getBlockY()) { +// return false; +// } +// if (sphere) { +// return cx2 + cy2 + cz2 <= radiusLengthSqr; +// } +// double cxd = (double) cx / radius.getBlockX(); +// double cyd = (double) cy / radius.getBlockY(); +// double czd = (double) cz / radius.getBlockZ(); +// return cxd * cxd + cyd * cyd + czd * czd <= 1; + public boolean contains(BlockVector3 position) { + return position.subtract(center).divide(radius).lengthSq() <= 1; } /** @@ -250,8 +252,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()).toBlockPoint()); } @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/IDelegateRegion.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/IDelegateRegion.java index 131e46b8b..be3c64e82 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/IDelegateRegion.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/IDelegateRegion.java @@ -1,6 +1,10 @@ package com.sk89q.worldedit.regions; import com.sk89q.worldedit.*; +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.world.World; import java.util.Iterator; import java.util.List; @@ -12,22 +16,22 @@ public interface IDelegateRegion extends Region { public Region getRegion(); @Override - default Iterator iterator() { + default Iterator iterator() { return getRegion().iterator(); } @Override - default Vector getMinimumPoint() { + default BlockVector3 getMinimumPoint() { return getRegion().getMinimumPoint(); } @Override - default Vector getMaximumPoint() { + default BlockVector3 getMaximumPoint() { return getRegion().getMaximumPoint(); } @Override - default Vector getCenter() { + default Vector3 getCenter() { return getRegion().getCenter(); } @@ -52,32 +56,32 @@ public interface IDelegateRegion extends Region { } @Override - default void expand(Vector... changes) throws RegionOperationException { + default void expand(BlockVector3... changes) throws RegionOperationException { getRegion().expand(changes); } @Override - default void contract(Vector... changes) throws RegionOperationException { + default void contract(BlockVector3... changes) throws RegionOperationException { getRegion().contract(changes); } @Override - default void shift(Vector change) throws RegionOperationException { + default void shift(BlockVector3 change) throws RegionOperationException { getRegion().shift(change); } @Override - default boolean contains(Vector position) { + default boolean contains(BlockVector3 position) { return getRegion().contains(position); } @Override - default Set getChunks() { + default Set getChunks() { return getRegion().getChunks(); } @Override - default Set getChunkCubes() { + default Set getChunkCubes() { return getRegion().getChunkCubes(); } @@ -98,7 +102,7 @@ public interface IDelegateRegion extends Region { } @Override - default List polygonize(int maxPoints) { + default List polygonize(int maxPoints) { return getRegion().polygonize(maxPoints); } } 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 7730b6756..7ac33b929 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,8 +19,14 @@ package com.sk89q.worldedit.regions; +<<<<<<< HEAD import com.sk89q.worldedit.*; import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.World; import java.util.*; @@ -33,18 +39,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 @@ -68,32 +74,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(); } @@ -113,27 +119,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 4371aec40..18d7e6b36 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,6 +277,7 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { } @Override +<<<<<<< HEAD public boolean contains(int targetX, int targetZ) { boolean inside = false; int npoints = points.size(); @@ -343,6 +327,9 @@ public class Polygonal2DRegion extends AbstractRegion implements FlatRegion { @Override public boolean contains(Vector position) { +======= + public boolean contains(BlockVector3 position) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return contains(points, minY, maxY, position); } @@ -355,7 +342,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; } @@ -446,12 +433,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); } @@ -464,10 +451,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(" - "); } @@ -483,7 +470,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 d35c0a5e7..db44b637d 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,7 +19,9 @@ package com.sk89q.worldedit.regions; -import com.sk89q.worldedit.*; +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 javax.annotation.Nullable; @@ -29,21 +31,21 @@ import java.util.Set; /** * 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 */ - public Vector getMinimumPoint(); + BlockVector3 getMinimumPoint(); /** * Get the upper point of a region. * * @return max. point */ - public Vector getMaximumPoint(); + BlockVector3 getMaximumPoint(); /** * Get the center point of a region. @@ -52,7 +54,7 @@ public interface Region extends Iterable, Cloneable { * * @return center point */ - public Vector getCenter(); + Vector3 getCenter(); /** * Get the number of blocks in the region. @@ -88,7 +90,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - public void expand(Vector... changes) throws RegionOperationException; + void expand(BlockVector3... changes) throws RegionOperationException; /** * Contract the region. @@ -96,7 +98,7 @@ public interface Region extends Iterable, Cloneable { * @param changes array/arguments with multiple related changes * @throws RegionOperationException */ - public void contract(Vector... changes) throws RegionOperationException; + void contract(BlockVector3... changes) throws RegionOperationException; /** * Shift the region. @@ -104,43 +106,43 @@ public interface Region extends Iterable, Cloneable { * @param change the change * @throws RegionOperationException */ - public void shift(Vector change) throws RegionOperationException; + void shift(BlockVector3 change) throws RegionOperationException; - /** - * Returns true based on whether the region contains the point. - * - * @param position the position - * @return true if contained - */ - public boolean contains(Vector position); default boolean contains(int x, int y, int z) { - return contains(MutableBlockVector.get(x, y, z)); + return contains(new BlockVector3(x, y, z)); } default boolean contains(int x, int z) { - return contains(MutableBlockVector.get(x, 0, z)); + return contains(new BlockVector3(x, 0, z)); } default boolean isGlobal() { - Vector pos1 = getMinimumPoint(); - Vector pos2 = getMaximumPoint(); + BlockVector3 pos1 = getMinimumPoint(); + BlockVector3 pos2 = getMaximumPoint(); return pos1.getBlockX() == Integer.MIN_VALUE && pos1.getBlockZ() == Integer.MIN_VALUE && pos2.getBlockX() == Integer.MAX_VALUE && pos2.getBlockZ() == Integer.MAX_VALUE && pos1.getBlockY() <= 0 && pos2.getBlockY() >= 255; } + /** + * Returns true based on whether the region contains the point. + * + * @param position the position + * @return true if contained + */ + boolean contains(BlockVector3 position); /** * Get a list of chunks. * * @return a list of chunk coordinates */ - public Set getChunks(); + Set getChunks(); /** * Return a list of 16*16*16 chunks in a region * * @return the chunk cubes this region overlaps with */ - public Set getChunkCubes(); + Set getChunkCubes(); /** * Sets the world that the selection is in. @@ -170,5 +172,5 @@ public interface Region extends Iterable, Cloneable { * @param maxPoints maximum number of points to generate. -1 for no limit. * @return the points. */ - public 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 247a9e250..9bdc81119 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 cff94d8cd..30b6acdd0 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 @@ -19,9 +19,17 @@ package com.sk89q.worldedit.regions; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.math.transform.Identity; import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.world.World; @@ -97,17 +105,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()); } @@ -132,50 +140,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 7cfeff11e..b091873a1 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 @@ -19,25 +19,36 @@ package com.sk89q.worldedit.regions.iterator; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.FlatRegion; import java.util.Iterator; import java.util.NoSuchElementException; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkNotNull; public class FlatRegion3DIterator implements Iterator { +======= +public class FlatRegion3DIterator implements Iterator { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner - 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 +74,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 803ce55a5..a3521e3ef 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 @@ -19,15 +19,27 @@ package com.sk89q.worldedit.regions.iterator; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.Region; import java.util.Iterator; +import java.util.NoSuchElementException; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkNotNull; public class FlatRegionIterator implements Iterator { +======= +public class FlatRegionIterator implements Iterator { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner private Region region; private int y; @@ -42,8 +54,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 +76,22 @@ public class FlatRegionIterator implements Iterator { } private void forward() { +<<<<<<< HEAD while (hasNext() && !region.contains(nextX, y, nextZ)) { +======= + while (hasNext() && !region.contains(new BlockVector3(nextX, y, nextZ))) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +111,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 9d3b4542d..6c5d7d7b2 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 @@ -19,21 +19,31 @@ package com.sk89q.worldedit.regions.iterator; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.Region; import java.util.Iterator; +<<<<<<< HEAD import static com.google.common.base.Preconditions.checkNotNull; public class RegionIterator implements Iterator { +======= +public class RegionIterator implements Iterator { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +53,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 +72,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 875af7659..6fc5383d4 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 @@ -19,16 +19,22 @@ package com.sk89q.worldedit.regions.polyhedron; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import static com.google.common.base.Preconditions.checkNotNull; 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 +77,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 +88,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 ed1ee46c8..93b160b59 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 @@ -19,15 +19,21 @@ package com.sk89q.worldedit.regions.polyhedron; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import static com.google.common.base.Preconditions.checkNotNull; 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 +43,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 +60,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 +83,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 +94,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 c60313581..1fe85b0e6 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 @@ -19,16 +19,22 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -48,7 +54,7 @@ import static com.google.common.base.Preconditions.checkNotNull; 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. @@ -98,9 +104,15 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion region = new ConvexPolyhedralRegion(oldRegion.getWorld()); +<<<<<<< HEAD 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)); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } learnChanges(); @@ -124,15 +136,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(); @@ -145,7 +157,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { return pos1; } @@ -175,7 +187,7 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion @Override public void learnChanges() { - pos1 = region.getVertices().iterator().next().toBlockVector(); + pos1 = region.getVertices().iterator().next(); } @Override @@ -200,7 +212,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); @@ -211,7 +223,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); @@ -243,12 +255,16 @@ public class ConvexPolyhedralRegionSelector implements RegionSelector, CUIRegion checkNotNull(player); checkNotNull(session); - Collection vertices = region.getVertices(); + Collection vertices = region.getVertices(); Collection triangles = region.getTriangles(); +<<<<<<< HEAD Map vertexIds = new HashMap(vertices.size()); +======= + Map vertexIds = new HashMap<>(vertices.size()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner int lastVertexId = -1; - for (Vector vertex : vertices) { + for (BlockVector3 vertex : vertices) { vertexIds.put(vertex, ++lastVertexId); session.dispatchCUIEvent(player, new SelectionPointEvent(lastVertexId, vertex, getArea())); } @@ -256,7 +272,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 c595bc335..226482a5c 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 @@ -19,6 +19,7 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.boydti.fawe.config.Commands; import com.boydti.fawe.util.chat.Message; @@ -28,9 +29,16 @@ import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.SelectionCommands; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -49,9 +57,15 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class CuboidRegionSelector implements RegionSelector, CUIRegion { +<<<<<<< HEAD public transient BlockVector position1; public transient BlockVector position2; public transient CuboidRegion region; +======= + protected transient BlockVector3 position1; + protected transient BlockVector3 position2; + protected transient CuboidRegion region; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner /** * Create a new region selector with a {@code null} world. @@ -66,7 +80,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); } /** @@ -90,8 +104,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); region.setPos2(position2); @@ -104,12 +118,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); } @@ -131,33 +145,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); @@ -176,7 +190,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); @@ -209,7 +223,7 @@ public class CuboidRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { if (position1 == null) { throw new IncompleteRegionException(); } @@ -238,8 +252,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 8c4fef073..5c212af98 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 @@ -19,17 +19,24 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.BlockVector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -97,12 +104,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())); @@ -118,7 +125,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); @@ -140,27 +147,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()); @@ -169,18 +176,28 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { } @Override +<<<<<<< HEAD public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_CENTER.send(player, pos, 0); +======= + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { + player.print("Starting a new cylindrical selection at " + pos + "."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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(); +<<<<<<< HEAD if (!center.equals(Vector.ZERO)) { BBC.SELECTOR_RADIUS.send(player, NUMBER_FORMAT.format(region.getRadius().getX()) + "/" + NUMBER_FORMAT.format(region.getRadius().getZ()), region.getArea()); +======= + 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() + ")."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } else { BBC.SELECTION_WAND.send(player); return; @@ -195,12 +212,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 @@ -219,7 +236,7 @@ public class CylinderRegionSelector implements RegionSelector, CUIRegion { @Override public boolean isDefined() { - return !region.getRadius().equals(Vector2D.ZERO); + return !region.getRadius().equals(Vector2.ZERO); } @Override @@ -240,10 +257,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()); } @@ -257,7 +274,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 b15d3627d..e3b8990eb 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 @@ -19,15 +19,21 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.BlockVector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +67,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 +89,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 +105,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,40 +124,58 @@ 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 +<<<<<<< HEAD public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_CENTER.send(player, region.getCenter(), region.getArea()); +======= + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { + if (isDefined()) { + player.print("Center position set to " + region.getCenter() + " (" + region.getArea() + ")."); + } else { + player.print("Center position set to " + region.getCenter() + "."); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.describeCUI(player); } @Override +<<<<<<< HEAD public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_RADIUS.send(player, region.getRadius(), region.getArea()); +======= + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { + if (isDefined()) { + player.print("Radius set to " + region.getRadius() + " (" + region.getArea() + ")."); + } else { + player.print("Radius set to " + region.getRadius() + "."); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.describeCUI(player); } @@ -186,8 +210,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 @@ -199,12 +223,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); } @@ -219,8 +243,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 @@ -245,8 +269,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 41ee319da..c55f11fd1 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,11 +19,14 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.BlockVector; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +66,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 +79,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 +117,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,15 +132,25 @@ public class ExtendingCuboidRegionSelector extends CuboidRegionSelector { } @Override +<<<<<<< HEAD public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_POS.send(player, 1, pos, region.getArea()); +======= + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { + player.print("Started selection at " + pos + " (" + region.getArea() + ")."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner explainRegionAdjust(player, session); } @Override +<<<<<<< HEAD public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_EXPANDED.send(player, pos, region.getArea()); +======= + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { + player.print("Extended selection to encompass " + pos + " (" + region.getArea() + ")."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 2f22fdcf5..6f0cc3abd 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 @@ -19,17 +19,23 @@ package com.sk89q.worldedit.regions.selector; +<<<<<<< HEAD import com.boydti.fawe.config.BBC; import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector2D; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +54,7 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { - private transient BlockVector pos1; + private transient BlockVector3 pos1; private transient Polygonal2DRegion region; /** @@ -96,9 +102,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); } } @@ -111,11 +117,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); } @@ -131,12 +137,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()); @@ -145,11 +151,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; } @@ -168,8 +174,13 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override +<<<<<<< HEAD public void explainPrimarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_POS.send(player, 1, pos, region.getArea()); +======= + public void explainPrimarySelection(Actor player, LocalSession session, BlockVector3 pos) { + player.print("Starting a new polygon at " + pos + "."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.dispatchCUIEvent(player, new SelectionShapeEvent(getTypeID())); session.dispatchCUIEvent(player, new SelectionPoint2DEvent(0, pos, getArea())); @@ -177,8 +188,13 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override +<<<<<<< HEAD public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_POS.send(player, region.size(), pos, region.getArea()); +======= + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { + player.print("Added point #" + region.size() + " at " + pos + "."); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.dispatchCUIEvent(player, new SelectionPoint2DEvent(region.size() - 1, pos, getArea())); session.dispatchCUIEvent(player, new SelectionMinMaxEvent(region.getMinimumY(), region.getMaximumY())); @@ -191,7 +207,7 @@ public class Polygonal2DRegionSelector implements RegionSelector, CUIRegion { } @Override - public BlockVector getPrimaryPosition() throws IncompleteRegionException { + public BlockVector3 getPrimaryPosition() throws IncompleteRegionException { if (pos1 == null) { throw new IncompleteRegionException(); } @@ -220,8 +236,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 @@ -256,7 +272,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 14dace6bf..815d4b652 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 @@ -21,8 +21,9 @@ package com.sk89q.worldedit.regions.selector; import com.boydti.fawe.config.BBC; 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,25 +69,34 @@ 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 +<<<<<<< HEAD public void explainSecondarySelection(Actor player, LocalSession session, Vector pos) { BBC.SELECTOR_RADIUS.send(player, region.getRadius().getX(), region.getArea()); +======= + public void explainSecondarySelection(Actor player, LocalSession session, BlockVector3 pos) { + if (isDefined()) { + player.print("Radius set to " + region.getRadius().getX() + " (" + region.getArea() + ")."); + } else { + player.print("Radius set to " + region.getRadius().getX() + "."); + } +>>>>>>> 399e0ad5... Refactor vector system to be cleaner session.describeCUI(player); } 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 30b1aaecd..e18363721 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,12 +19,12 @@ 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.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.Region; /** @@ -66,7 +66,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 c1119246f..7377a1657 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,12 @@ package com.sk89q.worldedit.regions.shape; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.regions.Region; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.regions.Region; @@ -36,7 +41,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 a889d8d88..a25210135 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,35 +19,35 @@ 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.extent.Extent; 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; private Extent extent; - public WorldEditExpressionEnvironment(EditSession editSession, Vector unit, Vector zero) { + public WorldEditExpressionEnvironment(EditSession editSession, Vector3 unit, Vector3 zero) { this((Extent) editSession, unit, zero); } - public WorldEditExpressionEnvironment(Extent extent, Vector unit, Vector zero) { + public WorldEditExpressionEnvironment(Extent extent, Vector3 unit, Vector3 zero) { this.extent = extent; 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); } @@ -81,7 +81,7 @@ public class WorldEditExpressionEnvironment implements ExpressionEnvironment { return extent.getBlock(toWorld(x, y, z)).getBlockType().getLegacyCombinedId() & 0xF; } - 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 ee8061800..8ccd26445 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 @@ -19,9 +19,14 @@ package com.sk89q.worldedit.session; +<<<<<<< HEAD import com.boydti.fawe.util.MaskTraverser; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; +======= +import static com.google.common.base.Preconditions.checkNotNull; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard; @@ -31,6 +36,7 @@ import com.sk89q.worldedit.function.mask.ExistingBlockMask; import com.sk89q.worldedit.function.mask.Mask; 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; @@ -45,7 +51,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; private boolean ignoreBiomes; private boolean ignoreEntities; @@ -71,7 +77,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 b6392f093..d74185d6d 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,7 +19,15 @@ package com.sk89q.worldedit.session.request; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +import com.sk89q.worldedit.IncompleteRegionException; +import com.sk89q.worldedit.LocalSession; +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.NullRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.RegionOperationException; @@ -59,17 +67,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(); } @@ -94,32 +102,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(); } @@ -139,12 +147,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 62b551bdd..70d73475e 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,8 +19,8 @@ package com.sk89q.worldedit.util; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.math.Vector3; import javax.annotation.Nullable; import java.util.HashMap; @@ -30,30 +30,30 @@ import java.util.HashMap; */ public enum Direction { - NORTH(new Vector(0, 0, -1), Flag.CARDINAL, 3, 1), - EAST(new Vector(1, 0, 0), Flag.CARDINAL, 0, 2), - SOUTH(new Vector(0, 0, 1), Flag.CARDINAL, 1, 3), - WEST(new Vector(-1, 0, 0), Flag.CARDINAL, 2, 0), + NORTH(new Vector3(0, 0, -1), Flag.CARDINAL, 3, 1), + EAST(new Vector3(1, 0, 0), Flag.CARDINAL, 0, 2), + SOUTH(new Vector3(0, 0, 1), Flag.CARDINAL, 1, 3), + WEST(new Vector3(-1, 0, 0), Flag.CARDINAL, 2, 0), - UP(new Vector(0, 1, 0), Flag.UPRIGHT, -1, -1), - DOWN(new Vector(0, -1, 0), Flag.UPRIGHT, -1, -1), + UP(new Vector3(0, 1, 0), Flag.UPRIGHT, -1, -1), + DOWN(new Vector3(0, -1, 0), Flag.UPRIGHT, -1, -1), - NORTHEAST(new Vector(1, 0, -1), Flag.ORDINAL, 7, 8), - NORTHWEST(new Vector(-1, 0, -1), Flag.ORDINAL, 9, 6), - SOUTHEAST(new Vector(1, 0, 1), Flag.ORDINAL, 6, 9), - SOUTHWEST(new Vector(-1, 0, 1), Flag.ORDINAL, 8, 7), + NORTHEAST(new Vector3(1, 0, -1), Flag.ORDINAL, 7, 8), + NORTHWEST(new Vector3(-1, 0, -1), Flag.ORDINAL, 9, 6), + SOUTHEAST(new Vector3(1, 0, 1), Flag.ORDINAL, 6, 9), + SOUTHWEST(new Vector3(-1, 0, 1), Flag.ORDINAL, 8, 7), - WEST_NORTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6), - WEST_SOUTHWEST(new Vector(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7), - NORTH_NORTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6), - NORTH_NORTHEAST(new Vector(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8), - EAST_NORTHEAST(new Vector(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8), - EAST_SOUTHEAST(new Vector(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9), - SOUTH_SOUTHEAST(new Vector(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9), - SOUTH_SOUTHWEST(new Vector(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7); + WEST_NORTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6), + WEST_SOUTHWEST(new Vector3(-Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7), + NORTH_NORTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 9, 6), + NORTH_NORTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, -Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8), + EAST_NORTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, -Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 7, 8), + EAST_SOUTHEAST(new Vector3(Math.cos(Math.PI / 8), 0, Math.sin(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9), + SOUTH_SOUTHEAST(new Vector3(Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 6, 9), + SOUTH_SOUTHWEST(new Vector3(-Math.sin(Math.PI / 8), 0, Math.cos(Math.PI / 8)), Flag.SECONDARY_ORDINAL, 8, 7); - private final Vector direction; - private final BlockVector blockVector; + private final Vector3 direction; + private final BlockVector3 blockVector; private final int flags, left, right; @@ -68,9 +68,9 @@ public enum Direction { } } - private Direction(Vector vector, int flags, int left, int right) { + private Direction(Vector3 vector, int flags, int left, int right) { this.direction = vector.normalize(); - this.blockVector = new BlockVector(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); + this.blockVector = new BlockVector3(Math.signum(vector.getX()), Math.signum(vector.getY()), Math.signum(vector.getZ())); this.flags = flags; this.left = left; this.right = right; @@ -159,19 +159,24 @@ public enum Direction { * * @return the vector */ - public Vector toVector() { + public Vector3 toVector() { return direction; } - public BlockVector toBlockVector() { - return this.blockVector; - } - @Override public String toString() { return name().toLowerCase(); } + /** + * Get the vector. + * + * @return the vector + */ + public BlockVector3 toBlockVector() { + return direction.toBlockPoint(); + } + /** * Find the closest direction to the given direction vector. * @@ -180,9 +185,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(); @@ -204,7 +209,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 new file mode 100644 index 000000000..35552b8d9 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/LocatedBlock.java @@ -0,0 +1,67 @@ +/* + * 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.util; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.block.BlockStateHolder; + +import java.util.Objects; + +/** + * Represents a block located at some position. + */ +public final class LocatedBlock { + + private final BlockVector3 location; + private final BlockStateHolder block; + + public LocatedBlock(BlockVector3 location, BlockStateHolder block) { + this.location = checkNotNull(location); + this.block = checkNotNull(block); + } + + public BlockVector3 getLocation() { + return location; + } + + public BlockStateHolder getBlock() { + return block; + } + + @Override + public int hashCode() { + return Objects.hash(location, block); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (this.getClass() != obj.getClass()) { + return false; + } + LocatedBlock lb = (LocatedBlock) obj; + return Objects.equals(location, lb.location) && Objects.equals(block, lb.block); + } + +} 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 98814eb4a..941748705 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 @@ -19,12 +19,11 @@ package com.sk89q.worldedit.util; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.world.NullWorld; - import static com.google.common.base.Preconditions.checkNotNull; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.Vector3; + /** * Represents a location in a world with has a direction. * @@ -35,9 +34,10 @@ import static com.google.common.base.Preconditions.checkNotNull; * {@link #equals(Object)} are subject to minor differences caused by * floating point errors.

*/ -public class Location extends Vector { +public class Location{ private final Extent extent; + private final Vector3 position; private final float pitch; private final float yaw; @@ -48,7 +48,7 @@ public class Location extends Vector { * @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 extends Vector { * @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 extends Vector { * @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 extends Vector { * @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 extends Vector { * @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 extends Vector { * @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,10 +125,12 @@ public class Location extends Vector { * @param yaw the yaw, in degrees * @param pitch the pitch, in degrees */ - public Location(Extent extent, Vector position, float yaw, float pitch) { - super(position); + + public Location(Extent extent, Vector3 position, float yaw, float pitch) { checkNotNull(extent); + checkNotNull(position); this.extent = extent; + this.position = position; this.pitch = pitch; this.yaw = yaw; } @@ -149,7 +151,7 @@ public class Location extends Vector { * @return the new instance */ public Location setExtent(Extent extent) { - return new Location(extent, this, getDirection()); + return new Location(extent, position, getDirection()); } /** @@ -168,7 +170,7 @@ public class Location extends Vector { * @return the new instance */ public Location setYaw(float yaw) { - return new Location(extent, this, yaw, pitch); + return new Location(extent, position, yaw, pitch); } /** @@ -187,7 +189,7 @@ public class Location extends Vector { * @return the new instance */ public Location setPitch(float pitch) { - return new Location(extent, this, yaw, pitch); + return new Location(extent, position, yaw, pitch); } /** @@ -198,7 +200,7 @@ public class Location extends Vector { * @return the new instance */ public Location setDirection(float yaw, float pitch) { - return new Location(extent, this, yaw, pitch); + return new Location(extent, position, yaw, pitch); } /** @@ -206,11 +208,11 @@ public class Location extends Vector { * * @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)); @@ -231,17 +233,35 @@ public class Location extends Vector { * @param direction the new direction * @return the new instance */ - public Location setDirection(Vector direction) { - return new Location(extent, this, 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() { - return this; + public Vector3 toVector() { + return position; + } + + /** + * Get the X component of the position vector. + * + * @return the X component + */ + public double getX() { + return position.getX(); + } + + /** + * Get the rounded X component of the position vector. + * + * @return the rounded X component + */ + public int getBlockX() { + return (int) Math.floor(position.getX()); } /** @@ -252,18 +272,25 @@ public class Location extends Vector { * @return a new immutable instance */ public Location setX(double x) { - return new Location(extent, super.setX(x), yaw, pitch); + return new Location(extent, position.withX(x), yaw, pitch); } /** - * Return a copy of this object with the X component of the new object - * set to the given value. + * Get the Y component of the position vector. * - * @param x the new value for the X component - * @return a new immutable instance + * @return the Y component */ - public Location setX(int x) { - return new Location(extent, super.setX(x), yaw, pitch); + public double getY() { + return position.getY(); + } + + /** + * Get the rounded Y component of the position vector. + * + * @return the rounded Y component + */ + public int getBlockY() { + return (int) Math.floor(position.getY()); } /** @@ -274,18 +301,25 @@ public class Location extends Vector { * @return a new immutable instance */ public Location setY(double y) { - return new Location(extent, super.setY(y), yaw, pitch); + return new Location(extent, position.withY(y), yaw, pitch); } /** - * Return a copy of this object with the Y component of the new object - * set to the given value. + * Get the Z component of the position vector. * - * @param y the new value for the Y component - * @return a new immutable instance + * @return the Z component */ - public Location setY(int y) { - return new Location(extent, super.setY(y), yaw, pitch); + public double getZ() { + return position.getZ(); + } + + /** + * Get the rounded Z component of the position vector. + * + * @return the rounded Z component + */ + public int getBlockZ() { + return (int) Math.floor(position.getZ()); } /** @@ -296,18 +330,7 @@ public class Location extends Vector { * @return a new immutable instance */ public Location setZ(double z) { - return new Location(extent, super.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, super.setZ(z), yaw, pitch); + return new Location(extent, position.withZ(z), yaw, pitch); } /** @@ -316,7 +339,7 @@ public class Location extends Vector { * @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 2ac640d5d..729c9b644 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,13 @@ package com.sk89q.worldedit.util; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +40,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 @@ -72,8 +77,12 @@ 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 */ +<<<<<<< HEAD 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) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner this.maxDistance = maxDistance; this.checkDistance = checkDistance; this.curDistance = 0; @@ -82,9 +91,15 @@ public class TargetBlock { double h = (checkDistance * Math.cos(Math.toRadians(yRotation))); +<<<<<<< HEAD offset = new Vector((h * Math.cos(Math.toRadians(xRotation))), (checkDistance * Math.sin(Math.toRadians(yRotation))), (h * Math.sin(Math.toRadians(xRotation)))); +======= + offset = new Vector3((h * Math.cos(Math.toRadians(xRotation))), + (checkDistance * Math.sin(Math.toRadians(yRotation))), + (h * Math.sin(Math.toRadians(xRotation)))); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner targetPosDouble = loc.add(0, viewHeight, 0); targetPos = targetPosDouble.toBlockPoint(); @@ -101,7 +116,11 @@ public class TargetBlock { boolean searchForLastBlock = true; Location lastBlock = null; while (getNextBlock() != null) { +<<<<<<< HEAD if (world.getBlockType(getCurrentBlock().toVector()).getMaterial().isAir()) { +======= + if (world.getBlock(targetPos).getBlockType().getMaterial().isAir()) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner if (searchForLastBlock) { lastBlock = getCurrentBlock(); if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { @@ -123,7 +142,11 @@ public class TargetBlock { * @return Block */ public Location getTargetBlock() { +<<<<<<< HEAD while (getNextBlock() != null && world.getBlockType(getCurrentBlock().toVector()).getMaterial().isAir()) ; +======= + while (getNextBlock() != null && world.getBlock(targetPos).getBlockType().getMaterial().isAir()) ; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return getCurrentBlock(); } @@ -134,7 +157,11 @@ public class TargetBlock { * @return Block */ public Location getSolidTargetBlock() { +<<<<<<< HEAD while (getNextBlock() != null && !world.getBlockType(getCurrentBlock().toVector()).getMaterial().isMovementBlocker()) ; +======= + while (getNextBlock() != null && !world.getBlock(targetPos).getBlockType().getMaterial().isMovementBlocker()) ; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner return getCurrentBlock(); } @@ -161,7 +188,7 @@ public class TargetBlock { return null; } - return new Location(world, targetPos); + return new Location(world, targetPos.toVector3()); } /** @@ -173,7 +200,7 @@ public class TargetBlock { if (curDistance > maxDistance) { return null; } else { - return new Location(world, targetPos); + return new Location(world, targetPos.toVector3()); } } @@ -183,7 +210,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 d63ef2f29..899ff229b 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,8 @@ 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.BlockState; import com.sk89q.worldedit.world.block.BlockTypes; @@ -49,7 +50,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 +59,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 +68,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 +84,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 +94,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 +140,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 +175,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 +251,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 +264,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 new file mode 100644 index 000000000..4f303acd6 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/collection/LocatedBlockList.java @@ -0,0 +1,88 @@ +/* + * 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.util.collection; + +import static com.google.common.base.Preconditions.checkNotNull; + +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.util.LocatedBlock; +import com.sk89q.worldedit.world.block.BlockStateHolder; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +/** + * Wrapper around a list of blocks located in the world. + */ +public class LocatedBlockList implements Iterable { + + private final List list; + + public LocatedBlockList() { + list = new ArrayList<>(); + } + + public LocatedBlockList(Collection collection) { + list = new ArrayList<>(collection); + } + + public void add(LocatedBlock setBlockCall) { + checkNotNull(setBlockCall); + list.add(setBlockCall); + } + + public void add(BlockVector3 location, BlockStateHolder block) { + add(new LocatedBlock(location, block)); + } + + public int size() { + return list.size(); + } + + public void clear() { + list.clear(); + } + + @Override + public Iterator iterator() { + return list.iterator(); + } + + public Iterator reverseIterator() { + return new Iterator() { + + private final ListIterator backingIterator = list.listIterator(list.size()); + + @Override + public boolean hasNext() { + return backingIterator.hasPrevious(); + } + + @Override + public LocatedBlock next() { + return backingIterator.previous(); + } + }; + } + +} 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 fd0417f3b..9af32bdd5 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.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -30,6 +28,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; @@ -47,12 +48,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); } @@ -67,36 +68,36 @@ 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 BlockState getLazyBlock(Vector position) { + public BlockState getLazyBlock(BlockVector3 position) { return new BaseBlock(getBlock(position)); } @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)); @@ -112,19 +113,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 @@ -133,11 +134,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 28b9c2a45..8c2a73249 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 @@ -19,10 +19,19 @@ package com.sk89q.worldedit.world; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +import com.sk89q.worldedit.EditSession; +import com.sk89q.worldedit.MaxChangedBlocksException; +import com.sk89q.worldedit.WorldEditException; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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; @@ -53,36 +62,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 @@ -91,7 +100,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; } @@ -114,11 +123,12 @@ public class NullWorld extends AbstractWorld { } @Override - public BlockState getBlock(Vector position) { + public BlockState getBlock(BlockVector3 position) { return BlockTypes.AIR.getDefaultState(); } @Override +<<<<<<< HEAD public BlockState getLazyBlock(Vector position) { return getBlock(position); } @@ -126,6 +136,10 @@ public class NullWorld extends AbstractWorld { @Override public BlockState getFullBlock(Vector position) { return getBlock(position); +======= + public BaseBlock getFullBlock(BlockVector3 position) { + return getBlock(position).toBaseBlock(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/SimpleWorld.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/SimpleWorld.java index 024621a09..31cd6f571 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/SimpleWorld.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/SimpleWorld.java @@ -32,6 +32,9 @@ import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.function.mask.BlockMask; 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.weather.WeatherType; import com.sk89q.worldedit.world.weather.WeatherTypes; @@ -46,22 +49,22 @@ import javax.annotation.Nullable; */ public interface SimpleWorld extends World { @Override - default boolean useItem(Vector position, BaseItem item, Direction face) { + default boolean useItem(BlockVector3 position, BaseItem item, Direction face) { return false; } @Override - default boolean setBlock(Vector position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { + default boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException { return setBlock(position, block); } @Override - default BlockState getFullBlock(Vector position) { + default BlockState getFullBlock(BlockVector3 position) { return getLazyBlock(position); } @Override - boolean setBlock(Vector pt, BlockStateHolder block) throws WorldEditException; + boolean setBlock(BlockVector3 pt, BlockStateHolder block) throws WorldEditException; @Override default int getMaxY() { @@ -74,43 +77,43 @@ public interface SimpleWorld extends World { } @Override - default void dropItem(Vector pt, BaseItemStack item, int times) { + default void dropItem(Vector3 pt, BaseItemStack item, int times) { for (int i = 0; i < times; ++i) { dropItem(pt, item); } } @Override - default void checkLoadedChunk(Vector pt) { + default void checkLoadedChunk(BlockVector3 pt) { } @Override - default void fixAfterFastMode(Iterable chunks) { + default void fixAfterFastMode(Iterable chunks) { } @Override - default void fixLighting(Iterable chunks) { + default void fixLighting(Iterable chunks) { } - @Override - default boolean playEffect(Vector position, int type, int data) { +// @Override + default boolean playEffect(BlockVector3 position, int type, int data) { return false; } @Override - default boolean queueBlockBreakEffect(Platform server, Vector position, BlockType blockType, double priority) { + default boolean queueBlockBreakEffect(Platform server, BlockVector3 position, BlockType blockType, double priority) { SetQueue.IMP.addTask(() -> playEffect(position, 2001, blockType.getLegacyCombinedId() >> 4)); return true; } @Override - default Vector getMinimumPoint() { - return new Vector(-30000000, 0, -30000000); + default BlockVector3 getMinimumPoint() { + return new BlockVector3(-30000000, 0, -30000000); } @Override - default Vector getMaximumPoint() { - return new Vector(30000000, 255, 30000000); + default BlockVector3 getMaximumPoint() { + return new BlockVector3(30000000, 255, 30000000); } @Override @@ -120,12 +123,12 @@ public interface SimpleWorld extends World { @Override - default boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, Vector position) throws MaxChangedBlocksException { + default boolean generateTree(TreeGenerator.TreeType type, EditSession editSession, BlockVector3 position) throws MaxChangedBlocksException { return false; } @Override - default void simulateBlockMine(Vector position) { + default void simulateBlockMine(BlockVector3 position) { try { setBlock(position, BlockTypes.AIR.getDefaultState()); } catch (WorldEditException e) { 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 1063454f2..feb1fbbfe 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,10 +19,8 @@ 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; @@ -32,6 +30,9 @@ import com.sk89q.worldedit.world.block.BlockType; 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; @@ -73,10 +74,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. @@ -93,7 +94,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. @@ -101,7 +102,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. @@ -109,7 +110,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. @@ -118,23 +119,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. @@ -154,19 +155,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 @@ -174,14 +175,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. @@ -191,7 +192,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. @@ -202,7 +203,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/block/BlockTypes.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java index ab4c3bd0f..8fb6e4d1d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockTypes.java @@ -26,7 +26,6 @@ import com.boydti.fawe.util.ReflectionUtils; import com.boydti.fawe.util.StringMan; import com.google.common.collect.Lists; import com.google.common.collect.Maps; -import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BlockMaterial; 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 cfca55233..19247cf06 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,10 +26,12 @@ 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; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; +======= +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -52,7 +54,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 +121,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 +154,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 +227,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 +242,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 +256,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 f5af9bf58..8af1fef05 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,9 +26,13 @@ import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.LongArrayTag; import com.sk89q.jnbt.NBTUtils; import com.sk89q.jnbt.Tag; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BaseBlock; +======= +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.block.BlockState; @@ -53,7 +57,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. @@ -202,7 +206,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); } } @@ -217,12 +221,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; } @@ -231,10 +235,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 09c7440d4..08a8bb4f2 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,5 +35,10 @@ public interface Chunk { * @return block the block * @throws DataException thrown on data error */ +<<<<<<< HEAD BlockStateHolder getBlock(Vector position) throws DataException; +======= + BlockStateHolder getBlock(BlockVector3 position) throws DataException; + +>>>>>>> 399e0ad5... Refactor vector system to be cleaner } 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 7e5b00e7f..52565b016 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,10 +25,12 @@ 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; +<<<<<<< HEAD import com.sk89q.worldedit.blocks.BaseBlock; +======= +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.DataException; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; @@ -52,7 +54,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. @@ -128,7 +130,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); } } @@ -142,12 +144,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; } @@ -155,13 +157,18 @@ public class OldChunk implements Chunk { } @Override +<<<<<<< HEAD public BlockStateHolder getBlock(Vector position) throws DataException { if(position.getBlockY() >= 128) return BlockTypes.VOID_AIR.getDefaultState(); +======= + public BlockStateHolder getBlock(BlockVector3 position) throws DataException { + if(position.getY() >= 128) return BlockTypes.VOID_AIR.getDefaultState().toBaseBlock(); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 ad34a0a86..a1913d04d 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 @@ -22,8 +22,12 @@ package com.sk89q.worldedit.world.registry; import com.google.common.io.Resources; import com.google.gson.*; import com.google.gson.reflect.TypeToken; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.blocks.BlockMaterial; +======= +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.util.gson.VectorAdapter; import java.io.IOException; @@ -74,6 +78,7 @@ public class BundledBlockData { */ private void loadFromResource() throws IOException { GsonBuilder gsonBuilder = new GsonBuilder(); +<<<<<<< HEAD gsonBuilder.registerTypeAdapter(Vector.class, new VectorAdapter()); gsonBuilder.registerTypeAdapter(int.class, new JsonDeserializer() { @Override @@ -87,6 +92,9 @@ public class BundledBlockData { return primitive.getAsInt(); } }); +======= + gsonBuilder.registerTypeAdapter(Vector3.class, new VectorAdapter()); +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 148d22db2..f3d7ba156 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,8 +25,15 @@ import com.google.common.io.Resources; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.registry.state.PropertyKey; +======= +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; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockType; @@ -75,7 +82,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 4d4a19939..61b035b48 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,13 +19,17 @@ package com.sk89q.worldedit.world.snapshot; -import com.sk89q.worldedit.BlockVector2D; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.Vector2D; import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; +======= +import com.sk89q.worldedit.math.BlockVector2; +import com.sk89q.worldedit.math.BlockVector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.world.DataException; @@ -46,11 +50,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; /** @@ -77,15 +81,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); } } @@ -100,16 +104,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)) { @@ -139,8 +143,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 { @@ -148,7 +152,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) { @@ -170,7 +174,7 @@ public class SnapshotRestore { * * @return a list of coordinates */ - public List getMissingChunks() { + public List getMissingChunks() { return missingChunks; } @@ -180,7 +184,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 dda18cd87..4f270fade 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 d7212e066..2bda8e7f6 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,17 @@ package com.sk89q.worldedit.world.storage; import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.Tag; +<<<<<<< HEAD import com.sk89q.worldedit.*; +======= +import com.sk89q.worldedit.math.BlockVector2; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 +49,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 +68,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/util/LocationTest.java b/worldedit-core/src/test/java/com/sk89q/worldedit/util/LocationTest.java index 1acdbc892..af01b888f 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 @@ -19,7 +19,14 @@ package com.sk89q.worldedit.util; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; + +import com.sk89q.worldedit.math.Vector3; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.world.World; import org.junit.Test; @@ -54,7 +61,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 +69,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 +94,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 +119,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 59df06287..b353e046c 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 @@ -19,7 +19,18 @@ package com.sk89q.worldedit.forge; +<<<<<<< HEAD import com.sk89q.worldedit.Vector; +======= +import com.google.common.collect.ImmutableList; +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; +import com.sk89q.worldedit.registry.state.IntegerProperty; +import com.sk89q.worldedit.registry.state.Property; +>>>>>>> 399e0ad5... Refactor vector system to be cleaner import com.sk89q.worldedit.util.Direction; import com.sk89q.worldedit.world.World; import net.minecraft.util.EnumFacing; @@ -35,15 +46,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()); } @@ -60,7 +71,24 @@ final class ForgeAdapter { } } +<<<<<<< HEAD public static BlockPos toBlockPos(Vector vector) { +======= + public static Direction adaptEnumFacing(EnumFacing face) { + switch (face) { + case NORTH: return Direction.NORTH; + case SOUTH: return Direction.SOUTH; + case WEST: return Direction.WEST; + case EAST: return Direction.EAST; + case DOWN: return Direction.DOWN; + case UP: + default: + return Direction.UP; + } + } + + public static BlockPos toBlockPos(BlockVector3 vector) { +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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 d4b906fc4..223031f4a 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,17 +20,18 @@ 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.item.ItemTypes; -import io.netty.buffer.Unpooled; + import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -45,6 +46,8 @@ import java.util.UUID; import javax.annotation.Nullable; +import io.netty.buffer.Unpooled; + public class ForgePlayer extends AbstractPlayerActor { private final EntityPlayerMP player; @@ -77,7 +80,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, @@ -139,7 +142,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); } @@ -165,6 +168,27 @@ public class ForgePlayer extends AbstractPlayerActor { } @Override +<<<<<<< HEAD +======= + public void sendFakeBlock(BlockVector3 pos, BlockStateHolder block) { + BlockPos loc = ForgeAdapter.toBlockPos(pos); + if (block == null) { + // TODO +// player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData()); + } else { + // TODO +// player.sendBlockChange(loc, BukkitAdapter.adapt(block)); + if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { + player.connection.sendPacket(new SPacketUpdateTileEntity( + new BlockPos(pos.getBlockX(), pos.getBlockY(), pos.getBlockZ()), 7, + NBTConverter.toNative(((BaseBlock) block).getNbtData())) + ); + } + } + } + + @Override +>>>>>>> 399e0ad5... Refactor vector system to be cleaner public SessionKey getSessionKey() { return new SessionKeyImpl(player.getUniqueID(), player.getName()); } 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 e5cbcaf4d..f0b68ebcb 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,11 +23,12 @@ import static com.google.common.base.Preconditions.checkNotNull; import com.google.common.io.Files; import com.sk89q.jnbt.CompoundTag; +<<<<<<< HEAD import com.sk89q.worldedit.BlockVector; +======= +>>>>>>> 399e0ad5... Refactor vector system to be cleaner 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.world.block.BaseBlock; import com.sk89q.worldedit.blocks.BaseItem; @@ -35,6 +36,9 @@ 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.util.Direction; @@ -157,7 +161,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); @@ -197,15 +201,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(); @@ -218,13 +222,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); @@ -238,7 +242,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) { @@ -253,7 +257,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); @@ -267,7 +271,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); @@ -298,13 +302,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) { @@ -346,12 +350,39 @@ 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 +<<<<<<< HEAD +======= + public void checkLoadedChunk(BlockVector3 pt) { + getWorld().getChunkFromBlockCoords(ForgeAdapter.toBlockPos(pt)); + } + + @Override + public void fixAfterFastMode(Iterable chunks) { + fixLighting(chunks); + } + + @Override + public void fixLighting(Iterable chunks) { + World world = getWorld(); + for (BlockVector2 chunk : chunks) { + world.getChunkFromChunkCoords(chunk.getBlockX(), chunk.getBlockZ()).resetRelightChecks(); + } + } + + @Override + public boolean playEffect(Vector3 position, int type, int data) { + getWorld().playEvent(type, ForgeAdapter.toBlockPos(position.toBlockPoint()), data); + return true; + } + + @Override +>>>>>>> 399e0ad5... Refactor vector system to be cleaner public WeatherType getWeather() { // TODO Weather implementation return null; @@ -373,7 +404,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 state = world.getBlockState(pos); @@ -382,7 +413,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); @@ -418,7 +449,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 37774dbc8..e517601a5 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,18 +21,20 @@ 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; 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; @@ -143,7 +145,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() ); @@ -184,6 +186,26 @@ public class SpongePlayer extends AbstractPlayerActor { } @Override +<<<<<<< HEAD +======= + 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()); + } else { + // TODO +// player.sendBlockChange(loc, BukkitAdapter.adapt(block)); +// if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) { +// BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); +// if (adapter != null) { +// adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData()); +// } +// } + } + } + + @Override +>>>>>>> 399e0ad5... Refactor vector system to be cleaner public SessionKey getSessionKey() { return new SessionKeyImpl(player.getUniqueId(), player.getName()); } 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()); }