diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/util/AbilityTargetHelper.java b/src/main/java/kamkeel/npcs/controllers/data/ability/util/AbilityTargetHelper.java index 7f4c772c7..3827f8691 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/util/AbilityTargetHelper.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/util/AbilityTargetHelper.java @@ -27,7 +27,10 @@ public class AbilityTargetHelper { * */ public static boolean isAlly(EntityLivingBase caster, Entity target) { + if (caster == null || target == null) return false; if (target == caster) return true; + // Ally resolution relies on server-owned player/party/faction state. + if (caster.worldObj == null || caster.worldObj.isRemote) return false; // NPC target checks if (target instanceof EntityNPCInterface) { @@ -44,7 +47,9 @@ public class AbilityTargetHelper { // Player caster: friendly faction = ally if (caster instanceof EntityPlayer) { - if (targetNpc.faction.isFriendlyToPlayer((EntityPlayer) caster)) return true; + EntityPlayer casterPlayer = (EntityPlayer) caster; + if (PlayerData.get(casterPlayer) == null) return false; + if (targetNpc.faction.isFriendlyToPlayer(casterPlayer)) return true; } return false; @@ -54,7 +59,9 @@ public class AbilityTargetHelper { if (target instanceof EntityPlayer && caster instanceof EntityNPCInterface) { // NPC caster vs Player target: faction friendly to player = ally EntityNPCInterface casterNpc = (EntityNPCInterface) caster; - return casterNpc.faction.isFriendlyToPlayer((EntityPlayer) target); + EntityPlayer targetPlayer = (EntityPlayer) target; + if (PlayerData.get(targetPlayer) == null) return false; + return casterNpc.faction.isFriendlyToPlayer(targetPlayer); } if (target instanceof EntityPlayer && caster instanceof EntityPlayer) { @@ -63,6 +70,7 @@ public class AbilityTargetHelper { EntityPlayer targetPlayer = (EntityPlayer) target; PlayerData casterData = PlayerData.get(casterPlayer); PlayerData targetData = PlayerData.get(targetPlayer); + if (casterData == null || targetData == null) return false; if (casterData.partyUUID != null && casterData.partyUUID.equals(targetData.partyUUID)) { Party party = PartyController.Instance().getParty(casterData.partyUUID); if (party != null && !party.friendlyFire()) return true; @@ -86,6 +94,8 @@ public class AbilityTargetHelper { */ public static boolean shouldAffect(EntityLivingBase caster, Entity target, TargetFilter filter, boolean includeSelf) { + if (caster == null || target == null || filter == null) return false; + if (caster.worldObj == null || caster.worldObj.isRemote) return false; if (target == caster) return includeSelf; if (!(target instanceof EntityLivingBase)) return false; if (!target.isEntityAlive()) return false; diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityBarrier.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityBarrier.java index 6c5fcc76c..6c1df56d3 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityBarrier.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityBarrier.java @@ -4,10 +4,12 @@ import kamkeel.npcs.controllers.data.ability.util.AbilityTargetHelper; import kamkeel.npcs.controllers.data.ability.data.energy.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.CustomNpcs; import noppes.npcs.EventHooks; import noppes.npcs.entity.EntityNPCInterface; @@ -439,16 +441,56 @@ public abstract class EntityAbilityBarrier extends EntityEnergyAbility { return this.dataWatcher.getWatchableObjectFloat(DW_HEALTH_PERCENT); } + /** + * Client prediction only runs for the local player. + */ + protected EntityPlayer getClientPredictionPlayer() { + return worldObj != null && worldObj.isRemote ? CustomNpcs.proxy.getPlayer() : null; + } + + /** + * Shared target filter used by Dome/Panel physics loops. + */ + protected boolean shouldSkipBarrierPhysicsTarget(EntityLivingBase entity, EntityPlayer clientPredictionPlayer) { + if (entity == null || !entity.isEntityAlive()) return true; + if (entity.getEntityId() == ownerEntityId) return true; + if (worldObj.isRemote && (clientPredictionPlayer == null || entity != clientPredictionPlayer)) return true; + return isAllyOfOwner(entity); + } + /** * Check if an entity is an ally of this barrier's owner. - * Allies are not affected by barrier physics. + * Server uses full relationship logic; client uses a lightweight safe approximation. */ protected boolean isAllyOfOwner(EntityLivingBase entity) { Entity owner = getOwnerEntity(); if (owner == null || !(owner instanceof EntityLivingBase)) return false; + if (worldObj != null && worldObj.isRemote) { + return isClientPredictedAlly((EntityLivingBase) owner, entity); + } return AbilityTargetHelper.isAlly((EntityLivingBase) owner, entity); } + /** + * Client-safe ally approximation used only for movement prediction. + * Avoids PlayerData/Party/Faction point lookups that are server-owned. + */ + protected boolean isClientPredictedAlly(EntityLivingBase owner, EntityLivingBase target) { + if (owner == null || target == null) return false; + if (owner == target) return true; + + if (target instanceof EntityNPCInterface) { + EntityNPCInterface targetNpc = (EntityNPCInterface) target; + if (targetNpc.faction.isPassive) return true; + if (owner instanceof EntityNPCInterface) { + EntityNPCInterface ownerNpc = (EntityNPCInterface) owner; + return ownerNpc.faction.id == targetNpc.faction.id; + } + } + + return false; + } + // ==================== CONTAINMENT & ABSORBING ==================== /** diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityDome.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityDome.java index cf20be91e..53bfe8358 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityDome.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityDome.java @@ -258,18 +258,11 @@ public class EntityAbilityDome extends EntityAbilityBarrier { posX + r + knockbackMargin, posY + r + knockbackMargin, posZ + r + knockbackMargin ); - // On client, identify local player for client-side solid prediction - EntityPlayer localPlayer = worldObj.isRemote ? CustomNpcs.proxy.getPlayer() : null; + EntityPlayer localPlayer = getClientPredictionPlayer(); List entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox); for (EntityLivingBase ent : entities) { - if (ent.getEntityId() == ownerEntityId) continue; - - // Client-side: only process local player for solid prediction - // Must be checked before isAllyOfOwner which uses server-only PlayerData - if (worldObj.isRemote && (localPlayer == null || ent != localPlayer)) continue; - - if (isAllyOfOwner(ent)) continue; + if (shouldSkipBarrierPhysicsTarget(ent, localPlayer)) continue; // Current position relative to dome center double dx = ent.posX - posX; diff --git a/src/main/java/kamkeel/npcs/entity/EntityAbilityPanel.java b/src/main/java/kamkeel/npcs/entity/EntityAbilityPanel.java index a0092a2d7..b34502e8a 100644 --- a/src/main/java/kamkeel/npcs/entity/EntityAbilityPanel.java +++ b/src/main/java/kamkeel/npcs/entity/EntityAbilityPanel.java @@ -13,7 +13,6 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.DamageSource; import net.minecraft.world.World; -import noppes.npcs.CustomNpcs; import noppes.npcs.NpcDamageSource; import noppes.npcs.entity.EntityNPCInterface; @@ -203,10 +202,8 @@ public class EntityAbilityPanel extends EntityAbilityBarrier { Entity owner = getOwnerEntity(); for (EntityLivingBase target : entities) { - if (target == owner) continue; - if (owner instanceof EntityNPCInterface && target instanceof EntityNPCInterface) { - if (((EntityNPCInterface) owner).faction.id == ((EntityNPCInterface) target).faction.id) continue; - } + if (target.getEntityId() == ownerEntityId) continue; + if (isAllyOfOwner(target)) continue; // Apply damage if (panelData.launchDamage > 0) { @@ -411,8 +408,7 @@ public class EntityAbilityPanel extends EntityAbilityBarrier { posX + halfW + searchExtension, posY + halfH + searchExtension, posZ + halfW + searchExtension ); - // On client, identify local player for client-side solid prediction - EntityPlayer localPlayer = worldObj.isRemote ? CustomNpcs.proxy.getPlayer() : null; + EntityPlayer localPlayer = getClientPredictionPlayer(); List entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox); float yawRad = (float) Math.toRadians(panelYaw); @@ -420,13 +416,7 @@ public class EntityAbilityPanel extends EntityAbilityBarrier { float normalZ = (float) Math.cos(yawRad); for (EntityLivingBase ent : entities) { - if (ent.getEntityId() == ownerEntityId) continue; - - // Client-side: only process local player for solid prediction - // Must be checked before isAllyOfOwner which uses server-only PlayerData - if (worldObj.isRemote && (localPlayer == null || ent != localPlayer)) continue; - - if (isAllyOfOwner(ent)) continue; + if (shouldSkipBarrierPhysicsTarget(ent, localPlayer)) continue; // Current position relative to panel center double dx = ent.posX - posX;