From 6631b6bdf0638b674b0f0dabad4eb77c0510e5df Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 28 Jul 2019 18:20:00 -0400 Subject: [PATCH 1/2] Make BlockStateHolder extend Pattern. Removes the need for wrapping them in BlockPattern. --- .../java/com/sk89q/worldedit/EditSession.java | 28 ++++++++----------- .../worldedit/command/BrushCommands.java | 4 +-- .../sk89q/worldedit/command/ToolCommands.java | 10 +++---- .../worldedit/command/tool/BlockReplacer.java | 5 ++-- .../command/tool/brush/CylinderBrush.java | 3 +- .../tool/brush/HollowCylinderBrush.java | 3 +- .../command/tool/brush/HollowSphereBrush.java | 3 +- .../command/tool/brush/SphereBrush.java | 3 +- .../pattern/BlockCategoryPatternParser.java | 5 ++-- .../pattern/RandomStatePatternParser.java | 3 +- .../pattern/SingleBlockPatternParser.java | 3 +- .../function/generator/FloraGenerator.java | 13 ++++----- .../generator/GardenPatchGenerator.java | 5 ++-- .../function/pattern/BlockPattern.java | 3 ++ .../worldedit/world/block/BaseBlock.java | 6 ++++ .../worldedit/world/block/BlockState.java | 6 ++++ .../world/block/BlockStateHolder.java | 9 +++++- 17 files changed, 59 insertions(+), 53 deletions(-) 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 8501ba917..07f4fd795 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -62,7 +62,6 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.function.util.RegionOffset; @@ -820,7 +819,7 @@ public class EditSession implements Extent, AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int fillXZ(BlockVector3 origin, B block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { - return fillXZ(origin, new BlockPattern(block), radius, depth, recursive); + return fillXZ(origin, (Pattern) block, radius, depth, recursive); } /** @@ -885,8 +884,7 @@ public class EditSession implements Extent, AutoCloseable { getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, height - 1, apothem - 1)); - Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); - return setBlocks(region, pattern); + return setBlocks(region, BlockTypes.AIR.getDefaultState()); } /** @@ -907,8 +905,7 @@ public class EditSession implements Extent, AutoCloseable { getWorld(), // Causes clamping of Y range position.add(-apothem + 1, 0, -apothem + 1), position.add(apothem - 1, -height + 1, apothem - 1)); - Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); - return setBlocks(region, pattern); + return setBlocks(region, BlockTypes.AIR.getDefaultState()); } /** @@ -929,8 +926,7 @@ public class EditSession implements Extent, AutoCloseable { 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); + return replaceBlocks(region, mask, BlockTypes.AIR.getDefaultState()); } /** @@ -942,7 +938,7 @@ public class EditSession implements Extent, AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int setBlocks(Region region, B block) throws MaxChangedBlocksException { - return setBlocks(region, new BlockPattern(block)); + return setBlocks(region, (Pattern) block); } /** @@ -974,7 +970,7 @@ public class EditSession implements Extent, AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int replaceBlocks(Region region, Set filter, B replacement) throws MaxChangedBlocksException { - return replaceBlocks(region, filter, new BlockPattern(replacement)); + return replaceBlocks(region, filter, (Pattern) replacement); } /** @@ -1046,7 +1042,7 @@ public class EditSession implements Extent, AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException { - return makeCuboidFaces(region, new BlockPattern(block)); + return makeCuboidFaces(region, block); } /** @@ -1098,7 +1094,7 @@ public class EditSession implements Extent, AutoCloseable { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ public > int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException { - return makeCuboidWalls(region, new BlockPattern(block)); + return makeCuboidWalls(region, (Pattern) block); } /** @@ -1165,7 +1161,7 @@ public class EditSession implements Extent, AutoCloseable { public > int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException { checkNotNull(block); - return overlayCuboidBlocks(region, new BlockPattern(block)); + return overlayCuboidBlocks(region, (Pattern) block); } /** @@ -1255,7 +1251,7 @@ public class EditSession implements Extent, AutoCloseable { // Remove the original blocks Pattern pattern = replacement != null ? replacement : - new BlockPattern(BlockTypes.AIR.getDefaultState()); + BlockTypes.AIR.getDefaultState(); BlockReplace remove = new BlockReplace(this, pattern); // Copy to a buffer so we don't destroy our original before we can copy all the blocks from it @@ -1334,7 +1330,7 @@ public class EditSession implements Extent, AutoCloseable { if (waterlogged) { replace = new BlockReplace(this, new WaterloggedRemover(this)); } else { - replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState())); + replace = new BlockReplace(this, BlockTypes.AIR.getDefaultState()); } RecursiveVisitor visitor = new RecursiveVisitor(mask, replace); @@ -1376,7 +1372,7 @@ public class EditSession implements Extent, AutoCloseable { blockMask ); - BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState())); + BlockReplace replace = new BlockReplace(this, fluid.getDefaultState()); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block 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 a5b6290d6..25f198e92 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 @@ -47,7 +47,6 @@ import com.sk89q.worldedit.function.factory.Paint; 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.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.factory.RegionFactory; @@ -207,8 +206,7 @@ public class BrushCommands { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); - Pattern fill = new BlockPattern(BlockTypes.AIR.getDefaultState()); - tool.setFill(fill); + tool.setFill(BlockTypes.AIR.getDefaultState()); tool.setSize(radius); tool.setMask(new BlockTypeMask(new RequestExtent(), BlockTypes.FIRE)); tool.setBrush(new SphereBrush(), "worldedit.brush.ex"); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java index 6bbd2d853..5c8de085c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ToolCommands.java @@ -37,10 +37,10 @@ import com.sk89q.worldedit.command.tool.TreePlanter; import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.TreeGenerator; +import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; @@ -209,11 +209,11 @@ public class ToolCommands { player.print("Long-range building tool bound to " + itemStack.getType().getName() + "."); String primaryName = "pattern"; String secondaryName = "pattern"; - if (primary instanceof BlockPattern) { - primaryName = ((BlockPattern) primary).getBlock().getBlockType().getName(); + if (primary instanceof BlockStateHolder) { + primaryName = ((BlockStateHolder) primary).getBlockType().getName(); } - if (secondary instanceof BlockPattern) { - secondaryName = ((BlockPattern) secondary).getBlock().getBlockType().getName(); + if (secondary instanceof BlockStateHolder) { + secondaryName = ((BlockStateHolder) secondary).getBlockType().getName(); } player.print("Left-click set to " + primaryName + "; right-click set to " + secondaryName + "."); 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 b48c8adca..65d3f0ea0 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 @@ -27,7 +27,6 @@ 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.util.Location; @@ -57,7 +56,7 @@ public class BlockReplacer implements DoubleActionBlockTool { try { editSession.disableBuffering(); BlockVector3 position = clicked.toVector().toBlockPoint(); - editSession.setBlock(position, pattern.apply(position)); + editSession.setBlock(position, pattern); } catch (MaxChangedBlocksException ignored) { } finally { session.remember(editSession); @@ -77,7 +76,7 @@ public class BlockReplacer implements DoubleActionBlockTool { BaseBlock targetBlock = player.getWorld().getFullBlock(clicked.toVector().toBlockPoint()); if (targetBlock != null) { - pattern = new BlockPattern(targetBlock); + pattern = targetBlock; player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); } 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 12a663ed3..1b1ddcb6f 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,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -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; @@ -37,7 +36,7 @@ public class CylinderBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = BlockTypes.COBBLESTONE.getDefaultState(); } editSession.makeCylinder(position, pattern, size, size, height, true); } 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 dbf959e1b..4cbef5503 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,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -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; @@ -37,7 +36,7 @@ public class HollowCylinderBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = BlockTypes.COBBLESTONE.getDefaultState(); } editSession.makeCylinder(position, pattern, size, size, height, false); } 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 0e89b3c16..c4170d00e 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,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -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; @@ -31,7 +30,7 @@ public class HollowSphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = BlockTypes.COBBLESTONE.getDefaultState(); } editSession.makeSphere(position, pattern, size, size, size, false); } 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 d8028f2ae..03b50a7e9 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,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; -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; @@ -31,7 +30,7 @@ public class SphereBrush implements Brush { @Override public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); + pattern = BlockTypes.COBBLESTONE.getDefaultState(); } editSession.makeSphere(position, pattern, size, size, size, true); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java index 3260fa438..4ff9cd913 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/BlockCategoryPatternParser.java @@ -23,7 +23,6 @@ import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.internal.registry.InputParser; @@ -70,10 +69,10 @@ public class BlockCategoryPatternParser extends InputParser { if (anyState) { blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> - randomPattern.add(new BlockPattern(state), 1.0)); + randomPattern.add(state, 1.0)); } else { for (BlockType blockType : blocks) { - randomPattern.add(new BlockPattern(blockType.getDefaultState()), 1.0); + randomPattern.add(blockType.getDefaultState(), 1.0); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomStatePatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomStatePatternParser.java index 3b6dc5c1f..d8f27b08c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomStatePatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/RandomStatePatternParser.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.extension.factory.parser.pattern; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomStatePattern; import com.sk89q.worldedit.internal.registry.InputParser; @@ -60,7 +59,7 @@ public class RandomStatePatternParser extends InputParser { context.setPreferringWildcard(wasFuzzy); if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) { // they requested random with *, but didn't leave any states empty - simplify - return new BlockPattern(block); + return block; } else if (block.toImmutableState() instanceof FuzzyBlockState) { return new RandomStatePattern((FuzzyBlockState) block.toImmutableState()); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/SingleBlockPatternParser.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/SingleBlockPatternParser.java index 30f844611..2565b5d70 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/SingleBlockPatternParser.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/factory/parser/pattern/SingleBlockPatternParser.java @@ -22,7 +22,6 @@ package com.sk89q.worldedit.extension.factory.parser.pattern; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.ParserContext; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.internal.registry.InputParser; @@ -41,7 +40,7 @@ public class SingleBlockPatternParser extends InputParser { @Override public Pattern parseFromInput(String input, ParserContext context) throws InputParseException { - return new BlockPattern(worldEdit.getBlockFactory().parseFromInput(input, context)); + return worldEdit.getBlockFactory().parseFromInput(input, context); } } 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 039d1a7fd..d133993cc 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 @@ -22,7 +22,6 @@ package com.sk89q.worldedit.function.generator; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.math.BlockVector3; @@ -83,9 +82,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getDesertPattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(BlockTypes.DEAD_BUSH.getDefaultState()), 30); - pattern.add(new BlockPattern(BlockTypes.CACTUS.getDefaultState()), 20); - pattern.add(new BlockPattern(BlockTypes.AIR.getDefaultState()), 300); + pattern.add(BlockTypes.DEAD_BUSH.getDefaultState(), 30); + pattern.add(BlockTypes.CACTUS.getDefaultState(), 20); + pattern.add(BlockTypes.AIR.getDefaultState(), 300); return pattern; } @@ -96,9 +95,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getTemperatePattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300); - pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5); - pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5); + pattern.add(BlockTypes.GRASS.getDefaultState(), 300); + pattern.add(BlockTypes.POPPY.getDefaultState(), 5); + pattern.add(BlockTypes.DANDELION.getDefaultState(), 5); return pattern; } 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 0d31760af..5d1aa01c5 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 @@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.function.RegionFunction; -import com.sk89q.worldedit.function.pattern.BlockPattern; import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.world.block.BlockState; @@ -187,7 +186,7 @@ public class GardenPatchGenerator implements RegionFunction { * @return a pumpkin pattern */ public static Pattern getPumpkinPattern() { - return new BlockPattern(BlockTypes.PUMPKIN.getDefaultState()); + return BlockTypes.PUMPKIN.getDefaultState(); } /** @@ -208,6 +207,6 @@ public class GardenPatchGenerator implements RegionFunction { * @return a melon pattern */ public static Pattern getMelonPattern() { - return new BlockPattern(BlockTypes.MELON.getDefaultState()); + return BlockTypes.MELON.getDefaultState(); } } 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 fa49f5108..a934bc17a 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 @@ -27,7 +27,10 @@ import com.sk89q.worldedit.world.block.BlockStateHolder; /** * A pattern that returns the same {@link BaseBlock} each time. + * + * @deprecated all BlockStateHolders can be used directly as a pattern */ +@Deprecated public class BlockPattern extends AbstractPattern { private BaseBlock block; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index bc913f2d7..713a36eff 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -25,6 +25,7 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.blocks.TileEntityBlock; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import java.util.Map; @@ -166,6 +167,11 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return this; } + @Override + public BaseBlock apply(BlockVector3 position) { + return this; + } + @Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { if (compoundTag == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index aeeae8210..c8c39cc78 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -28,6 +28,7 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.block.BlockStateIdAccess; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.registry.BlockRegistry; @@ -207,6 +208,11 @@ public class BlockState implements BlockStateHolder { return this.emptyBaseBlock; } + @Override + public BaseBlock apply(BlockVector3 position) { + return this.emptyBaseBlock; + } + @Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { if (compoundTag == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java index 481ee1d63..d6ada3d74 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockStateHolder.java @@ -20,13 +20,15 @@ package com.sk89q.worldedit.world.block; import com.sk89q.jnbt.CompoundTag; +import com.sk89q.worldedit.function.pattern.Pattern; +import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; -public interface BlockStateHolder> { +public interface BlockStateHolder> extends Pattern { /** * Get the block type @@ -89,6 +91,11 @@ public interface BlockStateHolder> { */ BaseBlock toBaseBlock(CompoundTag compoundTag); + @Override + default BaseBlock apply(BlockVector3 position) { + return toBaseBlock(); + } + default String getAsString() { if (getStates().isEmpty()) { return this.getBlockType().getId(); From 9d9e3ea065fd3c45eaf6f3886a4951c3bb17587a Mon Sep 17 00:00:00 2001 From: wizjany Date: Sun, 28 Jul 2019 22:50:42 -0400 Subject: [PATCH 2/2] Remove overrides. --- .../java/com/sk89q/worldedit/world/block/BaseBlock.java | 6 ------ .../java/com/sk89q/worldedit/world/block/BlockState.java | 6 ------ 2 files changed, 12 deletions(-) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java index 713a36eff..bc913f2d7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BaseBlock.java @@ -25,7 +25,6 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.blocks.TileEntityBlock; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import java.util.Map; @@ -167,11 +166,6 @@ public class BaseBlock implements BlockStateHolder, TileEntityBlock { return this; } - @Override - public BaseBlock apply(BlockVector3 position) { - return this; - } - @Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { if (compoundTag == null) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java index c8c39cc78..aeeae8210 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/world/block/BlockState.java @@ -28,7 +28,6 @@ import com.sk89q.jnbt.CompoundTag; import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.internal.block.BlockStateIdAccess; -import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.world.registry.BlockRegistry; @@ -208,11 +207,6 @@ public class BlockState implements BlockStateHolder { return this.emptyBaseBlock; } - @Override - public BaseBlock apply(BlockVector3 position) { - return this.emptyBaseBlock; - } - @Override public BaseBlock toBaseBlock(CompoundTag compoundTag) { if (compoundTag == null) {