use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.
the class BlockCocoa method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
MaterialData data = block.getState().getData();
if (data instanceof CocoaPlant) {
CocoaPlant cocoa = (CocoaPlant) data;
CocoaPlantSize size = cocoa.getSize();
if (size != CocoaPlantSize.LARGE && random.nextInt(5) == 0) {
if (size == CocoaPlantSize.SMALL) {
cocoa.setSize(CocoaPlantSize.MEDIUM);
} else if (size == CocoaPlantSize.MEDIUM) {
cocoa.setSize(CocoaPlantSize.LARGE);
} else {
return;
}
GlowBlockState state = block.getState();
state.setData(cocoa);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
} else {
warnMaterialData(CocoaPlant.class, data);
}
}
use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.
the class BlockCocoa method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
MaterialData data = block.getState().getData();
if (data instanceof CocoaPlant) {
CocoaPlant cocoa = (CocoaPlant) data;
CocoaPlantSize size = cocoa.getSize();
if (size == CocoaPlantSize.SMALL) {
cocoa.setSize(CocoaPlantSize.MEDIUM);
} else if (size == CocoaPlantSize.MEDIUM) {
cocoa.setSize(CocoaPlantSize.LARGE);
} else {
return;
}
GlowBlockState state = block.getState();
state.setData(cocoa);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
} else {
warnMaterialData(CocoaPlant.class, data);
}
}
use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.
the class BlockCocoa method placeBlock.
@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
state.setType(getMaterial());
MaterialData data = state.getData();
if (data instanceof CocoaPlant) {
CocoaPlant cocoa = (CocoaPlant) data;
cocoa.setFacingDirection(face.getOppositeFace());
cocoa.setSize(CocoaPlantSize.SMALL);
} else {
warnMaterialData(CocoaPlant.class, data);
}
}
use of org.bukkit.material.CocoaPlant in project Glowstone by GlowstoneMC.
the class CocoaTree method addCocoa.
private void addCocoa(int sourceX, int sourceY, int sourceZ) {
if (height > 5 && random.nextInt(5) == 0) {
for (int y = 0; y < 2; y++) {
for (BlockFace cocoaFace : COCOA_FACES) {
// rotate the 4 trunk faces
if (random.nextInt(COCOA_FACES.length - y) == 0) {
// higher it is, more chances there is
CocoaPlantSize size = COCOA_SIZE[random.nextInt(COCOA_SIZE.length)];
Block block = delegate.getBlockState(loc.getWorld(), sourceX, sourceY + height - 5 + y, sourceZ).getBlock().getRelative(cocoaFace);
delegate.setTypeAndData(loc.getWorld(), block.getX(), block.getY(), block.getZ(), Material.COCOA, new CocoaPlant(size, cocoaFace.getOppositeFace()));
}
}
}
}
}
Aggregations