Search in sources :

Example 1 with ItemTransportFlow

use of me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow in project FluffyMachines by NCBPFluffyBear.

the class AutoCrafter method constructMenu.

private void constructMenu(String displayName) {
    new BlockMenuPreset(getId(), displayName) {

        @Override
        public void init() {
            constructMenu(this);
        }

        @Override
        public void newInstance(@Nonnull BlockMenu menu, @Nonnull Block b) {
            if (!BlockStorage.hasBlockInfo(b) || BlockStorage.getLocationInfo(b.getLocation(), "enabled") == null || BlockStorage.getLocationInfo(b.getLocation(), "enabled").equals(String.valueOf(false))) {
                menu.replaceExistingItem(6, new CustomItemStack(Material.GUNPOWDER, "&7Enabled: &4\u2718", "", "&e> Click to enable this Machine"));
                menu.addMenuClickHandler(6, (p, slot, item, action) -> {
                    BlockStorage.addBlockInfo(b, "enabled", String.valueOf(true));
                    newInstance(menu, b);
                    return false;
                });
            } else {
                menu.replaceExistingItem(6, new CustomItemStack(Material.REDSTONE, "&7Enabled: &2\u2714", "", "&e> Click to disable this Machine"));
                menu.addMenuClickHandler(6, (p, slot, item, action) -> {
                    BlockStorage.addBlockInfo(b, "enabled", String.valueOf(false));
                    newInstance(menu, b);
                    return false;
                });
            }
        }

        @Override
        public boolean canOpen(@Nonnull Block b, @Nonnull Player p) {
            return p.hasPermission("slimefun.inventory.bypass") || Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.INTERACT_BLOCK);
        }

        @Override
        public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
            return new int[0];
        }

        @Override
        public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportFlow flow, ItemStack item) {
            return getCustomItemTransport(menu, flow, item);
        }
    };
}
Also used : Player(org.bukkit.entity.Player) BlockMenu(me.mrCookieSlime.Slimefun.api.inventory.BlockMenu) Nonnull(javax.annotation.Nonnull) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) Block(org.bukkit.block.Block) DirtyChestMenu(me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) BlockMenuPreset(me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset) ItemTransportFlow(me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow)

Aggregations

SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)1 CustomItemStack (io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)1 Nonnull (javax.annotation.Nonnull)1 BlockMenu (me.mrCookieSlime.Slimefun.api.inventory.BlockMenu)1 BlockMenuPreset (me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset)1 DirtyChestMenu (me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu)1 ItemTransportFlow (me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow)1 Block (org.bukkit.block.Block)1 Player (org.bukkit.entity.Player)1 ItemStack (org.bukkit.inventory.ItemStack)1