use of org.bukkit.event.world.StructureGrowEvent in project Glowstone by GlowstoneMC.
the class BlockMushroom method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
TreeType type;
if (mushroomType == Material.BROWN_MUSHROOM) {
type = TreeType.BROWN_MUSHROOM;
} else if (mushroomType == Material.RED_MUSHROOM) {
type = TreeType.RED_MUSHROOM;
} else {
return;
}
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player, blockStates);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
for (BlockState state : blockStates) {
state.update(true);
}
}
}
}
use of org.bukkit.event.world.StructureGrowEvent in project Glowstone by GlowstoneMC.
the class BlockSapling method generateTree.
private void generateTree(TreeType type, GlowBlock block, GlowPlayer player) {
// get data but filters sapling age
int data = block.getData() & 0x7;
// replaces the sapling block(s)
block.setType(Material.AIR);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.AIR);
block.getRelative(BlockFace.EAST).setType(Material.AIR);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.AIR);
}
// try to generate a tree
Location loc = block.getLocation();
BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
boolean canGrow = false;
if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, player != null, player, blockStates);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
canGrow = true;
for (BlockState state : blockStates) {
state.update(true);
}
}
}
if (!canGrow) {
// places the sapling block(s) back if the tree was not generated
// the sapling ages are overwritten but this is an expected
// vanilla behavior
block.setType(Material.SAPLING);
block.setData((byte) data);
if (type == TreeType.JUNGLE || type == TreeType.MEGA_REDWOOD || type == TreeType.DARK_OAK) {
block.getRelative(BlockFace.SOUTH).setType(Material.SAPLING);
block.getRelative(BlockFace.SOUTH).setData((byte) data);
block.getRelative(BlockFace.EAST).setType(Material.SAPLING);
block.getRelative(BlockFace.EAST).setData((byte) data);
block.getRelative(BlockFace.SOUTH_EAST).setType(Material.SAPLING);
block.getRelative(BlockFace.SOUTH_EAST).setData((byte) data);
}
}
}
Aggregations