Search in sources :

Example 66 with MaterialData

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

the class BlockWater method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    super.updateBlock(block);
    if (block.getLightFromBlocks() <= 11 - block.getMaterialValues().getLightOpacity()) {
        if (block.getRelative(BlockFace.UP).isEmpty() && hasNearSolidBlock(block) && GlowBiomeClimate.isCold(block)) {
            GlowBlockState state = block.getState();
            state.setType(Material.ICE);
            state.setData(new MaterialData(Material.ICE));
            BlockSpreadEvent spreadEvent = new BlockSpreadEvent(state.getBlock(), block, state);
            EventFactory.callEvent(spreadEvent);
            if (!spreadEvent.isCancelled()) {
                state.update(true);
            }
        }
    }
}
Also used : BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 67 with MaterialData

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

the class BlockTallGrass method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (data instanceof LongGrass) {
        GrassSpecies species = ((LongGrass) data).getSpecies();
        if (species == GrassSpecies.NORMAL || species == GrassSpecies.FERN_LIKE) {
            GlowBlockState headBlockState = block.getRelative(BlockFace.UP).getState();
            if (headBlockState.getType() == Material.AIR) {
                DoublePlantSpecies doublePlantSpecies = species == GrassSpecies.FERN_LIKE ? DoublePlantSpecies.LARGE_FERN : DoublePlantSpecies.DOUBLE_TALLGRASS;
                GlowBlockState blockState = block.getState();
                blockState.setType(Material.DOUBLE_PLANT);
                blockState.setData(new DoublePlant(doublePlantSpecies));
                headBlockState.setType(Material.DOUBLE_PLANT);
                headBlockState.setData(new DoublePlant(DoublePlantSpecies.PLANT_APEX));
                BlockGrowEvent growEvent = new BlockGrowEvent(block, blockState);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    blockState.update(true);
                    headBlockState.update(true);
                }
            }
        }
    } else {
        warnMaterialData(LongGrass.class, data);
    }
}
Also used : GrassSpecies(org.bukkit.GrassSpecies) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) LongGrass(org.bukkit.material.LongGrass) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent) DoublePlant(org.bukkit.material.DoublePlant)

Example 68 with MaterialData

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

the class BlockSkull method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowSkull skull = (GlowSkull) block.getState();
    skull.setSkullType(getType(holding.getDurability()));
    if (skull.getSkullType() == SkullType.PLAYER) {
        SkullMeta meta = (SkullMeta) holding.getItemMeta();
        if (meta != null) {
            skull.setOwner(meta.getOwner());
        }
    }
    MaterialData data = skull.getData();
    if (!(data instanceof Skull)) {
        warnMaterialData(Skull.class, data);
        return;
    }
    Skull skullData = (Skull) data;
    if (canRotate(skullData)) {
        // Can be rotated
        skull.setRotation(player.getFacing().getOppositeFace());
    }
    skull.update();
    // Wither
    for (int i = 0; i < 3; i++) {
        if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
            block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
            break;
        }
    }
}
Also used : GlowSkull(net.glowstone.block.state.GlowSkull) GlowSkull(net.glowstone.block.state.GlowSkull) Skull(org.bukkit.material.Skull) SkullMeta(org.bukkit.inventory.meta.SkullMeta) MaterialData(org.bukkit.material.MaterialData)

Example 69 with MaterialData

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

the class MelonDecorator method populate.

@Override
public void populate(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.getSeaLevel() << 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);
        if (world.getBlockAt(x, y, z).getType() == Material.AIR && world.getBlockAt(x, y - 1, z).getType() == Material.GRASS) {
            BlockState state = world.getBlockAt(x, y, z).getState();
            state.setType(Material.MELON_BLOCK);
            state.setData(new MaterialData(Material.MELON_BLOCK));
            state.update(true);
        }
    }
}
Also used : BlockState(org.bukkit.block.BlockState) MaterialData(org.bukkit.material.MaterialData)

Example 70 with MaterialData

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

the class GroundGenerator method generateTerrainColumn.

public void generateTerrainColumn(ChunkData chunkData, World world, Random random, int x, int z, Biome biome, double surfaceNoise) {
    int seaLevel = world.getSeaLevel();
    MaterialData topMat = topMaterial;
    MaterialData groundMat = groundMaterial;
    int chunkX = x;
    int chunkZ = z;
    x &= 0xF;
    z &= 0xF;
    int surfaceHeight = Math.max((int) (surfaceNoise / 3.0D + 3.0D + random.nextDouble() * 0.25D), 1);
    int deep = -1;
    for (int y = 255; y >= 0; y--) {
        if (y <= random.nextInt(5)) {
            chunkData.setBlock(x, y, z, Material.BEDROCK);
        } else {
            Material mat = chunkData.getType(x, y, z);
            if (mat == Material.AIR) {
                deep = -1;
            } else if (mat == Material.STONE) {
                if (deep == -1) {
                    if (y >= seaLevel - 5 && y <= seaLevel) {
                        topMat = topMaterial;
                        groundMat = groundMaterial;
                    }
                    deep = surfaceHeight;
                    if (y >= seaLevel - 2) {
                        chunkData.setBlock(x, y, z, topMat);
                    } else if (y < seaLevel - 8 - surfaceHeight) {
                        topMat = AIR;
                        groundMat = STONE;
                        chunkData.setBlock(x, y, z, Material.GRAVEL);
                    } else {
                        chunkData.setBlock(x, y, z, groundMat);
                    }
                } else if (deep > 0) {
                    deep--;
                    chunkData.setBlock(x, y, z, groundMat);
                    if (deep == 0 && groundMat.getItemType() == Material.SAND) {
                        deep = random.nextInt(4) + Math.max(0, y - seaLevel - 1);
                        groundMat = SANDSTONE;
                    }
                }
            } else if (mat == Material.STATIONARY_WATER && y == seaLevel - 2 && GlowBiomeClimate.isCold(biome, chunkX, y, chunkZ)) {
                chunkData.setBlock(x, y, z, Material.ICE);
            }
        }
    }
}
Also used : Material(org.bukkit.Material) 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