use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockSugarCane method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
if (!canPlaceAt(block, BlockFace.DOWN)) {
block.breakNaturally();
return;
}
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cane height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.SUGAR_CANE_BLOCK) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the sugar cane on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.SUGAR_CANE_BLOCK);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockCactus method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// TODO: Drop entity if the block has near blocks
GlowBlock blockAbove = block.getRelative(BlockFace.UP);
// check it's the highest block of cactus
if (blockAbove.isEmpty()) {
// check the current cactus height
Block blockBelow = block.getRelative(BlockFace.DOWN);
int height = 1;
while (blockBelow.getType() == Material.CACTUS) {
height++;
blockBelow = blockBelow.getRelative(BlockFace.DOWN);
}
if (height < 3) {
GlowBlockState state = block.getState();
if (state.getRawData() < 15) {
// increase age
state.setRawData((byte) (state.getRawData() + 1));
state.update(true);
} else {
// grow the cactus on the above block
state.setRawData((byte) 0);
state.update(true);
state = blockAbove.getState();
state.setType(Material.CACTUS);
state.setRawData((byte) 0);
BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
state.update(true);
}
updatePhysics(blockAbove);
}
}
}
}
use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockCrops 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);
}
}
use of org.bukkit.event.block.BlockGrowEvent in project Glowstone by GlowstoneMC.
the class BlockStem method updateBlock.
@Override
public void updateBlock(GlowBlock block) {
// in order to grow naturally (vanilla behavior)
if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
int cropState = block.getData();
if (cropState >= CropState.RIPE.ordinal()) {
// check around there's not already a fruit
if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
return;
}
// produce a fruit if possible
int n = random.nextInt(4);
BlockFace face;
switch(n) {
case 1:
face = BlockFace.WEST;
break;
case 2:
face = BlockFace.NORTH;
break;
case 3:
face = BlockFace.SOUTH;
break;
default:
face = BlockFace.EAST;
}
GlowBlock targetBlock = block.getRelative(face);
GlowBlockState targetBlockState = targetBlock.getState();
GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
targetBlockState.setType(fruitType);
if (fruitType == Material.PUMPKIN) {
targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
}
targetBlockState.update(true);
}
} else {
cropState++;
GlowBlockState state = block.getState();
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 BlockTallGrass method grow.
@Override
public void grow(GlowPlayer player, GlowBlock block) {
MaterialData data = block.getState().getData();
if (data instanceof LongGrass) {
GrassSpecies species = ((LongGrass) data).getSpecies();
if (species == GrassSpecies.NORMAL || species == GrassSpecies.FERN_LIKE) {
GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
if (headBlockState.getType() == Material.AIR) {
DoublePlantSpecies doublePlantSpecies = species == GrassSpecies.FERN_LIKE ? DoublePlantSpecies.LARGE_FERN : DoublePlantSpecies.DOUBLE_TALLGRASS;
GlowBlockState blockState = block.getState();
blockState.setType(Material.DOUBLE_PLANT);
blockState.setData(new DoublePlant(doublePlantSpecies));
headBlockState.setType(Material.DOUBLE_PLANT);
headBlockState.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX));
BlockGrowEvent growEvent = new BlockGrowEvent(block, blockState);
EventFactory.callEvent(growEvent);
if (!growEvent.isCancelled()) {
blockState.update(true);
headBlockState.update(true);
}
}
}
} else {
warnMaterialData(LongGrass.class, data);
}
}
Aggregations