Search in sources :

Example 11 with GlowBlockState

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

the class BlockLitRedstoneOre method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlockState state = block.getState();
    state.setType(Material.REDSTONE_ORE);
    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)

Example 12 with GlowBlockState

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

the class BlockLog method blockDestroy.

@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
    // vanilla set leaf decay check in a 9x9x9 neighboring when a log block is removed
    GlowWorld world = block.getWorld();
    for (int x = 0; x < 9; x++) {
        for (int z = 0; z < 9; z++) {
            for (int y = 0; y < 9; y++) {
                GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
                if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
                    GlowBlockState state = b.getState();
                    if ((state.getRawData() & 0x08) == 0 && (state.getRawData() & 0x04) == 0) {
                        // check decay is off and decay is on
                        // set decay check on for this leaves block
                        state.setRawData((byte) (state.getRawData() | 0x08));
                        state.update(true);
                    }
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 13 with GlowBlockState

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

the class BlockLava method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    super.updateBlock(block);
    if (!block.getWorld().getGameRuleMap().getBoolean("doFireTick")) {
        return;
    }
    int n = random.nextInt(3);
    if (n == 0) {
        for (int i = 0; i < 3; i++) {
            GlowBlock b = (GlowBlock) block.getLocation().add(-1 + random.nextInt(3), 0, -1 + random.nextInt(3)).getBlock();
            GlowBlock bAbove = b.getRelative(BlockFace.UP);
            if (bAbove.isEmpty() && b.isFlammable()) {
                BlockIgniteEvent igniteEvent = new BlockIgniteEvent(bAbove, IgniteCause.LAVA, block);
                EventFactory.callEvent(igniteEvent);
                if (!igniteEvent.isCancelled()) {
                    GlowBlockState state = bAbove.getState();
                    state.setType(Material.FIRE);
                    state.update(true);
                }
            }
        }
    } else {
        for (int i = 0; i < n; i++) {
            GlowBlock b = (GlowBlock) block.getLocation().add(-1 + random.nextInt(3), 1, -1 + random.nextInt(3)).getBlock();
            if (b.isEmpty()) {
                if (hasNearFlammableBlock(b)) {
                    BlockIgniteEvent igniteEvent = new BlockIgniteEvent(b, IgniteCause.LAVA, block);
                    EventFactory.callEvent(igniteEvent);
                    if (!igniteEvent.isCancelled()) {
                        GlowBlockState state = b.getState();
                        state.setType(Material.FIRE);
                        state.update(true);
                    }
                    break;
                }
            } else if (b.getType().isSolid()) {
                break;
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockIgniteEvent(org.bukkit.event.block.BlockIgniteEvent)

Example 14 with GlowBlockState

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

the class BlockStateDelegate method setType.

/**
     * Sets a block type and add it to the BlockState list.
     *
     * @param world the world which contains the block
     * @param x     the x-coordinate of this block
     * @param y     the y-coordinate of this block
     * @param z     the z-coordinate of this block
     * @param type  the new type of this block
     */
public void setType(World world, int x, int y, int z, Material type) {
    GlowBlockState state = (GlowBlockState) world.getBlockAt(x, y, z).getState();
    state.setType(type);
    blockStateMap.put(world.getBlockAt(x, y, z).getLocation(), state);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Example 15 with GlowBlockState

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

the class BlockCrops method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlockState state = block.getState();
    int cropState = block.getData();
    // in order to grow naturally (vanilla behavior)
    if (cropState < CropState.RIPE.ordinal() && block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
        cropState++;
        if (cropState > CropState.RIPE.ordinal()) {
            cropState = CropState.RIPE.ordinal();
        }
        state.setRawData((byte) cropState);
        BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            state.update(true);
        }
    }
    // we check for insufficient light on the block itself, then drop
    if (block.getLightLevel() < 8) {
        block.breakNaturally();
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

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