3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-07 12:00:07 +01:00

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;
}
@Override
public boolean isAir() {
return material == Material.AIR || material == Material.CAVE_AIR || material == Material.VOID_AIR;
}
@Override
public boolean isSolid() {
return material.isSolid();

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -1446,7 +1446,7 @@ public class EditSession implements Extent {
if (setBlock(pt, air)) {
++affected;
}
} else if (id == BlockTypes.AIR) {
} else if (id.getMaterial().isAir()) {
continue;
}
@ -1488,7 +1488,7 @@ public class EditSession implements Extent {
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 class EditSession implements Extent {
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 class EditSession implements Extent {
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;
}
}

Datei anzeigen

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

Datei anzeigen

@ -134,7 +134,7 @@ public class FloatingTreeRemover implements BlockTool {
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())) {

Datei anzeigen

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

Datei anzeigen

@ -57,7 +57,7 @@ public class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
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 class LongRangeBuildTool extends BrushTool implements DoubleActionTraceTo
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);

Datei anzeigen

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

Datei anzeigen

@ -48,7 +48,7 @@ public class GravityBrush implements Brush {
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());
}
@ -56,7 +56,7 @@ public class GravityBrush implements Brush {
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);

Datei anzeigen

@ -32,6 +32,7 @@ import com.sk89q.worldedit.util.TargetBlock;
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 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 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 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;
}

Datei anzeigen

@ -37,7 +37,7 @@ public abstract class BlockBag {
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 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);
}

Datei anzeigen

@ -87,7 +87,7 @@ public class BlockBagExtent extends AbstractDelegateExtent {
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 class BlockBagExtent extends AbstractDelegateExtent {
}
}
if (existing.getBlockType() != BlockTypes.AIR) {
if (!existing.getBlockType().getMaterial().isAir()) {
try {
blockBag.storeDroppedBlock(existing);
} catch (BlockBagException ignored) {

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

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

Datei anzeigen

@ -102,7 +102,7 @@ public class TargetBlock {
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 class TargetBlock {
* @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();
}

Datei anzeigen

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

Datei anzeigen

@ -154,7 +154,7 @@ public class OldChunk implements Chunk {
@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;

Datei anzeigen

@ -24,6 +24,13 @@ package com.sk89q.worldedit.world.registry;
*/
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.
*

Datei anzeigen

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

Datei anzeigen

@ -21,6 +21,7 @@ package com.sk89q.worldedit.world.registry;
class SimpleBlockMaterial implements BlockMaterial {
private boolean isAir;
private boolean fullCube;
private boolean opaque;
private boolean powerSource;
@ -40,6 +41,15 @@ class SimpleBlockMaterial implements BlockMaterial {
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;