Java Code Examples for org.bukkit.block.Block#getBlockData()

The following examples show how to use org.bukkit.block.Block#getBlockData() . 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: LeverEvent.java    From BetonQuest with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected Void execute(String playerID) throws QuestRuntimeException {
    Block block = loc.getLocation(playerID).getBlock();
    if (!block.getType().equals(Material.LEVER)) {
        return null;
    }

    Powerable lever = (Powerable) block.getBlockData();

    switch (type) {
        case ON:
            lever.setPowered(true);
            break;
        case OFF:
            lever.setPowered(false);
            break;
        case TOGGLE:
            lever.setPowered(!lever.isPowered());
            break;
    }
    return null;
}
 
Example 2
Source File: CropGrowthAccelerator.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean grow(Block machine, BlockMenu inv, Block crop) {
    Ageable ageable = (Ageable) crop.getBlockData();

    if (ageable.getAge() < ageable.getMaximumAge()) {
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), organicFertilizer, false)) {
                ChargableBlock.addCharge(machine, -getEnergyConsumption());
                inv.consumeItem(slot);

                ageable.setAge(ageable.getAge() + 1);
                crop.setBlockData(ageable);

                crop.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, crop.getLocation().add(0.5D, 0.5D, 0.5D), 4, 0.1F, 0.1F, 0.1F);
                return true;
            }
        }
    }

    return false;
}
 
Example 3
Source File: InfernalBonemeal.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Optional<Block> block = e.getClickedBlock();
        e.setUseBlock(Result.DENY);

        if (block.isPresent()) {
            Block b = block.get();

            if (b.getType() == Material.NETHER_WART) {
                Ageable ageable = (Ageable) b.getBlockData();

                if (ageable.getAge() < ageable.getMaximumAge()) {
                    ageable.setAge(ageable.getMaximumAge());
                    b.setBlockData(ageable);
                    b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, Material.REDSTONE_BLOCK);

                    if (e.getPlayer().getGameMode() != GameMode.CREATIVE) {
                        ItemUtils.consumeItem(e.getItem(), false);
                    }
                }
            }
        }
    };
}
 
Example 4
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static int getFluidLevel(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return -1;
        Levelled levelled = (Levelled) block.getBlockData();
        return levelled.getLevel();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 5
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static BlockFace getDirection(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Directional)) return BlockFace.SELF;
        Directional direction = (Directional) block.getBlockData();
        return direction.getFacing();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof org.bukkit.material.Directional) {
        return ((org.bukkit.material.Directional) data).getFacing();
    }
    return null;
}
 
Example 6
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static int getFluidLevel(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Levelled)) return -1;
        Levelled levelled = (Levelled) block.getBlockData();
        return levelled.getLevel();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 7
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
/**
 * Can be furnaces or redstone lamps.
 */
public static void setLit(Block block, boolean lit) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Lightable)) return;
        Lightable lightable = (Lightable) block.getBlockData();
        lightable.setLit(lit);
        return;
    }

    String name = block.getType().name();
    if (name.endsWith("FURNACE")) block.setType(Material.getMaterial("BURNING_FURNACE"));
    else if (name.startsWith("REDSTONE_LAMP")) block.setType(Material.getMaterial("REDSTONE_LAMP_ON"));
    else block.setType(Material.getMaterial("REDSTONE_TORCH_ON"));
}
 
Example 8
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static boolean isLit(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Lightable)) return false;
        Lightable lightable = (Lightable) block.getBlockData();
        return lightable.isLit();
    }

    return isMaterial(block, "REDSTONE_LAMP_ON", "REDSTONE_TORCH_ON", "BURNING_FURNACE");
}
 
Example 9
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static void setRotation(Block block, BlockFace facing) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Rotatable)) return;
        Rotatable rotatable = (Rotatable) block.getBlockData();
        rotatable.setRotation(facing);
    }
}
 
Example 10
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static BlockFace getRotation(Block block) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Rotatable)) return null;
        Rotatable rotatable = (Rotatable) block.getBlockData();
        return rotatable.getRotation();
    }

    return null;
}
 
Example 11
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static void setPowered(Block block, boolean powered) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Powerable)) return;
        Powerable powerable = (Powerable) block.getBlockData();
        powerable.setPowered(powered);
        return;
    }

    String name = block.getType().name();
    if (name.startsWith("REDSTONE_COMPARATOR")) block.setType(Material.getMaterial("REDSTONE_COMPARATOR_ON"));
}
 
Example 12
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public void toggleDoor(Block b) {
    if (b.getBlockData() instanceof Openable) {
        Openable openable = (Openable) b.getBlockData();
        openable.setOpen(!openable.isOpen());
        b.setBlockData(openable);
    }
}
 
Example 13
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static void setAge(Block block, int age) {
    if (XMaterial.ISFLAT) {
        if (!(block.getBlockData() instanceof Ageable)) return;
        Ageable ageable = (Ageable) block.getBlockData();
        ageable.setAge(age);
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    data.setData((byte) age);
    state.update(true);
}
 
Example 14
Source File: BlockAdapterBlockData.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void closeDoor(Block block) {
    if (!(block.getBlockData() instanceof Openable)) {
        throw new IllegalArgumentException("Block is not Openable");
    }
    Openable data = (Openable) block.getBlockData();
    data.setOpen(false);
    block.setBlockData(data);
}
 
Example 15
Source File: LumberAxe.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private void stripLog(Block b) {
    b.getWorld().playSound(b.getLocation(), Sound.ITEM_AXE_STRIP, 1, 1);
    Axis axis = ((Orientable) b.getBlockData()).getAxis();
    b.setType(Material.valueOf("STRIPPED_" + b.getType().name()));

    Orientable orientable = (Orientable) b.getBlockData();
    orientable.setAxis(axis);
    b.setBlockData(orientable);
}
 
Example 16
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static int getAge(Block block) {
    if (ISFLAT) {
        if (!(block.getBlockData() instanceof Ageable)) return 0;
        Ageable ageable = (Ageable) block.getBlockData();
        return ageable.getAge();
    }

    BlockState state = block.getState();
    MaterialData data = state.getData();
    return data.getData();
}
 
Example 17
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 5 votes vote down vote up
public Block getBlockRelative(Block block) {
    if (block.getState() instanceof Sign) {
        Directional dir = (Directional) block.getBlockData();
        return block.getRelative(dir.getFacing().getOppositeFace());
    }
    return null;
}
 
Example 18
Source File: WallMatcher.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Try and match a wall block
 *
 * @param block
 * @param matchingFace
 * @return
 */
private Block tryMatchBlock(Block block, BlockFace matchingFace) {
    byte direction = block.getData();
    BlockData blockData = block.getBlockData();

    // Blocks such as wall signs or banners
    if (PROTECTABLES_WALL.contains(block.getType()) && blockData instanceof Directional) {
        if (((Directional) block.getState().getBlockData()).getFacing() == matchingFace) {
            return block;
        }
    }

    // Levers, buttons
    else if (PROTECTABLES_LEVERS_ET_AL.contains(block.getType())) {
        byte EAST = 0x4;
        byte WEST = 0x3;
        byte SOUTH = 0x1;
        byte NORTH = 0x2;

        if (matchingFace == BlockFace.EAST && (direction & EAST) == EAST) {
            return block;
        } else if (matchingFace == BlockFace.WEST && (direction & WEST) == WEST) {
            return block;
        } else if (matchingFace == BlockFace.SOUTH && (direction & SOUTH) == SOUTH) {
            return block;
        } else if (matchingFace == BlockFace.NORTH && (direction & NORTH) == NORTH) {
            return block;
        }
    }

    return null;
}
 
Example 19
Source File: VersionUtils_1_13.java    From UhcCore with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setEndPortalFrameOrientation(Block block, BlockFace blockFace) {
    EndPortalFrame portalFrame = (EndPortalFrame) block.getBlockData();
    portalFrame.setFacing(blockFace);
    block.setBlockData(portalFrame);
}
 
Example 20
Source File: VersionHelperLatest.java    From RedProtect with GNU General Public License v3.0 4 votes vote down vote up
public boolean isOpenable(Block b) {
    return b.getBlockData() instanceof Openable;
}