Search in sources :

Example 1 with BlockStateDelegate

use of net.glowstone.util.BlockStateDelegate in project Glowstone by GlowstoneMC.

the class BlockMushroom method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    TreeType type;
    if (mushroomType == Material.BROWN_MUSHROOM) {
        type = TreeType.BROWN_MUSHROOM;
    } else if (mushroomType == Material.RED_MUSHROOM) {
        type = TreeType.RED_MUSHROOM;
    } else {
        return;
    }
    Location loc = block.getLocation();
    BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
    if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
        List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
        StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, true, player, blockStates);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            for (BlockState state : blockStates) {
                state.update(true);
            }
        }
    }
}
Also used : TreeType(org.bukkit.TreeType) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState) GlowBlockState(net.glowstone.block.GlowBlockState) ArrayList(java.util.ArrayList) StructureGrowEvent(org.bukkit.event.world.StructureGrowEvent) Location(org.bukkit.Location)

Example 2 with BlockStateDelegate

use of net.glowstone.util.BlockStateDelegate in project Glowstone by GlowstoneMC.

the class GlowWorld method generateTree.

@Override
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
    BlockStateDelegate blockStateDelegate = new BlockStateDelegate();
    if (GlowTree.newInstance(type, random, loc, blockStateDelegate).generate()) {
        List<BlockState> blockStates = new ArrayList<>(blockStateDelegate.getBlockStates());
        StructureGrowEvent growEvent = new StructureGrowEvent(loc, type, false, null, blockStates);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            for (BlockState state : blockStates) {
                state.update(true);
                if (delegate != null) {
                    delegate.setTypeIdAndData(state.getX(), state.getY(), state.getZ(), state.getTypeId(), state.getRawData());
                }
            }
            return true;
        }
    }
    return false;
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState)

Example 3 with BlockStateDelegate

use of net.glowstone.util.BlockStateDelegate in project Glowstone by GlowstoneMC.

the class DungeonPopulator method populate.

@Override
public void populate(World world, Random random, Chunk source) {
    SimplexNoiseGenerator noise = new SimplexNoiseGenerator(world);
    double density = noise.noise(source.getX(), source.getZ());
    if (density > 0.8) {
        // TODO later switch to this loop to have 8 attempts of dungeon placement per chunk, once we get caves and ravines
        //for (int i = 0; i < 8; i++) {
        int x = (source.getX() << 4) + random.nextInt(16);
        int z = (source.getZ() << 4) + random.nextInt(16);
        int y = random.nextInt(256);
        GlowDungeon dungeon = new GlowDungeon(random, new Location(world, x, y, z));
        BlockStateDelegate delegate = new BlockStateDelegate();
        if (dungeon.generate(world, random, new StructureBoundingBox(new Vector(x - 15, 1, z - 15), new Vector(x + 15, 511, z + 15)), delegate)) {
            delegate.updateBlockStates();
        }
    //}
    }
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) GlowDungeon(net.glowstone.generator.structures.GlowDungeon) StructureBoundingBox(net.glowstone.generator.structures.util.StructureBoundingBox) SimplexNoiseGenerator(org.bukkit.util.noise.SimplexNoiseGenerator) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Example 4 with BlockStateDelegate

use of net.glowstone.util.BlockStateDelegate in project Glowstone by GlowstoneMC.

the class JunglePopulator method populateOnGround.

@Override
public void populateOnGround(World world, Random random, Chunk chunk) {
    int sourceX = chunk.getX() << 4;
    int sourceZ = chunk.getZ() << 4;
    for (int i = 0; i < 7; i++) {
        int x = sourceX + random.nextInt(16);
        int z = sourceZ + random.nextInt(16);
        int y = world.getHighestBlockYAt(x, z);
        Block sourceBlock = world.getBlockAt(x, y, z);
        BlockStateDelegate delegate = new BlockStateDelegate();
        JungleBush bush = new JungleBush(random, sourceBlock.getLocation(), delegate);
        if (bush.generate()) {
            delegate.updateBlockStates();
        }
    }
    super.populateOnGround(world, random, chunk);
    melonDecorator.populate(world, random, chunk);
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) Block(org.bukkit.block.Block) JungleBush(net.glowstone.generator.objects.trees.JungleBush)

Example 5 with BlockStateDelegate

use of net.glowstone.util.BlockStateDelegate in project Glowstone by GlowstoneMC.

the class DesertWellDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    if (random.nextInt(1000) == 0) {
        int x = (source.getX() << 4) + random.nextInt(16);
        int z = (source.getZ() << 4) + random.nextInt(16);
        int y = world.getHighestBlockYAt(x, z);
        GlowDesertWell well = new GlowDesertWell(new Location(world, x, y, z));
        BlockStateDelegate delegate = new BlockStateDelegate();
        if (well.generate(world, random, new StructureBoundingBox(new Vector(x - 15, 1, z - 15), new Vector(x + 15, 511, z + 15)), delegate)) {
            delegate.updateBlockStates();
        }
    }
}
Also used : GlowDesertWell(net.glowstone.generator.structures.GlowDesertWell) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) StructureBoundingBox(net.glowstone.generator.structures.util.StructureBoundingBox) Vector(org.bukkit.util.Vector) Location(org.bukkit.Location)

Aggregations

BlockStateDelegate (net.glowstone.util.BlockStateDelegate)8 Location (org.bukkit.Location)4 BlockState (org.bukkit.block.BlockState)3 ArrayList (java.util.ArrayList)2 StructureBoundingBox (net.glowstone.generator.structures.util.StructureBoundingBox)2 Block (org.bukkit.block.Block)2 StructureGrowEvent (org.bukkit.event.world.StructureGrowEvent)2 Vector (org.bukkit.util.Vector)2 Entry (java.util.Map.Entry)1 GlowWorld (net.glowstone.GlowWorld)1 GlowBlockState (net.glowstone.block.GlowBlockState)1 Key (net.glowstone.chunk.GlowChunk.Key)1 GenericTree (net.glowstone.generator.objects.trees.GenericTree)1 JungleBush (net.glowstone.generator.objects.trees.JungleBush)1 GlowDesertWell (net.glowstone.generator.structures.GlowDesertWell)1 GlowDungeon (net.glowstone.generator.structures.GlowDungeon)1 GlowStructure (net.glowstone.generator.structures.GlowStructure)1 TreeType (org.bukkit.TreeType)1 SimplexNoiseGenerator (org.bukkit.util.noise.SimplexNoiseGenerator)1