Search in sources :

Example 71 with MaterialData

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

the class BlockPumpkinBase 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 Pumpkin) {
        ((Pumpkin) data).setFacingDirection(player.getDirection());
        state.setData(data);
    } else {
        warnMaterialData(Pumpkin.class, data);
    }
}
Also used : Pumpkin(org.bukkit.material.Pumpkin) MaterialData(org.bukkit.material.MaterialData)

Example 72 with MaterialData

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

the class ChunkManager method generateChunk.

/**
     * Initialize a single chunk from the chunk generator.
     */
private void generateChunk(GlowChunk chunk, int x, int z) {
    Random random = new Random(x * 341873128712L + z * 132897987541L);
    BiomeGrid biomes = new BiomeGrid();
    int[] biomeValues = biomeGrid[0].generateValues(x * GlowChunk.WIDTH, z * GlowChunk.HEIGHT, GlowChunk.WIDTH, GlowChunk.HEIGHT);
    for (int i = 0; i < biomeValues.length; i++) {
        biomes.biomes[i] = (byte) biomeValues[i];
    }
    // extended sections with data
    GlowChunkData glowChunkData = null;
    if (generator instanceof GlowChunkGenerator) {
        glowChunkData = (GlowChunkData) generator.generateChunkData(world, random, x, z, biomes);
    } else {
        ChunkGenerator.ChunkData chunkData = generator.generateChunkData(world, random, x, z, biomes);
        if (chunkData != null) {
            glowChunkData = new GlowChunkData(world);
            for (int i = 0; i < 16; ++i) {
                for (int j = 0; j < 16; ++j) {
                    int maxHeight = chunkData.getMaxHeight();
                    for (int k = 0; k < maxHeight; ++k) {
                        MaterialData materialData = chunkData.getTypeAndData(i, k, j);
                        if (materialData != null) {
                            glowChunkData.setBlock(i, k, j, materialData);
                        } else {
                            glowChunkData.setBlock(i, k, j, new MaterialData(Material.AIR));
                        }
                    }
                }
            }
        }
    }
    if (glowChunkData != null) {
        short[][] extSections = glowChunkData.getSections();
        if (extSections != null) {
            ChunkSection[] sections = new ChunkSection[extSections.length];
            for (int i = 0; i < extSections.length; ++i) {
                if (extSections[i] != null) {
                    sections[i] = ChunkSection.fromStateArray(extSections[i]);
                }
            }
            chunk.initializeSections(sections);
            chunk.setBiomes(biomes.biomes);
            chunk.automaticHeightMap();
            return;
        }
    }
    // extended sections
    short[][] extSections = generator.generateExtBlockSections(world, random, x, z, biomes);
    if (extSections != null) {
        ChunkSection[] sections = new ChunkSection[extSections.length];
        for (int i = 0; i < extSections.length; ++i) {
            if (extSections[i] != null) {
                sections[i] = ChunkSection.fromIdArray(extSections[i]);
            }
        }
        chunk.initializeSections(sections);
        chunk.setBiomes(biomes.biomes);
        chunk.automaticHeightMap();
        return;
    }
    // normal sections
    byte[][] blockSections = generator.generateBlockSections(world, random, x, z, biomes);
    if (blockSections != null) {
        ChunkSection[] sections = new ChunkSection[blockSections.length];
        for (int i = 0; i < blockSections.length; ++i) {
            if (blockSections[i] != null) {
                sections[i] = ChunkSection.fromIdArray(blockSections[i]);
            }
        }
        chunk.initializeSections(sections);
        chunk.setBiomes(biomes.biomes);
        chunk.automaticHeightMap();
        return;
    }
    // deprecated flat generation
    byte[] types = generator.generate(world, random, x, z);
    ChunkSection[] sections = new ChunkSection[8];
    for (int sy = 0; sy < sections.length; ++sy) {
        // We can't use a normal constructor here due to the "interesting"
        // choices used for this deprecated API (blocks are in vertical columns)
        ChunkSection sec = new ChunkSection();
        int by = 16 * sy;
        for (int cx = 0; cx < 16; ++cx) {
            for (int cz = 0; cz < 16; ++cz) {
                for (int cy = by; cy < by + 16; ++cy) {
                    char type = (char) types[(((cx << 4) + cz) << 7) + cy];
                    sec.setType(cx, cy, cz, (char) (type << 4));
                }
            }
        }
        sections[sy] = sec;
    }
    chunk.initializeSections(sections);
    chunk.setBiomes(biomes.biomes);
    chunk.automaticHeightMap();
}
Also used : GlowChunkData(net.glowstone.generator.GlowChunkData) GlowChunkGenerator(net.glowstone.generator.GlowChunkGenerator) MaterialData(org.bukkit.material.MaterialData) ChunkGenerator(org.bukkit.generator.ChunkGenerator) GlowChunkGenerator(net.glowstone.generator.GlowChunkGenerator)

Example 73 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 74 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 75 with MaterialData

use of org.bukkit.material.MaterialData in project Essentials by drtshock.

the class YamlStorageWriter method writeMaterialData.

private void writeMaterialData(final Object data) {
    final MaterialData matData = (MaterialData) data;
    writeMaterial(matData.getItemType());
    if (matData.getData() > 0) {
        writer.print(':');
        writer.print(matData.getData());
    }
}
Also used : MaterialData(org.bukkit.material.MaterialData)

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