use of net.glowstone.block.PistonMoveBehavior in project Glowstone by GlowstoneMC.
the class BlockPiston method addBlock.
private boolean addBlock(GlowBlock piston, BlockFace movementDirection, GlowBlock block, BlockFace ignoredFace, List<Block> blocksToMove, List<Block> blocksToBreak) {
boolean isPushing = (movementDirection == ignoredFace.getOppositeFace());
MaterialValueManager.ValueCollection materialValues = block.getMaterialValues();
PistonMoveBehavior moveBehavior = isPushing ? materialValues.getPistonPushBehavior() : materialValues.getPistonPullBehavior();
if (block.isEmpty()) {
return true;
}
if (blocksToMove.size() >= PUSH_LIMIT) {
return false;
}
if (isPushing) {
switch(moveBehavior) {
case MOVE_STICKY:
case MOVE:
blocksToMove.add(block);
break;
case BREAK:
blocksToBreak.add(block);
return true;
case DONT_MOVE:
return false;
default:
return true;
}
} else {
switch(moveBehavior) {
case MOVE_STICKY:
case MOVE:
blocksToMove.add(block);
break;
case BREAK:
case DONT_MOVE:
default:
return true;
}
}
if (moveBehavior == PistonMoveBehavior.MOVE_STICKY) {
boolean allowMovement = true;
for (BlockFace face : ADJACENT_FACES) {
GlowBlock nextBlock = block.getRelative(face);
if (nextBlock.getLocation().equals(piston.getLocation())) {
continue;
}
if (face == ignoredFace || blocksToMove.contains(nextBlock)) {
continue;
}
allowMovement = addBlock(piston, movementDirection, block.getRelative(face), face.getOppositeFace(), blocksToMove, blocksToBreak);
if (!allowMovement) {
break;
}
}
return allowMovement;
} else if (movementDirection != ignoredFace) {
GlowBlock nextBlock = block.getRelative(movementDirection);
if (nextBlock.getLocation().equals(piston.getLocation())) {
return false;
}
return addBlock(piston, movementDirection, nextBlock, movementDirection.getOppositeFace(), blocksToMove, blocksToBreak);
} else {
return true;
}
}
Aggregations