use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockMushroom method canPlaceAt.
@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
GlowBlock belowBlock = block.getRelative(BlockFace.DOWN);
Material type = belowBlock.getType();
MaterialData data = belowBlock.getState().getData();
if (type == Material.GRASS || data instanceof Dirt && ((Dirt) data).getType() != DirtType.PODZOL) {
if (block.getLightLevel() < 13) {
// checking light level for dirt, coarse dirt and grass
return true;
}
} else if (type == Material.MYCEL || data instanceof Dirt && ((Dirt) data).getType() == DirtType.PODZOL) {
// not checking light level if mycel or podzol
return true;
}
return false;
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockLever 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 Lever)) {
warnMaterialData(Lever.class, data);
return;
}
Lever lever = (Lever) data;
setAttachedFace(state, face.getOppositeFace());
lever.setFacingDirection(face == BlockFace.UP || face == BlockFace.DOWN ? player.getDirection() : face);
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockLog 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 Tree) {
((Tree) data).setDirection(face);
((Tree) data).setSpecies(TreeSpecies.getByData((byte) holding.getDurability()));
} else {
warnMaterialData(Tree.class, data);
}
state.setData(data);
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockFenceGate method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData materialData = state.getData();
if (materialData instanceof Gate) {
Gate gate = (Gate) materialData;
float yaw = player.getLocation().getYaw();
gate.setFacingDirection(blockFaceFromYaw(yaw));
state.update(true);
} else {
warnMaterialData(Gate.class, materialData);
}
}
use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.
the class BlockDoor method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
// place the door and calculate the facing
super.placeBlock(player, state, face, holding, clickedLoc);
MaterialData data = state.getData();
if (!(data instanceof Door)) {
warnMaterialData(Door.class, data);
return;
}
BlockFace facing = player.getDirection();
((Door) data).setFacingDirection(facing.getOppositeFace());
// modify facing for double-doors
GlowBlock leftBlock = null;
switch(facing) {
case NORTH:
leftBlock = state.getBlock().getRelative(BlockFace.WEST);
break;
case WEST:
leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
break;
case SOUTH:
leftBlock = state.getBlock().getRelative(BlockFace.EAST);
break;
case EAST:
leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
break;
}
if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
switch(facing) {
case NORTH:
data.setData((byte) 6);
break;
case WEST:
data.setData((byte) 5);
break;
case SOUTH:
data.setData((byte) 4);
break;
case EAST:
data.setData((byte) 7);
break;
}
}
// place top half of door
GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
topState.setType(state.getType());
MaterialData topData = topState.getData();
if (!(topData instanceof Door)) {
warnMaterialData(Door.class, data);
} else {
((Door) topData).setTopHalf(true);
topState.update(true);
}
}
Aggregations