Search in sources :

Example 41 with GlowBlockState

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

the class BlockFlowerPot method getDrops.

@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    List<ItemStack> drops = new LinkedList<>(Arrays.asList(new ItemStack(Material.FLOWER_POT)));
    GlowBlockState state = block.getState();
    if (state instanceof GlowFlowerPot) {
        MaterialData contents = ((GlowFlowerPot) state).getContents();
        if (contents != null) {
            drops.add(new ItemStack(contents.getItemType(), 1, contents.getData()));
        }
    }
    return Collections.unmodifiableList(drops);
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) ItemStack(org.bukkit.inventory.ItemStack) GlowFlowerPot(net.glowstone.block.state.GlowFlowerPot)

Example 42 with GlowBlockState

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

the class BlockGrass method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
        // grass block turns into dirt block
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    } else if (blockAbove.getLightLevel() >= 9) {
        GlowWorld world = block.getWorld();
        int sourceX = block.getX();
        int sourceY = block.getY();
        int sourceZ = block.getZ();
        // grass spread randomly around
        for (int i = 0; i < 4; i++) {
            int x = sourceX + random.nextInt(3) - 1;
            int z = sourceZ + random.nextInt(3) - 1;
            int y = sourceY + random.nextInt(5) - 3;
            GlowBlock targetBlock = world.getBlockAt(x, y, z);
            GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
            if (targetBlock.getChunk().isLoaded() && targetAbove.getChunk().isLoaded() && targetBlock.getType() == Material.DIRT && // only spread on normal dirt
            targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
                GlowBlockState state = targetBlock.getState();
                state.setType(Material.GRASS);
                state.setRawData((byte) 0);
                BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
                EventFactory.callEvent(spreadEvent);
                if (!spreadEvent.isCancelled()) {
                    state.update(true);
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 43 with GlowBlockState

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

the class BlockMycel method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
        // mycel block turns into dirt block
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    } else if (blockAbove.getLightLevel() >= 9) {
        GlowWorld world = block.getWorld();
        int sourceX = block.getX();
        int sourceY = block.getY();
        int sourceZ = block.getZ();
        // mycel spread randomly around
        for (int i = 0; i < 4; i++) {
            int x = sourceX + random.nextInt(3) - 1;
            int z = sourceZ + random.nextInt(3) - 1;
            int y = sourceY + random.nextInt(5) - 3;
            GlowBlock targetBlock = world.getBlockAt(x, y, z);
            GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
            if (targetBlock.getType() == Material.DIRT && // only spread on normal dirt
            targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
                GlowBlockState state = targetBlock.getState();
                state.setType(Material.MYCEL);
                state.setRawData((byte) 0);
                BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
                EventFactory.callEvent(spreadEvent);
                if (!spreadEvent.isCancelled()) {
                    state.update(true);
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 44 with GlowBlockState

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

the class BlockNetherWart method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    int cropState = block.getData();
    if (cropState < NetherWartsState.RIPE.ordinal() && random.nextInt(10) == 0) {
        cropState++;
        GlowBlockState state = block.getState();
        state.setRawData((byte) cropState);
        BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
        EventFactory.callEvent(growEvent);
        if (!growEvent.isCancelled()) {
            state.update(true);
        }
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 45 with GlowBlockState

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

the class BlockFenceGate method onRedstoneUpdate.

@Override
public void onRedstoneUpdate(GlowBlock block) {
    GlowBlockState state = block.getState();
    Gate gate = (Gate) state.getData();
    boolean powered = block.isBlockIndirectlyPowered();
    if (powered != gate.isOpen()) {
        gate.setOpen(powered);
        state.update();
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) Gate(org.bukkit.material.Gate)

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