-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
+Added Fix for item tooltip attack damage/speed; -Removed the text placeholders %playerex:level_top_1% to 10. +Added the text placeholder: %playerex:level_top/x% where x is the position on the server's level leaderboard. I.e. x = 1 would mean the highest level, then x = 2 would be the next highest level etc.
- Loading branch information
1 parent
8ce58e1
commit b613ef1
Showing
6 changed files
with
112 additions
and
20 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
src/main/java/com/github/clevernucleus/playerex/mixin/EntityAttributeInstanceMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.clevernucleus.playerex.mixin; | ||
|
||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
import com.github.clevernucleus.playerex.util.EntityAttributeInstanceAccess; | ||
|
||
import net.minecraft.entity.attribute.EntityAttributeInstance; | ||
import net.minecraft.entity.attribute.EntityAttributeModifier; | ||
import net.minecraft.entity.attribute.EntityAttributeModifier.Operation; | ||
|
||
@Mixin(EntityAttributeInstance.class) | ||
abstract class EntityAttributeInstanceMixin implements EntityAttributeInstanceAccess { | ||
|
||
@Final | ||
@Shadow | ||
private Map<EntityAttributeModifier.Operation, Set<EntityAttributeModifier>> operationToModifiers; | ||
|
||
@Override | ||
public Collection<EntityAttributeModifier> modifiersByOperation(Operation operationIn) { | ||
return (Collection<EntityAttributeModifier>)this.operationToModifiers.getOrDefault(operationIn, Collections.emptySet()); | ||
} | ||
} |
55 changes: 40 additions & 15 deletions
55
src/main/java/com/github/clevernucleus/playerex/mixin/client/ItemStackMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,63 @@ | ||
package com.github.clevernucleus.playerex.mixin.client; | ||
|
||
import java.util.UUID; | ||
import java.util.function.Supplier; | ||
|
||
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.ModifierData; | ||
import com.github.clevernucleus.playerex.util.EntityAttributeInstanceAccess; | ||
import com.github.clevernucleus.playerex.util.ItemFieldAccess; | ||
|
||
import net.minecraft.entity.attribute.EntityAttribute; | ||
import net.minecraft.entity.attribute.EntityAttributeInstance; | ||
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) | ||
abstract class ItemStackMixin { | ||
private double modifyGeneralisedValue(double dIn, PlayerEntity player, EntityAttribute attributeIn, Supplier<UUID> uuidIn) { | ||
if(player == null) return dIn; | ||
|
||
EntityAttributeInstance instance = player.getAttributeInstance(attributeIn); | ||
EntityAttributeInstanceAccess access = (EntityAttributeInstanceAccess)instance; | ||
|
||
double d = dIn; | ||
|
||
for(EntityAttributeModifier modifier : access.modifiersByOperation(EntityAttributeModifier.Operation.ADDITION)) { | ||
if(modifier.getId().equals(uuidIn.get())) continue; | ||
|
||
d += modifier.getValue(); | ||
} | ||
|
||
double e = d; | ||
|
||
for(EntityAttributeModifier modifier : access.modifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_BASE)) { | ||
e += d * modifier.getValue(); | ||
} | ||
|
||
for(EntityAttributeModifier modifier : access.modifiersByOperation(EntityAttributeModifier.Operation.MULTIPLY_TOTAL)) { | ||
e *= 1.0D + modifier.getValue(); | ||
} | ||
|
||
return attributeIn.clamp(e); | ||
} | ||
|
||
@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 1), ordinal = 0) | ||
private double modifyAttackDamage(double d, PlayerEntity player) { | ||
if(player == null) return d; | ||
|
||
ModifierData data = ExAPI.DATA.get(player); | ||
double value = data.get(EntityAttributes.GENERIC_ATTACK_DAMAGE); | ||
if(!ExAPI.CONFIG.get().enableTooltipFix()) return d; | ||
|
||
System.out.println("v: " + value); | ||
// TODO got sleepy will finish later | ||
return d + value + 10; | ||
return modifyGeneralisedValue(d, player, EntityAttributes.GENERIC_ATTACK_DAMAGE, ItemFieldAccess::attackDamageModifierId); | ||
} | ||
/* | ||
|
||
@ModifyVariable(method = "getTooltip", at = @At(value = "STORE", ordinal = 3), ordinal = 0) | ||
private double modifyAttackSpeed(double d, PlayerEntity player) { | ||
if(player == null) return d; | ||
ModifierData data = ExAPI.DATA.get(player); | ||
double value = data.get(EntityAttributes.GENERIC_ATTACK_SPEED); | ||
if(!ExAPI.CONFIG.get().enableTooltipFix()) return d; | ||
|
||
return d + value; | ||
}*/ | ||
return modifyGeneralisedValue(d, player, EntityAttributes.GENERIC_ATTACK_SPEED, ItemFieldAccess::attackSpeedModifierId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/github/clevernucleus/playerex/util/EntityAttributeInstanceAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.github.clevernucleus.playerex.util; | ||
|
||
import java.util.Collection; | ||
|
||
import net.minecraft.entity.attribute.EntityAttributeModifier; | ||
|
||
public interface EntityAttributeInstanceAccess { | ||
|
||
Collection<EntityAttributeModifier> modifiersByOperation(EntityAttributeModifier.Operation operationIn); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/github/clevernucleus/playerex/util/ItemFieldAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.github.clevernucleus.playerex.util; | ||
|
||
import java.util.UUID; | ||
|
||
import net.minecraft.item.Item; | ||
|
||
public final class ItemFieldAccess extends Item { | ||
private ItemFieldAccess() { | ||
super(new Item.Settings()); | ||
} | ||
|
||
public static UUID attackDamageModifierId() { | ||
return ATTACK_DAMAGE_MODIFIER_ID; | ||
} | ||
|
||
public static UUID attackSpeedModifierId() { | ||
return ATTACK_SPEED_MODIFIER_ID; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters