Search in sources :

Example 86 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class DeadBushDecorator 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);
    int sourceY = random.nextInt(world.getHighestBlockYAt(sourceX, sourceZ) << 1);
    while (sourceY > 0 && (world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || // TODO: 1.13 leaves
    world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEGACY_LEAVES)) {
        sourceY--;
    }
    for (int i = 0; i < 4; i++) {
        int x = sourceX + random.nextInt(8) - random.nextInt(8);
        int z = sourceZ + random.nextInt(8) - random.nextInt(8);
        int y = sourceY + random.nextInt(4) - random.nextInt(4);
        if (world.getBlockAt(x, y, z).isEmpty()) {
            Block blockBelow = world.getBlockAt(x, y - 1, z);
            for (Material soil : SOIL_TYPES) {
                if (soil == blockBelow.getType()) {
                    BlockState state = world.getBlockAt(x, y, z).getState();
                    state.setType(Material.DEAD_BUSH);
                    state.setData(new LongGrass(GrassSpecies.DEAD));
                    state.update(true);
                    break;
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Material(org.bukkit.Material) LongGrass(org.bukkit.material.LongGrass)

Example 87 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class FireDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    int amount = 1 + random.nextInt(1 + random.nextInt(10));
    for (int j = 0; j < amount; j++) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = 4 + random.nextInt(120);
        for (int i = 0; i < 64; i++) {
            int x = sourceX + random.nextInt(8) - random.nextInt(8);
            int z = sourceZ + random.nextInt(8) - random.nextInt(8);
            int y = sourceY + random.nextInt(4) - random.nextInt(4);
            Block block = world.getBlockAt(x, y, z);
            Block blockBelow = world.getBlockAt(x, y - 1, z);
            if (y < 128 && block.getType() == Material.AIR && blockBelow.getType() == Material.NETHERRACK) {
                BlockState state = block.getState();
                state.setType(Material.FIRE);
                state.setData(new MaterialData(Material.FIRE));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 88 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class BlockPatch method generate.

@Override
public boolean generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean succeeded = false;
    int n = random.nextInt(horizRadius - MIN_RADIUS) + MIN_RADIUS;
    int nsquared = n * n;
    for (int x = sourceX - n; x <= sourceX + n; x++) {
        for (int z = sourceZ - n; z <= sourceZ + n; z++) {
            if ((x - sourceX) * (x - sourceX) + (z - sourceZ) * (z - sourceZ) > nsquared) {
                continue;
            }
            for (int y = sourceY - vertRadius; y <= sourceY + vertRadius; y++) {
                Block block = world.getBlockAt(x, y, z);
                if (!overridables.contains(block.getType())) {
                    continue;
                }
                if (TerrainObject.killPlantAbove(block)) {
                    break;
                }
                BlockState state = block.getState();
                state.setType(type);
                state.setData(new MaterialData(type));
                state.update(true);
                succeeded = true;
                break;
            }
        }
    }
    return succeeded;
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 89 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class SugarCane method generate.

@Override
public boolean generate(World world, Random random, int x, int y, int z) {
    if (!world.getBlockAt(x, y, z).isEmpty()) {
        return false;
    }
    Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
    boolean adjacentWater = false;
    for (BlockFace face : FACES) {
        // needs a directly adjacent water block
        Material blockType = block.getRelative(face).getType();
        if (blockType == Material.WATER) {
            adjacentWater = true;
            break;
        }
    }
    if (!adjacentWater) {
        return false;
    }
    for (int n = 0; n <= random.nextInt(random.nextInt(3) + 1) + 1; n++) {
        block = world.getBlockAt(x, y + n, z).getRelative(BlockFace.DOWN);
        if (block.getType() == Material.SUGAR_CANE || block.getType() == Material.GRASS_BLOCK || block.getType() == Material.DIRT || block.getType() == Material.SAND) {
            Block caneBlock = block.getRelative(BlockFace.UP);
            if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
                return n > 0;
            }
            BlockState state = caneBlock.getState();
            state.setType(Material.SUGAR_CANE);
            state.update(true);
        }
    }
    return true;
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Block(org.bukkit.block.Block) Material(org.bukkit.Material)

Example 90 with BlockState

use of org.bukkit.block.BlockState in project Glowstone by GlowstoneMC.

the class FlowingLiquidDecorator 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);
    int sourceY = random.nextInt(random.nextInt(type == Material.LAVA ? random.nextInt(240) + 8 : 248) + 8);
    Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
    if ((block.getType() == Material.STONE || block.getType() == Material.AIR) && block.getRelative(BlockFace.DOWN).getType() == Material.STONE && block.getRelative(BlockFace.UP).getType() == Material.STONE) {
        int stoneBlockCount = 0;
        for (BlockFace face : SIDES) {
            if (block.getRelative(face).getType() == Material.STONE) {
                stoneBlockCount++;
            }
        }
        if (stoneBlockCount == 3) {
            int airBlockCount = 0;
            for (BlockFace face : SIDES) {
                if (block.getRelative(face).isEmpty()) {
                    airBlockCount++;
                }
            }
            if (airBlockCount == 1) {
                BlockState state = block.getState();
                state.setType(type);
                state.update(true);
                new PulseTask((GlowBlock) state.getBlock(), true, 1, true).startPulseTask();
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) PulseTask(net.glowstone.scheduler.PulseTask)

Aggregations

BlockState (org.bukkit.block.BlockState)127 Block (org.bukkit.block.Block)54 EventHandler (org.bukkit.event.EventHandler)35 Sign (org.bukkit.block.Sign)17 Location (org.bukkit.Location)16 World (org.bukkit.World)15 InventoryHolder (org.bukkit.inventory.InventoryHolder)14 Material (org.bukkit.Material)13 MaterialData (org.bukkit.material.MaterialData)13 ItemStack (org.bukkit.inventory.ItemStack)11 ArrayList (java.util.ArrayList)10 CreatureSpawner (org.bukkit.block.CreatureSpawner)10 Player (org.bukkit.entity.Player)10 BlockFace (org.bukkit.block.BlockFace)9 BlockStateChangeImpl (me.botsko.prism.events.BlockStateChangeImpl)7 Vector (org.bukkit.util.Vector)7 ChangeResultImpl (me.botsko.prism.appliers.ChangeResultImpl)5 Chunk (org.bukkit.Chunk)5 CommandBlock (org.bukkit.block.CommandBlock)5 Skull (org.bukkit.block.Skull)5