Search in sources :

Example 61 with MaterialData

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

the class StoneBoulder method generate.

public void generate(World world, Random random, int sourceX, int sourceY, int sourceZ) {
    boolean groundReached = false;
    while (!groundReached && sourceY > 3) {
        Block block = world.getBlockAt(sourceX, sourceY - 1, sourceZ);
        if (!block.isEmpty()) {
            for (Material mat : GROUND_TYPES) {
                if (mat == block.getType()) {
                    groundReached = true;
                    sourceY++;
                    break;
                }
            }
        }
        sourceY--;
    }
    if (groundReached && world.getBlockAt(sourceX, sourceY, sourceZ).isEmpty()) {
        for (int i = 0; i < 3; i++) {
            int radiusX = random.nextInt(2);
            int radiusZ = random.nextInt(2);
            int radiusY = random.nextInt(2);
            float f = (radiusX + radiusZ + radiusY) * 0.333F + 0.5F;
            for (int x = -radiusX; x <= radiusX; x++) {
                for (int z = -radiusZ; z <= radiusZ; z++) {
                    for (int y = -radiusY; y <= radiusY; y++) {
                        if (x * x + z * z + y * y <= f * f) {
                            BlockState state = world.getBlockAt(sourceX + x, sourceY + y, sourceZ + z).getState();
                            Block blockAbove = state.getBlock().getRelative(BlockFace.UP);
                            for (Material mat : PLANT_TYPES) {
                                if (blockAbove.getType() == mat) {
                                    if (mat == Material.DOUBLE_PLANT && blockAbove.getState().getData() instanceof DoublePlant && ((DoublePlant) blockAbove.getState().getData()).getSpecies() == DoublePlantSpecies.PLANT_APEX) {
                                        blockAbove.getRelative(BlockFace.UP).setType(Material.AIR);
                                    }
                                    blockAbove.setType(Material.AIR);
                                    break;
                                }
                            }
                            state.setType(Material.MOSSY_COBBLESTONE);
                            state.setData(new MaterialData(Material.MOSSY_COBBLESTONE));
                            state.update(true);
                        }
                    }
                }
            }
            sourceX += random.nextInt(4) - 1;
            sourceZ += random.nextInt(4) - 1;
            sourceY -= random.nextInt(2);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Block(org.bukkit.block.Block) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 62 with MaterialData

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

the class SugarCane method generate.

public void generate(World world, Random random, int x, int y, int z) {
    if (world.getBlockAt(x, y, z).isEmpty()) {
        Block block = world.getBlockAt(x, y, z).getRelative(BlockFace.DOWN);
        boolean adjacentWater = false;
        for (BlockFace face : FACES) {
            // needs a directly adjacent water block
            if (block.getRelative(face).getType() == Material.STATIONARY_WATER || block.getRelative(face).getType() == Material.WATER) {
                adjacentWater = true;
                break;
            }
        }
        if (adjacentWater) {
            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 || block.getType() == Material.GRASS || block.getType() == Material.DIRT && block.getState().getData() instanceof Dirt && ((Dirt) block.getState().getData()).getType() == DirtType.NORMAL || block.getType() == Material.SAND) {
                    Block caneBlock = block.getRelative(BlockFace.UP);
                    if (!caneBlock.isEmpty() && !caneBlock.getRelative(BlockFace.UP).isEmpty()) {
                        return;
                    }
                    BlockState state = caneBlock.getState();
                    state.setType(Material.SUGAR_CANE_BLOCK);
                    state.setData(new MaterialData(Material.SUGAR_CANE_BLOCK));
                    state.update(true);
                }
            }
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) BlockFace(org.bukkit.block.BlockFace) Dirt(org.bukkit.material.Dirt) Block(org.bukkit.block.Block) MaterialData(org.bukkit.material.MaterialData)

Example 63 with MaterialData

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

the class BlockSponge method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // TODO: Move this to a new method when physics works and run this on neighbour change too.
    MaterialData data = holding.getData();
    if (!(data instanceof Sponge)) {
        warnMaterialData(Sponge.class, data);
        return;
    }
    Sponge sponge = (Sponge) data;
    if (sponge.getType() == SpongeType.NORMAL) {
        GlowBlock block = state.getBlock();
        TaxicabBlockIterator iterator = new TaxicabBlockIterator(block);
        iterator.setMaxDistance(7);
        iterator.setMaxBlocks(66);
        iterator.setValidator(new BlockMaterialValidator(WATER_MATERIALS));
        if (iterator.hasNext()) {
            sponge = sponge.clone();
            sponge.setType(SpongeType.WET);
            do {
                iterator.next().setType(Material.AIR);
            } while (iterator.hasNext());
        }
    }
    state.setType(Material.SPONGE);
    state.setData(sponge);
}
Also used : TaxicabBlockIterator(net.glowstone.util.TaxicabBlockIterator) GlowBlock(net.glowstone.block.GlowBlock) BlockMaterialValidator(net.glowstone.util.BlockMaterialValidator) Sponge(org.bukkit.material.Sponge) MaterialData(org.bukkit.material.MaterialData)

Example 64 with MaterialData

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

the class BlockStairs 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 Stairs) {
        ((Stairs) data).setFacingDirection(player.getDirection());
        if (face == BlockFace.DOWN || face != BlockFace.UP && clickedLoc.getY() >= 0.5) {
            ((Stairs) data).setInverted(true);
        }
        state.setData(data);
    } else {
        warnMaterialData(Stairs.class, data);
    }
}
Also used : Stairs(org.bukkit.material.Stairs) MaterialData(org.bukkit.material.MaterialData)

Example 65 with MaterialData

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

the class BlockVine method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (random.nextInt(4) == 0) {
        GlowBlockState state = block.getState();
        MaterialData data = state.getData();
        if (data instanceof Vine) {
            Vine vine = (Vine) data;
            boolean hasNearVineBlocks = hasNearVineBlocks(block);
            BlockFace face = FACES[random.nextInt(FACES.length)];
            if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
                if (!hasNearVineBlocks) {
                    Vine v = (Vine) data;
                    for (BlockFace f : HORIZONTAL_FACES) {
                        if (random.nextInt(2) == 0 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
                            v.removeFromFace(f);
                        }
                    }
                    putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
                }
            } else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
                if (!hasNearVineBlocks) {
                    GlowBlock b = block.getRelative(face);
                    if (b.isEmpty()) {
                        BlockFace clockwiseFace = getClockwiseFace(face);
                        BlockFace counterClockwiseFace = getCounterClockwiseFace(face);
                        GlowBlock clockwiseBlock = b.getRelative(clockwiseFace);
                        GlowBlock counterClockwiseBlock = b.getRelative(counterClockwiseFace);
                        boolean isOnCWFace = vine.isOnFace(clockwiseFace);
                        boolean isOnCCWFace = vine.isOnFace(counterClockwiseFace);
                        if (isOnCWFace && clockwiseBlock.getType().isSolid()) {
                            putVine(b, new Vine(clockwiseFace), block);
                        } else if (isOnCCWFace && counterClockwiseBlock.getType().isSolid()) {
                            putVine(b, new Vine(counterClockwiseFace), block);
                        } else if (isOnCWFace && clockwiseBlock.isEmpty() && block.getRelative(clockwiseFace).getType().isSolid()) {
                            putVine(clockwiseBlock, new Vine(face.getOppositeFace()), block);
                        } else if (isOnCCWFace && counterClockwiseBlock.isEmpty() && block.getRelative(counterClockwiseFace).getType().isSolid()) {
                            putVine(counterClockwiseBlock, new Vine(face.getOppositeFace()), block);
                        } else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
                            putVine(b, new Vine(), block);
                        }
                    } else if (b.getType().isOccluding()) {
                        vine.putOnFace(face);
                        putVine(block, vine, null);
                    }
                }
            } else if (block.getY() > 1) {
                GlowBlock b = block.getRelative(BlockFace.DOWN);
                Vine v = (Vine) data;
                if (b.getType() == Material.VINE || b.isEmpty()) {
                    for (BlockFace f : HORIZONTAL_FACES) {
                        if (random.nextInt(2) == 0) {
                            v.removeFromFace(f);
                        }
                    }
                    putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
                }
            }
        } else {
            warnMaterialData(Vine.class, data);
        }
    }
}
Also used : Vine(org.bukkit.material.Vine) GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Aggregations

MaterialData (org.bukkit.material.MaterialData)93 GlowBlockState (net.glowstone.block.GlowBlockState)20 ItemStack (org.bukkit.inventory.ItemStack)20 Material (org.bukkit.Material)13 Block (org.bukkit.block.Block)12 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 BlockFace (org.bukkit.block.BlockFace)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 ArrayList (java.util.ArrayList)6 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 IOException (java.io.IOException)3 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3