apace100/apoli

Accidental `modify_death_ticks` function in `modify_resource` entity action type.

MerchantPug opened this issue · 0 comments

I've noticed a niche error within the modify_resource entity action type. It's niche enough that nobody would notice it without actually looking at the code because you'd usually want to use this action on an alive entity.

public static void action(SerializableData.Instance data, Entity entity) {
        if(entity instanceof LivingEntity living) {
            PowerHolderComponent component = PowerHolderComponent.KEY.get(entity);
            PowerType<?> powerType = data.get("resource");
            Power p = component.getPower(powerType);
            Modifier modifier = data.get("modifier");
            if(p instanceof VariableIntPower vip) {
                vip.setValue((int)modifier.apply(entity, vip.getValue()));
                PowerHolderComponent.syncPower(entity, powerType);
            } else if(p instanceof CooldownPower cp) {
                int targetRemainingTicks = (int)modifier.apply(entity, cp.getRemainingTicks());
                if(targetRemainingTicks < 0) {
                    targetRemainingTicks = 0;
                }
                cp.modify(targetRemainingTicks - cp.getRemainingTicks());
                PowerHolderComponent.syncPower(entity, powerType);
            }
            living.deathTime = (int)data.<Modifier>get("modifier").apply(entity, living.deathTime);
        }
    }

You might've picked it up by me pointing it out, but after the action functions, it will act as if it were a modify death ticks action.
living.deathTime = (int)data.<Modifier>get("modifier").apply(entity, living.deathTime);