use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class StructureBuilder method createMobSpawner.
public void createMobSpawner(Vector pos, EntityType entityType) {
Vector vec = translate(pos);
if (boundingBox.isVectorInside(vec)) {
BlockState state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
delegate.backupBlockState(state.getBlock());
state.setType(Material.MOB_SPAWNER);
state.update(true);
state = world.getBlockAt(vec.getBlockX(), vec.getBlockY(), vec.getBlockZ()).getState();
if (state instanceof CreatureSpawner) {
((CreatureSpawner) state).setSpawnedType(entityType);
}
}
}
use of org.bukkit.block.BlockState 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 org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class GlowLightningStrike method setBlockOnFire.
private void setBlockOnFire(GlowBlock block) {
if (block.isEmpty() && block.getRelative(BlockFace.DOWN).isFlammable()) {
BlockIgniteEvent igniteEvent = new BlockIgniteEvent(block, IgniteCause.LIGHTNING, this);
EventFactory.callEvent(igniteEvent);
if (!igniteEvent.isCancelled()) {
BlockState state = block.getState();
state.setType(Material.FIRE);
state.update(true);
}
}
}
use of org.bukkit.block.BlockState 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 org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.
the class GlowDungeon method generate.
@Override
public boolean generate(World world, Random random, StructureBoundingBox genBoundingBox, BlockStateDelegate delegate) {
if (!super.generate(world, random, boundingBox, delegate)) {
return false;
}
boundingBox.offset(new Vector(-radiusX, -1, -radiusZ));
StructureBuilder builder = new StructureBuilder(world, this, genBoundingBox, delegate);
if (!canPlace(builder)) {
return false;
}
Map<StructureMaterial, Integer> stones = new HashMap<>();
builder.addRandomMaterial(stones, 1, Material.COBBLESTONE, 0);
builder.addRandomMaterial(stones, 3, Material.MOSSY_COBBLESTONE, 0);
for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) {
for (int y = HEIGHT - 1; y >= 0; y--) {
BlockState state = builder.getBlockState(new Vector(x, y, z));
if (y > 0 && x > 0 && z > 0 && x < sizeX - 1 && y < HEIGHT - 1 && z < sizeZ - 1) {
// empty space inside
builder.setBlock(new Vector(x, y, z), Material.AIR);
} else if (!builder.getBlockState(new Vector(x, y - 1, z)).getType().isSolid()) {
// cleaning walls from non solid materials (because of air gaps below)
builder.setBlock(new Vector(x, y, z), Material.AIR);
} else if (state.getType().isSolid()) {
// preserve the air gaps
if (y == 0) {
builder.setBlockWithRandomMaterial(new Vector(x, y, z), random, stones);
} else {
builder.setBlock(new Vector(x, y, z), Material.COBBLESTONE);
}
}
}
}
}
RandomItemsContent chestContent = new RandomItemsContent();
chestContent.addItem(new RandomAmountItem(Material.SADDLE, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.IRON_INGOT, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.BREAD, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.WHEAT, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.SULPHUR, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.STRING, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.BUCKET, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLDEN_APPLE, 1, 1), 1);
chestContent.addItem(new RandomAmountItem(Material.REDSTONE, 1, 4), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLD_RECORD, 1, 1), 4);
chestContent.addItem(new RandomAmountItem(Material.GREEN_RECORD, 1, 1), 4);
chestContent.addItem(new RandomAmountItem(Material.NAME_TAG, 1, 1), 10);
chestContent.addItem(new RandomAmountItem(Material.GOLD_BARDING, 1, 1), 2);
chestContent.addItem(new RandomAmountItem(Material.IRON_BARDING, 1, 1), 5);
chestContent.addItem(new RandomAmountItem(Material.DIAMOND_BARDING, 1, 1), 1);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
int x = random.nextInt((radiusX << 1) - 1) + 1;
int z = random.nextInt((radiusZ << 1) - 1) + 1;
if (builder.getBlockState(new Vector(x, 1, z)).getType() == Material.AIR) {
BlockFace face = null;
int solidBlocksCount = 0;
if (builder.getBlockState(new Vector(x - 1, 1, z)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.EAST;
}
if (builder.getBlockState(new Vector(x + 1, 1, z)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.WEST;
}
if (builder.getBlockState(new Vector(x, 1, z - 1)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.SOUTH;
}
if (builder.getBlockState(new Vector(x, 1, z + 1)).getType() == Material.COBBLESTONE) {
solidBlocksCount++;
face = BlockFace.NORTH;
}
if (solidBlocksCount == 1) {
builder.createRandomItemsContainer(new Vector(x, 1, z), random, chestContent, new Chest(face), 8);
break;
}
}
}
}
builder.createMobSpawner(new Vector(radiusX, 1, radiusZ), mobTypes[random.nextInt(mobTypes.length)]);
GlowServer.logger.finer("dungeon generated: " + loc.getBlockX() + "," + loc.getBlockY() + "," + loc.getBlockZ());
return true;
}
Aggregations