Search in sources :

Example 1 with RedstoneWire

use of org.bukkit.material.RedstoneWire 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;
}
Also used : RedstoneWire(org.bukkit.material.RedstoneWire) PistonBaseMaterial(org.bukkit.material.PistonBaseMaterial) Material(org.bukkit.Material) PoweredRail(org.bukkit.material.PoweredRail) BlockState(org.bukkit.block.BlockState) MaterialBrush(com.elmakers.mine.bukkit.api.block.MaterialBrush) Lever(org.bukkit.material.Lever) Button(org.bukkit.material.Button) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) Block(org.bukkit.block.Block) FallingBlock(org.bukkit.entity.FallingBlock) MaterialData(org.bukkit.material.MaterialData) BlockData(com.elmakers.mine.bukkit.block.BlockData) PistonBaseMaterial(org.bukkit.material.PistonBaseMaterial)

Example 2 with RedstoneWire

use of org.bukkit.material.RedstoneWire in project MagicPlugin by elBukkit.

the class PowerBlockAction method perform.

@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
    Block block = context.getTargetBlock();
    if (!context.hasBuildPermission(block)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!context.isDestructible(block)) {
        return SpellResult.NO_TARGET;
    }
    context.getUndoList().setApplyPhysics(true);
    Material material = block.getType();
    BlockState blockState = block.getState();
    MaterialData data = blockState.getData();
    MageController controller = context.getController();
    boolean powerBlock = false;
    if (data instanceof Button) {
        Button powerData = (Button) data;
        context.registerForUndo(block);
        powerData.setPowered(!powerData.isPowered());
        powerBlock = true;
    } else if (data instanceof Lever) {
        Lever powerData = (Lever) data;
        context.registerForUndo(block);
        powerData.setPowered(!powerData.isPowered());
        powerBlock = true;
    } else if (data instanceof PistonBaseMaterial) {
        PistonBaseMaterial powerData = (PistonBaseMaterial) data;
        context.registerForUndo(block);
        powerData.setPowered(!powerData.isPowered());
        powerBlock = true;
    } else if (data instanceof PoweredRail) {
        PoweredRail powerData = (PoweredRail) data;
        context.registerForUndo(block);
        powerData.setPowered(!powerData.isPowered());
        powerBlock = true;
    } else if (data instanceof RedstoneWire) {
        RedstoneWire wireData = (RedstoneWire) data;
        context.registerForUndo(block);
        wireData.setData((byte) (15 - wireData.getData()));
        powerBlock = true;
    } else if (material == Material.REDSTONE_BLOCK) {
        context.registerForUndo(block);
        block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, material.getId());
        controller.getRedstoneReplacement().modify(block, applyPhysics);
    } else if (material == Material.REDSTONE_TORCH_OFF) {
        context.registerForUndo(block);
        block.setType(Material.REDSTONE_TORCH_ON);
    } else if (material == Material.REDSTONE_TORCH_ON) {
        context.registerForUndo(block);
        block.setType(Material.REDSTONE_TORCH_OFF);
    } else if (material == Material.TNT) {
        context.registerForUndo(block);
        block.setType(Material.AIR);
        // Kaboomy time!
        context.registerForUndo(block.getLocation().getWorld().spawnEntity(block.getLocation(), EntityType.PRIMED_TNT));
    }
    if (powerBlock) {
        blockState.update();
    }
    return SpellResult.CAST;
}
Also used : RedstoneWire(org.bukkit.material.RedstoneWire) MageController(com.elmakers.mine.bukkit.api.magic.MageController) BlockState(org.bukkit.block.BlockState) Lever(org.bukkit.material.Lever) Button(org.bukkit.material.Button) Block(org.bukkit.block.Block) PistonBaseMaterial(org.bukkit.material.PistonBaseMaterial) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) PoweredRail(org.bukkit.material.PoweredRail) PistonBaseMaterial(org.bukkit.material.PistonBaseMaterial)

Aggregations

Material (org.bukkit.Material)2 Block (org.bukkit.block.Block)2 BlockState (org.bukkit.block.BlockState)2 Button (org.bukkit.material.Button)2 Lever (org.bukkit.material.Lever)2 MaterialData (org.bukkit.material.MaterialData)2 PistonBaseMaterial (org.bukkit.material.PistonBaseMaterial)2 PoweredRail (org.bukkit.material.PoweredRail)2 RedstoneWire (org.bukkit.material.RedstoneWire)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 MaterialBrush (com.elmakers.mine.bukkit.api.block.MaterialBrush)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1 BlockData (com.elmakers.mine.bukkit.block.BlockData)1 FallingBlock (org.bukkit.entity.FallingBlock)1