From c8efc79e79191acc123c0423628776b27a1d10f5 Mon Sep 17 00:00:00 2001 From: Intybyte Date: Wed, 23 Oct 2024 13:29:44 +0200 Subject: [PATCH] Refactor some more stuff --- .../slimefun4/api/gps/GPSNetwork.java | 10 ++++----- .../slimefun4/api/items/SlimefunItem.java | 13 +++++++++++ .../electric/machines/FoodComposter.java | 22 +++++++++---------- .../items/magical/talismans/Talisman.java | 6 ++--- .../abstractItems/AContainer.java | 4 ++++ .../abstractItems/AGenerator.java | 2 +- 6 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java index 47574fb2ca..aa3b119377 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/gps/GPSNetwork.java @@ -149,7 +149,7 @@ public void openTransmitterControlPanel(@Nonnull Player p) { menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); } - menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, im -> { + menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER.getDelegate(), im -> { im.setDisplayName(ChatColor.GRAY + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters")); im.setLore(null); })); @@ -157,7 +157,7 @@ public void openTransmitterControlPanel(@Nonnull Player p) { menu.addMenuClickHandler(2, ChestMenuUtils.getEmptyClickHandler()); int complexity = getNetworkComplexity(p.getUniqueId()); - menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + getStatusText(p, complexity), "&8\u21E8 &7Complexity: &f" + complexity)); + menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL.getDelegate(), "&7Network Info", "", "&8\u21E8 &7Status: " + getStatusText(p, complexity), "&8\u21E8 &7Complexity: &f" + complexity)); menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler()); menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); @@ -177,7 +177,7 @@ public void openTransmitterControlPanel(@Nonnull Player p) { if (sfi instanceof GPSTransmitter transmitter) { int slot = inventory[index]; - menu.addItem(slot, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&bGPS Transmitter", "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &7Signal Strength: &f" + transmitter.getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms")); + menu.addItem(slot, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER.getDelegate(), "&bGPS Transmitter", "&8\u21E8 &7World: &f" + l.getWorld().getName(), "&8\u21E8 &7X: &f" + l.getX(), "&8\u21E8 &7Y: &f" + l.getY(), "&8\u21E8 &7Z: &f" + l.getZ(), "", "&8\u21E8 &7Signal Strength: &f" + transmitter.getMultiplier(l.getBlockY()), "&8\u21E8 &7Ping: &f" + NumberUtils.roundDecimalNumber(1000D / l.getY()) + "ms")); menu.addMenuClickHandler(slot, ChestMenuUtils.getEmptyClickHandler()); index++; @@ -232,14 +232,14 @@ public void openWaypointControlPanel(@Nonnull Player p) { menu.addItem(slot, ChestMenuUtils.getBackground(), ChestMenuUtils.getEmptyClickHandler()); } - menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER, "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); + menu.addItem(2, new CustomItemStack(SlimefunItems.GPS_TRANSMITTER.getDelegate(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.transmitters"), "", ChatColor.GRAY + "\u21E8 " + Slimefun.getLocalization().getMessage(p, "guide.tooltips.open-itemgroup"))); menu.addMenuClickHandler(2, (pl, slot, item, action) -> { openTransmitterControlPanel(pl); return false; }); int complexity = getNetworkComplexity(p.getUniqueId()); - menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL, "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity)); + menu.addItem(4, new CustomItemStack(SlimefunItems.GPS_CONTROL_PANEL.getDelegate(), "&7Network Info", "", "&8\u21E8 &7Status: " + (complexity > 0 ? "&2&lONLINE" : "&4&lOFFLINE"), "&8\u21E8 &7Complexity: &f" + complexity)); menu.addMenuClickHandler(4, ChestMenuUtils.getEmptyClickHandler()); menu.addItem(6, new CustomItemStack(HeadTexture.GLOBE_OVERWORLD.getAsItemStack(), "&7" + Slimefun.getLocalization().getMessage(p, "machines.GPS_CONTROL_PANEL.waypoints"))); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java index 7defbe029d..6bb890beb4 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/api/items/SlimefunItem.java @@ -1185,6 +1185,19 @@ public final int hashCode() { return Optional.ofNullable(getById(id)); } + public static @Nullable SlimefunItem getByItem(@Nullable SlimefunItemStack slimefunItemStack) { + if (slimefunItemStack == null) { + return null; + } + + var delegate = slimefunItemStack.getDelegate(); + if (delegate.getType() == Material.AIR) { + return null; + } + + return getById(slimefunItemStack.getItemId()); + } + /** * Retrieve a {@link SlimefunItem} from an {@link ItemStack}. * diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FoodComposter.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FoodComposter.java index 04f70d5490..7a2efcb226 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FoodComposter.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/electric/machines/FoodComposter.java @@ -20,17 +20,17 @@ public FoodComposter(ItemGroup itemGroup, SlimefunItemStack item, RecipeType rec @Override protected void registerDefaultRecipes() { - registerRecipe(30, new ItemStack[] { SlimefunItems.WHEAT_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.WHEAT_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.CARROT_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.CARROT_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.POTATO_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.POTATO_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.SEEDS_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.SEEDS_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.BEETROOT_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.BEETROOT_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.MELON_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.MELON_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.APPLE_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.APPLE_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.KELP_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.KELP_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.COCOA_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.COCOA_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.SWEET_BERRIES_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.SWEET_BERRIES_FERTILIZER, OrganicFertilizer.OUTPUT) }); - registerRecipe(30, new ItemStack[] { SlimefunItems.SEAGRASS_ORGANIC_FOOD }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.SEAGRASS_FERTILIZER, OrganicFertilizer.OUTPUT) }); + registerRecipe(30, SlimefunItems.WHEAT_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.WHEAT_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.CARROT_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.CARROT_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.POTATO_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.POTATO_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.SEEDS_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.SEEDS_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.BEETROOT_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.BEETROOT_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.MELON_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.MELON_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.APPLE_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.APPLE_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.KELP_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.KELP_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.COCOA_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.COCOA_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.SWEET_BERRIES_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.SWEET_BERRIES_FERTILIZER, OrganicFertilizer.OUTPUT)); + registerRecipe(30, SlimefunItems.SEAGRASS_ORGANIC_FOOD, new SlimefunItemStack(SlimefunItems.SEAGRASS_FERTILIZER, OrganicFertilizer.OUTPUT)); } @Override diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java index 9b63704637..23923d95ca 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/talismans/Talisman.java @@ -68,7 +68,7 @@ public Talisman(SlimefunItemStack item, ItemStack[] recipe, boolean consumable, @ParametersAreNonnullByDefault protected Talisman(ItemGroup itemGroup, SlimefunItemStack item, ItemStack[] recipe, boolean consumable, boolean cancelEvent, @Nullable String messageSuffix, int chance, PotionEffect... effects) { - super(itemGroup, item, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItemStack(item, consumable ? 4 : 1)); + super(itemGroup, item, RecipeType.MAGIC_WORKBENCH, recipe, new CustomItemStack(item.getDelegate(), consumable ? 4 : 1)); this.consumable = consumable; this.cancel = cancelEvent; @@ -194,9 +194,9 @@ public static boolean trigger(Event e, SlimefunItem item, boolean sendMessage) { } EnderTalisman enderTalisman = enderTalismanItem.getItem(EnderTalisman.class); - if (enderTalisman != null && SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalismanItem, true)) { + if (enderTalisman != null && SlimefunUtils.containsSimilarItem(p.getEnderChest(), enderTalismanItem.getDelegate(), true)) { if (talisman.canUse(p, true)) { - activateTalisman(e, p, p.getEnderChest(), enderTalisman, enderTalismanItem, sendMessage); + activateTalisman(e, p, p.getEnderChest(), enderTalisman, enderTalismanItem.getDelegate(), sendMessage); return true; } else { return false; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java index 04747b4f84..1a59d8a9e1 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AContainer.java @@ -317,6 +317,10 @@ public void registerRecipe(int seconds, ItemStack input, ItemStack output) { registerRecipe(new MachineRecipe(seconds, new ItemStack[] { input }, new ItemStack[] { output })); } + public void registerRecipe(int seconds, SlimefunItemStack input, SlimefunItemStack output) { + registerRecipe(seconds, input.getDelegate(), output.getDelegate()); + } + @Override public void preRegister() { addItemHandler(new BlockTicker() { diff --git a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java index db5555f6c9..b60a046880 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/Objects/SlimefunItem/abstractItems/AGenerator.java @@ -191,7 +191,7 @@ private boolean isBucket(@Nullable ItemStack item) { } ItemStackWrapper wrapper = ItemStackWrapper.wrap(item); - return item.getType() == Material.LAVA_BUCKET || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.FUEL_BUCKET, true) || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.OIL_BUCKET, true); + return item.getType() == Material.LAVA_BUCKET || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.FUEL_BUCKET.getDelegate(), true) || SlimefunUtils.isItemSimilar(wrapper, SlimefunItems.OIL_BUCKET.getDelegate(), true); } private MachineFuel findRecipe(BlockMenu menu, Map found) {