Skip to content

Commit

Permalink
Removed tooltip fix for weapons
Browse files Browse the repository at this point in the history
-Removed tooltip fix: we can implement a proper bug-free fix for PlayerEx, but when run with other mods (like Tiered) that also modify tooltips, tooltips break a little bit. Instead we're just not gonna implement any fix and hope people don't notice the discrepancy between displayed damage on the weapon and actual damage.

A few plans down the road for a 1.18 mod for rpg smithing (tinkers for fabric) and maybe we'll implement tooltip fixes for that mod.
  • Loading branch information
CleverNucleus committed Jun 28, 2021
1 parent cbd88bc commit 6b4b640
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.github.clevernucleus.playerex.handler.NetworkHandler;

import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
Expand All @@ -32,6 +31,5 @@ public void onInitializeClient() {

NameplateRenderEvent.ON_RENDER.register(ClientEventHandler::nameplateRender);
ScreenEvents.AFTER_INIT.register(ClientEventHandler::screenInit);
ItemTooltipCallback.EVENT.register(ClientEventHandler::tooltipModify);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package com.github.clevernucleus.playerex.mixin.client;

import java.util.Iterator;
import java.util.Map.Entry;
import java.util.UUID;

import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;

import com.github.clevernucleus.playerex.api.ExAPI;
import com.github.clevernucleus.playerex.api.PlayerAttributes;
import com.github.clevernucleus.playerex.api.attribute.AttributeData;
import com.google.common.collect.Multimap;

import net.minecraft.client.item.TooltipContext;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.attribute.EntityAttribute;
import net.minecraft.entity.attribute.EntityAttributeModifier;
import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;

@Mixin(ItemStack.class)
public class ItemStackMixin {
/*
private static final UUID ATTACK_DAMAGE_MODIFIER_ID = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
private static final UUID ATTACK_SPEED_MODIFIER_ID = UUID.fromString("FA233E1C-4180-4865-B01B-BCCE9785ACA3");
@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 1), name = "d", ordinal = 0)
private double attackDamageTooltip(double d, @Nullable PlayerEntity player, TooltipContext context) {
ItemStack stack = (ItemStack)(Object)this;
double cache = d;
double modifier = 0;
if(player != null) {
AttributeData data = ExAPI.DATA.get(player);
ItemStack held = player.getMainHandStack();
cache -= player.getAttributeBaseValue(EntityAttributes.GENERIC_ATTACK_DAMAGE);
modifier = cache;
cache += data.get(PlayerAttributes.MELEE_ATTACK_DAMAGE.get());
if(stack.equals(held)) {
cache -= modifier;
} else {
Multimap<EntityAttribute, EntityAttributeModifier> multimap = held.getAttributeModifiers(EquipmentSlot.MAINHAND);
if(!multimap.isEmpty()) {
Iterator<Entry<EntityAttribute, EntityAttributeModifier>> iterator = multimap.entries().iterator();
while(iterator.hasNext()) {
Entry<EntityAttribute, EntityAttributeModifier> entry = iterator.next();
EntityAttributeModifier entityAttributeModifier = (EntityAttributeModifier)entry.getValue();
double value = entityAttributeModifier.getValue();
if(entityAttributeModifier.getId().equals(ATTACK_DAMAGE_MODIFIER_ID)) {
value += (double)EnchantmentHelper.getAttackDamage(held, EntityGroup.DEFAULT);
cache -= value;
}
}
}
}
}
return cache;
}
@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 3), name = "d", ordinal = 0)
private double attackSpeedTooltip(double d, @Nullable PlayerEntity player, TooltipContext context) {
ItemStack stack = (ItemStack)(Object)this;
double cache = d;
double modifier = 0;
if(player != null) {
AttributeData data = ExAPI.DATA.get(player);
ItemStack held = player.getMainHandStack();
cache -= player.getAttributeBaseValue(EntityAttributes.GENERIC_ATTACK_SPEED);
modifier = cache;
cache += data.get(PlayerAttributes.ATTACK_SPEED.get());
if(stack.equals(held)) {
cache -= modifier;
} else {
Multimap<EntityAttribute, EntityAttributeModifier> multimap = held.getAttributeModifiers(EquipmentSlot.MAINHAND);
if(!multimap.isEmpty()) {
Iterator<Entry<EntityAttribute, EntityAttributeModifier>> iterator = multimap.entries().iterator();
while(iterator.hasNext()) {
Entry<EntityAttribute, EntityAttributeModifier> entry = iterator.next();
EntityAttributeModifier entityAttributeModifier = (EntityAttributeModifier)entry.getValue();
double value = entityAttributeModifier.getValue();
if(entityAttributeModifier.getId().equals(ATTACK_SPEED_MODIFIER_ID)) {
cache -= value;
}
}
}
}
}
return cache;
}
*/
}
3 changes: 2 additions & 1 deletion src/main/resources/playerex.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"client": [
"client.HandledScreenMixin",
"client.ClientPlayNetworkHandlerMixin",
"client.PlayerEntityRendererMixin"
"client.PlayerEntityRendererMixin",
"client.ItemStackMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 6b4b640

Please sign in to comment.