mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 19:59:56 +00:00
Scripting Ability Handling Improvement and Copy Data
This commit is contained in:
1 parent
50fd3c1856
commit
90735e6866
14 files changed
+71
-30
No files matched your search
@@ -26,10 +26,12 @@ public class ProjectileData {
|
||||
* If colorOverride is true, returns a copy with overridden inner/outer colors.
|
||||
*/
|
||||
public EnergyDisplayData resolveDisplay(EnergyDisplayData primary) {
|
||||
if (!colorOverride) return primary;
|
||||
// Always return a copy so entity mutations never bleed back into the ability template.
|
||||
EnergyDisplayData resolved = primary.copy();
|
||||
resolved.innerColor = this.innerColor;
|
||||
resolved.outerColor = this.outerColor;
|
||||
if (colorOverride) {
|
||||
resolved.innerColor = this.innerColor;
|
||||
resolved.outerColor = this.outerColor;
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
|
||||
// Beam-specific properties from homing data
|
||||
|
||||
this.homingData = homing;
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
this.beamWidth = beamWidth;
|
||||
this.headSize = headSize;
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class EntityAbilityDisc extends EntityEnergyProjectile {
|
||||
// Initialize base properties
|
||||
initProjectile(owner, target, x, y, z, 1.0f, display, combat, lightning, lifespan);
|
||||
|
||||
this.homingData = homing;
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
|
||||
this.boomerang = boomerang;
|
||||
this.boomerangDelay = boomerangDelay;
|
||||
|
||||
@@ -50,10 +50,11 @@ public class EntityAbilityDome extends EntityAbilityBarrier {
|
||||
this.stepHeight = 0.0F;
|
||||
this.ownerEntityId = owner.getEntityId();
|
||||
this.setDomeRadius(domeRadius);
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
this.barrierData = barrier;
|
||||
this.currentHealth = barrier.maxHealth;
|
||||
// Defensive copy: entities must never share data objects with the source ability.
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
this.barrierData = barrier != null ? barrier.copy() : new EnergyBarrierData();
|
||||
this.currentHealth = this.barrierData.maxHealth;
|
||||
this.setPosition(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
// Initialize base properties
|
||||
initProjectile(owner, target, x, y, z, orbSize, display, combat, lightning, lifespan);
|
||||
|
||||
this.homingData = homing;
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
|
||||
// Calculate initial velocity toward target
|
||||
calculateInitialVelocity(owner, target, x, y, z);
|
||||
|
||||
@@ -56,11 +56,12 @@ public class EntityAbilityPanel extends EntityAbilityBarrier {
|
||||
this.panelYaw = yaw;
|
||||
this.prevPanelYaw = yaw;
|
||||
this.mode = mode;
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
this.barrierData = barrier;
|
||||
this.panelData = panel;
|
||||
this.currentHealth = barrier.maxHealth;
|
||||
// Defensive copy: entities must never share data objects with the source ability.
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
this.barrierData = barrier != null ? barrier.copy() : new EnergyBarrierData();
|
||||
this.panelData = panel != null ? panel.copy() : new EnergyPanelData();
|
||||
this.currentHealth = this.barrierData.maxHealth;
|
||||
|
||||
// For launched panels, set initial velocity
|
||||
if (mode == PanelMode.LAUNCHED) {
|
||||
|
||||
@@ -79,7 +79,7 @@ public class EntityAbilitySweeper extends EntityEnergyAbility {
|
||||
this.beamLength = beamLength;
|
||||
this.beamWidth = beamWidth;
|
||||
this.beamHeight = beamHeight;
|
||||
this.displayData = displayData;
|
||||
this.displayData = displayData != null ? displayData.copy() : new EnergyDisplayData();
|
||||
this.sweepSpeed = sweepSpeed;
|
||||
this.numberOfRotations = numberOfRotations;
|
||||
this.damage = damage;
|
||||
|
||||
@@ -183,10 +183,13 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
// Visual
|
||||
this.size = size;
|
||||
|
||||
this.displayData = display;
|
||||
this.combatData = combat;
|
||||
this.lifespanData = lifespan; // deathWorldTime will be set on first tick when world is available
|
||||
this.lightningData = lightning;
|
||||
// Defensive copy: entities must never share data objects with the source ability.
|
||||
// Without copies, runtime mutations (e.g. barrier reflection changing colors/damage)
|
||||
// bleed back into the ability template and corrupt future projectiles.
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.combatData = combat != null ? combat.copy() : new EnergyCombatData();
|
||||
this.lifespanData = lifespan != null ? lifespan.copy() : new EnergyLifespanData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
syncProjectileColorWatchers();
|
||||
|
||||
// Initialize render size
|
||||
@@ -911,7 +914,15 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
* Set the effects list from the ability's configured effects.
|
||||
*/
|
||||
public void setEffects(List<AbilityPotionEffect> effects) {
|
||||
this.effects = effects != null ? effects : new ArrayList<>();
|
||||
if (effects == null || effects.isEmpty()) {
|
||||
this.effects = new ArrayList<>();
|
||||
} else {
|
||||
// Deep copy: entity must not share the ability's effects list or its entries.
|
||||
this.effects = new ArrayList<>(effects.size());
|
||||
for (AbilityPotionEffect effect : effects) {
|
||||
this.effects.add(effect.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void doExplosion() {
|
||||
@@ -1518,8 +1529,8 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
int chargeDuration) {
|
||||
this.setPreviewMode(true);
|
||||
this.setPreviewOwner(owner);
|
||||
this.displayData = display;
|
||||
this.lightningData = lightning;
|
||||
this.displayData = display != null ? display.copy() : new EnergyDisplayData();
|
||||
this.lightningData = lightning != null ? lightning.copy() : new EnergyLightningData();
|
||||
setupChargingState(anchor, chargeDuration);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ public class EntityEnergySlicer extends EntityEnergyProjectile {
|
||||
super(world);
|
||||
|
||||
initProjectile(owner, target, x, y, z, sliceWidth, display, combat, lightning, lifespan);
|
||||
this.homingData = homing;
|
||||
this.homingData = homing != null ? homing.copy() : new EnergyHomingData();
|
||||
this.sliceWidth = sliceWidth;
|
||||
this.sliceThickness = sliceThickness;
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
private transient IAbility abilityCopy;
|
||||
|
||||
public AbilityEvent(ICustomNpc npc, Ability ability, EntityLivingBase target) {
|
||||
super(npc);
|
||||
@@ -27,7 +28,10 @@ public class AbilityEvent extends NpcEvent implements IAbilityEvent {
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
return ability;
|
||||
if (abilityCopy == null && ability != null) {
|
||||
abilityCopy = ability.deepCopy();
|
||||
}
|
||||
return abilityCopy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import noppes.npcs.scripted.NpcAPI;
|
||||
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
private transient IAbility abilityCopy;
|
||||
|
||||
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player);
|
||||
@@ -27,7 +28,10 @@ public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEve
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
return ability;
|
||||
if (abilityCopy == null && ability != null) {
|
||||
abilityCopy = ability.deepCopy();
|
||||
}
|
||||
return abilityCopy;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -36,7 +36,12 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public IAbility[] getAbilities() {
|
||||
return data.getAbilities().toArray(new IAbility[0]);
|
||||
List<Ability> live = data.getAbilities();
|
||||
IAbility[] copies = new IAbility[live.size()];
|
||||
for (int i = 0; i < live.size(); i++) {
|
||||
copies[i] = live.get(i).deepCopy();
|
||||
}
|
||||
return copies;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +78,8 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public IAbility getAbility(String abilityId) {
|
||||
return data.getAbility(abilityId);
|
||||
Ability a = data.getAbility(abilityId);
|
||||
return a != null ? a.deepCopy() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,6 +121,17 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
|
||||
@Override
|
||||
public IAbility getCurrentAbility() {
|
||||
Ability a = data.getCurrentAbility();
|
||||
return a != null ? a.deepCopy() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getSourceAbility(String abilityId) {
|
||||
return data.getAbility(abilityId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getSourceCurrentAbility() {
|
||||
return data.getCurrentAbility();
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,8 @@ public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
@Override
|
||||
public IAbility getCurrentAbility() {
|
||||
return data.getCurrentAbility();
|
||||
Ability a = data.getCurrentAbility();
|
||||
return a != null ? a.deepCopy() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user