Whoops Forgot to Sync NBTs

This commit is contained in:
Kam committed 2026-02-21 04:56:53 -05:00
1 parent 06809933ed
commit 12c50d5f6a
6 files changed
+128 -11

No files matched your search

@@ -373,4 +373,50 @@ public class EntityAbilitySweeper extends EntityEnergyAbility {
protected void writeEntityToNBT(NBTTagCompound nbt) {
// Intentionally empty — ability entities are transient (not saved to world)
}
@Override
protected void writeSpawnNBT(NBTTagCompound nbt) {
writeEnergyBaseNBT(nbt);
nbt.setFloat("BeamLength", beamLength);
nbt.setFloat("BeamWidth", beamWidth);
nbt.setFloat("BeamHeight", beamHeight);
nbt.setFloat("SweepSpeed", sweepSpeed);
nbt.setInteger("NumRotations", numberOfRotations);
nbt.setInteger("CompletedRotations", completedRotations);
nbt.setInteger("MaxTicks", maxTicks);
nbt.setInteger("TargetId", targetEntityId);
nbt.setFloat("CurrentAngle", currentAngle);
nbt.setFloat("BaseYaw", baseYaw);
nbt.setLong("DeathWorldTime", deathWorldTime);
nbt.setFloat("Damage", damage);
nbt.setInteger("DamageInterval", damageInterval);
nbt.setBoolean("Piercing", piercing);
nbt.setBoolean("LockOnTarget", lockOnTarget);
}
@Override
protected void readSpawnNBT(NBTTagCompound nbt) {
readEnergyBaseNBT(nbt);
this.beamLength = sanitize(nbt.getFloat("BeamLength"), 10.0f, MAX_ENTITY_SIZE);
this.beamWidth = sanitize(nbt.getFloat("BeamWidth"), 0.3f, MAX_ENTITY_SIZE);
this.beamHeight = sanitize(nbt.getFloat("BeamHeight"), 1.0f, MAX_ENTITY_SIZE);
this.sweepSpeed = nbt.hasKey("SweepSpeed") ? nbt.getFloat("SweepSpeed") : 3.0f;
if (Float.isNaN(sweepSpeed) || Float.isInfinite(sweepSpeed) || sweepSpeed <= 0) sweepSpeed = 3.0f;
this.numberOfRotations = nbt.hasKey("NumRotations") ? nbt.getInteger("NumRotations") : 2;
if (numberOfRotations <= 0) numberOfRotations = 1;
this.completedRotations = nbt.getInteger("CompletedRotations");
this.maxTicks = nbt.hasKey("MaxTicks") ? nbt.getInteger("MaxTicks") : 400;
if (maxTicks <= 0) maxTicks = 400;
this.targetEntityId = nbt.getInteger("TargetId");
this.currentAngle = nbt.getFloat("CurrentAngle");
this.prevAngle = currentAngle;
this.baseYaw = nbt.getFloat("BaseYaw");
this.deathWorldTime = nbt.getLong("DeathWorldTime");
this.damage = nbt.hasKey("Damage") ? nbt.getFloat("Damage") : 5.0f;
if (Float.isNaN(damage) || Float.isInfinite(damage)) damage = 5.0f;
this.damageInterval = nbt.hasKey("DamageInterval") ? nbt.getInteger("DamageInterval") : 5;
if (damageInterval <= 0) damageInterval = 1;
this.piercing = !nbt.hasKey("Piercing") || nbt.getBoolean("Piercing");
this.lockOnTarget = nbt.getBoolean("LockOnTarget");
}
}
@@ -1,6 +1,6 @@
package kamkeel.npcs.entity;
import cpw.mods.fml.common.network.ByteBufUtils;
import kamkeel.npcs.util.ByteBufUtils;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -731,7 +731,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
@Override
public void writeSpawnData(ByteBuf buffer) {
buffer.writeInt(zoneType.ordinal());
ByteBufUtils.writeUTF8String(buffer, shape.name());
ByteBufUtils.writeString(buffer, shape.name());
buffer.writeInt(ownerEntityId);
buffer.writeFloat(radius);
buffer.writeInt(durationTicks);
@@ -757,7 +757,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
buffer.writeBoolean(lightning);
buffer.writeBoolean(particles);
buffer.writeInt(particleMotion);
ByteBufUtils.writeUTF8String(buffer, particleDir);
ByteBufUtils.writeString(buffer, particleDir);
buffer.writeInt(particleSize);
buffer.writeBoolean(particleGlow);
@@ -772,14 +772,14 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
effectList.appendTag(effect.writeNBT());
}
effectsNbt.setTag("Effects", effectList);
ByteBufUtils.writeTag(buffer, effectsNbt);
ByteBufUtils.writeNBT(buffer, effectsNbt);
}
@Override
public void readSpawnData(ByteBuf buffer) {
int zoneTypeOrd = buffer.readInt();
this.zoneType = (zoneTypeOrd >= 0 && zoneTypeOrd < ZoneType.values().length) ? ZoneType.values()[zoneTypeOrd] : ZoneType.TRAP;
String shapeName = ByteBufUtils.readUTF8String(buffer);
String shapeName = ByteBufUtils.readString(buffer);
try {
this.shape = ZoneShape.valueOf(shapeName);
} catch (Exception e) {
@@ -810,7 +810,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
this.lightning = buffer.readBoolean();
this.particles = buffer.readBoolean();
this.particleMotion = buffer.readInt();
this.particleDir = ByteBufUtils.readUTF8String(buffer);
this.particleDir = ByteBufUtils.readString(buffer);
this.particleSize = buffer.readInt();
this.particleGlow = buffer.readBoolean();
@@ -818,7 +818,7 @@ public class EntityAbilityZone extends Entity implements IEntityAdditionalSpawnD
this.visible = buffer.readBoolean();
// Effects
NBTTagCompound effectsNbt = ByteBufUtils.readTag(buffer);
NBTTagCompound effectsNbt = ByteBufUtils.readNBT(buffer);
effects.clear();
if (effectsNbt != null && effectsNbt.hasKey("Effects")) {
NBTTagList effectList = effectsNbt.getTagList("Effects", 10);
@@ -7,6 +7,7 @@ import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.data.ability.Ability;
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
import kamkeel.npcs.controllers.data.ability.data.EnergyLightningData;
import kamkeel.npcs.util.ByteBufUtils;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.nbt.NBTTagCompound;
@@ -314,12 +315,30 @@ public abstract class EntityEnergyAbility extends Entity implements IEntityAddit
// ==================== SPAWN DATA ====================
/**
* Write entity data for client sync. Subclasses override this
* to serialize their fields. Separate from writeEntityToNBT
* which is intentionally empty (entities are transient, not saved to world).
*/
protected void writeSpawnNBT(NBTTagCompound nbt) {
writeEnergyBaseNBT(nbt);
}
/**
* Read entity data from client sync. Subclasses override this
* to deserialize their fields. Separate from readEntityFromNBT
* which is intentionally empty (entities are transient, not saved to world).
*/
protected void readSpawnNBT(NBTTagCompound nbt) {
readEnergyBaseNBT(nbt);
}
@Override
public void writeSpawnData(ByteBuf buffer) {
try {
NBTTagCompound compound = new NBTTagCompound();
this.writeEntityToNBT(compound);
cpw.mods.fml.common.network.ByteBufUtils.writeTag(buffer, compound);
this.writeSpawnNBT(compound);
ByteBufUtils.writeNBT(buffer, compound);
} catch (Exception e) {
noppes.npcs.LogWriter.error("Error writing energy ability spawn data", e);
}
@@ -328,9 +347,9 @@ public abstract class EntityEnergyAbility extends Entity implements IEntityAddit
@Override
public void readSpawnData(ByteBuf buffer) {
try {
NBTTagCompound compound = cpw.mods.fml.common.network.ByteBufUtils.readTag(buffer);
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
if (compound != null) {
this.readEntityFromNBT(compound);
this.readSpawnNBT(compound);
}
} catch (Exception e) {
noppes.npcs.LogWriter.error("Error reading energy ability spawn data", e);
@@ -606,4 +606,20 @@ public class EntityEnergyDome extends EntityEnergyBarrier {
protected void writeEntityToNBT(NBTTagCompound nbt) {
// Intentionally empty — ability entities are transient (not saved to world)
}
@Override
protected void writeSpawnNBT(NBTTagCompound nbt) {
writeBarrierBaseNBT(nbt);
nbt.setFloat("DomeRadius", domeRadius);
nbt.setFloat("TargetDomeRadius", targetDomeRadius);
nbt.setBoolean("FollowCaster", followCaster);
}
@Override
protected void readSpawnNBT(NBTTagCompound nbt) {
readBarrierBaseNBT(nbt);
this.setDomeRadius(sanitize(nbt.getFloat("DomeRadius"), 5.0f, MAX_ENTITY_RADIUS));
this.targetDomeRadius = sanitize(nbt.hasKey("TargetDomeRadius") ? nbt.getFloat("TargetDomeRadius") : domeRadius, 5.0f, MAX_ENTITY_RADIUS);
this.followCaster = nbt.hasKey("FollowCaster") && nbt.getBoolean("FollowCaster");
}
}
@@ -563,4 +563,28 @@ public class EntityEnergyPanel extends EntityEnergyBarrier {
protected void writeEntityToNBT(NBTTagCompound nbt) {
// Intentionally empty — ability entities are transient (not saved to world)
}
@Override
protected void writeSpawnNBT(NBTTagCompound nbt) {
writeBarrierBaseNBT(nbt);
nbt.setFloat("PanelYaw", panelYaw);
nbt.setInteger("PanelMode", mode.ordinal());
nbt.setFloat("TargetPanelWidth", targetPanelWidth);
nbt.setFloat("TargetPanelHeight", targetPanelHeight);
panelData.writeNBT(nbt);
}
@Override
protected void readSpawnNBT(NBTTagCompound nbt) {
readBarrierBaseNBT(nbt);
this.panelYaw = nbt.getFloat("PanelYaw");
int modeOrdinal = nbt.getInteger("PanelMode");
this.mode = (modeOrdinal >= 0 && modeOrdinal < PanelMode.values().length)
? PanelMode.values()[modeOrdinal] : PanelMode.PLACED;
panelData.readNBT(nbt);
panelData.panelWidth = sanitize(panelData.panelWidth, 3.0f, MAX_ENTITY_SIZE);
panelData.panelHeight = sanitize(panelData.panelHeight, 3.0f, MAX_ENTITY_SIZE);
this.targetPanelWidth = sanitize(nbt.hasKey("TargetPanelWidth") ? nbt.getFloat("TargetPanelWidth") : panelData.panelWidth, 3.0f, MAX_ENTITY_SIZE);
this.targetPanelHeight = sanitize(nbt.hasKey("TargetPanelHeight") ? nbt.getFloat("TargetPanelHeight") : panelData.panelHeight, 3.0f, MAX_ENTITY_SIZE);
}
}
@@ -934,6 +934,18 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
// Intentionally empty — ability entities are transient (not saved to world)
}
@Override
protected void writeSpawnNBT(NBTTagCompound nbt) {
writeBaseNBT(nbt);
writeProjectileNBT(nbt);
}
@Override
protected void readSpawnNBT(NBTTagCompound nbt) {
readBaseNBT(nbt);
readProjectileNBT(nbt);
}
/**
* Read base projectile properties from NBT.
*/