Skip to content

Commit

Permalink
[fix] Small levelling fixes (#58)
Browse files Browse the repository at this point in the history
* [fix] Small fixes
- Adds `#c:armor` to `#playerex:armor`
- Makes ranged weapons actually work

* Move % Dmg reduction tooltip
  • Loading branch information
naomieow authored Dec 14, 2024
1 parent 3706c04 commit 7a17102
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/main/java/com/bibireden/playerex/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
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 @@ -111,6 +115,9 @@ 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")))) {
PlayerEXUtil.addToModifier(hashmap, EntityAttributes_RangedWeapon.DAMAGE.attribute, getLevel() * PlayerEX.CONFIG.getWeaponLevelingSettings().getDamagePerLevel());
}
}
if (PlayerEX.CONFIG.getArmorLevelingSettings().getEnabled() && PlayerEXUtil.isArmor(stack)) {
PlayerEXUtil.addToModifier(hashmap, Attributes.ARMOR, getLevel() * PlayerEX.CONFIG.getArmorLevelingSettings().getArmorPerLevel());
Expand Down Expand Up @@ -270,18 +277,9 @@ private double getReduction() {
if (PlayerEXUtil.isLevelable(itemStack)) {
list.add(Component.translatable("playerex.item.level", getLevel(), PlayerEXUtil.getMaxLevel(itemStack)));
list.add(Component.translatable("playerex.item.experience", getXp(), PlayerEXUtil.getRequiredXpForNextLevel(itemStack)));
}
}

@Inject(method = "getTooltipLines", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", ordinal = 6, shift = At.Shift.AFTER))
private void playerex$insertReductionTooltip(
Player player, TooltipFlag context,
CallbackInfoReturnable<List<Component>> info,
@Local List<Component> list
) {
ItemStack itemStack = (ItemStack) (Object) this;
if (PlayerEXUtil.isArmor(itemStack)) {
list.add(Component.translatable("playerex.item.reduction", String.format("%.2f", getReduction())));
if (PlayerEXUtil.isArmor(itemStack)) {
list.add(Component.translatable("playerex.item.reduction", String.format("%.2f", getReduction())));
}
}
}
}
4 changes: 4 additions & 0 deletions src/main/resources/data/playerex/tags/items/armor.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"replace": false,
"values": [
{
"id": "#c:armor",
"required": false
},
"minecraft:leather_helmet",
"minecraft:leather_chestplate",
"minecraft:leather_leggings",
Expand Down

0 comments on commit 7a17102

Please sign in to comment.