From 70aceb3837b67fcda0444d441f4dd35e9729df8b Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 19 Jun 2018 11:55:35 +1000 Subject: [PATCH] Use default state a bit more. --- .../java/com/sk89q/worldedit/EditSession.java | 30 +++++++++---------- .../worldedit/blocks/type/BlockState.java | 4 +++ .../worldedit/command/BrushCommands.java | 9 +++--- .../worldedit/command/UtilityCommands.java | 4 +-- .../command/tool/RecursivePickaxe.java | 3 +- .../worldedit/command/tool/SinglePickaxe.java | 2 +- .../command/tool/brush/CylinderBrush.java | 2 +- .../platform/AbstractPlayerActor.java | 2 +- .../extent/world/BlockQuirkExtent.java | 8 ++--- .../worldedit/function/block/Naturalizer.java | 7 +++-- .../function/generator/FloraGenerator.java | 13 ++++---- .../function/generator/ForestGenerator.java | 4 +-- .../generator/GardenPatchGenerator.java | 2 +- .../worldedit/math/convolution/HeightMap.java | 7 ++--- .../sk89q/worldedit/util/TreeGenerator.java | 14 +++++---- .../sk89q/worldedit/world/AbstractWorld.java | 2 +- 16 files changed, 59 insertions(+), 54 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 543cda5a3..531c2527a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java @@ -688,7 +688,7 @@ public class EditSession implements Extent { 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(new BaseBlock(BlockTypes.AIR)); + Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return setBlocks(region, pattern); } @@ -710,7 +710,7 @@ public class EditSession implements Extent { 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(new BaseBlock(BlockTypes.AIR)); + Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return setBlocks(region, pattern); } @@ -723,17 +723,17 @@ public class EditSession implements Extent { * @return number of blocks affected * @throws MaxChangedBlocksException thrown if too many blocks are changed */ - public int removeNear(Vector position, int blockType, int apothem) throws MaxChangedBlocksException { + public int removeNear(Vector position, com.sk89q.worldedit.blocks.type.BlockType blockType, int apothem) throws MaxChangedBlocksException { checkNotNull(position); checkArgument(apothem >= 1, "apothem >= 1"); - Mask mask = new FuzzyBlockMask(this, new BaseBlock(blockType, -1)); + Mask mask = new FuzzyBlockMask(this, blockType.getDefaultState().toFuzzy()); Vector adjustment = new Vector(1, 1, 1).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(new BaseBlock(BlockTypes.AIR)); + Pattern pattern = new BlockPattern(BlockTypes.AIR.getDefaultState()); return replaceBlocks(region, mask, pattern); } @@ -1059,7 +1059,7 @@ public class EditSession implements Extent { // Remove the original blocks com.sk89q.worldedit.function.pattern.Pattern pattern = replacement != null ? new BlockPattern(replacement) : - new BlockPattern(new BaseBlock(BlockTypes.AIR)); + new BlockPattern(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 @@ -1146,15 +1146,15 @@ public class EditSession implements Extent { // Our origins can only be liquids BlockMask liquidMask = new BlockMask( this, - new BaseBlock(moving), - new BaseBlock(stationary)); + moving.getDefaultState(), + stationary.getDefaultState()); // But we will also visit air blocks MaskIntersection blockMask = new MaskUnion(liquidMask, new BlockMask( this, - new BaseBlock(BlockTypes.AIR))); + BlockTypes.AIR.getDefaultState())); // There are boundaries that the routine needs to stay in MaskIntersection mask = new MaskIntersection( @@ -1162,7 +1162,7 @@ public class EditSession implements Extent { new RegionMask(new EllipsoidRegion(null, origin, new Vector(radius, radius, radius))), blockMask); - BlockReplace replace = new BlockReplace(this, new BlockPattern(new BaseBlock(stationary))); + BlockReplace replace = new BlockReplace(this, new BlockPattern(stationary.getDefaultState())); NonRisingVisitor visitor = new NonRisingVisitor(mask, replace); // Around the origin in a 3x3 block @@ -1433,8 +1433,8 @@ public class EditSession implements Extent { int oy = position.getBlockY(); int oz = position.getBlockZ(); - BaseBlock air = new BaseBlock(BlockTypes.AIR); - BaseBlock water = new BaseBlock(BlockTypes.WATER); + BlockState air = BlockTypes.AIR.getDefaultState(); + BlockState water = BlockTypes.WATER.getDefaultState(); int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { @@ -1483,8 +1483,8 @@ public class EditSession implements Extent { int oy = position.getBlockY(); int oz = position.getBlockZ(); - BaseBlock ice = new BaseBlock(BlockTypes.ICE); - BaseBlock snow = new BaseBlock(BlockTypes.SNOW); + BlockState ice = BlockTypes.ICE.getDefaultState(); + BlockState snow = BlockTypes.SNOW.getDefaultState(); int ceilRadius = (int) Math.ceil(radius); for (int x = ox - ceilRadius; x <= ox + ceilRadius; ++x) { @@ -1659,7 +1659,7 @@ public class EditSession implements Extent { ++affected; break; } else if (t == BlockTypes.SNOW) { - setBlock(new Vector(x, y, z), new BaseBlock(BlockTypes.AIR)); + setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState()); } else if (t != BlockTypes.AIR) { // Trees won't grow on this! break; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockState.java b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockState.java index 39c48b410..43a867180 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockState.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/blocks/type/BlockState.java @@ -110,6 +110,10 @@ public class BlockState implements BlockStateHolder { return Collections.unmodifiableMap(this.values); } + public BlockState toFuzzy() { + return new BlockState(this.getBlockType(), new HashMap<>()); + } + @Override public boolean equalsFuzzy(BlockStateHolder o) { if (!getBlockType().equals(o.getBlockType())) { 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 8f61f5593..eaf2ac45d 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 @@ -19,6 +19,8 @@ package com.sk89q.worldedit.command; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.minecraft.util.commands.Command; import com.sk89q.minecraft.util.commands.CommandContext; import com.sk89q.minecraft.util.commands.CommandPermissions; @@ -28,7 +30,6 @@ import com.sk89q.worldedit.LocalSession; 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.type.BlockTypes; import com.sk89q.worldedit.command.tool.BrushTool; import com.sk89q.worldedit.command.tool.brush.ButcherBrush; @@ -50,8 +51,6 @@ import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.command.binding.Switch; import com.sk89q.worldedit.util.command.parametric.Optional; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Commands to set brush shape. */ @@ -194,10 +193,10 @@ public class BrushCommands { worldEdit.checkMaxBrushRadius(radius); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); - Pattern fill = new BlockPattern(new BaseBlock(BlockTypes.AIR)); + Pattern fill = new BlockPattern(BlockTypes.AIR.getDefaultState()); tool.setFill(fill); tool.setSize(radius); - tool.setMask(new BlockMask(editSession, new BaseBlock(BlockTypes.FIRE))); + tool.setMask(new BlockMask(editSession, BlockTypes.FIRE.getDefaultState().toFuzzy())); tool.setBrush(new SphereBrush(), "worldedit.brush.ex"); player.print(String.format("Extinguisher equipped (%.0f).", radius)); 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 447e42c7b..d14065951 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 @@ -261,7 +261,7 @@ public class UtilityCommands { int size = Math.max(1, args.getInteger(1, 50)); we.checkMaxRadius(size); - int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType().getLegacyId(), size); + int affected = editSession.removeNear(session.getPlacementPosition(player), block.getBlockType(), size); player.print(affected + " block(s) have been removed."); } @@ -381,7 +381,7 @@ public class UtilityCommands { : defaultRadius; we.checkMaxRadius(size); - int affected = editSession.removeNear(session.getPlacementPosition(player), 51, size); + int affected = editSession.removeNear(session.getPlacementPosition(player), BlockTypes.FIRE, size); player.print(affected + " block(s) have been removed."); } 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 ef3bb3f88..7734b3c0c 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 @@ -21,6 +21,7 @@ package com.sk89q.worldedit.command.tool; import com.sk89q.worldedit.*; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockType; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.entity.Player; @@ -37,7 +38,7 @@ import java.util.Set; */ public class RecursivePickaxe implements BlockTool { - private static final BaseBlock air = new BaseBlock(BlockTypes.AIR); + private static final BlockState air = BlockTypes.AIR.getDefaultState(); private double range; public RecursivePickaxe(double range) { 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 8dfe64bb8..b8fc29c7f 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 @@ -54,7 +54,7 @@ public class SinglePickaxe implements BlockTool { editSession.getSurvivalExtent().setToolUse(config.superPickaxeDrop); try { - editSession.setBlock(clicked.toVector(), new BaseBlock(BlockTypes.AIR)); + editSession.setBlock(clicked.toVector(), BlockTypes.AIR.getDefaultState()); } catch (MaxChangedBlocksException e) { player.printError("Max blocks change limit reached."); } finally { 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 6f1eb3540..b860e4db9 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 @@ -38,7 +38,7 @@ public class CylinderBrush implements Brush { @Override public void build(EditSession editSession, Vector position, Pattern pattern, double size) throws MaxChangedBlocksException { if (pattern == null) { - pattern = new BlockPattern(new BaseBlock(BlockTypes.COBBLESTONE)); + pattern = new BlockPattern(BlockTypes.COBBLESTONE.getDefaultState()); } editSession.makeCylinder(position, pattern, size, size, height, true); } 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 245ee0503..f6bbd8c87 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 @@ -299,7 +299,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { @Override public void floatAt(int x, int y, int z, boolean alwaysGlass) { try { - getLocation().getExtent().setBlock(new Vector(x, y - 1, z), new BaseBlock(BlockTypes.GLASS)); + getLocation().getExtent().setBlock(new Vector(x, y - 1, z), BlockTypes.GLASS.getDefaultState()); } catch (WorldEditException e) { e.printStackTrace(); } 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 80b3dc1d4..9f306fc5d 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 @@ -55,12 +55,12 @@ public class BlockQuirkExtent extends AbstractDelegateExtent { @Override public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEditException { BaseBlock lazyBlock = getExtent().getLazyBlock(position); - int existing = lazyBlock.getBlockType().getLegacyId(); + com.sk89q.worldedit.blocks.type.BlockType existing = lazyBlock.getBlockType(); - if (BlockType.isContainerBlock(existing)) { + if (BlockType.isContainerBlock(existing.getLegacyId())) { world.clearContainerBlockContents(position); // Clear the container block so that it doesn't drop items - } else if (existing == BlockID.ICE) { - world.setBlock(position, new BaseBlock(BlockTypes.AIR)); // Ice turns until water so this has to be done first + } else if (existing == BlockTypes.ICE) { + world.setBlock(position, BlockTypes.AIR.getDefaultState()); // Ice turns until water so this has to be done first } return super.setBlock(position, block); 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 6b9967250..3be5a2345 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 @@ -24,6 +24,7 @@ import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.Vector; import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.function.LayerFunction; import com.sk89q.worldedit.function.mask.BlockMask; @@ -38,9 +39,9 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class Naturalizer implements LayerFunction { - private static final BaseBlock grass = new BaseBlock(BlockTypes.GRASS_BLOCK); - private static final BaseBlock dirt = new BaseBlock(BlockTypes.DIRT); - private static final BaseBlock stone = new BaseBlock(BlockTypes.STONE); + private static final BlockState grass = BlockTypes.GRASS_BLOCK.getDefaultState(); + private static final BlockState dirt = BlockTypes.DIRT.getDefaultState(); + private static final BlockState stone = BlockTypes.STONE.getDefaultState(); private final EditSession editSession; private final Mask mask; 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 a0bbf9f87..4833cc439 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.Vector; import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.type.BlockStateHolder; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.function.RegionFunction; @@ -84,9 +83,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getDesertPattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.DEAD_BUSH)), 30); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.CACTUS)), 20); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.AIR)), 300); + 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); return pattern; } @@ -97,9 +96,9 @@ public class FloraGenerator implements RegionFunction { */ public static Pattern getTemperatePattern() { RandomPattern pattern = new RandomPattern(); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.GRASS)), 300); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.POPPY)), 5); - pattern.add(new BlockPattern(new BaseBlock(BlockTypes.DANDELION)), 5); + pattern.add(new BlockPattern(BlockTypes.GRASS.getDefaultState()), 300); + pattern.add(new BlockPattern(BlockTypes.POPPY.getDefaultState()), 5); + pattern.add(new BlockPattern(BlockTypes.DANDELION.getDefaultState()), 5); return pattern; } 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 3c0a0660c..644a183db 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 @@ -58,11 +58,11 @@ public class ForestGenerator implements RegionFunction { treeGenerator.generate(editSession, position.add(0, 1, 0)); return true; } else if (t == BlockTypes.TALL_GRASS || t == BlockTypes.DEAD_BUSH || t == BlockTypes.POPPY || t == BlockTypes.DANDELION) { // TODO: This list needs to be moved - editSession.setBlock(position, new BaseBlock(BlockTypes.AIR)); + editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); treeGenerator.generate(editSession, position); return true; } else if (t == BlockTypes.SNOW) { - editSession.setBlock(position, new BaseBlock(BlockTypes.AIR)); + editSession.setBlock(position, BlockTypes.AIR.getDefaultState()); return false; } else { // Trees won't grow on this! return false; 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 0e851d2f4..ee5f4b1b4 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 @@ -214,6 +214,6 @@ public class GardenPatchGenerator implements RegionFunction { * @return a melon pattern */ public static Pattern getMelonPattern() { - return new BlockPattern(new BaseBlock(BlockTypes.MELON_BLOCK)); + return new BlockPattern(BlockTypes.MELON_BLOCK.getDefaultState()); } } 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 606c8caf9..2ab320f2c 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 @@ -19,16 +19,15 @@ package com.sk89q.worldedit.math.convolution; +import static com.google.common.base.Preconditions.checkNotNull; + import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.blocks.BaseBlock; import com.sk89q.worldedit.blocks.type.BlockState; import com.sk89q.worldedit.blocks.type.BlockTypes; import com.sk89q.worldedit.regions.Region; -import static com.google.common.base.Preconditions.checkNotNull; - /** * Allows applications of Kernels onto the region's height map. * @@ -123,7 +122,7 @@ public class HeightMap { int originZ = minY.getBlockZ(); int maxY = region.getMaximumPoint().getBlockY(); - BaseBlock fillerAir = new BaseBlock(BlockTypes.AIR); + BlockState fillerAir = BlockTypes.AIR.getDefaultState(); int blocksChanged = 0; 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 039f27ab2..55546b95a 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 @@ -23,10 +23,10 @@ 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.blocks.BaseBlock; +import com.sk89q.worldedit.blocks.type.BlockState; +import com.sk89q.worldedit.blocks.type.BlockStateHolder; import com.sk89q.worldedit.blocks.type.BlockTypes; -import javax.annotation.Nullable; import java.util.Collections; import java.util.EnumSet; import java.util.HashMap; @@ -34,6 +34,8 @@ import java.util.Map; import java.util.Random; import java.util.Set; +import javax.annotation.Nullable; + /** * Tree generator. */ @@ -198,8 +200,8 @@ public class TreeGenerator { int trunkHeight = (int) Math.floor(Math.random() * 2) + 3; int height = (int) Math.floor(Math.random() * 5) + 8; - BaseBlock logBlock = new BaseBlock(BlockTypes.OAK_LOG); - BaseBlock leavesBlock = new BaseBlock(BlockTypes.OAK_LEAVES); + BlockState logBlock = BlockTypes.OAK_LOG.getDefaultState(); + BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); // Create trunk for (int i = 0; i < trunkHeight; ++i) { @@ -269,7 +271,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, BaseBlock block, double probability) + private static boolean setChanceBlockIfAir(EditSession session, Vector position, BlockStateHolder block, double probability) throws MaxChangedBlocksException { return Math.random() <= probability && setBlockIfAir(session, position, block); } @@ -282,7 +284,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, BaseBlock block) throws MaxChangedBlocksException { + private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { return session.getBlock(position).getBlockType() == BlockTypes.AIR && session.setBlock(position, block); } } 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 7d9532170..c7fb04f33 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 @@ -94,7 +94,7 @@ public abstract class AbstractWorld implements World { } try { - setBlock(pt, new BaseBlock(BlockTypes.AIR)); + setBlock(pt, BlockTypes.AIR.getDefaultState()); } catch (WorldEditException e) { throw new RuntimeException(e); }