Search in sources :

Example 1 with Dispenser

use of org.bukkit.material.Dispenser 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 2 with Dispenser

use of org.bukkit.material.Dispenser 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 3 with Dispenser

use of org.bukkit.material.Dispenser in project Glowstone by GlowstoneMC.

the class BlockDispenser method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Dispenser) {
        ((Dispenser) data).setFacingDirection(getOppositeBlockFace(player.getLocation(), true));
        state.setData(data);
    } else {
        warnMaterialData(Dispenser.class, data);
    }
}
Also used : Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) MaterialData(org.bukkit.material.MaterialData)

Aggregations

GlowDispenser (net.glowstone.block.state.GlowDispenser)3 Dispenser (org.bukkit.material.Dispenser)3 MaterialData (org.bukkit.material.MaterialData)3 GlowBlockState (net.glowstone.block.GlowBlockState)2 GlowBlock (net.glowstone.block.GlowBlock)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1