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