Search in sources :

Example 6 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockDispenser method getFacing.

public static BlockFace getFacing(GlowBlock block) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return BlockFace.SELF;
    }
    Dispenser dispenserData = (Dispenser) data;
    return dispenserData.getFacing();
}
Also used : Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 7 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockDispenser method updatePhysics.

@Override
public void updatePhysics(GlowBlock block) {
    GlowBlock up = block.getRelative(BlockFace.UP);
    boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return;
    }
    boolean isTriggered = (data.getData() >> 3 & 1) != 0;
    if (powered && !isTriggered) {
        new BukkitRunnable() {

            @Override
            public void run() {
                trigger(block);
            }
        }.runTaskLater(null, 4);
        // TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
        data.setData((byte) (data.getData() | 0x8));
        state.update();
    } else if (!powered && isTriggered) {
        data.setData((byte) (data.getData() & ~0x8));
        state.update();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Example 8 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockDoor method blockInteract.

/**
     * Opens and closes the door when right-clicked by the player.
     */
@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    // handles opening and closing the door
    if (block.getType() == Material.IRON_DOOR_BLOCK) {
        return false;
    }
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (data instanceof Door) {
        Door door = (Door) data;
        if (door.isTopHalf()) {
            door = null;
            block = block.getWorld().getBlockAt(block.getX(), block.getY() - 1, block.getZ());
            state = block.getState();
            data = state.getData();
            if (data instanceof Door) {
                door = (Door) data;
            }
        }
        if (door != null) {
            door.setOpen(!door.isOpen());
        }
        state.update(true);
    }
    return true;
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Door(org.bukkit.material.Door)

Example 9 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
    headBlockState.setType(Material.DOUBLE_PLANT);
    headBlockState.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX));
    headBlockState.update(true);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) DoublePlant(org.bukkit.material.DoublePlant)

Example 10 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockLever method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Lever)) {
        warnMaterialData(Lever.class, data);
        return false;
    }
    Lever lever = (Lever) data;
    lever.setPowered(!lever.isPowered());
    block.getWorld().playSound(block.getLocation(), Sound.BLOCK_LEVER_CLICK, 0.3F, lever.isPowered() ? 0.6F : 0.5F);
    state.update();
    extraUpdate(block);
    return true;
}
Also used : Lever(org.bukkit.material.Lever) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)54 GlowBlock (net.glowstone.block.GlowBlock)21 MaterialData (org.bukkit.material.MaterialData)20 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowWorld (net.glowstone.GlowWorld)10 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)7 BlockFace (org.bukkit.block.BlockFace)6 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)5 ItemStack (org.bukkit.inventory.ItemStack)4 Material (org.bukkit.Material)3 Block (org.bukkit.block.Block)3 Door (org.bukkit.material.Door)3 DoublePlant (org.bukkit.material.DoublePlant)3 BlockType (net.glowstone.block.blocktype.BlockType)2 ItemType (net.glowstone.block.itemtype.ItemType)2 GlowDispenser (net.glowstone.block.state.GlowDispenser)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 BlockIgniteEvent (org.bukkit.event.block.BlockIgniteEvent)2 CocoaPlant (org.bukkit.material.CocoaPlant)2 CocoaPlantSize (org.bukkit.material.CocoaPlant.CocoaPlantSize)2