Permalink
Browse files

Add a material to check if air is air, because there are now 3 types …

…of air.
  • Loading branch information...
me4502 committed Aug 16, 2018
1 parent c31161d commit bc5609114b6c632fcc656dc0cee309d30598c16f
Showing with 65 additions and 33 deletions.
  1. +5 −0 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockRegistry.java
  2. +2 −2 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayerBlockBag.java
  3. +1 −1 worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/EditSessionBlockChangeDelegate.java
  4. +4 −4 worldedit-core/src/main/java/com/sk89q/worldedit/EditSession.java
  5. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/AreaPickaxe.java
  6. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloatingTreeRemover.java
  7. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/FloodFillTool.java
  8. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/LongRangeBuildTool.java
  9. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/RecursivePickaxe.java
  10. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/brush/GravityBrush.java
  11. +4 −3 worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/AbstractPlayerActor.java
  12. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBag.java
  13. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/extent/inventory/BlockBagExtent.java
  14. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SurvivalModeExtent.java
  15. +5 −5 worldedit-core/src/main/java/com/sk89q/worldedit/function/generator/GardenPatchGenerator.java
  16. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/function/mask/ExistingBlockMask.java
  17. +2 −2 worldedit-core/src/main/java/com/sk89q/worldedit/util/TargetBlock.java
  18. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/util/TreeGenerator.java
  19. +1 −1 worldedit-core/src/main/java/com/sk89q/worldedit/world/chunk/OldChunk.java
  20. +7 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/BlockMaterial.java
  21. +9 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/PassthroughBlockMaterial.java
  22. +10 −0 worldedit-core/src/main/java/com/sk89q/worldedit/world/registry/SimpleBlockMaterial.java
@@ -60,6 +60,11 @@ public BukkitBlockMaterial(@Nullable BlockMaterial material, Material bukkitMate
this.material = bukkitMaterial;
}
@Override
public boolean isAir() {
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;
}
@Override
public boolean isSolid() {
return material.isSolid();
@@ -64,7 +64,7 @@ public Player getPlayer() {
@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");
}
@@ -108,7 +108,7 @@ public void fetchBlock(BlockState blockState) throws BlockBagException {
@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()) {
@@ -59,7 +59,7 @@ public int getHeight() {
@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();
}
}
@@ -1446,7 +1446,7 @@ public int thaw(Vector position, double radius)
if (setBlock(pt, air)) {
++affected;
}
} else if (id == BlockTypes.AIR) {
} else if (id.getMaterial().isAir()) {
continue;
}
@@ -1488,7 +1488,7 @@ public int simulateSnow(Vector position, double radius) throws MaxChangedBlocksE
Vector pt = new Vector(x, y, z);
BlockType id = getBlock(pt).getBlockType();
if (id == BlockTypes.AIR) {
if (id.getMaterial().isAir()) {
continue;
}
@@ -1619,7 +1619,7 @@ public int makeForest(Vector basePosition, int size, double density, TreeGenerat
for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ()
+ size; ++z) {
// Don't want to be in the ground
if (getBlock(new Vector(x, basePosition.getBlockY(), z)).getBlockType() != BlockTypes.AIR) {
if (!getBlock(new Vector(x, basePosition.getBlockY(), z)).getBlockType().getMaterial().isAir()) {
continue;
}
// The gods don't want a tree here
@@ -1636,7 +1636,7 @@ public int makeForest(Vector basePosition, int size, double density, TreeGenerat
break;
} else if (t == BlockTypes.SNOW) {
setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState());
} else if (t != BlockTypes.AIR) { // Trees won't grow on this!
} else if (!t.getMaterial().isAir()) { // Trees won't grow on this!
break;
}
}
@@ -54,7 +54,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
int oz = clicked.getBlockZ();
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) {
if (initialType.getMaterial().isAir()) {
return true;
}
@@ -134,7 +134,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config,
if (visited.add(next)) {
BlockState state = world.getBlock(next);
if (state.getBlockType() == BlockTypes.AIR || state.getBlockType() == BlockTypes.SNOW) {
if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
continue;
}
if (isTreeBlock(state.getBlockType())) {
@@ -61,7 +61,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) {
if (initialType.getMaterial().isAir()) {
return true;
}
@@ -57,7 +57,7 @@ public boolean actSecondary(Platform server, LocalConfiguration config, Player p
EditSession eS = session.createEditSession(player);
try {
BlockStateHolder applied = secondary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) {
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(pos.toVector(), secondary);
} else {
eS.setBlock(pos.getDirection(), secondary);
@@ -77,7 +77,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
EditSession eS = session.createEditSession(player);
try {
BlockStateHolder applied = primary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) {
if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(pos.toVector(), primary);
} else {
eS.setBlock(pos.getDirection(), primary);
@@ -58,7 +58,7 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) {
if (initialType.getMaterial().isAir()) {
return true;
}
@@ -48,15 +48,15 @@ public void build(EditSession editSession, Vector position, Pattern pattern, dou
for (; y > position.getBlockY() - size; --y) {
final Vector pt = new Vector(x, y, z);
final BlockStateHolder block = editSession.getBlock(pt);
if (block.getBlockType() != BlockTypes.AIR) {
if (!block.getBlockType().getMaterial().isAir()) {
blockTypes.add(block);
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
}
}
Vector pt = new Vector(x, y, z);
Collections.reverse(blockTypes);
for (int i = 0; i < blockTypes.size();) {
if (editSession.getBlock(pt).getBlockType() == BlockTypes.AIR) {
if (editSession.getBlock(pt).getBlockType().getMaterial().isAir()) {
editSession.setBlock(pt, blockTypes.get(i++));
}
pt = pt.add(0, 1, 0);
@@ -32,6 +32,7 @@
import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes;
@@ -210,10 +211,10 @@ public boolean descendLevel() {
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 BlockType type = block.getBlockType();
// Don't want to end up in lava
if (type != BlockTypes.AIR && type != BlockTypes.LAVA) {
if (!type.getMaterial().isAir() && type != BlockTypes.LAVA) {
// Found a block!
setPosition(platform.add(0.5, 1, 0.5));
return true;
@@ -246,7 +247,7 @@ public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
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;
}
@@ -37,7 +37,7 @@
public void storeDroppedBlock(BlockState blockState) throws BlockBagException {
BlockState dropped = blockState; // TODO BlockType.getBlockBagItem(id, data);
if (dropped == null) return;
if (dropped.getBlockType() == BlockTypes.AIR) return;
if (dropped.getBlockType().getMaterial().isAir()) return;
storeBlock(dropped);
}
@@ -57,7 +57,7 @@ public void fetchPlacedBlock(BlockState blockState) throws BlockBagException {
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);
}
@@ -87,7 +87,7 @@ public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEdi
if (blockBag != null) {
BlockState existing = getExtent().getBlock(position);
if (block.getBlockType() != BlockTypes.AIR) {
if (!block.getBlockType().getMaterial().isAir()) {
try {
blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) {
@@ -102,7 +102,7 @@ public boolean setBlock(Vector position, BlockStateHolder block) throws WorldEdi
}
}
if (existing.getBlockType() != BlockTypes.AIR) {
if (!existing.getBlockType().getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(existing);
} catch (BlockBagException ignored) {
@@ -81,7 +81,7 @@ public void setToolUse(boolean toolUse) {
@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 {
@@ -86,11 +86,11 @@ public int getAffected() {
*/
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 @@ private void placeVine(Vector basePos, Vector pos) throws MaxChangedBlocksExcept
@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 boolean apply(Vector position) throws WorldEditException {
BlockState 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 static Pattern getPumpkinPattern() {
* @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);
}
/**
@@ -42,7 +42,7 @@ public ExistingBlockMask(Extent extent) {
@Override
public boolean test(Vector vector) {
return getExtent().getBlock(vector).getBlockType() != BlockTypes.AIR;
return !getExtent().getBlock(vector).getBlockType().getMaterial().isAir();
}
@Nullable
@@ -102,7 +102,7 @@ public Location getAnyTargetBlock() {
boolean searchForLastBlock = true;
Location lastBlock = null;
while (getNextBlock() != null) {
if (world.getBlock(getCurrentBlock().toVector()).getBlockType() == BlockTypes.AIR) {
if (world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) {
if (searchForLastBlock) {
lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
@@ -124,7 +124,7 @@ public Location getAnyTargetBlock() {
* @return Block
*/
public Location getTargetBlock() {
while (getNextBlock() != null && world.getBlock(getCurrentBlock().toVector()).getBlockType() == BlockTypes.AIR) ;
while (getNextBlock() != null && world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) ;
return getCurrentBlock();
}
@@ -264,6 +264,6 @@ private static boolean setChanceBlockIfAir(EditSession session, Vector position,
* @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);
}
}
@@ -154,7 +154,7 @@ private CompoundTag getBlockTileEntity(Vector position) throws DataException {
@Override
public BaseBlock getBlock(Vector position) throws DataException {
if(position.getBlockY() >= 128) BlockTypes.AIR.getDefaultState().toBaseBlock();
if(position.getBlockY() >= 128) BlockTypes.VOID_AIR.getDefaultState().toBaseBlock();
int id, dataVal;
int x = position.getBlockX() - rootX * 16;
@@ -24,6 +24,13 @@
*/
public interface BlockMaterial {
/**
* Gets if this block is a type of air.
*
* @return If it's air
*/
boolean isAir();
/**
* Get whether this block is a full sized cube.
*
@@ -29,6 +29,15 @@ public PassthroughBlockMaterial(@Nullable BlockMaterial material) {
this.blockMaterial = material;
}
@Override
public boolean isAir() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAir();
}
}
@Override
public boolean isFullCube() {
if (blockMaterial == null) {
@@ -21,6 +21,7 @@
class SimpleBlockMaterial implements BlockMaterial {
private boolean isAir;
private boolean fullCube;
private boolean opaque;
private boolean powerSource;
@@ -40,6 +41,15 @@
private boolean isTranslucent;
private boolean hasContainer;
@Override
public boolean isAir() {
return this.isAir;
}
public void setIsAir(boolean isAir) {
this.isAir = isAir;
}
@Override
public boolean isFullCube() {
return fullCube;

0 comments on commit bc56091

Please sign in to comment.