use of com.elmakers.mine.bukkit.block.BlockData in project MagicPlugin by elBukkit.
the class ConstructBatch method constructBlock.
@SuppressWarnings("deprecation")
public boolean constructBlock(int dx, int dy, int dz) {
// Special-case hackiness..
if (limitYAxis && minOrientDimension != null && dy < -minOrientDimension)
return true;
if (limitYAxis && maxOrientDimension != null && dy > maxOrientDimension)
return true;
if (bounds != null) {
if (dx > bounds.getX() || dy > bounds.getY() || dz > bounds.getZ())
return true;
if (dx < -bounds.getX() || dy < -bounds.getY() || dz < -bounds.getZ())
return true;
}
// Initial range checks, we skip everything if this is not sane.
int x = center.getBlockX() + dx;
int y = center.getBlockY() + dy;
int z = center.getBlockZ() + dz;
if (y < 0 || y > center.getWorld().getMaxHeight())
return true;
// Make sure the block is loaded.
Block block = center.getWorld().getBlockAt(x, y, z);
if (!block.getChunk().isLoaded()) {
block.getChunk().load();
return false;
}
// Destructibility and permission checks
if (!spell.isDestructible(block)) {
return true;
}
if (replace != null && replace.size() > 0) {
com.elmakers.mine.bukkit.block.MaterialAndData check = new com.elmakers.mine.bukkit.block.MaterialAndData(block);
if (!replace.contains(check.getKey()) && !replace.contains(check.getWildDataKey())) {
return true;
}
}
// Prepare material brush, it may update
// given the current target (clone, replicate)
MaterialBrush brush = spell.getBrush();
brush.update(mage, block.getLocation());
if (brush.isErase()) {
if (!spell.hasBreakPermission(block)) {
return true;
}
} else {
if (!spell.hasBuildPermission(block)) {
return true;
}
}
// Check for power mode.
if (power) {
Material material = block.getType();
BlockState blockState = block.getState();
MaterialData data = blockState.getData();
boolean powerBlock = false;
if (data instanceof Button) {
Button powerData = (Button) data;
registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof Lever) {
Lever powerData = (Lever) data;
registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof PistonBaseMaterial) {
PistonBaseMaterial powerData = (PistonBaseMaterial) data;
registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof PoweredRail) {
PoweredRail powerData = (PoweredRail) data;
registerForUndo(block);
powerData.setPowered(!powerData.isPowered());
powerBlock = true;
} else if (data instanceof RedstoneWire) {
RedstoneWire wireData = (RedstoneWire) data;
registerForUndo(block);
wireData.setData((byte) (15 - wireData.getData()));
powerBlock = true;
} else if (material == Material.REDSTONE_BLOCK) {
registerForUndo(block);
block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material.getId());
controller.getRedstoneReplacement().modify(block, applyPhysics);
} else if (material == Material.REDSTONE_TORCH_OFF) {
registerForUndo(block);
block.setType(Material.REDSTONE_TORCH_ON);
} else if (material == Material.REDSTONE_TORCH_ON) {
registerForUndo(block);
block.setType(Material.REDSTONE_TORCH_OFF);
} else if (material == Material.TNT) {
registerForUndo(block);
block.setType(Material.AIR);
// Kaboomy time!
registerForUndo(block.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT));
}
if (powerBlock) {
blockState.update();
}
return true;
}
// Make sure the brush is ready, it may need to load chunks.
if (!brush.isReady()) {
brush.prepare();
return false;
}
// Postpone attachable blocks to a second batch
if (attachables.testMaterialAndData(brush) || attachablesWall.testMaterialAndData(brush) || attachablesDouble.testMaterialAndData(brush)) {
BlockData attachBlock = new BlockData(block);
attachBlock.updateFrom(brush);
attachedBlockMap.put(attachBlock.getId(), attachBlock);
attachedBlockList.add(attachBlock);
return true;
}
if (delayed.testMaterialAndData(brush)) {
BlockData delayBlock = new BlockData(block);
delayBlock.updateFrom(brush);
delayedBlocks.add(delayBlock);
return true;
}
modifyWith(block, brush);
return true;
}
Aggregations