Open Averso opened 1 year ago
my fix for this looks like this
@Mixin(value = HandlerFasterAttack.class, remap = false)
public abstract class MixinHandlerFasterAttack {
@Unique private static final String ATTRIBUTE_UUID = "578e84b7-327d-4a19-87f1-cb5de98a977d";
/**
* @author Cadentem
* @reason Fix broken implementation
*/
@Overwrite
public static void handlerPlayerTick(final Player player) {
if (player.tickCount % 10 != 0) {
return;
}
AttributeInstance attribute = player.getAttribute(Attributes.ATTACK_SPEED);
if (attribute != null) {
int level = player.getItemInHand(player.getUsedItemHand()).getEnchantmentLevel(ModEnchantments.FASTER_ATTACK.get());
AttributeModifier modifier = attribute.getModifier(UUID.fromString(ATTRIBUTE_UUID));
if (modifier != null) {
attribute.removeModifier(modifier);
}
if (level > 0) {
attribute.addTransientModifier(new AttributeModifier(UUID.fromString(ATTRIBUTE_UUID), "Faster Attack enchantment", level, AttributeModifier.Operation.MULTIPLY_BASE));
}
}
}
}
If I set some weapons with different Faster Attack lvl in toolbar, then switching between them (using mouse scroll) doesn't apply proper enchant lvl.
Here I have swords with this enchantment arranged from V to I. The last one sword lvl 1 has attack speed value as the first one with enchantment lvl 5:
Here's code example that could solve that (in HandlerFasterAttack.java):