use of org.bukkit.block.data.Bisected 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(block.getType());
Bisected upper = getCastedBlockData(Bisected.class, block.getType().createBlockData());
upper.setHalf(Half.TOP);
headBlockState.setBlockData(upper);
headBlockState.update(true);
}
use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
Bisected data = getCastedBlockData(Bisected.class, block.getBlockData());
if (data.getHalf() == Half.TOP) {
GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
if (!getMaterials().contains(block.getType())) {
return;
}
blockUnder.setType(Material.AIR);
} else {
GlowBlock blockTop = block.getRelative(BlockFace.UP);
if (!getMaterials().contains(block.getType())) {
return;
}
blockTop.setType(Material.AIR);
}
}
use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method canAbsorb.
@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
Material species = block.getType();
if (species == Material.TALL_GRASS || species == Material.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(null, block, face)) {
block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
}
return true;
}
Bisected data = getCastedBlockData(Bisected.class, block.getBlockData());
if (data.getHalf() == Half.TOP) {
GlowBlock under = block.getRelative(BlockFace.DOWN);
if (getMaterials().contains(under.getType())) {
Material underSpecies = under.getType();
if (underSpecies == Material.TALL_GRASS || underSpecies == Material.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(null, block, face)) {
under.setType(Material.AIR, (byte) 0, false);
}
return true;
}
}
}
return false;
}
use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.
the class DoubleTallPlant method generate.
/**
* Generates up to 64 plants around the given point.
*
* @return true if at least one plant was successfully generated
*/
@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
boolean placed = false;
for (int i = 0; i < 64; i++) {
int x = sourceX + random.nextInt(8) - random.nextInt(8);
int z = sourceZ + random.nextInt(8) - random.nextInt(8);
int y = sourceY + random.nextInt(4) - random.nextInt(4);
Block block = world.getBlockAt(x, y, z);
Block topBlock = block.getRelative(BlockFace.UP);
if (y < 255 && block.isEmpty() && topBlock.isEmpty() && block.getRelative(BlockFace.DOWN).getType() == Material.GRASS_BLOCK) {
BlockState state = block.getState();
state.setType(species);
Bisected lower = (Bisected) species.createBlockData();
lower.setHalf(Half.BOTTOM);
state.setBlockData(lower);
state.update(true);
state = topBlock.getState();
state.setType(species);
Bisected upper = (Bisected) species.createBlockData();
upper.setHalf(Half.TOP);
state.setBlockData(upper);
placed = true;
}
}
return placed;
}
use of org.bukkit.block.data.Bisected in project Glowstone by GlowstoneMC.
the class TerrainObject method killPlantAbove.
/**
* Removes the grass, shrub, flower or mushroom directly above the given block, if present. Does
* not drop an item.
*
* @param block the block to update
* @return true if a plant was removed; false if none was present
*/
static boolean killPlantAbove(Block block) {
Block blockAbove = block.getRelative(BlockFace.UP);
BlockData blockAboveData = blockAbove.getBlockData();
Material mat = blockAboveData.getMaterial();
if (PLANT_TYPES.contains(mat)) {
if (blockAboveData instanceof Bisected && ((Bisected) blockAboveData).getHalf() == Bisected.Half.BOTTOM) {
// Large plant
Block plantTop = blockAbove.getRelative(BlockFace.UP);
BlockData plantTopData = plantTop.getBlockData();
if (plantTopData.getMaterial() == mat && ((Bisected) plantTopData).getHalf() == Bisected.Half.TOP) {
plantTop.setType(Material.AIR);
}
}
blockAbove.setType(Material.AIR);
return true;
}
return false;
}
Aggregations