Search in sources :

Example 1 with GenericTree

use of net.glowstone.generator.objects.trees.GenericTree in project Glowstone by GlowstoneMC.

the class TreeDecorator 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);
    Block sourceBlock = world.getBlockAt(sourceX, world.getHighestBlockYAt(sourceX, sourceZ), sourceZ);
    Class<? extends GenericTree> clazz = getRandomTree(random, trees);
    if (clazz != null) {
        BlockStateDelegate delegate = new BlockStateDelegate();
        GenericTree tree;
        try {
            Constructor<? extends GenericTree> c = clazz.getConstructor(Random.class, Location.class, BlockStateDelegate.class);
            tree = c.newInstance(random, sourceBlock.getLocation(), delegate);
        } catch (Exception ex) {
            tree = new GenericTree(random, sourceBlock.getLocation(), delegate);
        }
        if (tree.generate()) {
            delegate.updateBlockStates();
        }
    }
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) GenericTree(net.glowstone.generator.objects.trees.GenericTree) Block(org.bukkit.block.Block)

Aggregations

GenericTree (net.glowstone.generator.objects.trees.GenericTree)1 BlockStateDelegate (net.glowstone.util.BlockStateDelegate)1 Block (org.bukkit.block.Block)1