What are the dud BlockCategories?

This commit is contained in:
Jesse Boyd 2018-08-14 11:00:44 +10:00
parent 76a55b7712
commit 1740c845d2
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
13 changed files with 40 additions and 31 deletions

View File

@ -63,7 +63,7 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag
@Override @Override
public void fetchBlock(BlockState blockState) throws BlockBagException { 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"); throw new IllegalArgumentException("Can't fetch air block");
} }
@ -107,7 +107,7 @@ public class BukkitPlayerBlockBag extends BlockBag implements SlottableBlockBag
@Override @Override
public void storeBlock(BlockState blockState, int amount) throws BlockBagException { 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"); throw new IllegalArgumentException("Can't store air block");
} }
if (!blockState.getBlockType().hasItemType()) { if (!blockState.getBlockType().hasItemType()) {

View File

@ -59,7 +59,7 @@ public class EditSessionBlockChangeDelegate implements BlockChangeDelegate {
@Override @Override
public boolean isEmpty(int x, int y, int z) { 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();
} }
} }

View File

@ -233,7 +233,7 @@ public class PlayerWrapper extends AbstractPlayerActor {
Extent world = getLocation().getExtent(); Extent world = getLocation().getExtent();
// No free space above // 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; return false;
} }

View File

@ -148,7 +148,7 @@ public class CuboidClipboard {
// } // }
// //
// public boolean setBlock(int x, int y, int z, BaseBlock block) { // 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 i = x + z * dx + (y >> 4) * dxz;
// int y2 = y & 0xF; // int y2 = y & 0xF;
// int[] idArray = states[i]; // int[] idArray = states[i];
@ -238,7 +238,7 @@ public class CuboidClipboard {
// final int newZ = v.getBlockZ(); // final int newZ = v.getBlockZ();
// for (int y = 0; y < height; ++y) { // for (int y = 0; y < height; ++y) {
// BaseBlock block = getBlock(x, y, z); // BaseBlock block = getBlock(x, y, z);
// if (block.getBlockType() == BlockTypes.AIR) { // if (block.getBlockType().getMaterial().isAir()) {
// continue; // continue;
// } // }
// if (reverse) { // if (reverse) {
@ -484,7 +484,7 @@ public class CuboidClipboard {
// if (block == null) { // if (block == null) {
// continue; // continue;
// } // }
// if (noAir && block.getBlockType() == BlockTypes.AIR) { // if (noAir && block.getBlockType().getMaterial().isAir()) {
// continue; // continue;
// } // }
// editSession.setBlock(x + ox, y + oy, z + oz, block); // editSession.setBlock(x + ox, y + oy, z + oz, block);

View File

@ -1026,7 +1026,7 @@ public class LocalSession implements TextureHolder {
public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException { public void setTool(BaseItem item, @Nullable Tool tool, Player player) throws InvalidToolBindException {
ItemTypes type = item.getType(); 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"); throw new InvalidToolBindException(type, "Blocks can't be used");
} else if (type == config.wandItem) { } else if (type == config.wandItem) {
throw new InvalidToolBindException(type, "Already used for the wand"); throw new InvalidToolBindException(type, "Already used for the wand");

View File

@ -134,7 +134,12 @@ public class FloatingTreeRemover implements BlockTool {
if (visited.add(next)) { if (visited.add(next)) {
BlockState state = world.getBlock(next); BlockState state = world.getBlock(next);
if (state.getBlockType() == BlockTypes.AIR || state.getBlockType() == BlockTypes.SNOW) { BlockTypes type = state.getBlockType();
switch (type) {
case AIR:
case CAVE_AIR:
case VOID_AIR:
case SNOW:
continue; continue;
} }
if (isTreeBlock(state.getBlockType())) { if (isTreeBlock(state.getBlockType())) {

View File

@ -214,18 +214,22 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
while (y >= 0) { while (y >= 0) {
final Vector platform = new Vector(x, y, z); final Vector platform = new Vector(x, y, z);
final BlockStateHolder block = world.getBlock(platform); 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 // Don't want to end up in lava
if (type != BlockTypes.AIR && type != BlockTypes.LAVA) { switch (type) {
case AIR:
case CAVE_AIR:
case VOID_AIR:
case LAVA:
--y;
continue;
default:
// Found a block! // Found a block!
setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5)); setPosition(platform.add(0.5, BlockType.centralTopLimit(block), 0.5));
return true; return true;
} }
--y;
} }
return false; return false;
} }
@ -250,7 +254,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
Extent world = getLocation().getExtent(); Extent world = getLocation().getExtent();
// No free space above // 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; return false;
} }

View File

@ -58,7 +58,7 @@ public abstract class BlockBag {
fetchBlock(blockState); fetchBlock(blockState);
} catch (OutOfBlocksException e) { } catch (OutOfBlocksException e) {
BlockState placed = blockState;// TODO BlockType.getBlockBagItem(id, data); 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); fetchBlock(placed);
} }

View File

@ -82,7 +82,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
@Override @Override
public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException { public boolean setBlock(Vector location, BlockStateHolder block) throws WorldEditException {
if (toolUse && block.getBlockType() == BlockTypes.AIR) { if (toolUse && block.getBlockType().getMaterial().isAir()) {
world.simulateBlockMine(location); world.simulateBlockMine(location);
return true; return true;
} else { } else {
@ -92,7 +92,7 @@ public class SurvivalModeExtent extends AbstractDelegateExtent {
@Override @Override
public boolean setBlock(int x, int y, int z, BlockStateHolder block) throws WorldEditException { 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)); world.simulateBlockMine(MutableBlockVector.get(x, y, z));
return true; return true;
} else { } else {

View File

@ -86,11 +86,11 @@ public class GardenPatchGenerator implements RegionFunction {
*/ */
private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException { private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksException {
if (pos.distance(basePos) > 4) return; 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) { for (int i = -1; i > -3; --i) {
Vector testPos = pos.add(0, i, 0); Vector testPos = pos.add(0, i, 0);
if (editSession.getBlock(testPos).getBlockType() == BlockTypes.AIR) { if (editSession.getBlock(testPos).getBlockType().getMaterial().isAir()) {
pos = testPos; pos = testPos;
} else { } else {
break; break;
@ -159,7 +159,7 @@ public class GardenPatchGenerator implements RegionFunction {
@Override @Override
public boolean apply(Vector position) throws WorldEditException { 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); position = position.add(0, 1, 0);
} }
@ -169,7 +169,7 @@ public class GardenPatchGenerator implements RegionFunction {
BlockStateHolder leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); BlockStateHolder leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState();
if (editSession.getBlock(position).getBlockType() == BlockTypes.AIR) { if (editSession.getBlock(position).getBlockType().getMaterial().isAir()) {
editSession.setBlock(position, leavesBlock); editSession.setBlock(position, leavesBlock);
} }
@ -199,7 +199,7 @@ public class GardenPatchGenerator implements RegionFunction {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { private static boolean setBlockIfAir(EditSession session, 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);
} }
/** /**

View File

@ -42,7 +42,7 @@ public class ExistingBlockMask extends AbstractExtentMask {
@Override @Override
public boolean test(Vector vector) { public boolean test(Vector vector) {
return getExtent().getBlock(vector).getBlockType() != BlockTypes.AIR; return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir();
} }
@Nullable @Nullable

View File

@ -264,6 +264,6 @@ public class TreeGenerator {
* @throws MaxChangedBlocksException thrown if too many blocks are changed * @throws MaxChangedBlocksException thrown if too many blocks are changed
*/ */
private static boolean setBlockIfAir(EditSession session, Vector position, BlockStateHolder block) throws MaxChangedBlocksException { private static boolean setBlockIfAir(EditSession session, 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);
} }
} }

View File

@ -211,7 +211,7 @@ public class SpongeWorldEdit {
BlockType interactedType = targetBlock.getState().getType(); BlockType interactedType = targetBlock.getState().getType();
if (event instanceof InteractBlockEvent.Primary) { if (event instanceof InteractBlockEvent.Primary) {
if (interactedType != BlockTypes.AIR) { if (!interactedType.getMaterial().isAir()) {
if (!optLoc.isPresent()) { if (!optLoc.isPresent()) {
return; return;
} }
@ -233,7 +233,7 @@ public class SpongeWorldEdit {
} }
} }
} else if (event instanceof InteractBlockEvent.Secondary) { } else if (event instanceof InteractBlockEvent.Secondary) {
if (interactedType != BlockTypes.AIR) { if (!interactedType.getMaterial().isAir()) {
if (!optLoc.isPresent()) { if (!optLoc.isPresent()) {
return; return;
} }