Search in sources :

Example 1 with BlockMenu

use of me.mrCookieSlime.Slimefun.api.inventory.BlockMenu in project FluffyMachines by NCBPFluffyBear.

the class AdvancedAutoDisenchanter method onBreak.

private BlockBreakHandler onBreak() {
    return new BlockBreakHandler(false, false) {

        @Override
        public void onPlayerBreak(@Nonnull BlockBreakEvent e, @Nonnull ItemStack item, @Nonnull List<ItemStack> drops) {
            Block b = e.getBlock();
            BlockMenu inv = BlockStorage.getInventory(b);
            if (inv != null) {
                inv.dropItems(b.getLocation(), ITEM_SLOT);
                inv.dropItems(b.getLocation(), BOOK_SLOT);
                inv.dropItems(b.getLocation(), OUTPUT_SLOTS);
            }
        }
    };
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Nonnull(javax.annotation.Nonnull) BlockBreakHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 2 with BlockMenu

use of me.mrCookieSlime.Slimefun.api.inventory.BlockMenu in project FluffyMachines by NCBPFluffyBear.

the class AdvancedChargingBench method tick.

@Override
protected void tick(Block b) {
    if (getCharge(b.getLocation()) < getEnergyConsumption()) {
        return;
    }
    BlockMenu inv = BlockStorage.getInventory(b);
    tier = Integer.parseInt(BlockStorage.getLocationInfo(b.getLocation(), "tier"));
    for (int slot : getInputSlots()) {
        ItemStack item = inv.getItemInSlot(slot);
        if (charge(b, inv, slot, item, tier)) {
            return;
        }
    }
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 3 with BlockMenu

use of me.mrCookieSlime.Slimefun.api.inventory.BlockMenu in project FluffyMachines by NCBPFluffyBear.

the class AutoAncientAltar method craftIfValid.

private void craftIfValid(Block block, boolean craftOnce) {
    BlockMenu menu = BlockStorage.getInventory(block);
    List<ItemStack> pedestalItems = new ArrayList<>();
    // Make sure at least 1 slot is free
    for (int outSlot : getOutputSlots()) {
        ItemStack outItem = menu.getItemInSlot(outSlot);
        if (outItem == null || outItem.getAmount() < outItem.getMaxStackSize()) {
            break;
        } else if (outSlot == getOutputSlots()[1]) {
            return;
        }
    }
    for (int slot : getInputSlots()) {
        ItemStack slotItem = menu.getItemInSlot(slot);
        if (slotItem == null) {
            return;
        }
        Material type = slotItem.getType();
        if (!craftOnce && type.getMaxStackSize() != 1 && slotItem.getAmount() == 1) {
            return;
        }
    }
    // Check and append altar items
    for (int i = 0; i < 8; i++) {
        int slot = mockPedestalSlots[i];
        ItemStack pedestalItem = menu.getItemInSlot(slot);
        SlimefunItem sfPedestalItem = SlimefunItem.getByItem(pedestalItem);
        if (sfPedestalItem != null) {
            SlimefunItemStack pedestalItemStack = new SlimefunItemStack(sfPedestalItem.getId(), pedestalItem);
            pedestalItems.add(new SlimefunItemStack(pedestalItemStack, 1));
        } else {
            pedestalItems.add(new CustomItemStack(pedestalItem, 1));
        }
    }
    // Check and append catalyst
    int mockAltarSlot = 29;
    ItemStack catalystItem = menu.getItemInSlot(mockAltarSlot);
    SlimefunItem sfCatalyst = SlimefunItem.getByItem(catalystItem);
    ItemStack catalyst;
    if (sfCatalyst != null) {
        SlimefunItemStack catalystStack = new SlimefunItemStack(sfCatalyst.getId(), catalystItem);
        catalyst = new SlimefunItemStack(catalystStack, 1);
    } else if (!catalystItem.hasItemMeta()) {
        catalyst = new ItemStack(catalystItem.getType(), 1);
    } else {
        return;
    }
    if (Constants.isSoulJarsInstalled && sfCatalyst != null && sfCatalyst.getId().startsWith("FILLED") && sfCatalyst.getId().endsWith("SOUL_JAR")) {
        try {
            EntityType entityType = EntityType.valueOf(sfCatalyst.getId().replace("FILLED_", "").replace("_SOUL_JAR", ""));
            if (entityType == EntityType.UNKNOWN) {
                return;
            }
            BrokenSpawner brokenSpawner = SlimefunItems.BROKEN_SPAWNER.getItem(BrokenSpawner.class);
            ItemStack spawnerItem = brokenSpawner.getItemForEntityType(entityType);
            if (pedestalItems.equals(jarInputs)) {
                removeCharge(block.getLocation(), ENERGY_CONSUMPTION);
                for (int slot : getInputSlots()) {
                    menu.consumeItem(slot);
                }
                menu.pushItem(spawnerItem.clone(), getOutputSlots());
            }
        } catch (IllegalArgumentException ignored) {
        }
    } else if (SlimefunUtils.isItemSimilar(catalystItem, SlimefunItems.BROKEN_SPAWNER, false, false)) {
        Optional<ItemStack> result = checkRecipe(SlimefunItems.BROKEN_SPAWNER, pedestalItems);
        if (result.isPresent()) {
            RepairedSpawner spawner = (RepairedSpawner) SlimefunItems.REPAIRED_SPAWNER.getItem();
            ItemStack spawnerResult = spawner.getItemForEntityType(spawner.getEntityType(catalystItem).orElse(EntityType.PIG));
            craft(block, menu, spawnerResult);
        }
    } else {
        Optional<ItemStack> result = checkRecipe(catalyst, pedestalItems);
        result.ifPresent(itemStack -> craft(block, menu, itemStack));
    }
}
Also used : ItemTransportFlow(me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow) AltarRecipe(io.github.thebusybiscuit.slimefun4.implementation.items.altar.AltarRecipe) ClickAction(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ClickAction) Arrays(java.util.Arrays) AdvancedMenuClickHandler(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu.AdvancedMenuClickHandler) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) EnergyNetComponent(io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) Player(org.bukkit.entity.Player) EnergyNetComponentType(io.github.thebusybiscuit.slimefun4.core.networks.energy.EnergyNetComponentType) ArrayList(java.util.ArrayList) SlimefunItems(io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems) Block(org.bukkit.block.Block) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) BrokenSpawner(io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BrokenSpawner) BlockPlacerPlaceEvent(io.github.thebusybiscuit.slimefun4.api.events.BlockPlacerPlaceEvent) Nonnull(javax.annotation.Nonnull) DirtyChestMenu(me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu) Material(org.bukkit.Material) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) BlockBreakHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler) SlimefunUtils(io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils) Interaction(io.github.thebusybiscuit.slimefun4.libraries.dough.protection.Interaction) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) EntityType(org.bukkit.entity.EntityType) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) Config(me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) AncientAltar(io.github.thebusybiscuit.slimefun4.implementation.items.altar.AncientAltar) Constants(io.ncbpfluffybear.fluffymachines.utils.Constants) Optional(java.util.Optional) Comparator(java.util.Comparator) BlockMenuPreset(me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset) RepairedSpawner(io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner) BlockTicker(me.mrCookieSlime.Slimefun.Objects.handlers.BlockTicker) BrokenSpawner(io.github.thebusybiscuit.slimefun4.implementation.items.blocks.BrokenSpawner) BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Optional(java.util.Optional) ArrayList(java.util.ArrayList) RepairedSpawner(io.github.thebusybiscuit.slimefun4.implementation.items.blocks.RepairedSpawner) Material(org.bukkit.Material) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) EntityType(org.bukkit.entity.EntityType) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 4 with BlockMenu

use of me.mrCookieSlime.Slimefun.api.inventory.BlockMenu in project FluffyMachines by NCBPFluffyBear.

the class AutoCraftingTable method onBreak.

private BlockBreakHandler onBreak() {
    return new BlockBreakHandler(false, false) {

        @Override
        public void onPlayerBreak(@Nonnull BlockBreakEvent e, @Nonnull ItemStack item, @Nonnull List<ItemStack> drops) {
            Block b = e.getBlock();
            BlockMenu inv = BlockStorage.getInventory(b);
            Location location = b.getLocation();
            if (inv != null) {
                inv.dropItems(location, getInputSlots());
                inv.dropItems(location, getOutputSlots());
                inv.dropItems(location, keySlot);
            }
        }
    };
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Nonnull(javax.annotation.Nonnull) BlockBreakHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block) ArrayList(java.util.ArrayList) List(java.util.List) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Location(org.bukkit.Location)

Example 5 with BlockMenu

use of me.mrCookieSlime.Slimefun.api.inventory.BlockMenu in project FluffyMachines by NCBPFluffyBear.

the class AutoTableSaw method onBreak.

private BlockBreakHandler onBreak() {
    return new BlockBreakHandler(false, false) {

        @Override
        public void onPlayerBreak(@Nonnull BlockBreakEvent e, @Nonnull ItemStack item, @Nonnull List<ItemStack> drops) {
            Block b = e.getBlock();
            BlockMenu inv = BlockStorage.getInventory(b);
            Location location = b.getLocation();
            if (inv != null) {
                inv.dropItems(location, inputSlots);
                inv.dropItems(location, outputSlots);
            }
        }
    };
}
Also used : BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Nonnull(javax.annotation.Nonnull) BlockBreakHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) Block(org.bukkit.block.Block) List(java.util.List) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Location(org.bukkit.Location)

Aggregations

BlockMenu (me.mrCookieSlime.Slimefun.api.inventory.BlockMenu)96 ItemStack (org.bukkit.inventory.ItemStack)58 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)54 CustomItemStack (io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)41 Block (org.bukkit.block.Block)38 Nonnull (javax.annotation.Nonnull)27 List (java.util.List)18 BlockBreakEvent (org.bukkit.event.block.BlockBreakEvent)18 BlockBreakHandler (io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler)17 ArrayList (java.util.ArrayList)15 SimpleBlockBreakHandler (io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler)14 CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)13 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)13 UniversalBlockMenu (me.mrCookieSlime.Slimefun.api.inventory.UniversalBlockMenu)13 Location (org.bukkit.Location)12 Config (me.mrCookieSlime.CSCoreLibPlugin.Configuration.Config)9 InventoryBlock (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.InventoryBlock)9 BlockMenuPreset (me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset)7 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)6 MachineRecipe (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe)6