Search in sources :

Example 1 with DoublePlantSpecies

use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method blockDestroy.

@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
    MaterialData data = block.getState().getData();
    if (data instanceof DoublePlant) {
        DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
        if (species == DoublePlantSpecies.PLANT_APEX) {
            GlowBlock blockUnder = block.getRelative(BlockFace.DOWN);
            if (!(blockUnder.getState().getData() instanceof DoublePlant)) {
                return;
            }
            blockUnder.setType(Material.AIR);
        } else {
            GlowBlock blockTop = block.getRelative(BlockFace.UP);
            if (!(blockTop.getState().getData() instanceof DoublePlant)) {
                return;
            }
            blockTop.setType(Material.AIR);
        }
    } else {
        warnMaterialData(DoublePlant.class, data);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 2 with DoublePlantSpecies

use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.

the class BlockDoublePlant method canAbsorb.

@Override
public boolean canAbsorb(GlowBlock block, BlockFace face, ItemStack holding) {
    MaterialData data = block.getState().getData();
    BlockType holdingType = ItemTable.instance().getBlock(holding.getType());
    if (data instanceof DoublePlant) {
        DoublePlantSpecies species = ((DoublePlant) data).getSpecies();
        if (species == DoublePlantSpecies.DOUBLE_TALLGRASS || species == DoublePlantSpecies.LARGE_FERN) {
            if (holdingType != null && holdingType.canPlaceAt(block, face)) {
                block.getRelative(BlockFace.UP).setType(Material.AIR, (byte) 0, false);
            }
            return true;
        }
        if (species == DoublePlantSpecies.PLANT_APEX) {
            GlowBlock under = block.getRelative(BlockFace.DOWN);
            MaterialData underData = under.getState().getData();
            if (underData instanceof DoublePlant) {
                DoublePlantSpecies underSpecies = ((DoublePlant) underData).getSpecies();
                if (underSpecies == DoublePlantSpecies.DOUBLE_TALLGRASS || underSpecies == DoublePlantSpecies.LARGE_FERN) {
                    if (holdingType != null && holdingType.canPlaceAt(block, face)) {
                        under.setType(Material.AIR, (byte) 0, false);
                    }
                    return true;
                }
            }
        }
    } else {
        warnMaterialData(DoublePlant.class, data);
    }
    return false;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) MaterialData(org.bukkit.material.MaterialData) DoublePlant(org.bukkit.material.DoublePlant)

Example 3 with DoublePlantSpecies

use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.

the class DoublePlantDecorator 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) + 32);
    DoublePlantSpecies species = getRandomDoublePlant(random, doublePlants);
    new DoubleTallPlant(species).generate(world, random, sourceX, sourceY, sourceZ);
}
Also used : DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) DoubleTallPlant(net.glowstone.generator.objects.DoubleTallPlant)

Example 4 with DoublePlantSpecies

use of org.bukkit.material.types.DoublePlantSpecies in project Glowstone by GlowstoneMC.

the class ForestPopulator method populateOnGround.

@Override
public void populateOnGround(World world, Random random, Chunk chunk) {
    int sourceX = chunk.getX() << 4;
    int sourceZ = chunk.getZ() << 4;
    int amount = random.nextInt(5) - doublePlantLoweringAmount;
    int i = 0;
    while (i < amount) {
        for (int j = 0; j < 5; j++, i++) {
            int x = sourceX + random.nextInt(16);
            int z = sourceZ + random.nextInt(16);
            int y = random.nextInt(world.getHighestBlockYAt(x, z) + 32);
            DoublePlantSpecies species = DOUBLE_PLANTS[random.nextInt(DOUBLE_PLANTS.length)];
            if (new DoubleTallPlant(species).generate(world, random, x, y, z)) {
                i++;
                break;
            }
        }
    }
    super.populateOnGround(world, random, chunk);
}
Also used : DoublePlantSpecies(org.bukkit.material.types.DoublePlantSpecies) DoubleTallPlant(net.glowstone.generator.objects.DoubleTallPlant)

Example 5 with DoublePlantSpecies

use of org.bukkit.material.types.DoublePlantSpecies 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)

Aggregations

DoublePlantSpecies (org.bukkit.material.types.DoublePlantSpecies)5 DoublePlant (org.bukkit.material.DoublePlant)3 MaterialData (org.bukkit.material.MaterialData)3 GlowBlock (net.glowstone.block.GlowBlock)2 DoubleTallPlant (net.glowstone.generator.objects.DoubleTallPlant)2 GlowBlockState (net.glowstone.block.GlowBlockState)1 GrassSpecies (org.bukkit.GrassSpecies)1 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)1 LongGrass (org.bukkit.material.LongGrass)1