From 0b37572cc3f9dd5087612bc103e8280499c03e5f Mon Sep 17 00:00:00 2001 From: Pug <81167232+MerchantPug@users.noreply.github.com> Date: Mon, 13 Nov 2023 03:36:06 +1100 Subject: [PATCH] Add `should_damage_condition` field to `freeze` power type. --- CHANGELOG.md | 1 + .../mixin/xplatform/common/LivingEntityMixin.java | 2 +- .../apugli/power/factory/FreezePowerFactory.java | 13 +++++++++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 560a639b..389a2fbf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Added `function` field to `modify_durability_change` power type. Can be `floor`, `round`, or `ceiling`. Defaults to `floor`. - Added `self_target_bientity_action`, `self_nearby_bientity_action`, and `target_nearby_bientity_action` to `damage_nearby_on_hit` power type. (All optional). - Added `attacker_target_bientity_action`, `attacker_nearby_bientity_action`, and `self_nearby_bientity_action` to `damage_nearby_when_hit` power type. (All optional). +- Added `should_damage_condition` to `freeze` power type. ### Bi-entity Condition Types - Added `compare_dimensions` bi-entity condition type. diff --git a/Common/src/main/java/net/merchantpug/apugli/mixin/xplatform/common/LivingEntityMixin.java b/Common/src/main/java/net/merchantpug/apugli/mixin/xplatform/common/LivingEntityMixin.java index 67a2eee9..0c835789 100644 --- a/Common/src/main/java/net/merchantpug/apugli/mixin/xplatform/common/LivingEntityMixin.java +++ b/Common/src/main/java/net/merchantpug/apugli/mixin/xplatform/common/LivingEntityMixin.java @@ -153,7 +153,7 @@ public LivingEntityMixin(EntityType extends LivingEntity> entityType, Level wo @ModifyExpressionValue(method = "aiStep", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/LivingEntity;canFreeze()Z", ordinal = 1)) private boolean apugli$stopFreezeDamage(boolean original) { - if (Services.POWER.hasPower((LivingEntity)(Object)this, ApugliPowers.FREEZE.get()) && Services.POWER.getPowers((LivingEntity)(Object)this, ApugliPowers.FREEZE.get()).stream().anyMatch(p -> !ApugliPowers.FREEZE.get().shouldDamage(p))) { + if (Services.POWER.hasPower((LivingEntity)(Object)this, ApugliPowers.FREEZE.get()) && Services.POWER.getPowers((LivingEntity)(Object)this, ApugliPowers.FREEZE.get()).stream().anyMatch(p -> !ApugliPowers.FREEZE.get().shouldDamage(p, (LivingEntity)(Object)this))) { return false; } return original; diff --git a/Common/src/main/java/net/merchantpug/apugli/power/factory/FreezePowerFactory.java b/Common/src/main/java/net/merchantpug/apugli/power/factory/FreezePowerFactory.java index e4ee7331..35a0526f 100644 --- a/Common/src/main/java/net/merchantpug/apugli/power/factory/FreezePowerFactory.java +++ b/Common/src/main/java/net/merchantpug/apugli/power/factory/FreezePowerFactory.java @@ -2,16 +2,25 @@ import io.github.apace100.calio.data.SerializableData; import io.github.apace100.calio.data.SerializableDataTypes; +import net.merchantpug.apugli.platform.Services; +import net.minecraft.world.entity.Entity; public interface FreezePowerFactory
extends ValueModifyingPowerFactory
{ static SerializableData getSerializableData() { return ValueModifyingPowerFactory.getSerializableData() + .add("should_damage_condition", Services.CONDITION.entityDataType(), null) .add("should_damage", SerializableDataTypes.BOOLEAN, true); } - default boolean shouldDamage(P power) { - return getDataFromPower(power).getBoolean("should_damage"); + default boolean shouldDamage(P power, Entity entity) { + SerializableData.Instance data = getDataFromPower(power); + + if (!Services.CONDITION.checkEntity(data, "should_damage_condition", entity)) { + return false; + } + + return data.getBoolean("should_damage"); } }