use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockGrass method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
GlowWorld world = block.getWorld();
int i = 0;
do {
int j = 0;
while (true) {
// if there's available space
if (block.getRelative(BlockFace.UP).getType() == Material.AIR) {
GlowBlock b = block.getRelative(BlockFace.UP);
GlowBlockState blockState = b.getState();
if (random.nextFloat() < 0.125D) {
// sometimes grow random flower
// would be better to call a method that choose a random
// flower depending on the biome
FlowerType[] flowers = FlowerForestPopulator.FLOWERS;
Material flower = flowers[random.nextInt(flowers.length)].getType();
if (ItemTable.instance().getBlock(flower).canPlaceAt(b, BlockFace.DOWN)) {
blockState.setType(flower);
}
} else {
Material tallGrass = Material.LONG_GRASS;
if (ItemTable.instance().getBlock(tallGrass).canPlaceAt(b, BlockFace.DOWN)) {
// grow tall grass if possible
blockState.setType(tallGrass);
blockState.setData(new LongGrass(GrassSpecies.NORMAL));
}
}
BlockGrowEvent growEvent = new BlockGrowEvent(b, blockState);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
blockState.update(true);
}
} else if (j < i / 16) {
// look around for grass block
int x = block.getX();
int y = block.getY();
int z = block.getZ();
x += random.nextInt(3) - 1;
y += random.nextInt(3) * random.nextInt(3) / 2;
z += random.nextInt(3) - 1;
if (world.getBlockAt(x, y, z).getType() == Material.GRASS) {
j++;
continue;
}
}
i++;
break;
}
} while (i < 128);
}
use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockCrops method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
GlowBlockState state = block.getState();
int cropState = block.getData();
// in order to grow naturally (vanilla behavior)
if (cropState < CropState.RIPE.ordinal() && block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
cropState++;
if (cropState > CropState.RIPE.ordinal()) {
cropState = CropState.RIPE.ordinal();
}
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
// we check for insufficient light on the block itself, then drop
if (block.getLightLevel() < 8) {
block.breakNaturally();
}
}
use of org.bukkit.event.block.BlockGrowEvent 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.event.block.BlockGrowEvent 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.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockStem method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
GlowBlockState state = block.getState();
int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
if (cropState > CropState.RIPE.ordinal()) {
cropState = CropState.RIPE.ordinal();
}
state.setRawData((byte) cropState);
BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
}
Aggregations