Make BlockStateHolder extend Pattern.

Removes the need for wrapping them in BlockPattern.
This commit is contained in:
wizjany 2019-07-28 18:20:00 -04:00
parent f4c238c3da
commit 6631b6bdf0
17 changed files with 59 additions and 53 deletions

View File

@ -62,7 +62,6 @@ import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.OperationQueue; import com.sk89q.worldedit.function.operation.OperationQueue;
import com.sk89q.worldedit.function.operation.Operations; 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.Pattern;
import com.sk89q.worldedit.function.pattern.WaterloggedRemover; import com.sk89q.worldedit.function.pattern.WaterloggedRemover;
import com.sk89q.worldedit.function.util.RegionOffset; 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int fillXZ(BlockVector3 origin, B block, double radius, int depth, boolean recursive) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> 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 getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, height - 1, apothem - 1)); position.add(apothem - 1, height - 1, apothem - 1));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return setBlocks(region, BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
} }
/** /**
@ -907,8 +905,7 @@ public class EditSession implements Extent, AutoCloseable {
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
position.add(-apothem + 1, 0, -apothem + 1), position.add(-apothem + 1, 0, -apothem + 1),
position.add(apothem - 1, -height + 1, apothem - 1)); position.add(apothem - 1, -height + 1, apothem - 1));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return setBlocks(region, BlockTypes.AIR.getDefaultState());
return setBlocks(region, pattern);
} }
/** /**
@ -929,8 +926,7 @@ public class EditSession implements Extent, AutoCloseable {
getWorld(), // Causes clamping of Y range getWorld(), // Causes clamping of Y range
position.add(adjustment.multiply(-1)), position.add(adjustment.multiply(-1)),
position.add(adjustment)); position.add(adjustment));
Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return replaceBlocks(region, mask, BlockTypes.AIR.getDefaultState());
return replaceBlocks(region, mask, pattern);
} }
/** /**
@ -942,7 +938,7 @@ public class EditSession implements Extent, AutoCloseable {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> filter, B replacement) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> int replaceBlocks(Region region, Set<BaseBlock> 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int makeCuboidFaces(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> 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 * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
public <B extends BlockStateHolder<B>> int makeCuboidWalls(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> 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 <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException { public <B extends BlockStateHolder<B>> int overlayCuboidBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(block); 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 // Remove the original blocks
Pattern pattern = replacement != null ? Pattern pattern = replacement != null ?
replacement : replacement :
new BlockPattern(BlockTypes.AIR.getDefaultState()); BlockTypes.AIR.getDefaultState();
BlockReplace remove = new BlockReplace(this, pattern); 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 // 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) { if (waterlogged) {
replace = new BlockReplace(this, new WaterloggedRemover(this)); replace = new BlockReplace(this, new WaterloggedRemover(this));
} else { } else {
replace = new BlockReplace(this, new BlockPattern(BlockTypes.AIR.getDefaultState())); replace = new BlockReplace(this, BlockTypes.AIR.getDefaultState());
} }
RecursiveVisitor visitor = new RecursiveVisitor(mask, replace); RecursiveVisitor visitor = new RecursiveVisitor(mask, replace);
@ -1376,7 +1372,7 @@ public class EditSession implements Extent, AutoCloseable {
blockMask blockMask
); );
BlockReplace replace = new BlockReplace(this, new BlockPattern(fluid.getDefaultState())); BlockReplace replace = new BlockReplace(this, fluid.getDefaultState());
NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace);
// Around the origin in a 3x3 block // Around the origin in a 3x3 block

View File

@ -47,7 +47,6 @@ import com.sk89q.worldedit.function.factory.Paint;
import com.sk89q.worldedit.function.mask.BlockTypeMask; import com.sk89q.worldedit.function.mask.BlockTypeMask;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operation; 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.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.factory.RegionFactory; import com.sk89q.worldedit.regions.factory.RegionFactory;
@ -207,8 +206,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
Pattern fill = new BlockPattern(BlockTypes.AIR.getDefaultState()); tool.setFill(BlockTypes.AIR.getDefaultState());
tool.setFill(fill);
tool.setSize(radius); tool.setSize(radius);
tool.setMask(new BlockTypeMask(new RequestExtent(), BlockTypes.FIRE)); tool.setMask(new BlockTypeMask(new RequestExtent(), BlockTypes.FIRE));
tool.setBrush(new SphereBrush(), "worldedit.brush.ex"); tool.setBrush(new SphereBrush(), "worldedit.brush.ex");

View File

@ -37,10 +37,10 @@ import com.sk89q.worldedit.command.tool.TreePlanter;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.HandSide;
import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
@ -209,11 +209,11 @@ public class ToolCommands {
player.print("Long-range building tool bound to " + itemStack.getType().getName() + "."); player.print("Long-range building tool bound to " + itemStack.getType().getName() + ".");
String primaryName = "pattern"; String primaryName = "pattern";
String secondaryName = "pattern"; String secondaryName = "pattern";
if (primary instanceof BlockPattern) { if (primary instanceof BlockStateHolder) {
primaryName = ((BlockPattern) primary).getBlock().getBlockType().getName(); primaryName = ((BlockStateHolder<?>) primary).getBlockType().getName();
} }
if (secondary instanceof BlockPattern) { if (secondary instanceof BlockStateHolder) {
secondaryName = ((BlockPattern) secondary).getBlock().getBlockType().getName(); secondaryName = ((BlockStateHolder<?>) secondary).getBlockType().getName();
} }
player.print("Left-click set to " + primaryName + "; right-click set to " player.print("Left-click set to " + primaryName + "; right-click set to "
+ secondaryName + "."); + secondaryName + ".");

View File

@ -27,7 +27,6 @@ import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Platform; import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extent.inventory.BlockBag; 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.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
@ -57,7 +56,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
try { try {
editSession.disableBuffering(); editSession.disableBuffering();
BlockVector3 position = clicked.toVector().toBlockPoint(); BlockVector3 position = clicked.toVector().toBlockPoint();
editSession.setBlock(position, pattern.apply(position)); editSession.setBlock(position, pattern);
} catch (MaxChangedBlocksException ignored) { } catch (MaxChangedBlocksException ignored) {
} finally { } finally {
session.remember(editSession); session.remember(editSession);
@ -77,7 +76,7 @@ public class BlockReplacer implements DoubleActionBlockTool {
BaseBlock targetBlock = player.getWorld().getFullBlock(clicked.toVector().toBlockPoint()); BaseBlock targetBlock = player.getWorld().getFullBlock(clicked.toVector().toBlockPoint());
if (targetBlock != null) { if (targetBlock != null) {
pattern = new BlockPattern(targetBlock); pattern = targetBlock;
player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName()); player.print("Replacer tool switched to: " + targetBlock.getBlockType().getName());
} }

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -37,7 +36,7 @@ public class CylinderBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = BlockTypes.COBBLESTONE.getDefaultState();
} }
editSession.makeCylinder(position, pattern, size, size, height, true); editSession.makeCylinder(position, pattern, size, size, height, true);
} }

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -37,7 +36,7 @@ public class HollowCylinderBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = BlockTypes.COBBLESTONE.getDefaultState();
} }
editSession.makeCylinder(position, pattern, size, size, height, false); editSession.makeCylinder(position, pattern, size, size, height, false);
} }

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -31,7 +30,7 @@ public class HollowSphereBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = BlockTypes.COBBLESTONE.getDefaultState();
} }
editSession.makeSphere(position, pattern, size, size, size, false); editSession.makeSphere(position, pattern, size, size, size, false);
} }

View File

@ -21,7 +21,6 @@ package com.sk89q.worldedit.command.tool.brush;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.function.pattern.BlockPattern;
import com.sk89q.worldedit.function.pattern.Pattern; import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
@ -31,7 +30,7 @@ public class SphereBrush implements Brush {
@Override @Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException { public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws MaxChangedBlocksException {
if (pattern == null) { if (pattern == null) {
pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); pattern = BlockTypes.COBBLESTONE.getDefaultState();
} }
editSession.makeSphere(position, pattern, size, size, size, true); editSession.makeSphere(position, pattern, size, size, size, true);
} }

View File

@ -23,7 +23,6 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.SuggestionHelper; import com.sk89q.worldedit.command.util.SuggestionHelper;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; 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.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
@ -70,10 +69,10 @@ public class BlockCategoryPatternParser extends InputParser<Pattern> {
if (anyState) { if (anyState) {
blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state -> blocks.stream().flatMap(blockType -> blockType.getAllStates().stream()).forEach(state ->
randomPattern.add(new BlockPattern(state), 1.0)); randomPattern.add(state, 1.0));
} else { } else {
for (BlockType blockType : blocks) { for (BlockType blockType : blocks) {
randomPattern.add(new BlockPattern(blockType.getDefaultState()), 1.0); randomPattern.add(blockType.getDefaultState(), 1.0);
} }
} }

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; 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.Pattern;
import com.sk89q.worldedit.function.pattern.RandomStatePattern; import com.sk89q.worldedit.function.pattern.RandomStatePattern;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
@ -60,7 +59,7 @@ public class RandomStatePatternParser extends InputParser<Pattern> {
context.setPreferringWildcard(wasFuzzy); context.setPreferringWildcard(wasFuzzy);
if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) { if (block.getStates().size() == block.getBlockType().getPropertyMap().size()) {
// they requested random with *, but didn't leave any states empty - simplify // they requested random with *, but didn't leave any states empty - simplify
return new BlockPattern(block); return block;
} else if (block.toImmutableState() instanceof FuzzyBlockState) { } else if (block.toImmutableState() instanceof FuzzyBlockState) {
return new RandomStatePattern((FuzzyBlockState) block.toImmutableState()); return new RandomStatePattern((FuzzyBlockState) block.toImmutableState());
} else { } else {

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.extension.factory.parser.pattern;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.input.InputParseException; import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext; 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.Pattern;
import com.sk89q.worldedit.internal.registry.InputParser; import com.sk89q.worldedit.internal.registry.InputParser;
@ -41,7 +40,7 @@ public class SingleBlockPatternParser extends InputParser<Pattern> {
@Override @Override
public Pattern parseFromInput(String input, ParserContext context) throws InputParseException { public Pattern parseFromInput(String input, ParserContext context) throws InputParseException {
return new BlockPattern(worldEdit.getBlockFactory().parseFromInput(input, context)); return worldEdit.getBlockFactory().parseFromInput(input, context);
} }
} }

View File

@ -22,7 +22,6 @@ package com.sk89q.worldedit.function.generator;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction; 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.Pattern;
import com.sk89q.worldedit.function.pattern.RandomPattern; import com.sk89q.worldedit.function.pattern.RandomPattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -83,9 +82,9 @@ public class FloraGenerator implements RegionFunction {
*/ */
public static Pattern getDesertPattern() { public static Pattern getDesertPattern() {
RandomPattern pattern = new RandomPattern(); RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(BlockTypes.DEAD_BUSH.getDefaultState()), 30); pattern.add(BlockTypes.DEAD_BUSH.getDefaultState(), 30);
pattern.add(new BlockPattern(BlockTypes.CACTUS.getDefaultState()), 20); pattern.add(BlockTypes.CACTUS.getDefaultState(), 20);
pattern.add(new BlockPattern(BlockTypes.AIR.getDefaultState()), 300); pattern.add(BlockTypes.AIR.getDefaultState(), 300);
return pattern; return pattern;
} }
@ -96,9 +95,9 @@ public class FloraGenerator implements RegionFunction {
*/ */
public static Pattern getTemperatePattern() { public static Pattern getTemperatePattern() {
RandomPattern pattern = new RandomPattern(); RandomPattern pattern = new RandomPattern();
pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300); pattern.add(BlockTypes.GRASS.getDefaultState(), 300);
pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5); pattern.add(BlockTypes.POPPY.getDefaultState(), 5);
pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5); pattern.add(BlockTypes.DANDELION.getDefaultState(), 5);
return pattern; return pattern;
} }

View File

@ -23,7 +23,6 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.function.RegionFunction; 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.Pattern;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -187,7 +186,7 @@ public class GardenPatchGenerator implements RegionFunction {
* @return a pumpkin pattern * @return a pumpkin pattern
*/ */
public static Pattern getPumpkinPattern() { 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 * @return a melon pattern
*/ */
public static Pattern getMelonPattern() { public static Pattern getMelonPattern() {
return new BlockPattern(BlockTypes.MELON.getDefaultState()); return BlockTypes.MELON.getDefaultState();
} }
} }

View File

@ -27,7 +27,10 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
/** /**
* A pattern that returns the same {@link BaseBlock} each time. * 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 { public class BlockPattern extends AbstractPattern {
private BaseBlock block; private BaseBlock block;

View File

@ -25,6 +25,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import java.util.Map; import java.util.Map;
@ -166,6 +167,11 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
return this; return this;
} }
@Override
public BaseBlock apply(BlockVector3 position) {
return this;
}
@Override @Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) { public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag == null) { if (compoundTag == null) {

View File

@ -28,6 +28,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.internal.block.BlockStateIdAccess; import com.sk89q.worldedit.internal.block.BlockStateIdAccess;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property; import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry;
@ -207,6 +208,11 @@ public class BlockState implements BlockStateHolder<BlockState> {
return this.emptyBaseBlock; return this.emptyBaseBlock;
} }
@Override
public BaseBlock apply(BlockVector3 position) {
return this.emptyBaseBlock;
}
@Override @Override
public BaseBlock toBaseBlock(CompoundTag compoundTag) { public BaseBlock toBaseBlock(CompoundTag compoundTag) {
if (compoundTag == null) { if (compoundTag == null) {

View File

@ -20,13 +20,15 @@
package com.sk89q.worldedit.world.block; package com.sk89q.worldedit.world.block;
import com.sk89q.jnbt.CompoundTag; 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 com.sk89q.worldedit.registry.state.Property;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public interface BlockStateHolder<B extends BlockStateHolder<B>> { public interface BlockStateHolder<B extends BlockStateHolder<B>> extends Pattern {
/** /**
* Get the block type * Get the block type
@ -89,6 +91,11 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> {
*/ */
BaseBlock toBaseBlock(CompoundTag compoundTag); BaseBlock toBaseBlock(CompoundTag compoundTag);
@Override
default BaseBlock apply(BlockVector3 position) {
return toBaseBlock();
}
default String getAsString() { default String getAsString() {
if (getStates().isEmpty()) { if (getStates().isEmpty()) {
return this.getBlockType().getId(); return this.getBlockType().getId();