use of org.bukkit.material.MaterialData 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 org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
MaterialData data = block.getState().getData();
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
if (!(blockUnder.getState().getData() instanceof DoublePlant)) {
return;
}
blockUnder.setType(Material.AIR);
} else {
GlowBlock blockTop = block.getRelative(BlockFace.UP);
if (!(blockTop.getState().getData() instanceof DoublePlant)) {
return;
}
blockTop.setType(Material.AIR);
}
} else {
warnMaterialData(DoublePlant.class, data);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method canAbsorb.
@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
MaterialData data = block.getState().getData();
BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.DOUBLE_TALLGRASS || species == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
}
return true;
}
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock under = block.getRelative(BlockFace.DOWN);
MaterialData underData = under.getState().getData();
if (underData instanceof DoublePlant) {
DoublePlantSpecies underSpecies = ((DoublePlant) underData).getSpecies();
if (underSpecies == DoublePlantSpecies.DOUBLE_TALLGRASS || underSpecies == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
under.setType(Material.AIR, (byte) 0, false);
}
return true;
}
}
}
} else {
warnMaterialData(DoublePlant.class, data);
}
return false;
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockEnderChest 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 EnderChest) {
((EnderChest) data).setFacingDirection(getOppositeBlockFace(player.getLocation(), false));
state.setData(data);
} else {
warnMaterialData(EnderChest.class, data);
}
}
use of org.bukkit.material.MaterialData 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