Java Code Examples for org.bukkit.Material#MOVING_PISTON

The following examples show how to use org.bukkit.Material#MOVING_PISTON . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MultiBlock.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean compareBlocks(Material a, Material b) {
    if (b != null) {

        for (Tag<Material> tag : SUPPORTED_TAGS) {
            if (tag.isTagged(b)) {
                return tag.isTagged(a);
            }
        }

        // This ensures that the Industrial Miner is still recognized while operating
        if (a == Material.PISTON) {
            return a == b || b == Material.MOVING_PISTON;
        }

        // This ensures that the Industrial Miner is still recognized while operating
        if (b == Material.PISTON) {
            return a == b || a == Material.MOVING_PISTON;
        }

        if (b != a) {
            return false;
        }
    }

    return true;
}
 
Example 2
Source File: TestMultiBlocks.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testEqualWithMovingPistons() {
    SlimefunItem item = TestUtilities.mockSlimefunItem(plugin, "PISTON_MULTIBLOCK_TEST", new CustomItem(Material.BRICK, "&5Multiblock Test"));

    // Some Pistons are moving but that should not interefere with the Multiblock
    MultiBlock multiblock = new MultiBlock(item, new Material[] { Material.PISTON, Material.MOVING_PISTON, Material.PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
    MultiBlock multiblock2 = new MultiBlock(item, new Material[] { Material.MOVING_PISTON, Material.PISTON, Material.MOVING_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);
    MultiBlock multiblock3 = new MultiBlock(item, new Material[] { Material.PISTON, Material.PISTON, Material.STICKY_PISTON, null, Material.CRAFTING_TABLE, null, Material.PISTON, Material.STONE, Material.PISTON }, BlockFace.DOWN);

    Assertions.assertTrue(multiblock.equals(multiblock2));
    Assertions.assertFalse(multiblock.equals(multiblock3));
}
 
Example 3
Source File: ActiveMiner.java    From Slimefun4 with GNU General Public License v3.0 4 votes vote down vote up
private void setPistonState(Block block, boolean extended) {
    if (!running) {
        return;
    }

    try {
        // Smoke Particles around the Chest for dramatic effect
        Location particleLoc = chest.getLocation().clone().add(0, -1, 0);
        block.getWorld().spawnParticle(Particle.SMOKE_NORMAL, particleLoc, 20, 0.7, 0.7, 0.7, 0);

        if (block.getType() == Material.MOVING_PISTON) {
            // Yeah it isn't really cool when this happens
            block.getRelative(BlockFace.UP).setType(Material.AIR);
        }
        else if (block.getType() == Material.PISTON) {
            Block above = block.getRelative(BlockFace.UP);

            // Check if the above block is valid
            if (above.isEmpty() || above.getType() == Material.PISTON_HEAD) {
                Piston piston = (Piston) block.getBlockData();

                // Check if the piston is actually facing upwards
                if (piston.getFacing() == BlockFace.UP) {
                    setExtended(block, piston, extended);
                }
                else {
                    // The pistons must be facing upwards
                    stop("machines.INDUSTRIAL_MINER.piston-facing");
                }
            }
            else {
                // The pistons must be facing upwards
                stop("machines.INDUSTRIAL_MINER.piston-space");
            }
        }
        else {
            // The piston has been destroyed
            stop("machines.INDUSTRIAL_MINER.destroyed");
        }
    }
    catch (Exception e) {
        Slimefun.getLogger().log(Level.SEVERE, e, () -> "An Error occurred while moving a Piston for an Industrial Miner at " + new BlockPosition(block));
        stop();
    }
}