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);
}
}
}
}
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;
}
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();
}
//}
}
}
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);
}
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();
}
}
}
Aggregations