Search in sources :

Example 31 with GlowBlockState

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

the class BlockBed method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    if (block.getType() == Material.BED_BLOCK) {
        BlockFace direction = ((Bed) block.getState().getData()).getFacing();
        GlowBlock headBlock = block.getRelative(direction);
        headBlock.setType(Material.BED_BLOCK);
        GlowBlockState headBlockState = headBlock.getState();
        MaterialData data = headBlockState.getData();
        ((Bed) data).setHeadOfBed(true);
        ((Bed) data).setFacingDirection(direction);
        headBlockState.setData(data);
        headBlockState.update(true);
    }
}
Also used : Bed(org.bukkit.material.Bed) GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 32 with GlowBlockState

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

the class BlockCrops method grow.

@Override
public void grow(GlowPlayer player, GlowBlock block) {
    GlowBlockState state = block.getState();
    int cropState = block.getData() + random.nextInt(CropState.MEDIUM.ordinal()) + CropState.VERY_SMALL.ordinal();
    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);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 33 with GlowBlockState

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

the class BlockSoil method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (isNearWater(block) || GlowBiomeClimate.isRainy(block)) {
        // set this block as fully wet
        block.setData((byte) 7);
    } else if (block.getData() > 0) {
        // if this block is wet, it becomes less wet
        block.setData((byte) (block.getData() - 1));
    } else if (!Arrays.asList(possibleCrops).contains(block.getRelative(BlockFace.UP).getType())) {
        // turns block back to dirt if nothing is planted on
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        state.setRawData((byte) 0);
        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 34 with GlowBlockState

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

the class BlockStem method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // in order to grow naturally (vanilla behavior)
    if (block.getRelative(BlockFace.UP).getLightLevel() >= 9 && random.nextInt((int) (25.0F / getGrowthRateModifier(block)) + 1) == 0) {
        int cropState = block.getData();
        if (cropState >= CropState.RIPE.ordinal()) {
            // check around there's not already a fruit
            if (block.getRelative(BlockFace.EAST).getType() == fruitType || block.getRelative(BlockFace.WEST).getType() == fruitType || block.getRelative(BlockFace.NORTH).getType() == fruitType || block.getRelative(BlockFace.SOUTH).getType() == fruitType) {
                return;
            }
            // produce a fruit if possible
            int n = random.nextInt(4);
            BlockFace face;
            switch(n) {
                case 1:
                    face = BlockFace.WEST;
                    break;
                case 2:
                    face = BlockFace.NORTH;
                    break;
                case 3:
                    face = BlockFace.SOUTH;
                    break;
                default:
                    face = BlockFace.EAST;
            }
            GlowBlock targetBlock = block.getRelative(face);
            GlowBlockState targetBlockState = targetBlock.getState();
            GlowBlock belowTargetBlock = targetBlock.getRelative(BlockFace.DOWN);
            if (targetBlock.getType() == Material.AIR && (belowTargetBlock.getType() == Material.SOIL || belowTargetBlock.getType() == Material.DIRT || belowTargetBlock.getType() == Material.GRASS)) {
                targetBlockState.setType(fruitType);
                if (fruitType == Material.PUMPKIN) {
                    targetBlockState.setData(new Pumpkin(face.getOppositeFace()));
                }
                targetBlockState.update(true);
            }
        } else {
            cropState++;
            GlowBlockState state = block.getState();
            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 : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) Pumpkin(org.bukkit.material.Pumpkin) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 35 with GlowBlockState

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

the class BlockVine method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    if (random.nextInt(4) == 0) {
        GlowBlockState state = block.getState();
        MaterialData data = state.getData();
        if (data instanceof Vine) {
            Vine vine = (Vine) data;
            boolean hasNearVineBlocks = hasNearVineBlocks(block);
            BlockFace face = FACES[random.nextInt(FACES.length)];
            if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
                if (!hasNearVineBlocks) {
                    Vine v = (Vine) data;
                    for (BlockFace f : HORIZONTAL_FACES) {
                        if (random.nextInt(2) == 0 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
                            v.removeFromFace(f);
                        }
                    }
                    putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
                }
            } else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
                if (!hasNearVineBlocks) {
                    GlowBlock b = block.getRelative(face);
                    if (b.isEmpty()) {
                        BlockFace clockwiseFace = getClockwiseFace(face);
                        BlockFace counterClockwiseFace = getCounterClockwiseFace(face);
                        GlowBlock clockwiseBlock = b.getRelative(clockwiseFace);
                        GlowBlock counterClockwiseBlock = b.getRelative(counterClockwiseFace);
                        boolean isOnCWFace = vine.isOnFace(clockwiseFace);
                        boolean isOnCCWFace = vine.isOnFace(counterClockwiseFace);
                        if (isOnCWFace && clockwiseBlock.getType().isSolid()) {
                            putVine(b, new Vine(clockwiseFace), block);
                        } else if (isOnCCWFace && counterClockwiseBlock.getType().isSolid()) {
                            putVine(b, new Vine(counterClockwiseFace), block);
                        } else if (isOnCWFace && clockwiseBlock.isEmpty() && block.getRelative(clockwiseFace).getType().isSolid()) {
                            putVine(clockwiseBlock, new Vine(face.getOppositeFace()), block);
                        } else if (isOnCCWFace && counterClockwiseBlock.isEmpty() && block.getRelative(counterClockwiseFace).getType().isSolid()) {
                            putVine(counterClockwiseBlock, new Vine(face.getOppositeFace()), block);
                        } else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
                            putVine(b, new Vine(), block);
                        }
                    } else if (b.getType().isOccluding()) {
                        vine.putOnFace(face);
                        putVine(block, vine, null);
                    }
                }
            } else if (block.getY() > 1) {
                GlowBlock b = block.getRelative(BlockFace.DOWN);
                Vine v = (Vine) data;
                if (b.getType() == Material.VINE || b.isEmpty()) {
                    for (BlockFace f : HORIZONTAL_FACES) {
                        if (random.nextInt(2) == 0) {
                            v.removeFromFace(f);
                        }
                    }
                    putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
                }
            }
        } else {
            warnMaterialData(Vine.class, data);
        }
    }
}
Also used : Vine(org.bukkit.material.Vine) GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

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