Search in sources :

Example 36 with GlowBlockState

use of net.glowstone.block.GlowBlockState 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 37 with GlowBlockState

use of net.glowstone.block.GlowBlockState 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 38 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockRedstoneOre method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    EntityChangeBlockEvent changeBlockEvent = new EntityChangeBlockEvent(player, block, Material.GLOWING_REDSTONE_ORE, (byte) 0);
    EventFactory.callEvent(changeBlockEvent);
    if (!changeBlockEvent.isCancelled()) {
        GlowBlockState state = block.getState();
        state.setType(Material.GLOWING_REDSTONE_ORE);
        state.update(true);
    }
    return false;
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) EntityChangeBlockEvent(org.bukkit.event.entity.EntityChangeBlockEvent)

Example 39 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class ItemSeeds method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    if (target.getType() == soilType && target.getRelative(BlockFace.UP).getType() == Material.AIR && face == BlockFace.UP) {
        GlowBlockState state = target.getRelative(BlockFace.UP).getState();
        state.setType(cropsType);
        state.setRawData((byte) 0);
        state.update(true);
        // deduct from stack if not in creative mode
        if (player.getGameMode() != GameMode.CREATIVE) {
            holding.setAmount(holding.getAmount() - 1);
        }
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Example 40 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockFire method burnBlock.

private void burnBlock(GlowBlock block, int burnResistance, int fireAge) {
    if (random.nextInt(burnResistance) < block.getMaterialValues().getFireResistance()) {
        BlockBurnEvent burnEvent = new BlockBurnEvent(block);
        EventFactory.callEvent(burnEvent);
        if (!burnEvent.isCancelled()) {
            if (block.getType() == Material.TNT) {
                BlockTNT.igniteBlock(block, false);
            } else {
                GlowBlockState state = block.getState();
                if (random.nextInt(10 + fireAge) < 5 && !GlowBiomeClimate.isRainy(block)) {
                    int increasedAge = increaseFireAge(fireAge);
                    state.setType(Material.FIRE);
                    state.setRawData((byte) (increasedAge > MAX_FIRE_AGE ? MAX_FIRE_AGE : increasedAge));
                } else {
                    state.setType(Material.AIR);
                    state.setRawData((byte) 0);
                }
                state.update(true);
            }
        }
    }
}
Also used : BlockBurnEvent(org.bukkit.event.block.BlockBurnEvent) GlowBlockState(net.glowstone.block.GlowBlockState)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)54 GlowBlock (net.glowstone.block.GlowBlock)21 MaterialData (org.bukkit.material.MaterialData)20 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowWorld (net.glowstone.GlowWorld)10 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)7 BlockFace (org.bukkit.block.BlockFace)6 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)5 ItemStack (org.bukkit.inventory.ItemStack)4 Material (org.bukkit.Material)3 Block (org.bukkit.block.Block)3 Door (org.bukkit.material.Door)3 DoublePlant (org.bukkit.material.DoublePlant)3 BlockType (net.glowstone.block.blocktype.BlockType)2 ItemType (net.glowstone.block.itemtype.ItemType)2 GlowDispenser (net.glowstone.block.state.GlowDispenser)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 BlockIgniteEvent (org.bukkit.event.block.BlockIgniteEvent)2 CocoaPlant (org.bukkit.material.CocoaPlant)2 CocoaPlantSize (org.bukkit.material.CocoaPlant.CocoaPlantSize)2