From 41d678809539a9e06879c2457079a1e605978286 Mon Sep 17 00:00:00 2001 From: ItzKatze <136186750+ItzKatze@users.noreply.github.com> Date: Sat, 6 Dec 2025 10:46:23 +0100 Subject: [PATCH 1/2] fix: dupe bug with enchant/reforge gui feat: conflicting enchants --- .../skyblock/items/vanilla/blocks/others.yml | 39 ++++++++++ .../collection/CustomCollectionAward.java | 1 + .../enchantment/EnchantmentType.java | 6 +- .../enchantment/abstr/ConflictingEnch.java | 9 +++ .../enchantment/impl/EnchantmentFortune.java | 77 +++++++++++++++++++ .../impl/EnchantmentSilkTouch.java | 9 ++- .../impl/EnchantmentSmeltingTouch.java | 9 ++- .../gui/inventories/GUIEnchantmentTable.java | 32 ++++++-- .../gui/inventories/GUIReforge.java | 33 ++++---- 9 files changed, 188 insertions(+), 27 deletions(-) create mode 100644 configuration/skyblock/items/vanilla/blocks/others.yml create mode 100644 type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/abstr/ConflictingEnch.java create mode 100644 type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentFortune.java diff --git a/configuration/skyblock/items/vanilla/blocks/others.yml b/configuration/skyblock/items/vanilla/blocks/others.yml new file mode 100644 index 000000000..13199faf7 --- /dev/null +++ b/configuration/skyblock/items/vanilla/blocks/others.yml @@ -0,0 +1,39 @@ +items: + - id: BOOKSHELF + material: BOOKSHELF + rarity: COMMON + components: + - id: CUSTOM_DROP + rules: + - conditions: + silk_touch: true + drops: + - item: BOOKSHELF + chance: 1.0 + amount: 1 + - conditions: + drops: + - item: BOOK + chance: 1.0 + amount: 3 + - id: PLACEABLE + - id: SELLABLE + value: 20 + - id: DEFAULT_CRAFTABLE + recipes: + - type: SHAPED + recipe-type: NONE + pattern: + - AAA + - BBB + - AAA + ingredients: + A: + type: OAK_PLANKS + amount: 1 + B: + type: BOOK + amount: 1 + result: + type: BOOKSHELF + amount: 1 \ No newline at end of file diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/collection/CustomCollectionAward.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/collection/CustomCollectionAward.java index 540f7974d..6ca3da456 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/collection/CustomCollectionAward.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/collection/CustomCollectionAward.java @@ -26,6 +26,7 @@ public enum CustomCollectionAward { IMPALING_DISCOUNT("§9Impaling §7Exp Discount §a(-25%)"), BANE_OF_ARTHROPODS_DISCOUNT("§9Bane of Arthropods §7Exp Discount §a(-25%)"), CUBISM_DISCOUNT("§9Cubism §7Exp Discount §a(-25%)"), + FORTUNE_DISCOUNT("§9Fortune §7Exp Discount §a(-25%)"), // BAGS QUIVER("§aQuiver"), diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/EnchantmentType.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/EnchantmentType.java index 5101d05d7..06420361d 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/EnchantmentType.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/EnchantmentType.java @@ -31,17 +31,15 @@ public enum EnchantmentType { IMPALING(EnchantmentImpaling.class), BANE_OF_ARTHROPODS(EnchantmentBaneOfArthropods.class), CUBISM(EnchantmentCubism.class), + FORTUNE(EnchantmentFortune.class), ; private final Class clazz; - private final List conflicts; - private final Ench ench; @SneakyThrows - EnchantmentType(Class ench, EnchantmentType... conflicts) { + EnchantmentType(Class ench) { this.clazz = ench; - this.conflicts = List.of(conflicts); this.ench = ench.getConstructor().newInstance(); } diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/abstr/ConflictingEnch.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/abstr/ConflictingEnch.java new file mode 100644 index 000000000..aa664238f --- /dev/null +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/abstr/ConflictingEnch.java @@ -0,0 +1,9 @@ +package net.swofty.type.skyblockgeneric.enchantment.abstr; + +import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType; + +import java.util.List; + +public interface ConflictingEnch { + List getConflictingEnchantments(); +} diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentFortune.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentFortune.java new file mode 100644 index 000000000..0df7baa79 --- /dev/null +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentFortune.java @@ -0,0 +1,77 @@ +package net.swofty.type.skyblockgeneric.enchantment.impl; + +import net.swofty.commons.statistics.ItemStatistic; +import net.swofty.commons.statistics.ItemStatistics; +import net.swofty.type.skyblockgeneric.collection.CustomCollectionAward; +import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType; +import net.swofty.type.skyblockgeneric.enchantment.abstr.ConflictingEnch; +import net.swofty.type.skyblockgeneric.enchantment.abstr.Ench; +import net.swofty.type.skyblockgeneric.enchantment.abstr.EnchFromTable; +import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; +import net.swofty.type.skyblockgeneric.utility.groups.EnchantItemGroups; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EnchantmentFortune implements Ench, EnchFromTable, ConflictingEnch { + + public static final int[] MINING_FORTUNE_BONUS = new int[]{10, 20, 30, 45}; + + @Override + public String getDescription(int level) { + return "Grants §a+" + MINING_FORTUNE_BONUS[level - 1] + " " + ItemStatistic.MINING_FORTUNE.getDisplayName() + + "§7, which increases your chance for multiple drops."; + } + + @Override + public ApplyLevels getLevelsToApply(@NotNull SkyBlockPlayer player) { + HashMap levels = new HashMap<>(Map.of( + 4, 0 + )); + + if (player.hasCustomCollectionAward(CustomCollectionAward.FORTUNE_DISCOUNT)) { + levels.replaceAll((k, v) -> (int) (v * 0.75)); + } + + return new ApplyLevels(levels); + } + + @Override + public List getGroups() { + return List.of(EnchantItemGroups.GAUNTLET, EnchantItemGroups.PICKAXE, EnchantItemGroups.DRILL); + } + + @Override + public ItemStatistics getStatistics(int level) { + return ItemStatistics.builder() + .withBase(ItemStatistic.MINING_FORTUNE, (double) MINING_FORTUNE_BONUS[level - 1]) + .build(); + } + + @Override + public TableLevels getLevelsFromTableToApply(@NotNull SkyBlockPlayer player) { + HashMap levels = new HashMap<>(Map.of( + 1, 15, + 2, 30, + 3, 45 + )); + + if (player.hasCustomCollectionAward(CustomCollectionAward.FORTUNE_DISCOUNT)) { + levels.replaceAll((k, v) -> (int) (v * 0.75)); + } + + return new TableLevels(levels); + } + + @Override + public int getRequiredBookshelfPower() { + return 0; + } + + @Override + public List getConflictingEnchantments() { + return List.of(EnchantmentType.SILK_TOUCH); + } +} \ No newline at end of file diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSilkTouch.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSilkTouch.java index 7298b3640..2ba79a154 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSilkTouch.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSilkTouch.java @@ -1,6 +1,8 @@ package net.swofty.type.skyblockgeneric.enchantment.impl; import lombok.NonNull; +import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType; +import net.swofty.type.skyblockgeneric.enchantment.abstr.ConflictingEnch; import net.swofty.type.skyblockgeneric.enchantment.abstr.Ench; import net.swofty.type.skyblockgeneric.enchantment.abstr.EnchFromTable; import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; @@ -10,7 +12,7 @@ import java.util.List; import java.util.Map; -public class EnchantmentSilkTouch implements Ench, EnchFromTable { +public class EnchantmentSilkTouch implements Ench, EnchFromTable, ConflictingEnch { @Override public String getDescription(int level) { @@ -45,4 +47,9 @@ public TableLevels getLevelsFromTableToApply(@NonNull SkyBlockPlayer player) { public int getRequiredBookshelfPower() { return 5; } + + @Override + public List getConflictingEnchantments() { + return List.of(EnchantmentType.SMELTING_TOUCH, EnchantmentType.FORTUNE); + } } \ No newline at end of file diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSmeltingTouch.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSmeltingTouch.java index 671557d2e..772647352 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSmeltingTouch.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/enchantment/impl/EnchantmentSmeltingTouch.java @@ -1,6 +1,8 @@ package net.swofty.type.skyblockgeneric.enchantment.impl; import lombok.NonNull; +import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType; +import net.swofty.type.skyblockgeneric.enchantment.abstr.ConflictingEnch; import net.swofty.type.skyblockgeneric.enchantment.abstr.Ench; import net.swofty.type.skyblockgeneric.enchantment.abstr.EnchFromTable; import net.swofty.type.skyblockgeneric.user.SkyBlockPlayer; @@ -10,7 +12,7 @@ import java.util.List; import java.util.Map; -public class EnchantmentSmeltingTouch implements Ench, EnchFromTable { +public class EnchantmentSmeltingTouch implements Ench, EnchFromTable, ConflictingEnch { @Override public String getDescription(int level) { @@ -45,4 +47,9 @@ public TableLevels getLevelsFromTableToApply(@NonNull SkyBlockPlayer player) { public int getRequiredBookshelfPower() { return 0; } + + @Override + public List getConflictingEnchantments() { + return List.of(EnchantmentType.SILK_TOUCH); + } } \ No newline at end of file diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIEnchantmentTable.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIEnchantmentTable.java index 4d1505380..1b6e2f68f 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIEnchantmentTable.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIEnchantmentTable.java @@ -21,6 +21,8 @@ import net.swofty.type.skyblockgeneric.enchantment.EnchantmentSource; import net.swofty.type.skyblockgeneric.enchantment.EnchantmentType; import net.swofty.type.skyblockgeneric.enchantment.SkyBlockEnchantment; +import net.swofty.type.skyblockgeneric.enchantment.abstr.ConflictingEnch; +import net.swofty.type.skyblockgeneric.enchantment.abstr.Ench; import net.swofty.type.skyblockgeneric.item.ItemAttributeHandler; import net.swofty.type.skyblockgeneric.item.SkyBlockItem; import net.swofty.type.skyblockgeneric.item.components.EnchantableComponent; @@ -129,11 +131,13 @@ public ItemStack.Builder getItem(HypixelPlayer p) { @Override public void run(InventoryPreClickEvent e, HypixelPlayer p) { SkyBlockPlayer player = (SkyBlockPlayer) p; - ItemStack stack = p.getInventory().getCursorItem(); + ItemStack stack = player.getInventory().getCursorItem(); if (stack.get(DataComponents.CUSTOM_NAME) == null) return; + e.setCancelled(true); SkyBlockItem item = new SkyBlockItem(stack); + player.getInventory().setCursorItem(ItemStack.AIR); updateFromItem(item, null); } @@ -156,15 +160,13 @@ public ItemStack.Builder getItem(HypixelPlayer p) { @Override public void run(InventoryPreClickEvent e, HypixelPlayer p) { SkyBlockPlayer player = (SkyBlockPlayer) p; - ItemStack stack = p.getInventory().getCursorItem(); + ItemStack stack = player.getInventory().getCursorItem(); - if (stack.get(DataComponents.CUSTOM_NAME) == null) { + if (stack == ItemStack.AIR) { + e.setCancelled(true); + player.getInventory().setCursorItem(PlayerItemUpdater.playerUpdate(player, item.getItemStack()).build()); updateFromItem(null, null); - return; } - - SkyBlockItem item = new SkyBlockItem(stack); - updateFromItem(item, null); } @Override @@ -303,6 +305,15 @@ public ItemStack.Builder getItem(HypixelPlayer p) { lore.add("§a "); + if (selected.getEnch() instanceof ConflictingEnch conflictingEnch) { + for (EnchantmentType ench : conflictingEnch.getConflictingEnchantments()) { + if (item.getAttributeHandler().hasEnchantment(ench)) { + lore.add("§c§lWARNING: This will remove " + StringUtility.toNormalCase(ench.name()) + "."); + break; + } + } + } + if (finalHasLevel == finalLevel) { lore.add("§cThis enchantment is already present"); lore.add("§cand can be removed."); @@ -368,6 +379,13 @@ public void run(InventoryPreClickEvent e, HypixelPlayer p) { new SkyBlockEnchantment(selected, finalLevel) ); + if (selected.getEnch() instanceof ConflictingEnch conflictingEnch) { + for (EnchantmentType enchant : conflictingEnch.getConflictingEnchantments()) { + System.out.printf("conflicting enchant: " + enchant.name()); + if (item.getAttributeHandler().hasEnchantment(enchant)) item.getAttributeHandler().removeEnchantment(enchant); + } + } + player.setLevel(player.getLevel() - selected.getEnchFromTable().getLevelsFromTableToApply(player).get(finalLevel)); player.sendMessage("§aYou enchanted your " + itemName + " §awith " + StringUtility.toNormalCase(selected.name()) + " " + StringUtility.getAsRomanNumeral(finalLevel) + "!"); diff --git a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIReforge.java b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIReforge.java index 9eb68d401..69c084699 100644 --- a/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIReforge.java +++ b/type.skyblockgeneric/src/main/java/net/swofty/type/skyblockgeneric/gui/inventories/GUIReforge.java @@ -62,14 +62,13 @@ public void updateFromItem(SkyBlockItem item) { @Override public void run(InventoryPreClickEvent e, HypixelPlayer p) { SkyBlockPlayer player = (SkyBlockPlayer) p; - ItemStack stack = p.getInventory().getCursorItem(); + ItemStack stack = player.getInventory().getCursorItem(); - if (stack.get(DataComponents.CUSTOM_NAME) == null) { - updateFromItem(null); - return; - } + if (stack.get(DataComponents.CUSTOM_NAME) == null) return; + e.setCancelled(true); SkyBlockItem item = new SkyBlockItem(stack); + player.getInventory().setCursorItem(ItemStack.AIR); updateFromItem(item); } @@ -109,20 +108,26 @@ public ItemStack.Builder getItem(HypixelPlayer p) { set(new GUIClickableItem(13) { @Override - public ItemStack.Builder getItem(HypixelPlayer p) { + public void run(InventoryPreClickEvent e, HypixelPlayer p) { SkyBlockPlayer player = (SkyBlockPlayer) p; - return PlayerItemUpdater.playerUpdate(player, item.getItemStack()); + ItemStack stack = player.getInventory().getCursorItem(); + + if (stack == ItemStack.AIR) { + e.setCancelled(true); + player.getInventory().setCursorItem(PlayerItemUpdater.playerUpdate(player, item.getItemStack()).build()); + updateFromItem(null); + } } @Override - public void run(InventoryPreClickEvent e, HypixelPlayer p) { - SkyBlockPlayer player = (SkyBlockPlayer) p; - ItemStack stack = e.getClickedItem(); - if (stack.isAir()) return; - - updateFromItem(null); + public boolean canPickup() { + return true; + } - player.addAndUpdateItem(stack); + @Override + public ItemStack.Builder getItem(HypixelPlayer p) { + SkyBlockPlayer player = (SkyBlockPlayer) p; + return PlayerItemUpdater.playerUpdate(player, item.getItemStack()); } }); From 97d1653da87e411705be34d800711f0c84c90d6e Mon Sep 17 00:00:00 2001 From: ItzKatze <136186750+ItzKatze@users.noreply.github.com> Date: Sat, 6 Dec 2025 11:01:26 +0100 Subject: [PATCH 2/2] added discounts to collections --- configuration/skyblock/collections/combat.yml | 6 ++++++ configuration/skyblock/collections/farming.yml | 3 +++ configuration/skyblock/collections/fishing.yml | 3 +++ configuration/skyblock/collections/mining.yml | 11 +++++++++++ 4 files changed, 23 insertions(+) diff --git a/configuration/skyblock/collections/combat.yml b/configuration/skyblock/collections/combat.yml index ce87fc9ca..87a385a37 100644 --- a/configuration/skyblock/collections/combat.yml +++ b/configuration/skyblock/collections/combat.yml @@ -332,6 +332,9 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: GIANT_KILLER_DISCOUNT - amount: 1000 rewards: - type: XP @@ -669,6 +672,9 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: BANE_OF_ARTHROPODS_DISCOUNT - amount: 5000 rewards: - type: XP diff --git a/configuration/skyblock/collections/farming.yml b/configuration/skyblock/collections/farming.yml index 021363778..8b8bcc60e 100644 --- a/configuration/skyblock/collections/farming.yml +++ b/configuration/skyblock/collections/farming.yml @@ -1044,6 +1044,9 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: CUBISM_DISCOUNT - amount: 2500 rewards: - type: XP diff --git a/configuration/skyblock/collections/fishing.yml b/configuration/skyblock/collections/fishing.yml index bd37140bd..4fbba5961 100644 --- a/configuration/skyblock/collections/fishing.yml +++ b/configuration/skyblock/collections/fishing.yml @@ -314,6 +314,9 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: IMPALING_DISCOUNT - amount: 25 rewards: - type: XP diff --git a/configuration/skyblock/collections/mining.yml b/configuration/skyblock/collections/mining.yml index 7ce3a5976..8c0b315ee 100644 --- a/configuration/skyblock/collections/mining.yml +++ b/configuration/skyblock/collections/mining.yml @@ -350,6 +350,14 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: FORTUNE_DISCOUNT + - amount: 500000 + rewards: + - type: XP + data: + xp: 4 - itemType: LAPIS_LAZULI rewards: - amount: 250 @@ -497,6 +505,9 @@ collections: - type: XP data: xp: 4 + - type: CUSTOM_AWARD + data: + customAward: EXECUTE_DISCOUNT - amount: 250 rewards: - type: XP