Search in sources :

Example 21 with BlockState

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

the class MegaPineTree method generatePodzolPatch.

private void generatePodzolPatch(int sourceX, int sourceY, int sourceZ) {
    for (int x = -2; x <= 2; x++) {
        for (int z = -2; z <= 2; z++) {
            if (Math.abs(x) != 2 || Math.abs(z) != 2) {
                for (int y = 2; y >= -3; y--) {
                    Block block = loc.getWorld().getBlockAt(sourceX + x, sourceY + y, sourceZ + z);
                    if (block.getType() == Material.GRASS || block.getType() == Material.DIRT) {
                        BlockState state = block.getState();
                        state.setType(Material.DIRT);
                        DirtType dirtType = DirtType.PODZOL;
                        if (loc.getWorld().getBlockAt(sourceX + x, sourceY + y + 1, sourceZ + z).getType().isOccluding()) {
                            dirtType = DirtType.NORMAL;
                        }
                        state.setData(new Dirt(dirtType));
                        state.update(true);
                    } else if (!block.isEmpty() && sourceY + y < sourceY) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : DirtType(org.bukkit.material.types.DirtType) BlockState(org.bukkit.block.BlockState) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block)

Example 22 with BlockState

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

the class TallGrass method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    while ((world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty() || world.getBlockAt(sourceX, sourceY, sourceZ).getType() == Material.LEAVES) && sourceY > 0) {
        sourceY--;
    }
    for (int i = 0; i < 128; 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);
        if (y < 255 && block.getType() == Material.AIR && (block.getRelative(BlockFace.DOWN).getType() == Material.GRASS || block.getRelative(BlockFace.DOWN).getType() == Material.DIRT)) {
            BlockState state = block.getState();
            state.setType(Material.LONG_GRASS);
            state.setData(grassType);
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block)

Example 23 with BlockState

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

the class UpdateSignHandler method handle.

@Override
public void handle(GlowSession session, UpdateSignMessage message) {
    GlowPlayer player = session.getPlayer();
    Location location = new Location(player.getWorld(), message.getX(), message.getY(), message.getZ());
    if (!player.checkSignLocation(location)) {
        GlowServer.logger.warning(session + " tried to edit sign at " + location);
        return;
    }
    // filter out json messages that aren't plaintext
    String[] lines = new String[4];
    for (int i = 0; i < lines.length; ++i) {
        lines[i] = message.getMessage()[i].asPlaintext();
    }
    SignChangeEvent event = new SignChangeEvent(location.getBlock(), player, lines);
    EventFactory.callEvent(event);
    if (event.isCancelled()) {
        GlowServer.logger.warning("Sign was cancelled");
        return;
    }
    // update the sign if it's actually still there
    BlockState state = location.getBlock().getState();
    if (state instanceof Sign) {
        Sign sign = (Sign) state;
        for (int i = 0; i < lines.length; ++i) {
            sign.setLine(i, lines[i]);
        }
        sign.update();
    }
}
Also used : BlockState(org.bukkit.block.BlockState) GlowPlayer(net.glowstone.entity.GlowPlayer) Sign(org.bukkit.block.Sign) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) Location(org.bukkit.Location)

Example 24 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 25 with BlockState

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

the class LavaDecorator 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 = flowing ? 4 + random.nextInt(120) : 10 + random.nextInt(108);
    Block block = world.getBlockAt(sourceX, sourceY, sourceZ);
    if ((block.getType() == Material.NETHERRACK || block.isEmpty()) && block.getRelative(BlockFace.UP).getType() == Material.NETHERRACK) {
        int netherrackBlockCount = 0;
        for (BlockFace face : SIDES) {
            if (block.getRelative(face).getType() == Material.NETHERRACK) {
                netherrackBlockCount++;
            }
        }
        int airBlockCount = 0;
        for (BlockFace face : SIDES) {
            if (block.getRelative(face).isEmpty()) {
                airBlockCount++;
            }
        }
        if (netherrackBlockCount == 5 || flowing && airBlockCount == 1 && netherrackBlockCount == 4) {
            BlockState state = block.getState();
            state.setType(Material.LAVA);
            state.update(true);
            new PulseTask((GlowBlock) block, 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)59 Block (org.bukkit.block.Block)26 EventHandler (org.bukkit.event.EventHandler)15 MaterialData (org.bukkit.material.MaterialData)12 Location (org.bukkit.Location)11 BlockFace (org.bukkit.block.BlockFace)8 Material (org.bukkit.Material)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 BlockStateChange (me.botsko.prism.events.BlockStateChange)5 World (org.bukkit.World)5 GlowBlockState (net.glowstone.block.GlowBlockState)4 CreatureSpawner (org.bukkit.block.CreatureSpawner)4 ItemStack (org.bukkit.inventory.ItemStack)4 GlowBlock (net.glowstone.block.GlowBlock)3 HashMap (java.util.HashMap)2 Handler (me.botsko.prism.actions.Handler)2 ChangeResult (me.botsko.prism.appliers.ChangeResult)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)2 Element (net.aufdemrand.denizencore.objects.Element)2