Search in sources :

Example 26 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class MushroomDecorator 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(128);
    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 && Arrays.asList(MATERIALS).contains(blockBelow.getType())) {
            BlockState state = block.getState();
            state.setType(type);
            state.setData(new MaterialData(type));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 27 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class WaterLilyDecorator 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 (world.getBlockAt(sourceX, sourceY - 1, sourceZ).getType() == Material.AIR && sourceY > 0) {
        sourceY--;
    }
    for (int j = 0; j < 10; j++) {
        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 (y >= 0 && y <= 255 && world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.STATIONARY_WATER) {
            BlockState state = world.getBlockAt(x, y, z).getState();
            state.setType(Material.WATER_LILY);
            state.setData(new MaterialData(Material.WATER_LILY));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) MaterialData(org.bukkit.material.MaterialData)

Example 28 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class MushroomDecorator method decorate.

@Override
public void decorate(World world, Random random, Chunk source) {
    if (random.nextFloat() < density) {
        int sourceX = (source.getX() << 4) + random.nextInt(16);
        int sourceZ = (source.getZ() << 4) + random.nextInt(16);
        int sourceY = world.getHighestBlockYAt(sourceX, sourceZ);
        sourceY = fixedHeightRange ? sourceY : random.nextInt(sourceY << 1);
        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 < 255 && block.getType() == Material.AIR && ((blockBelow.getType() == Material.GRASS || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() != DirtType.PODZOL) && block.getLightLevel() < 13 || blockBelow.getType() == Material.MYCEL || blockBelow.getState().getData() instanceof Dirt && ((Dirt) blockBelow.getState().getData()).getType() == DirtType.PODZOL)) {
                BlockState state = block.getState();
                state.setType(type);
                state.setData(new MaterialData(type));
                state.update(true);
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 29 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockSkull method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (!(data instanceof Skull)) {
        warnMaterialData(Skull.class, data);
        return;
    }
    Skull skull = (Skull) data;
    skull.setFacingDirection(face);
}
Also used : GlowSkull(net.glowstone.block.state.GlowSkull) Skull(org.bukkit.material.Skull) MaterialData(org.bukkit.material.MaterialData)

Example 30 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockSlab method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    Material blockType = state.getBlock().getType();
    if (blockType == Material.STEP) {
        state.setType(Material.DOUBLE_STEP);
        state.setData(holding.getData());
        return;
    } else if (blockType == Material.WOOD_STEP) {
        state.setType(Material.WOOD_DOUBLE_STEP);
        state.setData(holding.getData());
        return;
    } else if (blockType == Material.STONE_SLAB2) {
        state.setType(Material.DOUBLE_STONE_SLAB2);
        state.setData(holding.getData());
        return;
    } else if (blockType == Material.PURPUR_SLAB) {
        state.setType(Material.PURPUR_DOUBLE_SLAB);
        state.setData(holding.getData());
        return;
    }
    if (face == BlockFace.DOWN || face != BlockFace.UP && clickedLoc.getY() >= 0.5) {
        MaterialData data = state.getData();
        if (data instanceof Step) {
            ((Step) data).setInverted(true);
        } else if (data instanceof WoodenStep) {
            ((WoodenStep) data).setInverted(true);
        } else if (data.getItemType() == Material.STONE_SLAB2 || data.getItemType() == Material.PURPUR_SLAB) {
            Step slab = new Step(data.getItemType());
            slab.setInverted(true);
            data = slab;
        }
        state.setData(data);
    }
}
Also used : WoodenStep(org.bukkit.material.WoodenStep) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) WoodenStep(org.bukkit.material.WoodenStep) Step(org.bukkit.material.Step)

Aggregations

MaterialData (org.bukkit.material.MaterialData)75 GlowBlockState (net.glowstone.block.GlowBlockState)20 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 Material (org.bukkit.Material)10 Block (org.bukkit.block.Block)9 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)8 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)3 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 ArrayList (java.util.ArrayList)2 GlowWorld (net.glowstone.GlowWorld)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 GlowSkull (net.glowstone.block.state.GlowSkull)2 Location (org.bukkit.Location)2