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);
}
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);
}
}
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;
}
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);
}
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));
}
Aggregations