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();
}
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();
}
}
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);
}
}
Aggregations