Dome, Panel Settings

This commit is contained in:
Kam committed 2026-02-20 18:16:52 -05:00
1 parent 14545818bd
commit f620e820e8
16 files changed
+752 -146

No files matched your search

@@ -5,12 +5,18 @@ import kamkeel.npcs.controllers.data.ability.data.EnergyBarrierData;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
import noppes.npcs.EventHooks;
import noppes.npcs.entity.EntityNPCInterface;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Base class for energy barrier entities (Dome, Panel).
* Provides shared health, damage, hit flash, knockback target,
@@ -19,6 +25,35 @@ import noppes.npcs.entity.EntityNPCInterface;
*/
public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
// ==================== ACTIVE BARRIER REGISTRY ====================
private static final List<WeakReference<EntityEnergyBarrier>> activeBarriers = new ArrayList<>();
private boolean tracked = false;
public static void trackBarrier(EntityEnergyBarrier barrier) {
activeBarriers.add(new WeakReference<>(barrier));
}
/**
* Get all living barriers in the given world. Auto-cleans dead refs.
*/
public static List<EntityEnergyBarrier> getActiveBarriers(World world) {
List<EntityEnergyBarrier> result = new ArrayList<>();
Iterator<WeakReference<EntityEnergyBarrier>> it = activeBarriers.iterator();
while (it.hasNext()) {
EntityEnergyBarrier b = it.next().get();
if (b == null || b.isDead) {
it.remove();
} else if (b.worldObj == world) {
result.add(b);
}
}
return result;
}
public static void clearAllBarriers() {
activeBarriers.clear();
}
// ==================== BARRIER PROPERTIES ====================
protected EnergyBarrierData barrierData = new EnergyBarrierData();
protected float currentHealth;
@@ -63,6 +98,65 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
*/
protected abstract void knockbackEntities();
/**
* Get the maximum extent of this barrier for distance pre-filtering.
* Dome returns radius, Panel returns max(width, height) / 2.
*/
public abstract float getMaxExtent();
/**
* Check if a generic (non-CNPC+) projectile is incoming toward this barrier.
* Uses the same geometric logic as isIncomingProjectile but with raw position data.
*
* @param posX, posY, posZ Current (or predicted) position of the projectile
* @param motionX, motionY, motionZ Current velocity of the projectile
* @param prevPosX, prevPosY, prevPosZ Previous position of the projectile
* @param ownerEntityId Entity ID of the projectile's shooter
*/
public abstract boolean isIncomingGenericProjectile(
double posX, double posY, double posZ,
double motionX, double motionY, double motionZ,
double prevPosX, double prevPosY, double prevPosZ,
int ownerEntityId);
// ==================== GENERIC PROJECTILE HIT ====================
/**
* Apply damage from a generic (non-CNPC+) projectile to this barrier.
* Uses the typeId for damage multiplier lookup (e.g. "dbc.ki_attack").
*
* @param projectileEntity The entity that hit the barrier (for context)
* @param damage Base damage to apply
* @param typeId Type identifier for damage multiplier lookup
* @return true if the barrier absorbed the hit (projectile should be destroyed)
*/
public boolean onGenericProjectileHit(Entity projectileEntity, float damage, String typeId) {
float multiplier = barrierData.getMultiplier(typeId);
float finalDamage = damage * multiplier;
if (!worldObj.isRemote) {
float eventDamage = EventHooks.onEnergyBarrierHit(this, ownerEntityId, null, finalDamage);
if (eventDamage < 0) return false;
finalDamage = eventDamage;
}
triggerHitFlash();
if (!barrierData.useHealth) {
return true;
}
currentHealth -= finalDamage;
syncHealthPercent();
if (currentHealth <= 0) {
onBarrierDestroyed();
this.setDead();
}
return true;
}
// ==================== PROJECTILE HIT ====================
/**
@@ -146,8 +240,12 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
*/
protected boolean updateBarrierTick() {
if (!worldObj.isRemote) {
// Fire spawned event on first tick
// Track barrier and fire spawned event on first tick
if (ticksAlive == 1) {
if (!tracked) {
trackBarrier(this);
tracked = true;
}
EventHooks.onEnergyBarrierSpawned(this, ownerEntityId);
}
@@ -247,6 +345,83 @@ public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
return AbilityTargetHelper.isAlly((EntityLivingBase) owner, entity);
}
// ==================== CONTAINMENT & PROTECTION ====================
/**
* Check if an entity is geometrically inside this barrier's protected zone.
* Override in subclasses (dome checks sphere containment).
*/
public boolean isEntityInside(Entity entity) {
return false;
}
/**
* Check if a damage source originates from outside this barrier.
* Uses geometry-specific containment check via isEntityInside().
*/
public boolean isDamageFromOutside(DamageSource source) {
Entity attacker = source.getEntity();
if (attacker == null) return true; // Environmental damage treated as outside
return !isEntityInside(attacker);
}
/**
* Find a barrier that would protect the given entity from outside damage.
* Returns the barrier if: damageProtection is enabled AND entity is inside.
* Any entity inside a dome with damageProtection gets redirected damage.
*/
public static EntityEnergyBarrier getProtectingBarrier(Entity entity) {
if (entity == null || entity.worldObj == null) return null;
List<EntityEnergyBarrier> barriers = getActiveBarriers(entity.worldObj);
for (EntityEnergyBarrier barrier : barriers) {
if (barrier.isDead) continue;
if (!barrier.barrierData.damageProtection) continue;
if (barrier.isEntityInside(entity)) {
return barrier;
}
}
return null;
}
/**
* Absorb damage from an external source. Reduces barrier health directly.
* Used by damage protection to redirect attacks on inside entities to the barrier.
*
* @param amount The damage amount to absorb
* @return true if damage was absorbed (barrier still alive or just destroyed)
*/
public boolean absorbDamage(float amount) {
if (worldObj.isRemote) return false;
triggerHitFlash();
if (!barrierData.useHealth) {
return true; // Duration-only: absorb but no health loss
}
currentHealth -= amount;
syncHealthPercent();
if (currentHealth <= 0) {
onBarrierDestroyed();
this.setDead();
}
return true;
}
/**
* Teleport an entity to a position. Uses network handler for players
* to ensure reliable client synchronization.
*/
protected void teleportEntity(EntityLivingBase ent, double x, double y, double z) {
if (ent instanceof EntityPlayerMP) {
EntityPlayerMP player = (EntityPlayerMP) ent;
player.playerNetServerHandler.setPlayerLocation(x, y, z, player.rotationYaw, player.rotationPitch);
} else {
ent.setPosition(x, y, z);
}
}
// ==================== GETTERS ====================
public EnergyBarrierData getBarrierData() {