From d926a9e5553133568c961846a9603d4d096b1218 Mon Sep 17 00:00:00 2001 From: "Plamen K. Kosseff" Date: Mon, 6 Dec 2021 19:17:45 +0200 Subject: [PATCH] fixed #74, added support for thrown Loyalty items. --- .../org/anti_ad/mc/ipnext/config/Configs.kt | 7 +++++ .../inventoryprofilesnext/lang/en_us.json | 9 +++++- .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 5 +++- .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 5 +++- .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 4 +++ .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 4 +++ .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 4 +++ .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 4 +++ platforms/forge-1.18/build.gradle.kts | 2 +- .../anti_ad/mc/common/vanilla/alias/item.kt | 4 +++ .../mc/ipnext/item/ItemTypeExtensions.kt | 10 +++++-- .../mc/ipnext/event/AutoRefillHandler.kt | 29 ++++++++++++------- 18 files changed, 94 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt b/common/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt index ff0697a5..c8e914d4 100644 --- a/common/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt +++ b/common/src/main/java/org/anti_ad/mc/ipnext/config/Configs.kt @@ -82,6 +82,7 @@ object AutoRefillSettings : ConfigDeclaration { val DISABLE_FOR_DROP_ITEM /**/ by bool(false) val REFILL_ARMOR /**/ by bool(true) val REFILL_BEFORE_TOOL_BREAK /**/ by bool(true) + val DISABLE_FOR_LOYALTY_ITEMS /**/ by bool(true) val TOOL_DAMAGE_THRESHOLD /**/ by int(10, 0, 100) @@ -89,6 +90,12 @@ object AutoRefillSettings : ConfigDeclaration { val AUTO_REFILL_WAIT_TICK /**/ by int(0, 0, 100) + .CATEGORY("$category.auto-refill.non-enchanted") + val ALLOW_BREAK_FOR_NON_ENCHANTED /**/ by bool(false) + val TOOL_MAX_DURABILITY_THRESHOLD /**/ by int(500, + 0, + 5000) + } diff --git a/common/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json b/common/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json index 1bfda13f..6e6073f6 100644 --- a/common/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json +++ b/common/src/main/resources/assets/inventoryprofilesnext/lang/en_us.json @@ -126,21 +126,28 @@ "inventoryprofiles.config.description.show_move_all_button": "Show \"Move All\" buttons in the container/player Gui.", "inventoryprofiles.config.description.show_button_tooltips": "Display tooltips for the buttons.", - "inventoryprofiles.gui.config.AutoRefillSettings": "Auto Refill", + "inventoryprofiles.gui.config.AutoRefillSettings": "Auto Refill", + "inventoryprofiles.config.category.auto-refill.non-enchanted": "Non Enchanted Items", "inventoryprofiles.config.name.disable_for_drop_item": "Disable For Dropped Item", "inventoryprofiles.config.name.refill_armor": "Refill Armor Before It Breaks", "inventoryprofiles.config.name.refill_before_tool_break": "Replace Tools Before They Break", + "inventoryprofiles.config.name.disable_for_loyalty_items": "Don't Replace Loyalty Gear", "inventoryprofiles.config.name.tool_damage_threshold": "Damage Threshold", "inventoryprofiles.config.name.threshold_unit": "Threshold Units", "inventoryprofiles.config.name.auto_refill_wait_tick": "Number of Ticks to Wait Before Auto Refill", + "inventoryprofiles.config.name.allow_break_for_non_enchanted": "Allow Some Non Enchanted Gear to Break", + "inventoryprofiles.config.name.tool_max_durability_threshold": "Max Durability Threshold", "inventoryprofiles.config.description.enable_auto_refill": "Refill the active item when the stack runs out.", "inventoryprofiles.config.description.disable_for_drop_item": "Disable \"Auto Refill\" for dropped items", "inventoryprofiles.config.description.refill_armor": "Refill armor slots if items are about to break", "inventoryprofiles.config.description.refill_before_tool_break": "Refill tools and armor before they break.\nSee \"Damage Threshold\" for more information.", + "inventoryprofiles.config.description.disable_for_loyalty_items": "Disable replacement of Loyalty enchanted gear.\nWhen this is true anything that is enchanted with any level of Loyalty\n will not be replaced when thrown or dropped.", "inventoryprofiles.config.description.tool_damage_threshold": "Controls the durability level that will trigger auto refill.", "inventoryprofiles.config.description.threshold_unit": "Set the unit for \"Damage Threshold\".\nAbsolute value and percentage (%%) are supported.", "inventoryprofiles.config.description.auto_refill_wait_tick": "Auto refill will wait this many ticks before doing the swap. \nThis might be useful on some during high server lag. \nHowever, depending on the \"Damage Threshold\" value, the tool might break before a swap is initiated.", + "inventoryprofiles.config.description.allow_break_for_non_enchanted": "Don't try to save non enchanted items.\nThat has maximum durability less than the setting below.", + "inventoryprofiles.config.description.tool_max_durability_threshold": "Tools with maximum durability below this value will be allowed to break if the setting above is true.\nThe idea that most players don't really want to keep stone tools,\n but will be annoyed if they break a dimond one.", diff --git a/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index 84ca24ba..801913d2 100644 --- a/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.common.vanilla.alias import net.minecraft.command.arguments.NbtPathArgumentType +import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.Enchantments import net.minecraft.entity.effect.StatusEffectInstance import net.minecraft.item.Item import net.minecraft.item.ItemGroup @@ -52,6 +54,8 @@ typealias StringNbtReader = StringNbtReader // JsonToNBT.getTagFromJson = String // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index 5bf71e36..ce107ffa 100644 --- a/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/fabric-1.15/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -1,8 +1,8 @@ package org.anti_ad.mc.ipnext.item - import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -98,6 +98,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCursed) -0.001 else level.toDouble() / enchantment.maximumLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.getEnchantments(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageable inline val ItemType.maxDamage: Int diff --git a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index 4b829ec7..1701b011 100644 --- a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.common.vanilla.alias import net.minecraft.command.argument.NbtPathArgumentType +import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.Enchantments import net.minecraft.entity.effect.StatusEffectInstance import net.minecraft.item.Item import net.minecraft.item.ItemGroup @@ -52,6 +54,8 @@ typealias StringNbtReader = StringNbtReader // JsonToNBT.getTagFromJson = String // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index 00b312ee..3c18c17b 100644 --- a/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/fabric-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -1,8 +1,8 @@ package org.anti_ad.mc.ipnext.item - import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -98,6 +98,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCursed) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.get(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageable inline val ItemType.maxDamage: Int diff --git a/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index b40d7f73..e274c142 100644 --- a/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.common.vanilla.alias import net.minecraft.command.argument.NbtPathArgumentType +import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.Enchantments import net.minecraft.entity.effect.StatusEffectInstance import net.minecraft.item.Item import net.minecraft.item.ItemGroup @@ -53,6 +55,8 @@ typealias StringNbtReader = StringNbtReader // JsonToNBT.getTagFromJson = String // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index c8f4da6e..2b5409bc 100644 --- a/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/fabric-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -2,6 +2,7 @@ package org.anti_ad.mc.ipnext.item import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -96,6 +97,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCursed) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.get(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageable inline val ItemType.maxDamage: Int diff --git a/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index b40d7f73..e274c142 100644 --- a/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.common.vanilla.alias import net.minecraft.command.argument.NbtPathArgumentType +import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.Enchantments import net.minecraft.entity.effect.StatusEffectInstance import net.minecraft.item.Item import net.minecraft.item.ItemGroup @@ -53,6 +55,8 @@ typealias StringNbtReader = StringNbtReader // JsonToNBT.getTagFromJson = String // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index c8f4da6e..2b5409bc 100644 --- a/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/fabric-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -2,6 +2,7 @@ package org.anti_ad.mc.ipnext.item import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -96,6 +97,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCursed) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.get(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageable inline val ItemType.maxDamage: Int diff --git a/platforms/forge-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/forge-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index b09dd5b5..9f5f5eac 100644 --- a/platforms/forge-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/forge-1.16/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.common.vanilla.alias import net.minecraft.command.arguments.NBTPathArgument +import net.minecraft.enchantment.Enchantment import net.minecraft.enchantment.EnchantmentHelper +import net.minecraft.enchantment.Enchantments import net.minecraft.item.Item import net.minecraft.item.ItemGroup import net.minecraft.item.ItemStack @@ -52,6 +54,8 @@ typealias StringNbtReader = JsonToNBT // JsonToNBT.getTagFromJson = StringNbtRea // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/forge-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/forge-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index c690b309..76092e35 100644 --- a/platforms/forge-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/forge-1.16/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -2,6 +2,7 @@ package org.anti_ad.mc.ipnext.item import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -99,6 +100,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCurse) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.getEnchantments(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageable // .isDamageableItem inline val ItemType.maxDamage: Int diff --git a/platforms/forge-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/forge-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index dbb14a7f..ac1864d8 100644 --- a/platforms/forge-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/forge-1.17/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -16,7 +16,9 @@ import net.minecraft.world.item.Item import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items import net.minecraft.world.item.alchemy.PotionUtils +import net.minecraft.world.item.enchantment.Enchantment import net.minecraft.world.item.enchantment.EnchantmentHelper +import net.minecraft.world.item.enchantment.Enchantments import net.minecraft.nbt.Tag as NbtTag import net.minecraft.tags.Tag as TagTag @@ -52,6 +54,8 @@ typealias StringNbtReader = TagParser// JsonToNBT.getTagFromJson = StringNbtRea // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/forge-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/forge-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index 9f41334b..4faf1825 100644 --- a/platforms/forge-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/forge-1.17/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -2,6 +2,7 @@ package org.anti_ad.mc.ipnext.item import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -98,6 +99,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCurse) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.getEnchantments(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageableItem //isDamageable // .isDamageableItem inline val ItemType.maxDamage: Int diff --git a/platforms/forge-1.18/build.gradle.kts b/platforms/forge-1.18/build.gradle.kts index 35909b83..c9aef8f2 100644 --- a/platforms/forge-1.18/build.gradle.kts +++ b/platforms/forge-1.18/build.gradle.kts @@ -12,7 +12,7 @@ val supported_minecraft_versions = listOf("1.18") val mod_loader = "forge" val mod_version = project.version val minecraft_version = "1.18" -val forge_version = "38.0.14" +val forge_version = "38.0.15" val mod_artefact_version = project.ext["mod_artefact_version"] diff --git a/platforms/forge-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt b/platforms/forge-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt index dbb14a7f..ac1864d8 100644 --- a/platforms/forge-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt +++ b/platforms/forge-1.18/src/main/java/org/anti_ad/mc/common/vanilla/alias/item.kt @@ -16,7 +16,9 @@ import net.minecraft.world.item.Item import net.minecraft.world.item.ItemStack import net.minecraft.world.item.Items import net.minecraft.world.item.alchemy.PotionUtils +import net.minecraft.world.item.enchantment.Enchantment import net.minecraft.world.item.enchantment.EnchantmentHelper +import net.minecraft.world.item.enchantment.Enchantments import net.minecraft.nbt.Tag as NbtTag import net.minecraft.tags.Tag as TagTag @@ -52,6 +54,8 @@ typealias StringNbtReader = TagParser// JsonToNBT.getTagFromJson = StringNbtRea // ============ typealias EnchantmentHelper = EnchantmentHelper +typealias Enchantment = Enchantment +typealias Enchantments = Enchantments // ============ // potion diff --git a/platforms/forge-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt b/platforms/forge-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt index 9f41334b..fc5d8552 100644 --- a/platforms/forge-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt +++ b/platforms/forge-1.18/src/main/java/org/anti_ad/mc/ipnext/item/ItemTypeExtensions.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.ipnext.item +import net.minecraftforge.registries.ForgeRegistries import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.ifTrue +import org.anti_ad.mc.common.vanilla.alias.Enchantment import org.anti_ad.mc.common.vanilla.alias.EnchantmentHelper import org.anti_ad.mc.common.vanilla.alias.Identifier import org.anti_ad.mc.common.vanilla.alias.ItemGroup @@ -98,6 +100,9 @@ inline val ItemType.enchantmentsScore: Double acc + if (enchantment.isCurse) -0.001 else level.toDouble() / enchantment.maxLevel } // cursed enchantments +0 scores +inline val ItemType.enchantments: MutableMap + get() = EnchantmentHelper.getEnchantments(vanillaStack) + inline val ItemType.isDamageable: Boolean get() = vanillaStack.isDamageableItem //isDamageable // .isDamageableItem inline val ItemType.maxDamage: Int @@ -133,8 +138,9 @@ inline val ItemType.comparablePotionEffects: List @Suppress("ObjectPropertyName") inline val StatusEffectInstance.`(asComparable)`: PotionEffect get() = PotionEffect( - Registry.MOB_EFFECT.getId(this.effect) - .toString(), // forge EFFECTS = STATUS_EFFECT == MOB_EFFECT | effectType = potion = effect + //this.effect.descriptionId + ForgeRegistries.MOB_EFFECTS.getKey(this.effect).toString(), + ////Registry.MOB_EFFECT.getId(this.effect).toString(), // forge EFFECTS = STATUS_EFFECT == MOB_EFFECT | effectType = potion = effect this.amplifier, this.duration ) diff --git a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt index 8d52de52..b1590204 100644 --- a/shared-sources/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt +++ b/shared-sources/src/main/java/org/anti_ad/mc/ipnext/event/AutoRefillHandler.kt @@ -1,7 +1,9 @@ package org.anti_ad.mc.ipnext.event +import org.anti_ad.mc.common.Log import org.anti_ad.mc.common.extensions.tryCatch import org.anti_ad.mc.common.vanilla.Vanilla +import org.anti_ad.mc.common.vanilla.alias.Enchantments import org.anti_ad.mc.common.vanilla.alias.Items import org.anti_ad.mc.common.vanilla.alias.items.ArmorItem import org.anti_ad.mc.common.vanilla.alias.items.AxeItem @@ -30,6 +32,7 @@ import org.anti_ad.mc.ipnext.item.ItemStack import org.anti_ad.mc.ipnext.item.ItemType import org.anti_ad.mc.ipnext.item.comparablePotionEffects import org.anti_ad.mc.ipnext.item.durability +import org.anti_ad.mc.ipnext.item.enchantments import org.anti_ad.mc.ipnext.item.hasPotionEffects import org.anti_ad.mc.ipnext.item.isBucket import org.anti_ad.mc.ipnext.item.isDamageable @@ -141,8 +144,7 @@ object AutoRefillHandler { private fun isSwapped(): Boolean { // check this current == other lastTick and other current == this lastTick if (currentItem == lastTickItem) return false return anothers.any { another -> - this.currentItem == another.lastTickItem - && this.lastTickItem == another.currentItem + this.currentItem == another.lastTickItem && this.lastTickItem == another.currentItem } } @@ -174,23 +176,28 @@ object AutoRefillHandler { var checkingItem = storedItem // use to select private fun shouldHandleItem(): Boolean { checkingItem = storedItem + + if (storedItem.isEmpty()) return false // nothing become anything - if (currentItem.isEmpty()) return true // something become nothing + if (currentItem.isEmpty()) { + return !(AutoRefillSettings.DISABLE_FOR_LOYALTY_ITEMS.value && storedItem.itemType.enchantments[Enchantments.LOYALTY] != null) + } val itemType = currentItem.itemType if (itemType.isDamageable) { if (AutoRefillSettings.REFILL_BEFORE_TOOL_BREAK.booleanValue) { - val threshold = getThreshold(itemType) - if (itemType.durability <= threshold) return true.also { checkingItem = currentItem } + if (!(AutoRefillSettings.ALLOW_BREAK_FOR_NON_ENCHANTED.value + && itemType.enchantments.isEmpty() + && itemType.maxDamage < AutoRefillSettings.TOOL_MAX_DURABILITY_THRESHOLD.value)) { + val threshold = getThreshold(itemType) + if (itemType.durability <= threshold) return true.also { checkingItem = currentItem } + } } } + if (storedItem.itemType.isBucket) return false // todo potion -> bottle, soup -> bowl etc - if (storedItem.itemType.item == Items.POTION - && currentItem.itemType.item == Items.GLASS_BOTTLE - ) return true - if (storedItem.itemType.isStew - && currentItem.itemType.item == Items.BOWL - ) return true + if (storedItem.itemType.item == Items.POTION && currentItem.itemType.item == Items.GLASS_BOTTLE) return true + if (storedItem.itemType.isStew && currentItem.itemType.item == Items.BOWL) return true // todo any else? return false