Search in sources :

Example 81 with MaterialData

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

the class BlockIce method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (block.getLightFromBlocks() > 11 - block.getMaterialValues().getLightOpacity()) {
        Material type = block.getWorld().getEnvironment() == Environment.NETHER ? Material.AIR : Material.STATIONARY_WATER;
        GlowBlockState state = block.getState();
        state.setType(type);
        state.setData(new MaterialData(type));
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    }
}
Also used : BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) GlowBlockState(net.glowstone.block.GlowBlockState) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData)

Example 82 with MaterialData

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

the class BlockLadder 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 Ladder) {
        if (face != BlockFace.DOWN && face != BlockFace.UP && isTargetOccluding(state, face.getOppositeFace())) {
            ((Ladder) data).setFacingDirection(face.getOppositeFace());
        } else {
            if (isTargetOccluding(state, BlockFace.SOUTH)) {
                ((Ladder) data).setFacingDirection(BlockFace.SOUTH);
            } else if (isTargetOccluding(state, BlockFace.WEST)) {
                ((Ladder) data).setFacingDirection(BlockFace.WEST);
            } else if (isTargetOccluding(state, BlockFace.NORTH)) {
                ((Ladder) data).setFacingDirection(BlockFace.NORTH);
            } else if (isTargetOccluding(state, BlockFace.EAST)) {
                ((Ladder) data).setFacingDirection(BlockFace.EAST);
            } else {
                return;
            }
        }
        state.setData(data);
    } else {
        warnMaterialData(Ladder.class, data);
    }
}
Also used : Ladder(org.bukkit.material.Ladder) MaterialData(org.bukkit.material.MaterialData)

Example 83 with MaterialData

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

the class BlockOpenable method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowBlockState blockState = block.getState();
    MaterialData materialData = blockState.getData();
    if (materialData instanceof Openable) {
        Openable toOpen = (Openable) materialData;
        boolean wasOpen = toOpen.isOpen();
        toOpen.setOpen(!wasOpen);
        if (wasOpen) {
            onClosed(player, block, face, clickedLoc, blockState, materialData);
        } else {
            onOpened(player, block, face, clickedLoc, blockState, materialData);
        }
        blockState.update(true);
        return true;
    } else {
        warnMaterialData(Openable.class, materialData);
        return false;
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Openable(org.bukkit.material.Openable)

Example 84 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 85 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)

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