From 1740c845d2381b1b604ed91c1bd841a791db1eab Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Tue, 14 Aug 2018 11:00:44 +1000 Subject: [PATCH] What are the dud BlockCategories? --- .../bukkit/BukkitPlayerBlockBag.java | 4 ++-- .../EditSessionBlockChangeDelegate.java | 2 +- .../boydti/fawe/wrappers/PlayerWrapper.java | 2 +- .../com/sk89q/worldedit/CuboidClipboard.java | 6 ++--- .../com/sk89q/worldedit/LocalSession.java | 2 +- .../command/tool/FloatingTreeRemover.java | 9 ++++++-- .../platform/AbstractPlayerActor.java | 22 +++++++++++-------- .../worldedit/extent/inventory/BlockBag.java | 2 +- .../extent/world/SurvivalModeExtent.java | 4 ++-- .../generator/GardenPatchGenerator.java | 10 ++++----- .../function/mask/ExistingBlockMask.java | 2 +- .../sk89q/worldedit/util/TreeGenerator.java | 2 +- .../worldedit/sponge/SpongeWorldEdit.java | 4 ++-- 13 files changed, 40 insertions(+), 31 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java index 64b5f96e9..2d4c64582 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java @@ -63,7 +63,7 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag @Override public void fetchBlock(BlockState blockState) throws BlockBagException { - if (blockState.getBlockType() == BlockTypes.AIR) { + if (blockState.getBlockType().getMaterial().isAir()) { throw new IllegalArgumentException("Can't fetch air block"); } @@ -107,7 +107,7 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag @Override public void storeBlock(BlockState blockState, int amount) throws BlockBagException { - if (blockState.getBlockType() == BlockTypes.AIR) { + if (blockState.getBlockType().getMaterial().isAir()) { throw new IllegalArgumentException("Can't store air block"); } if (!blockState.getBlockType().hasItemType()) { 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 24e14d964..97fa2b170 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 @@ -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() == BlockTypes.AIR; + return editSession.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isAir(); } } diff --git a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java index 30be0e7f5..a5ec89f5f 100644 --- a/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java +++ b/worldedit-core/src/main/java/com/boydti/fawe/wrappers/PlayerWrapper.java @@ -233,7 +233,7 @@ public class PlayerWrapper extends AbstractPlayerActor { Extent world = getLocation().getExtent(); // No free space above - if (world.getBlock(new Vector(x, y, z)).getBlockType() != BlockTypes.AIR) { + if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isAir()) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index 58b624736..8b39a3712 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -148,7 +148,7 @@ public class CuboidClipboard { // } // // public boolean setBlock(int x, int y, int z, BaseBlock block) { -// if (block == null || block.getBlockType() == BlockTypes.AIR) { +// if (block == null || block.getBlockType().getMaterial().isAir()) { // int i = x + z * dx + (y >> 4) * dxz; // int y2 = y & 0xF; // int[] idArray = states[i]; @@ -238,7 +238,7 @@ public class CuboidClipboard { // final int newZ = v.getBlockZ(); // for (int y = 0; y < height; ++y) { // BaseBlock block = getBlock(x, y, z); -// if (block.getBlockType() == BlockTypes.AIR) { +// if (block.getBlockType().getMaterial().isAir()) { // continue; // } // if (reverse) { @@ -484,7 +484,7 @@ public class CuboidClipboard { // if (block == null) { // continue; // } -// if (noAir && block.getBlockType() == BlockTypes.AIR) { +// if (noAir && block.getBlockType().getMaterial().isAir()) { // continue; // } // editSession.setBlock(x + ox, y + oy, z + oz, block); 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 a65ed5dcb..92617b693 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/LocalSession.java @@ -1026,7 +1026,7 @@ public class LocalSession implements TextureHolder { public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException { ItemTypes type = item.getType(); - if (type.hasBlockType() && type.getBlockType() != BlockTypes.AIR) { + if (!type.hasBlockType() && type.getBlockType().getMaterial().isAir()) { throw new InvalidToolBindException(type, "Blocks can't be used"); } else if (type == config.wandItem) { throw new InvalidToolBindException(type, "Already used for the wand"); 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 90397323e..43a840cf6 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 @@ -134,8 +134,13 @@ public class FloatingTreeRemover implements BlockTool { if (visited.add(next)) { BlockState state = world.getBlock(next); - if (state.getBlockType() == BlockTypes.AIR || state.getBlockType() == BlockTypes.SNOW) { - continue; + BlockTypes type = state.getBlockType(); + switch (type) { + case AIR: + case CAVE_AIR: + case VOID_AIR: + case SNOW: + continue; } if (isTreeBlock(state.getBlockType())) { queue.addLast(next); 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 bf4da5a9d..581dc53bd 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 @@ -214,18 +214,22 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable { while (y >= 0) { final Vector platform = new Vector(x, y, z); final BlockStateHolder block = world.getBlock(platform); - final com.sk89q.worldedit.world.block.BlockType type = block.getBlockType(); + final com.sk89q.worldedit.world.block.BlockTypes type = block.getBlockType(); // Don't want to end up in lava - if (type != BlockTypes.AIR && type != BlockTypes.LAVA) { - // Found a block! - setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5)); - return true; + switch (type) { + case AIR: + case CAVE_AIR: + case VOID_AIR: + case LAVA: + --y; + continue; + default: + // Found a block! + setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5)); + return true; } - - --y; } - return false; } @@ -250,7 +254,7 @@ 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() != BlockTypes.AIR) { + if (!world.getBlock(new Vector(x, y, z)).getBlockType().getMaterial().isAir()) { return false; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java index 62c5713f0..23aec0ed0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java @@ -58,7 +58,7 @@ public abstract class BlockBag { fetchBlock(blockState); } catch (OutOfBlocksException e) { BlockState placed = blockState;// TODO BlockType.getBlockBagItem(id, data); - if (placed == null || placed.getBlockType() == BlockTypes.AIR) throw e; // TODO: check + if (placed == null || placed.getBlockType().getMaterial().isAir()) throw e; // TODO: check fetchBlock(placed); } 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 216487ca8..0519efae4 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 @@ -82,7 +82,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { @Override public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { - if (toolUse && block.getBlockType() == BlockTypes.AIR) { + if (toolUse && block.getBlockType().getMaterial().isAir()) { world.simulateBlockMine(location); return true; } else { @@ -92,7 +92,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent { @Override public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { - if (toolUse && block.getBlockType() == BlockTypes.AIR) { + if (toolUse && block.getBlockType().getMaterial().isAir()) { world.simulateBlockMine(MutableBlockVector.get(x, y, z)); return true; } else { 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 2cea1f29d..d6377db25 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 @@ -86,11 +86,11 @@ public class GardenPatchGenerator implements RegionFunction { */ private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException { if (pos.distance(basePos) > 4) return; - if (editSession.getBlock(pos).getBlockType() != BlockTypes.AIR) return; + if (!editSession.getBlock(pos).getBlockType().getMaterial().isAir()) return; for (int i = -1; i > -3; --i) { Vector testPos = pos.add(0, i, 0); - if (editSession.getBlock(testPos).getBlockType() == BlockTypes.AIR) { + if (editSession.getBlock(testPos).getBlockType().getMaterial().isAir()) { pos = testPos; } else { break; @@ -159,7 +159,7 @@ public class GardenPatchGenerator implements RegionFunction { @Override public boolean apply(Vector position) throws WorldEditException { - if (editSession.getBlock(position).getBlockType() != BlockTypes.AIR) { + if (!editSession.getBlock(position).getBlockType().getMaterial().isAir()) { position = position.add(0, 1, 0); } @@ -169,7 +169,7 @@ public class GardenPatchGenerator implements RegionFunction { BlockStateHolder leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); - if (editSession.getBlock(position).getBlockType() == BlockTypes.AIR) { + if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) { editSession.setBlock(position, leavesBlock); } @@ -199,7 +199,7 @@ public class GardenPatchGenerator implements RegionFunction { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { - return session.getBlock(position).getBlockType() == BlockTypes.AIR && session.setBlock(position, block); + return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } /** 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 c942ddc5c..4633dfa5b 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 @@ -42,7 +42,7 @@ public class ExistingBlockMask extends AbstractExtentMask { @Override public boolean test(Vector vector) { - return getExtent().getBlock(vector).getBlockType() != BlockTypes.AIR; + return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir(); } @Nullable 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 46f640a1b..d63ef2f29 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 @@ -264,6 +264,6 @@ public class TreeGenerator { * @throws MaxChangedBlocksException thrown if too many blocks are changed */ private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { - return session.getBlock(position).getBlockType() == BlockTypes.AIR && session.setBlock(position, block); + return session.getBlock(position).getBlockType().getMaterial().isAir() && session.setBlock(position, block); } } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java index f2ba77982..6c494c56f 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeWorldEdit.java @@ -211,7 +211,7 @@ public class SpongeWorldEdit { BlockType interactedType = targetBlock.getState().getType(); if (event instanceof InteractBlockEvent.Primary) { - if (interactedType != BlockTypes.AIR) { + if (!interactedType.getMaterial().isAir()) { if (!optLoc.isPresent()) { return; } @@ -233,7 +233,7 @@ public class SpongeWorldEdit { } } } else if (event instanceof InteractBlockEvent.Secondary) { - if (interactedType != BlockTypes.AIR) { + if (!interactedType.getMaterial().isAir()) { if (!optLoc.isPresent()) { return; }