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

Dieser Commit ist enthalten in:
Matthew Miller 2018-08-16 15:42:11 +10:00
Ursprung c31161d068
Commit bc5609114b
22 geänderte Dateien mit 65 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -60,6 +60,11 @@ public class BukkitBlockRegistry extends BundledBlockRegistry {
this.material = bukkitMaterial; this.material = bukkitMaterial;
} }
@Override
public boolean isAir() {
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;
}
@Override @Override
public boolean isSolid() { public boolean isSolid() {
return material.isSolid(); return material.isSolid();

Datei anzeigen

@ -64,7 +64,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
@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");
} }
@ -108,7 +108,7 @@ public class BukkitPlayerBlockBag extends BlockBag {
@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()) {

Datei anzeigen

@ -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();
} }
} }

Datei anzeigen

@ -1446,7 +1446,7 @@ public class EditSession implements Extent {
if (setBlock(pt, air)) { if (setBlock(pt, air)) {
++affected; ++affected;
} }
} else if (id == BlockTypes.AIR) { } else if (id.getMaterial().isAir()) {
continue; continue;
} }
@ -1488,7 +1488,7 @@ public class EditSession implements Extent {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
BlockType id = getBlock(pt).getBlockType(); BlockType id = getBlock(pt).getBlockType();
if (id == BlockTypes.AIR) { if (id.getMaterial().isAir()) {
continue; continue;
} }
@ -1619,7 +1619,7 @@ public class EditSession implements Extent {
for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ() for (int z = basePosition.getBlockZ() - size; z <= basePosition.getBlockZ()
+ size; ++z) { + size; ++z) {
// Don't want to be in the ground // 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; continue;
} }
// The gods don't want a tree here // The gods don't want a tree here
@ -1636,7 +1636,7 @@ public class EditSession implements Extent {
break; break;
} else if (t == BlockTypes.SNOW) { } else if (t == BlockTypes.SNOW) {
setBlock(new Vector(x, y, z), BlockTypes.AIR.getDefaultState()); 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; break;
} }
} }

Datei anzeigen

@ -54,7 +54,7 @@ public class AreaPickaxe implements BlockTool {
int oz = clicked.getBlockZ(); int oz = clicked.getBlockZ();
BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType(); BlockType initialType = clicked.getExtent().getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) { if (initialType.getMaterial().isAir()) {
return true; return true;
} }

Datei anzeigen

@ -134,7 +134,7 @@ 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) { if (state.getBlockType().getMaterial().isAir() || state.getBlockType() == BlockTypes.SNOW) {
continue; continue;
} }
if (isTreeBlock(state.getBlockType())) { if (isTreeBlock(state.getBlockType())) {

Datei anzeigen

@ -61,7 +61,7 @@ public class FloodFillTool implements BlockTool {
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType(); BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) { if (initialType.getMaterial().isAir()) {
return true; return true;
} }

Datei anzeigen

@ -57,7 +57,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
EditSession eS = session.createEditSession(player); EditSession eS = session.createEditSession(player);
try { try {
BlockStateHolder applied = secondary.apply(pos.toVector()); BlockStateHolder applied = secondary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) { if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(pos.toVector(), secondary); eS.setBlock(pos.toVector(), secondary);
} else { } else {
eS.setBlock(pos.getDirection(), secondary); eS.setBlock(pos.getDirection(), secondary);
@ -77,7 +77,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
EditSession eS = session.createEditSession(player); EditSession eS = session.createEditSession(player);
try { try {
BlockStateHolder applied = primary.apply(pos.toVector()); BlockStateHolder applied = primary.apply(pos.toVector());
if (applied.getBlockType() == BlockTypes.AIR) { if (applied.getBlockType().getMaterial().isAir()) {
eS.setBlock(pos.toVector(), primary); eS.setBlock(pos.toVector(), primary);
} else { } else {
eS.setBlock(pos.getDirection(), primary); eS.setBlock(pos.getDirection(), primary);

Datei anzeigen

@ -58,7 +58,7 @@ public class RecursivePickaxe implements BlockTool {
BlockType initialType = world.getBlock(clicked.toVector()).getBlockType(); BlockType initialType = world.getBlock(clicked.toVector()).getBlockType();
if (initialType == BlockTypes.AIR) { if (initialType.getMaterial().isAir()) {
return true; return true;
} }

Datei anzeigen

@ -48,7 +48,7 @@ public class GravityBrush implements Brush {
for (; y > position.getBlockY() - size; --y) { for (; y > position.getBlockY() - size; --y) {
final Vector pt = new Vector(x, y, z); final Vector pt = new Vector(x, y, z);
final BlockStateHolder block = editSession.getBlock(pt); final BlockStateHolder block = editSession.getBlock(pt);
if (block.getBlockType() != BlockTypes.AIR) { if (!block.getBlockType().getMaterial().isAir()) {
blockTypes.add(block); blockTypes.add(block);
editSession.setBlock(pt, BlockTypes.AIR.getDefaultState()); editSession.setBlock(pt, BlockTypes.AIR.getDefaultState());
} }
@ -56,7 +56,7 @@ public class GravityBrush implements Brush {
Vector pt = new Vector(x, y, z); Vector pt = new Vector(x, y, z);
Collections.reverse(blockTypes); Collections.reverse(blockTypes);
for (int i = 0; i < blockTypes.size();) { 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++)); editSession.setBlock(pt, blockTypes.get(i++));
} }
pt = pt.add(0, 1, 0); pt = pt.add(0, 1, 0);

Datei anzeigen

@ -32,6 +32,7 @@ import com.sk89q.worldedit.util.TargetBlock;
import com.sk89q.worldedit.util.auth.AuthorizationException; import com.sk89q.worldedit.util.auth.AuthorizationException;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; 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.block.BlockTypes;
import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameMode;
import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.gamemode.GameModes;
@ -210,10 +211,10 @@ 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 BlockType 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) { if (!type.getMaterial().isAir() && type != BlockTypes.LAVA) {
// Found a block! // Found a block!
setPosition(platform.add(0.5, 1, 0.5)); setPosition(platform.add(0.5, 1, 0.5));
return true; return true;
@ -246,7 +247,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;
} }

Datei anzeigen

@ -37,7 +37,7 @@ public abstract class BlockBag {
public void storeDroppedBlock(BlockState blockState) throws BlockBagException { public void storeDroppedBlock(BlockState blockState) throws BlockBagException {
BlockState dropped = blockState; // TODO BlockType.getBlockBagItem(id, data); BlockState dropped = blockState; // TODO BlockType.getBlockBagItem(id, data);
if (dropped == null) return; if (dropped == null) return;
if (dropped.getBlockType() == BlockTypes.AIR) return; if (dropped.getBlockType().getMaterial().isAir()) return;
storeBlock(dropped); storeBlock(dropped);
} }
@ -57,7 +57,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);
} }

Datei anzeigen

@ -87,7 +87,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
if (blockBag != null) { if (blockBag != null) {
BlockState existing = getExtent().getBlock(position); BlockState existing = getExtent().getBlock(position);
if (block.getBlockType() != BlockTypes.AIR) { if (!block.getBlockType().getMaterial().isAir()) {
try { try {
blockBag.fetchPlacedBlock(block.toImmutableState()); blockBag.fetchPlacedBlock(block.toImmutableState());
} catch (UnplaceableBlockException e) { } catch (UnplaceableBlockException e) {
@ -102,7 +102,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
} }
} }
if (existing.getBlockType() != BlockTypes.AIR) { if (!existing.getBlockType().getMaterial().isAir()) {
try { try {
blockBag.storeDroppedBlock(existing); blockBag.storeDroppedBlock(existing);
} catch (BlockBagException ignored) { } catch (BlockBagException ignored) {

Datei anzeigen

@ -81,7 +81,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 {

Datei anzeigen

@ -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 {
BlockState leavesBlock = BlockTypes.OAK_LEAVES.getDefaultState(); BlockState 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);
} }
/** /**

Datei anzeigen

@ -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

Datei anzeigen

@ -102,7 +102,7 @@ public class TargetBlock {
boolean searchForLastBlock = true; boolean searchForLastBlock = true;
Location lastBlock = null; Location lastBlock = null;
while (getNextBlock() != null) { while (getNextBlock() != null) {
if (world.getBlock(getCurrentBlock().toVector()).getBlockType() == BlockTypes.AIR) { if (world.getBlock(getCurrentBlock().toVector()).getBlockType().getMaterial().isAir()) {
if (searchForLastBlock) { if (searchForLastBlock) {
lastBlock = getCurrentBlock(); lastBlock = getCurrentBlock();
if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) { if (lastBlock.getBlockY() <= 0 || lastBlock.getBlockY() >= world.getMaxY()) {
@ -124,7 +124,7 @@ public class TargetBlock {
* @return Block * @return Block
*/ */
public Location getTargetBlock() { 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(); return getCurrentBlock();
} }

Datei anzeigen

@ -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);
} }
} }

Datei anzeigen

@ -154,7 +154,7 @@ public class OldChunk implements Chunk {
@Override @Override
public BaseBlock getBlock(Vector position) throws DataException { 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 id, dataVal;
int x = position.getBlockX() - rootX * 16; int x = position.getBlockX() - rootX * 16;

Datei anzeigen

@ -24,6 +24,13 @@ package com.sk89q.worldedit.world.registry;
*/ */
public interface BlockMaterial { 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. * Get whether this block is a full sized cube.
* *

Datei anzeigen

@ -29,6 +29,15 @@ public class PassthroughBlockMaterial implements BlockMaterial {
this.blockMaterial = material; this.blockMaterial = material;
} }
@Override
public boolean isAir() {
if (blockMaterial == null) {
return false;
} else {
return blockMaterial.isAir();
}
}
@Override @Override
public boolean isFullCube() { public boolean isFullCube() {
if (blockMaterial == null) { if (blockMaterial == null) {

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.registry;
class SimpleBlockMaterial implements BlockMaterial { class SimpleBlockMaterial implements BlockMaterial {
private boolean isAir;
private boolean fullCube; private boolean fullCube;
private boolean opaque; private boolean opaque;
private boolean powerSource; private boolean powerSource;
@ -40,6 +41,15 @@ class SimpleBlockMaterial implements BlockMaterial {
private boolean isTranslucent; private boolean isTranslucent;
private boolean hasContainer; private boolean hasContainer;
@Override
public boolean isAir() {
return this.isAir;
}
public void setIsAir(boolean isAir) {
this.isAir = isAir;
}
@Override @Override
public boolean isFullCube() { public boolean isFullCube() {
return fullCube; return fullCube;