2018-09-16 00:45:44 +02:00
|
|
|
package com.minelittlepony.unicopia.player;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2018-09-19 09:09:30 +02:00
|
|
|
import com.minelittlepony.unicopia.inventory.InventoryOfHolding;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.SharedMonsterAttributes;
|
|
|
|
import net.minecraft.entity.ai.attributes.AttributeModifier;
|
|
|
|
import net.minecraft.entity.ai.attributes.IAttribute;
|
|
|
|
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-09-19 09:09:30 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
|
|
|
class PlayerAttributes {
|
|
|
|
public static final int ADD = 0;
|
|
|
|
public static final int ADD_PERCENTAGE = 1;
|
|
|
|
public static final int MULTIPLY = 2;
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
private static final AttributeModifier EARTH_PONY_STRENGTH =
|
2018-09-16 00:45:44 +02:00
|
|
|
new AttributeModifier(UUID.fromString("777a5505-521e-480b-b9d5-6ea54f259564"), "Earth Pony Strength", 0.6, MULTIPLY);
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
private static final AttributeModifier PEGASUS_SPEED =
|
2018-09-16 00:45:44 +02:00
|
|
|
new AttributeModifier(UUID.fromString("9e2699fc-3b8d-4f71-9d2d-fb92ee19b4f7"), "Pegasus Speed", 0.2, MULTIPLY);
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
private static final AttributeModifier PEGASUS_REACH =
|
2018-09-16 00:45:44 +02:00
|
|
|
new AttributeModifier(UUID.fromString("707b50a8-03e8-40f4-8553-ecf67025fd6d"), "Pegasus Reach", 1.5, ADD);
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
private double loadStrength = 0;
|
|
|
|
|
2019-01-31 18:17:11 +01:00
|
|
|
private final WalkSpeed walker = new WalkSpeed();
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
public void applyAttributes(EntityPlayer entity, Race race) {
|
2018-09-19 09:09:30 +02:00
|
|
|
loadStrength = 0;
|
|
|
|
|
|
|
|
for (ItemStack item : entity.inventory.mainInventory) {
|
|
|
|
loadStrength += InventoryOfHolding.decodeStackWeight(item);
|
|
|
|
}
|
|
|
|
for (ItemStack item : entity.inventory.armorInventory) {
|
|
|
|
loadStrength += InventoryOfHolding.decodeStackWeight(item);
|
|
|
|
}
|
|
|
|
|
2019-01-31 18:17:11 +01:00
|
|
|
walker.setPlayerWalkSpeed(entity.capabilities, 0.1F - (float)(loadStrength / 100000));
|
2018-09-19 09:09:30 +02:00
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
applyAttribute(entity, SharedMonsterAttributes.ATTACK_DAMAGE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
|
|
|
applyAttribute(entity, SharedMonsterAttributes.KNOCKBACK_RESISTANCE, EARTH_PONY_STRENGTH, race.canUseEarth());
|
|
|
|
applyAttribute(entity, SharedMonsterAttributes.MOVEMENT_SPEED, PEGASUS_SPEED, race.canFly());
|
|
|
|
applyAttribute(entity, SharedMonsterAttributes.ATTACK_SPEED, PEGASUS_SPEED, race.canFly());
|
|
|
|
applyAttribute(entity, EntityPlayer.REACH_DISTANCE, PEGASUS_REACH, race.canFly());
|
|
|
|
}
|
|
|
|
|
|
|
|
private void applyAttribute(EntityPlayer entity, IAttribute attribute, AttributeModifier modifier, boolean enable) {
|
|
|
|
IAttributeInstance instance = entity.getEntityAttribute(attribute);
|
|
|
|
|
|
|
|
if (enable) {
|
|
|
|
if (instance.getModifier(modifier.getID()) == null) {
|
|
|
|
instance.applyModifier(modifier);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (instance.getModifier(modifier.getID()) != null) {
|
|
|
|
instance.removeModifier(modifier);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|