From 12322468f91789b39a096a9fd2ad5873d10947af Mon Sep 17 00:00:00 2001 From: Naomi Roberts Date: Mon, 16 Dec 2024 16:29:06 +0000 Subject: [PATCH 1/6] [fix] Remove shields from weapons tag --- src/main/resources/data/playerex/tags/items/weapons.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/main/resources/data/playerex/tags/items/weapons.json b/src/main/resources/data/playerex/tags/items/weapons.json index 587cfc5d..4015ad93 100644 --- a/src/main/resources/data/playerex/tags/items/weapons.json +++ b/src/main/resources/data/playerex/tags/items/weapons.json @@ -13,10 +13,6 @@ "id": "#c:spears", "required": false }, - { - "id": "#c:shields", - "required": false - }, { "id": "#c:bows", "required": false From d9d0e61633631fe36c2bdec590776f06d25debdc Mon Sep 17 00:00:00 2001 From: Naomi Roberts Date: Mon, 16 Dec 2024 16:31:38 +0000 Subject: [PATCH 2/6] [fix] Implement extra check for armour - As `#c:armor` tag didn't officially exist in this version, almost 0 mods use it. --- src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt | 3 +++ src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt b/src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt index 7e109687..ce0fed97 100644 --- a/src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt +++ b/src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt @@ -14,4 +14,7 @@ object PlayerEXTags { @JvmField val ARMOR: TagKey = TagKey.create(Registries.ITEM, PlayerEX.id("armor")) + + @JvmField + val ARMOR_BLACKLIST: TagKey = TagKey.create(Registries.ITEM, PlayerEX.id("armor_blacklist")) } diff --git a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt index 69afed4f..d194bbfa 100644 --- a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt +++ b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt @@ -6,9 +6,11 @@ import com.bibireden.playerex.api.PlayerEXTags import com.bibireden.playerex.ext.level import com.bibireden.playerex.ext.xp import com.google.common.collect.Multimap +import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.world.entity.ai.attributes.Attribute import net.minecraft.world.entity.ai.attributes.AttributeModifier import net.minecraft.world.entity.player.Player +import net.minecraft.world.item.ArmorItem import net.minecraft.world.item.ItemStack import net.objecthunter.exp4j.Expression import net.objecthunter.exp4j.ExpressionBuilder @@ -109,7 +111,9 @@ object PlayerEXUtil { @JvmStatic fun isArmor(stack: ItemStack): Boolean { - return stack.`is`(PlayerEXTags.ARMOR) + return BuiltInRegistries.ITEM.stream().filter { + (it is ArmorItem || it.defaultInstance.`is`(PlayerEXTags.ARMOR)) && !it.defaultInstance.`is`(PlayerEXTags.ARMOR_BLACKLIST) + }.anyMatch { stack.`is`(it) }; } @JvmStatic From 383e1c4c110acb40dbe547b0320319bd58bf2850 Mon Sep 17 00:00:00 2001 From: Naomi Roberts Date: Mon, 16 Dec 2024 16:53:41 +0000 Subject: [PATCH 3/6] [fix] Ranged weapon fixes --- .../com/bibireden/playerex/mixin/ItemStackMixin.java | 5 +---- .../resources/data/playerex/tags/items/weapons.json | 12 ++++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java b/src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java index 71da4f4c..eb7cc61b 100644 --- a/src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java +++ b/src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java @@ -10,13 +10,10 @@ import com.llamalad7.mixinextras.sugar.Local; import net.fabric_extras.ranged_weapon.api.EntityAttributes_RangedWeapon; import net.minecraft.ChatFormatting; -import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; -import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; -import net.minecraft.tags.TagKey; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -115,7 +112,7 @@ public void modifyAttributeModifiers(EquipmentSlot slot, CallbackInfoReturnable< HashMultimap hashmap = HashMultimap.create(cir.getReturnValue()); if (PlayerEX.CONFIG.getWeaponLevelingSettings().getEnabled() && PlayerEXUtil.isWeapon(stack)) { PlayerEXUtil.addToModifier(hashmap, Attributes.ATTACK_DAMAGE, getLevel() * PlayerEX.CONFIG.getWeaponLevelingSettings().getDamagePerLevel()); - if (stack.is(TagKey.create(Registries.ITEM, ResourceLocation.tryBuild("c", "bows")))) { + if (hashmap.containsKey(EntityAttributes_RangedWeapon.DAMAGE.attribute)) { PlayerEXUtil.addToModifier(hashmap, EntityAttributes_RangedWeapon.DAMAGE.attribute, getLevel() * PlayerEX.CONFIG.getWeaponLevelingSettings().getDamagePerLevel()); } } diff --git a/src/main/resources/data/playerex/tags/items/weapons.json b/src/main/resources/data/playerex/tags/items/weapons.json index 4015ad93..e0df7d72 100644 --- a/src/main/resources/data/playerex/tags/items/weapons.json +++ b/src/main/resources/data/playerex/tags/items/weapons.json @@ -5,6 +5,14 @@ "id": "#c:swords", "required": false }, + { + "id": "#fabric:swords", + "required": false + }, + { + "id": "#c:weapons", + "required": false + }, { "id": "#c:axes", "required": false @@ -17,6 +25,10 @@ "id": "#c:bows", "required": false }, + { + "id": "#fabric:bows", + "required": false + }, "#minecraft:swords", "#minecraft:axes", "minecraft:bow", From df2863d034db7502398d8d53b5e49f1d9c236299 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Mon, 16 Dec 2024 13:59:39 -0600 Subject: [PATCH 4/6] [fix] Use cached `ItemStack#item` instead of iteration Lazily evaluated methods are an insidious killer at times --- src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt index d194bbfa..dec26770 100644 --- a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt +++ b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt @@ -111,9 +111,7 @@ object PlayerEXUtil { @JvmStatic fun isArmor(stack: ItemStack): Boolean { - return BuiltInRegistries.ITEM.stream().filter { - (it is ArmorItem || it.defaultInstance.`is`(PlayerEXTags.ARMOR)) && !it.defaultInstance.`is`(PlayerEXTags.ARMOR_BLACKLIST) - }.anyMatch { stack.`is`(it) }; + return (stack.item is ArmorItem || stack.item.defaultInstance.`is`(PlayerEXTags.ARMOR)) && !stack.item.defaultInstance.`is`(PlayerEXTags.ARMOR_BLACKLIST) } @JvmStatic From 121334f1e7df8aa66993340cf8b6ebee743918d2 Mon Sep 17 00:00:00 2001 From: Naomi Roberts Date: Mon, 16 Dec 2024 21:46:29 +0000 Subject: [PATCH 5/6] [fix] Remove unneeded item conversion --- src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt index dec26770..610446a8 100644 --- a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt +++ b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt @@ -111,7 +111,7 @@ object PlayerEXUtil { @JvmStatic fun isArmor(stack: ItemStack): Boolean { - return (stack.item is ArmorItem || stack.item.defaultInstance.`is`(PlayerEXTags.ARMOR)) && !stack.item.defaultInstance.`is`(PlayerEXTags.ARMOR_BLACKLIST) + return (stack.item is ArmorItem || stack.`is`(PlayerEXTags.ARMOR)) && !stack.`is`(PlayerEXTags.ARMOR_BLACKLIST) } @JvmStatic From 82b1c9f6201d2909a0ce46bdc9e7d0057fb5d755 Mon Sep 17 00:00:00 2001 From: Bibi Reden Date: Mon, 16 Dec 2024 21:59:15 -0600 Subject: [PATCH 6/6] [fix] target `SwordItem`, `CrossbowItem` und `BowItem` in `isWeapon` --- src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt index 610446a8..2f16e138 100644 --- a/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt +++ b/src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt @@ -6,12 +6,14 @@ import com.bibireden.playerex.api.PlayerEXTags import com.bibireden.playerex.ext.level import com.bibireden.playerex.ext.xp import com.google.common.collect.Multimap -import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.world.entity.ai.attributes.Attribute import net.minecraft.world.entity.ai.attributes.AttributeModifier import net.minecraft.world.entity.player.Player import net.minecraft.world.item.ArmorItem +import net.minecraft.world.item.BowItem +import net.minecraft.world.item.CrossbowItem import net.minecraft.world.item.ItemStack +import net.minecraft.world.item.SwordItem import net.objecthunter.exp4j.Expression import net.objecthunter.exp4j.ExpressionBuilder import net.objecthunter.exp4j.function.Function @@ -106,7 +108,7 @@ object PlayerEXUtil { @JvmStatic fun isWeapon(stack: ItemStack): Boolean { - return stack.`is`(PlayerEXTags.WEAPONS) + return stack.item is BowItem || stack.item is CrossbowItem || stack.item is SwordItem || stack.`is`(PlayerEXTags.WEAPONS) } @JvmStatic