Search in sources :

Example 6 with GlowBlock

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

use of net.glowstone.block.GlowBlock 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 8 with GlowBlock

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

the class BlockHopper method pullItems.

private void pullItems(GlowBlock block, HopperEntity hopper) {
    GlowBlock source = block.getRelative(BlockFace.UP);
    MaterialData data = source.getState().getData();
    if (!source.getType().isSolid() || (data instanceof Step && !((Step) data).isInverted()) || (data instanceof WoodenStep && !((WoodenStep) data).isInverted()) || (data instanceof Sign) || (data instanceof Rails)) {
        GlowItem item = getFirstDroppedItem(source.getLocation());
        if (item == null) {
            return;
        }
        ItemStack stack = item.getItemStack();
        HashMap<Integer, ItemStack> add = hopper.getInventory().addItem(stack);
        if (add.size() > 0) {
            item.setItemStack(add.get(0));
        } else {
            item.remove();
        }
    } else if (source.getBlockEntity() != null && source.getBlockEntity() instanceof ContainerEntity) {
        ContainerEntity sourceContainer = (ContainerEntity) source.getBlockEntity();
        if (sourceContainer.getInventory() == null || sourceContainer.getInventory().getContents().length == 0) {
            return;
        }
        ItemStack item = getFirstItem(sourceContainer);
        if (item == null) {
            return;
        }
        ItemStack clone = item.clone();
        clone.setAmount(1);
        if (hopper.getInventory().addItem(clone).size() > 0) {
            return;
        }
        if (item.getAmount() - 1 == 0) {
            sourceContainer.getInventory().remove(item);
        } else {
            item.setAmount(item.getAmount() - 1);
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) ContainerEntity(net.glowstone.block.entity.ContainerEntity) ItemStack(org.bukkit.inventory.ItemStack) GlowItem(net.glowstone.entity.objects.GlowItem)

Example 9 with GlowBlock

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

the class BlockLever method extraUpdate.

private void extraUpdate(GlowBlock block) {
    Lever lever = (Lever) block.getState().getData();
    ItemTable itemTable = ItemTable.instance();
    GlowBlock target = block.getRelative(lever.getAttachedFace());
    if (target.getType().isSolid()) {
        for (BlockFace face2 : ADJACENT) {
            GlowBlock target2 = target.getRelative(face2);
            BlockType notifyType = itemTable.getBlock(target2.getTypeId());
            if (notifyType != null) {
                if (target2.getFace(block) == null) {
                    notifyType.onNearBlockChanged(target2, BlockFace.SELF, block, block.getType(), block.getData(), block.getType(), block.getData());
                }
                notifyType.onRedstoneUpdate(target2);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Lever(org.bukkit.material.Lever) ItemTable(net.glowstone.block.ItemTable) BlockFace(org.bukkit.block.BlockFace)

Example 10 with GlowBlock

use of net.glowstone.block.GlowBlock 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)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)72 BlockFace (org.bukkit.block.BlockFace)23 GlowBlockState (net.glowstone.block.GlowBlockState)21 Block (org.bukkit.block.Block)16 GlowWorld (net.glowstone.GlowWorld)14 MaterialData (org.bukkit.material.MaterialData)13 ItemTable (net.glowstone.block.ItemTable)10 BlockType (net.glowstone.block.blocktype.BlockType)7 ItemType (net.glowstone.block.itemtype.ItemType)7 Material (org.bukkit.Material)7 Vector (org.bukkit.util.Vector)7 BlockEntity (net.glowstone.block.entity.BlockEntity)6 ItemStack (org.bukkit.inventory.ItemStack)6 BlockVector (org.bukkit.util.BlockVector)5 Message (com.flowpowered.network.Message)4 IOException (java.io.IOException)4 GlowPlayer (net.glowstone.entity.GlowPlayer)4 Title (com.destroystokyo.paper.Title)3 ByteBufUtils (com.flowpowered.network.util.ByteBufUtils)3 Preconditions (com.google.common.base.Preconditions)3