Skip to content

Commit

Permalink
Item detection changes (#60)
Browse files Browse the repository at this point in the history
* [fix] Remove shields from weapons tag

* [fix] Implement extra check for armour
- As `#c:armor` tag didn't officially exist in this version, almost 0 mods use it.

* [fix] Ranged weapon fixes

* [fix] Use cached `ItemStack#item` instead of iteration

Lazily evaluated methods are an insidious killer at times

* [fix] Remove unneeded item conversion

* [fix] target `SwordItem`, `CrossbowItem` und `BowItem` in `isWeapon`

---------

Co-authored-by: Bibi Reden <[email protected]>
  • Loading branch information
naomieow and bibi-reden authored Dec 17, 2024
1 parent 3899668 commit 15204e4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -115,7 +112,7 @@ public void modifyAttributeModifiers(EquipmentSlot slot, CallbackInfoReturnable<
HashMultimap<Attribute, AttributeModifier> 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());
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/com/bibireden/playerex/api/PlayerEXTags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ object PlayerEXTags {

@JvmField
val ARMOR: TagKey<Item> = TagKey.create(Registries.ITEM, PlayerEX.id("armor"))

@JvmField
val ARMOR_BLACKLIST: TagKey<Item> = TagKey.create(Registries.ITEM, PlayerEX.id("armor_blacklist"))
}
8 changes: 6 additions & 2 deletions src/main/kotlin/com/bibireden/playerex/util/PlayerEXUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import com.google.common.collect.Multimap
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
Expand Down Expand Up @@ -104,12 +108,12 @@ 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
fun isArmor(stack: ItemStack): Boolean {
return stack.`is`(PlayerEXTags.ARMOR)
return (stack.item is ArmorItem || stack.`is`(PlayerEXTags.ARMOR)) && !stack.`is`(PlayerEXTags.ARMOR_BLACKLIST)
}

@JvmStatic
Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/data/playerex/tags/items/weapons.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
"id": "#c:swords",
"required": false
},
{
"id": "#fabric:swords",
"required": false
},
{
"id": "#c:weapons",
"required": false
},
{
"id": "#c:axes",
"required": false
Expand All @@ -14,11 +22,11 @@
"required": false
},
{
"id": "#c:shields",
"id": "#c:bows",
"required": false
},
{
"id": "#c:bows",
"id": "#fabric:bows",
"required": false
},
"#minecraft:swords",
Expand Down

0 comments on commit 15204e4

Please sign in to comment.