Add Absorbing Radius to Barriers

This commit is contained in:
Kam committed 2026-03-09 17:26:55 -04:00
1 parent 2f4ddb30ec
commit b960ef602c
6 files changed
+72 -3

No files matched your search

@@ -32,6 +32,11 @@ public class EnergyBarrierData {
// Absorbing: caster's damage is redirected to the barrier
public boolean absorbing = false;
// Absorb radius: max distance from barrier's current position for absorption to work
// -1 = no radius limit (absorb regardless of distance)
// 0 = use barrier's own extent as the radius (dome radius, panel half-size, etc.)
// positive = owner must be within this many blocks of the barrier entity
public float absorbRadius = 0.0f;
// Melee: barrier can be hit by melee attacks
public boolean meleeEnabled = false;
@@ -148,6 +153,14 @@ public class EnergyBarrierData {
this.targetOwner = targetOwner;
}
public float getAbsorbRadius() {
return absorbRadius;
}
public void setAbsorbRadius(float absorbRadius) {
this.absorbRadius = absorbRadius;
}
// ==================== NBT ====================
public void writeNBT(NBTTagCompound nbt) {
@@ -160,6 +173,7 @@ public class EnergyBarrierData {
nbt.setBoolean("barrierKnockback", knockbackEnabled);
nbt.setFloat("barrierKnockbackStr", knockbackStrength);
nbt.setBoolean("barrierAbsorbing", absorbing);
nbt.setFloat("barrierAbsorbRadius", absorbRadius);
nbt.setBoolean("barrierMelee", meleeEnabled);
nbt.setFloat("barrierMeleeMult", meleeDamageMultiplier);
nbt.setBoolean("barrierReflect", reflect);
@@ -183,6 +197,7 @@ public class EnergyBarrierData {
knockbackEnabled = nbt.hasKey("barrierKnockback") && nbt.getBoolean("barrierKnockback");
knockbackStrength = nbt.hasKey("barrierKnockbackStr") ? nbt.getFloat("barrierKnockbackStr") : 1.0f;
absorbing = nbt.hasKey("barrierAbsorbing") && nbt.getBoolean("barrierAbsorbing");
absorbRadius = nbt.hasKey("barrierAbsorbRadius") ? nbt.getFloat("barrierAbsorbRadius") : 0.0f;
meleeEnabled = nbt.hasKey("barrierMelee") && nbt.getBoolean("barrierMelee");
meleeDamageMultiplier = nbt.hasKey("barrierMeleeMult") ? nbt.getFloat("barrierMeleeMult") : 1.0f;
reflect = nbt.hasKey("barrierReflect") && nbt.getBoolean("barrierReflect");
@@ -207,6 +222,7 @@ public class EnergyBarrierData {
copy.knockbackEnabled = knockbackEnabled;
copy.knockbackStrength = knockbackStrength;
copy.absorbing = absorbing;
copy.absorbRadius = absorbRadius;
copy.meleeEnabled = meleeEnabled;
copy.meleeDamageMultiplier = meleeDamageMultiplier;
copy.reflect = reflect;
@@ -292,6 +292,14 @@ public abstract class AbilityBarrier extends AbilityEnergy {
barrierData.absorbing = absorbing;
}
public float getAbsorbRadius() {
return barrierData.absorbRadius;
}
public void setAbsorbRadius(float radius) {
barrierData.absorbRadius = radius;
}
// Reflection data
public boolean isReflect() {
return barrierData.reflect;
@@ -395,6 +403,9 @@ public abstract class AbilityBarrier extends AbilityEnergy {
.range(0, 10).visibleWhen(this::isKnockbackEnabled));
defs.add(FieldDef.boolField("ability.absorbing", this::isAbsorbing, this::setAbsorbing)
.hover("ability.hover.absorbing"));
defs.add(FieldDef.floatField("ability.absorbRadius", this::getAbsorbRadius, this::setAbsorbRadius)
.range(-1, 128).visibleWhen(this::isAbsorbing)
.hover("ability.hover.absorbRadius"));
defs.add(FieldDef.boolField("ability.reflect", this::isReflect, this::setReflect)
.hover("ability.hover.reflect"));
defs.add(FieldDef.floatField("ability.reflectStrength", this::getReflectStrengthPct, this::setReflectStrengthPct)
@@ -630,7 +630,13 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
/**
* Find a barrier that would absorb damage for the given entity (its caster).
* Returns the barrier if: absorbing is enabled AND entity is the barrier's owner.
* Returns the barrier if: absorbing is enabled, entity is the barrier's owner,
* and entity is within the barrier's absorb radius of the barrier's current position.
*
* Absorb radius behavior:
* -1 = no limit (absorb regardless of distance)
* 0 = uses the barrier's extent as the radius (dome radius, panel half-size, etc.)
* >0 = owner must be within this many blocks of the barrier entity
*/
public static EntityEnergyBarrier getAbsorbingBarrier(Entity entity) {
if (entity == null || entity.worldObj == null) return null;
@@ -638,7 +644,33 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
for (EntityEnergyBarrier barrier : barriers) {
if (barrier.isDead) continue;
if (!barrier.barrierData.absorbing) continue;
if (barrier.ownerEntityId == entity.getEntityId()) {
if (barrier.ownerEntityId != entity.getEntityId()) continue;
float absorbRadius = barrier.barrierData.absorbRadius;
// -1 = unlimited range
if (absorbRadius < 0) {
return barrier;
}
// 0 = use barrier's own extent as the effective radius
// Domes: dome radius. Panels: max(width, height) * 0.5 + 1.0, doubled.
float effectiveRadius;
if (absorbRadius > 0) {
effectiveRadius = absorbRadius;
} else if (barrier instanceof EntityEnergyDome) {
effectiveRadius = barrier.getMaxExtent();
} else {
effectiveRadius = barrier.getMaxExtent() * 3.0f;
}
// Distance check from barrier's current position to the owner
double dx = entity.posX - barrier.posX;
double dy = (entity.posY + entity.height * 0.5) - barrier.posY;
double dz = entity.posZ - barrier.posZ;
double distSq = dx * dx + dy * dy + dz * dz;
if (distSq <= (double) effectiveRadius * effectiveRadius) {
return barrier;
}
}
@@ -121,6 +121,14 @@ public class ScriptEnergyBarrier<T extends EntityEnergyBarrier> extends ScriptEn
entity.getBarrierData().absorbing = absorbing;
}
public float getAbsorbRadius() {
return entity.getBarrierData().absorbRadius;
}
public void setAbsorbRadius(float radius) {
entity.getBarrierData().absorbRadius = radius;
}
public boolean isReflect() {
return entity.getBarrierData().reflect;
}