use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method blockDestroy.
@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
MaterialData data = block.getState().getData();
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
if (!(blockUnder.getState().getData() instanceof DoublePlant)) {
return;
}
blockUnder.setType(Material.AIR);
} else {
GlowBlock blockTop = block.getRelative(BlockFace.UP);
if (!(blockTop.getState().getData() instanceof DoublePlant)) {
return;
}
blockTop.setType(Material.AIR);
}
} else {
warnMaterialData(DoublePlant.class, data);
}
}
use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.
the class BlockDoublePlant method canAbsorb.
@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
MaterialData data = block.getState().getData();
BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
if (data instanceof DoublePlant) {
DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
if (species == DoublePlantSpecies.DOUBLE_TALLGRASS || species == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
}
return true;
}
if (species == DoublePlantSpecies.PLANT_APEX) {
GlowBlock under = block.getRelative(BlockFace.DOWN);
MaterialData underData = under.getState().getData();
if (underData instanceof DoublePlant) {
DoublePlantSpecies underSpecies = ((DoublePlant) underData).getSpecies();
if (underSpecies == DoublePlantSpecies.DOUBLE_TALLGRASS || underSpecies == DoublePlantSpecies.LARGE_FERN) {
if (holdingType != null && holdingType.canPlaceAt(block, face)) {
under.setType(Material.AIR, (byte) 0, false);
}
return true;
}
}
}
} else {
warnMaterialData(DoublePlant.class, data);
}
return false;
}
use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.
the class DoublePlantDecorator method decorate.
@Override
public void decorate(World world, Random random, Chunk source) {
int sourceX = (source.getX() << 4) + random.nextInt(16);
int sourceZ = (source.getZ() << 4) + random.nextInt(16);
int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) + 32);
DoublePlantSpecies species = getRandomDoublePlant(random, doublePlants);
new DoubleTallPlant(species).generate(world, random, sourceX, sourceY, sourceZ);
}
use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.
the class ForestPopulator method populateOnGround.
@Override
public void populateOnGround(World world, Random random, Chunk chunk) {
int sourceX = chunk.getX() << 4;
int sourceZ = chunk.getZ() << 4;
int amount = random.nextInt(5) - doublePlantLoweringAmount;
int i = 0;
while (i < amount) {
for (int j = 0; j < 5; j++, i++) {
int x = sourceX + random.nextInt(16);
int z = sourceZ + random.nextInt(16);
int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32);
DoublePlantSpecies species = DOUBLE_PLANTS[random.nextInt(DOUBLE_PLANTS.length)];
if (new DoubleTallPlant(species).generate(world, random, x, y, z)) {
i++;
break;
}
}
}
super.populateOnGround(world, random, chunk);
}
use of org.bukkit.material.types.DoublePlantSpecies 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