mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 03:26:44 +01:00
Include max health in what's swapped by the mind swap spell
This commit is contained in:
parent
4b776c4d2b
commit
9a19ed36c1
2 changed files with 19 additions and 1 deletions
|
@ -3,10 +3,12 @@ package com.minelittlepony.unicopia.entity.behaviour;
|
|||
import java.util.*;
|
||||
|
||||
import com.minelittlepony.unicopia.entity.Living;
|
||||
import com.minelittlepony.unicopia.entity.player.PlayerAttributes;
|
||||
import com.minelittlepony.unicopia.util.Swap;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.mob.PathAwareEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket;
|
||||
|
@ -46,12 +48,22 @@ public interface EntitySwap {
|
|||
effects.forEach(entity::addStatusEffect);
|
||||
}
|
||||
);
|
||||
Swap<LivingEntity> MAX_HEALTH = Swap.of(LivingEntity::getMaxHealth, (e, newMax) -> {
|
||||
float oldHealthPercentage = e.getHealth() / e.getMaxHealth();
|
||||
e.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).removeModifier(PlayerAttributes.HEALTH_SWAPPING_MODIFIER_ID);
|
||||
|
||||
float change = newMax - e.getMaxHealth();
|
||||
if (!MathHelper.approximatelyEquals(change, 0)) {
|
||||
e.getAttributeInstance(EntityAttributes.GENERIC_MAX_HEALTH).addPersistentModifier(PlayerAttributes.healthChange(change));
|
||||
}
|
||||
e.setHealth(oldHealthPercentage * newMax);
|
||||
});
|
||||
Swap<LivingEntity> HEALTH = Swap.of(LivingEntity::getHealth, LivingEntity::getMaxHealth, LivingEntity::setHealth, Number::floatValue);
|
||||
Swap<LivingEntity> AIR = Swap.of(LivingEntity::getAir, LivingEntity::getMaxAir, LivingEntity::setAir, Number::intValue);
|
||||
|
||||
List<Swap<Entity>> REGISTRY = new ArrayList<>(List.of(
|
||||
Swap.union(POSITION, VELOCITY, PITCH, YAW, HEAD_YAW, BODY_YAW, FIRE_TICKS, PASSENGERS),
|
||||
Swap.union(STATUS_EFFECTS, HEALTH, AIR).upcast(e -> e instanceof LivingEntity)
|
||||
Swap.union(STATUS_EFFECTS, MAX_HEALTH, HEALTH, AIR).upcast(e -> e instanceof LivingEntity)
|
||||
));
|
||||
Swap<Entity> ALL = Swap.union(REGISTRY);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,12 @@ public class PlayerAttributes implements Tickable {
|
|||
public static final EntityAttributeModifier BAT_HANGING =
|
||||
new EntityAttributeModifier(UUID.fromString("a54f2595-521e-480b-b9d5-6e750577a564"), "Bat Pony Hanging", -2, Operation.MULTIPLY_TOTAL);
|
||||
|
||||
public static final UUID HEALTH_SWAPPING_MODIFIER_ID = UUID.fromString("7b93803e-4b25-11ed-951e-00155d43e0a2");
|
||||
|
||||
public static EntityAttributeModifier healthChange(float addition) {
|
||||
return new EntityAttributeModifier(HEALTH_SWAPPING_MODIFIER_ID, "Health Swap", addition, Operation.ADDITION);
|
||||
}
|
||||
|
||||
private final Pony pony;
|
||||
|
||||
public PlayerAttributes(Pony pony) {
|
||||
|
|
Loading…
Reference in a new issue