Search in sources :

Example 16 with BlockState

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);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Vector(org.bukkit.util.Vector) CreatureSpawner(org.bukkit.block.CreatureSpawner)

Example 17 with BlockState

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);
            }
        }
    }
}
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 18 with BlockState

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);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 19 with BlockState

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;
}
Also used : BlockStateDelegate(net.glowstone.util.BlockStateDelegate) BlockState(org.bukkit.block.BlockState)

Example 20 with BlockState

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;
}
Also used : Chest(org.bukkit.material.Chest) BlockState(org.bukkit.block.BlockState) RandomAmountItem(net.glowstone.generator.objects.RandomItemsContent.RandomAmountItem) HashMap(java.util.HashMap) StructureBuilder(net.glowstone.generator.structures.util.StructureBuilder) BlockFace(org.bukkit.block.BlockFace) RandomItemsContent(net.glowstone.generator.objects.RandomItemsContent) StructureMaterial(net.glowstone.generator.structures.util.StructureBuilder.StructureMaterial) Vector(org.bukkit.util.Vector)

Aggregations

BlockState (org.bukkit.block.BlockState)62 Block (org.bukkit.block.Block)27 EventHandler (org.bukkit.event.EventHandler)16 Location (org.bukkit.Location)12 MaterialData (org.bukkit.material.MaterialData)12 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)7 World (org.bukkit.World)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 ItemStack (org.bukkit.inventory.ItemStack)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)4 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 Sign (org.bukkit.block.Sign)4 Vector (org.bukkit.util.Vector)4 GlowBlock (net.glowstone.block.GlowBlock)3 TreeType (org.bukkit.TreeType)3 InventoryHolder (org.bukkit.inventory.InventoryHolder)3 HashMap (java.util.HashMap)2