Search in sources :

Example 16 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class ElevatorPlate method openFloorSelector.

@ParametersAreNonnullByDefault
private void openFloorSelector(Block b, List<ElevatorFloor> floors, Player p, int page) {
    ChestMenu menu = new ChestMenu(Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.pick-a-floor"));
    menu.setEmptySlotsClickable(false);
    int index = GUI_SIZE * (page - 1);
    for (int i = 0; i < Math.min(GUI_SIZE, floors.size() - index); i++) {
        ElevatorFloor floor = floors.get(index + i);
        // @formatter:off
        if (floor.getAltitude() == b.getY()) {
            menu.addItem(i, new CustomItemStack(Material.COMPASS, ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.current-floor") + ' ' + ChatColor.WHITE + floor.getName()), ChestMenuUtils.getEmptyClickHandler());
        } else {
            menu.addItem(i, new CustomItemStack(Material.PAPER, ChatColor.GRAY.toString() + floor.getNumber() + ". " + ChatColor.BLACK + floor.getName(), Slimefun.getLocalization().getMessage(p, "machines.ELEVATOR.click-to-teleport") + ' ' + ChatColor.WHITE + floor.getName()), (player, slot, itemStack, clickAction) -> {
                teleport(player, floor);
                return false;
            });
        }
    // @formatter:on
    }
    int pages = 1 + (floors.size() / GUI_SIZE);
    // 0 index so size is the first slot of the last row.
    for (int i = GUI_SIZE; i < GUI_SIZE + 9; i++) {
        if (i == GUI_SIZE + 2 && pages > 1 && page != 1) {
            menu.addItem(i, ChestMenuUtils.getPreviousButton(p, page, pages), (player, i1, itemStack, clickAction) -> {
                openFloorSelector(b, floors, p, page - 1);
                return false;
            });
        } else if (i == GUI_SIZE + 6 && pages > 1 && page != pages) {
            menu.addItem(i, ChestMenuUtils.getNextButton(p, page, pages), (player, i1, itemStack, clickAction) -> {
                openFloorSelector(b, floors, p, page + 1);
                return false;
            });
        } else {
            menu.addItem(i, ChestMenuUtils.getBackground(), (player, i1, itemStack, clickAction) -> false);
        }
    }
    menu.open(p);
}
Also used : BlockUseHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockUseHandler) BlockStorage(me.mrCookieSlime.Slimefun.api.BlockStorage) Player(org.bukkit.entity.Player) PaperLib(io.papermc.lib.PaperLib) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Inventory(org.bukkit.inventory.Inventory) HashSet(java.util.HashSet) ChatColors(io.github.bakedlibs.dough.common.ChatColors) Block(org.bukkit.block.Block) SimpleSlimefunItem(io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem) Location(org.bukkit.Location) WorldUtils(io.github.thebusybiscuit.slimefun4.utils.WorldUtils) RecipeType(io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) Material(org.bukkit.Material) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) BlockPlaceHandler(io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler) ItemGroup(io.github.thebusybiscuit.slimefun4.api.items.ItemGroup) ChestMenuUtils(io.github.thebusybiscuit.slimefun4.utils.ChestMenuUtils) Set(java.util.Set) UUID(java.util.UUID) ChatUtils(io.github.thebusybiscuit.slimefun4.utils.ChatUtils) ItemStack(org.bukkit.inventory.ItemStack) List(java.util.List) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Slimefun(io.github.thebusybiscuit.slimefun4.implementation.Slimefun) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ChatColor(org.bukkit.ChatColor) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ChestMenu(me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 17 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class MagicWorkbench method craft.

@ParametersAreNonnullByDefault
private void craft(Inventory inv, Block dispenser, Player p, Block b, ItemStack output) {
    Inventory fakeInv = createVirtualInventory(inv);
    Inventory outputInv = findOutputInventory(output, dispenser, inv, fakeInv);
    if (outputInv != null) {
        SlimefunItem sfItem = SlimefunItem.getByItem(output);
        if (sfItem instanceof SlimefunBackpack) {
            upgradeBackpack(p, inv, (SlimefunBackpack) sfItem, output);
        }
        for (int j = 0; j < 9; j++) {
            if (inv.getContents()[j] != null && inv.getContents()[j].getType() != Material.AIR) {
                if (inv.getContents()[j].getAmount() > 1) {
                    inv.setItem(j, new CustomItemStack(inv.getContents()[j], inv.getContents()[j].getAmount() - 1));
                } else {
                    inv.setItem(j, null);
                }
            }
        }
        startAnimation(p, b, inv, dispenser, output);
    } else {
        Slimefun.getLocalization().sendMessage(p, "machines.full-inventory", true);
    }
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) SlimefunBackpack(io.github.thebusybiscuit.slimefun4.implementation.items.backpacks.SlimefunBackpack) SlimefunItem(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem) Inventory(org.bukkit.inventory.Inventory) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault)

Example 18 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class ProduceCollector method getDisplayRecipes.

@Override
@Nonnull
public List<ItemStack> getDisplayRecipes() {
    List<ItemStack> displayRecipes = new ArrayList<>();
    displayRecipes.add(new CustomItemStack(Material.BUCKET, null, "&fRequires &bCow &fnearby"));
    displayRecipes.add(new ItemStack(Material.MILK_BUCKET));
    if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
        displayRecipes.add(new CustomItemStack(Material.BUCKET, null, "&fRequires &bGoat &fnearby"));
        displayRecipes.add(new ItemStack(Material.MILK_BUCKET));
    }
    displayRecipes.add(new CustomItemStack(Material.BOWL, null, "&fRequires &bMooshroom &fnearby"));
    displayRecipes.add(new ItemStack(Material.MUSHROOM_STEW));
    return displayRecipes;
}
Also used : ArrayList(java.util.ArrayList) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) Nonnull(javax.annotation.Nonnull)

Example 19 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestItemStackWrapper method testWrapperChecking.

@Test
@DisplayName("Test if the ItemStackWrapper static method constructors are checking for nested wrapping properly")
void testWrapperChecking() {
    Assertions.assertThrows(IllegalArgumentException.class, () -> ItemStackWrapper.wrap(null));
    Assertions.assertThrows(IllegalArgumentException.class, () -> ItemStackWrapper.forceWrap(null));
    ItemStack item = new CustomItemStack(Material.IRON_INGOT, "A Name", "line 1", "line2");
    ItemStackWrapper wrapper = ItemStackWrapper.wrap(item);
    ItemStackWrapper secondWrap = ItemStackWrapper.wrap(wrapper);
    // We want to check that the wrapper returned is of reference equality
    Assertions.assertSame(wrapper, secondWrap);
    ItemStackWrapper forceSecondWrap = ItemStackWrapper.forceWrap(wrapper);
    // Want to check that the wrapper returned is of different reference equality
    Assertions.assertNotSame(wrapper, forceSecondWrap);
    assertWrapped(wrapper, forceSecondWrap);
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStackWrapper(io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 20 with CustomItemStack

use of io.github.bakedlibs.dough.items.CustomItemStack in project Slimefun4 by Slimefun.

the class TestItemStackWrapper method testImmutability.

@Test
@DisplayName("Test if an ItemStackWrapper is immutable")
void testImmutability() {
    ItemStack item = new CustomItemStack(Material.LAVA_BUCKET, "&4SuperHot.exe", "", "&6Hello");
    ItemStackWrapper wrapper = ItemStackWrapper.wrap(item);
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setType(Material.BEDROCK));
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setAmount(3));
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.setItemMeta(item.getItemMeta()));
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.addUnsafeEnchantment(null, 1));
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.hashCode());
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.clone());
    Assertions.assertThrows(UnsupportedOperationException.class, () -> wrapper.equals(wrapper));
}
Also used : CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) CustomItemStack(io.github.bakedlibs.dough.items.CustomItemStack) ItemStackWrapper(io.github.thebusybiscuit.slimefun4.utils.itemstack.ItemStackWrapper) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

CustomItemStack (io.github.bakedlibs.dough.items.CustomItemStack)172 Test (org.junit.jupiter.api.Test)100 DisplayName (org.junit.jupiter.api.DisplayName)90 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)83 ItemStack (org.bukkit.inventory.ItemStack)70 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)43 NamespacedKey (org.bukkit.NamespacedKey)31 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 Player (org.bukkit.entity.Player)25 ChestMenu (me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.ChestMenu)22 ItemGroup (io.github.thebusybiscuit.slimefun4.api.items.ItemGroup)20 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)18 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)12 PlayerProfile (io.github.thebusybiscuit.slimefun4.api.player.PlayerProfile)11 FlexItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.FlexItemGroup)10 ArrayList (java.util.ArrayList)10 Nonnull (javax.annotation.Nonnull)10 Material (org.bukkit.Material)10 LockedItemGroup (io.github.thebusybiscuit.slimefun4.api.items.groups.LockedItemGroup)9 Location (org.bukkit.Location)9