mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 20:53:08 +00:00
Create Barrier Abilities + Heavy Refactoring
This commit is contained in:
1 parent
d1f2c9695c
commit
c07e9e7006
53 files changed
+1890
-1460
No files matched your search
@@ -25,7 +25,7 @@ import java.util.List;
|
||||
*
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
public class EntityAbilityBeam extends EntityEnergyProjectile {
|
||||
|
||||
// Beam shape properties
|
||||
private float beamWidth = 0.3f;
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
*
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public class EntityAbilityDisc extends EntityAbilityProjectile {
|
||||
public class EntityAbilityDisc extends EntityEnergyProjectile {
|
||||
|
||||
// Disc-specific movement propertie
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import java.util.Set;
|
||||
*
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public class EntityAbilityLaser extends EntityAbilityProjectile {
|
||||
public class EntityAbilityLaser extends EntityEnergyProjectile {
|
||||
|
||||
// Laser-specific properties
|
||||
private float laserWidth = 0.2f;
|
||||
|
||||
@@ -15,11 +15,11 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* Orb projectile - spherical homing energy ball.
|
||||
* Extends EntityAbilityProjectile for shared functionality.
|
||||
* Extends EntityEnergyAbility for shared functionality.
|
||||
*
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
public class EntityAbilityOrb extends EntityEnergyProjectile {
|
||||
|
||||
public EntityAbilityOrb(World world) {
|
||||
super(world);
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -24,19 +22,16 @@ import java.util.Set;
|
||||
* Sweeper ability entity - a rotating beam attached to the NPC.
|
||||
* Unlike other projectiles, this handles its own damage logic since it's
|
||||
* attached to and rotates around the caster.
|
||||
* Extends EntityEnergyAbility for shared visual/owner/charging state.
|
||||
*
|
||||
* Design: Similar to Beam trail visuals but rotating around origin.
|
||||
*/
|
||||
public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpawnData {
|
||||
public class EntityAbilitySweeper extends EntityEnergyAbility {
|
||||
|
||||
// Beam properties
|
||||
private float beamLength = 10.0f;
|
||||
private float beamWidth = 0.3f; // Thin like beam trail
|
||||
private float beamHeight = 0.8f;
|
||||
private int innerColor = 0xFF6600;
|
||||
private int outerColor = 0xFF0000;
|
||||
private boolean outerColorEnabled = true;
|
||||
private float outerColorWidth = 1.8f;
|
||||
|
||||
// Combat properties
|
||||
private float damage = 5.0f;
|
||||
@@ -52,18 +47,13 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
private float baseYaw = 0; // Starting yaw direction
|
||||
private boolean lockOnTarget = false;
|
||||
|
||||
// Owner tracking
|
||||
private int ownerEntityId = -1;
|
||||
// Target tracking
|
||||
private int targetEntityId = -1;
|
||||
|
||||
// Lifetime
|
||||
private int maxTicks = 400;
|
||||
private long deathWorldTime = -1;
|
||||
|
||||
// Preview mode
|
||||
private boolean previewMode = false;
|
||||
private EntityLivingBase previewOwner = null;
|
||||
|
||||
// Damage state
|
||||
private transient int ticksSinceDamage = 0;
|
||||
private transient Set<Integer> hitThisTick = new HashSet<>();
|
||||
@@ -72,8 +62,6 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
super(world);
|
||||
this.setSize(0.1f, 0.1f);
|
||||
this.noClip = true;
|
||||
this.isImmuneToFire = true;
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
public EntityAbilitySweeper(World world, EntityLivingBase owner, EntityLivingBase target,
|
||||
@@ -89,10 +77,7 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
this.beamLength = beamLength;
|
||||
this.beamWidth = beamWidth;
|
||||
this.beamHeight = beamHeight;
|
||||
this.innerColor = displayData.innerColor;
|
||||
this.outerColor = displayData.outerColor;
|
||||
this.outerColorEnabled = displayData.outerColorEnabled;
|
||||
this.outerColorWidth = displayData.outerColorWidth;
|
||||
this.displayData = displayData;
|
||||
this.sweepSpeed = sweepSpeed;
|
||||
this.numberOfRotations = numberOfRotations;
|
||||
this.damage = damage;
|
||||
@@ -121,7 +106,7 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
// No DataWatcher needed
|
||||
super.entityInit();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -144,7 +129,7 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
return;
|
||||
}
|
||||
|
||||
Entity owner = getOwner();
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner != null && owner.isDead) {
|
||||
this.setDead();
|
||||
return;
|
||||
@@ -297,12 +282,6 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
this.previewOwner = owner;
|
||||
}
|
||||
|
||||
private Entity getOwner() {
|
||||
if (previewMode && previewOwner != null) return previewOwner;
|
||||
if (ownerEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(ownerEntityId);
|
||||
}
|
||||
|
||||
// ==================== RENDERING ====================
|
||||
|
||||
@Override
|
||||
@@ -311,22 +290,6 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
return distance < 16384.0D; // 128 blocks squared
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1; // Translucent pass
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getBrightness(float partialTicks) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float partialTicks) {
|
||||
return 0xF000F0;
|
||||
}
|
||||
|
||||
// ==================== GETTERS FOR RENDERER ====================
|
||||
|
||||
public float getBeamLength() {
|
||||
@@ -341,22 +304,6 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
return beamHeight;
|
||||
}
|
||||
|
||||
public int getInnerColor() {
|
||||
return innerColor;
|
||||
}
|
||||
|
||||
public int getOuterColor() {
|
||||
return outerColor;
|
||||
}
|
||||
|
||||
public boolean isOuterColorEnabled() {
|
||||
return outerColorEnabled;
|
||||
}
|
||||
|
||||
public float getOuterColorWidth() {
|
||||
return outerColorWidth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full interpolated angle INCLUDING base yaw for rendering.
|
||||
*/
|
||||
@@ -382,18 +329,14 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
this.beamLength = nbt.getFloat("BeamLength");
|
||||
this.beamWidth = nbt.getFloat("BeamWidth");
|
||||
this.beamHeight = nbt.getFloat("BeamHeight");
|
||||
this.innerColor = nbt.getInteger("InnerColor");
|
||||
this.outerColor = nbt.getInteger("OuterColor");
|
||||
this.outerColorEnabled = !nbt.hasKey("OuterColorEnabled") || nbt.getBoolean("OuterColorEnabled");
|
||||
this.outerColorWidth = nbt.hasKey("OuterColorWidth") ? nbt.getFloat("OuterColorWidth") : 1.8f;
|
||||
this.sweepSpeed = nbt.getFloat("SweepSpeed");
|
||||
this.numberOfRotations = nbt.getInteger("NumRotations");
|
||||
this.completedRotations = nbt.getInteger("CompletedRotations");
|
||||
this.maxTicks = nbt.getInteger("MaxTicks");
|
||||
this.ownerEntityId = nbt.getInteger("OwnerId");
|
||||
this.targetEntityId = nbt.getInteger("TargetId");
|
||||
this.currentAngle = nbt.getFloat("CurrentAngle");
|
||||
this.baseYaw = nbt.getFloat("BaseYaw");
|
||||
@@ -406,18 +349,14 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
nbt.setFloat("BeamLength", beamLength);
|
||||
nbt.setFloat("BeamWidth", beamWidth);
|
||||
nbt.setFloat("BeamHeight", beamHeight);
|
||||
nbt.setInteger("InnerColor", innerColor);
|
||||
nbt.setInteger("OuterColor", outerColor);
|
||||
nbt.setBoolean("OuterColorEnabled", outerColorEnabled);
|
||||
nbt.setFloat("OuterColorWidth", outerColorWidth);
|
||||
nbt.setFloat("SweepSpeed", sweepSpeed);
|
||||
nbt.setInteger("NumRotations", numberOfRotations);
|
||||
nbt.setInteger("CompletedRotations", completedRotations);
|
||||
nbt.setInteger("MaxTicks", maxTicks);
|
||||
nbt.setInteger("OwnerId", ownerEntityId);
|
||||
nbt.setInteger("TargetId", targetEntityId);
|
||||
nbt.setFloat("CurrentAngle", currentAngle);
|
||||
nbt.setFloat("BaseYaw", baseYaw);
|
||||
@@ -427,53 +366,4 @@ public class EntityAbilitySweeper extends Entity implements IEntityAdditionalSpa
|
||||
nbt.setBoolean("Piercing", piercing);
|
||||
nbt.setBoolean("LockOnTarget", lockOnTarget);
|
||||
}
|
||||
|
||||
// ==================== SPAWN DATA ====================
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
buffer.writeFloat(beamLength);
|
||||
buffer.writeFloat(beamWidth);
|
||||
buffer.writeFloat(beamHeight);
|
||||
buffer.writeInt(innerColor);
|
||||
buffer.writeInt(outerColor);
|
||||
buffer.writeBoolean(outerColorEnabled);
|
||||
buffer.writeFloat(outerColorWidth);
|
||||
buffer.writeFloat(sweepSpeed);
|
||||
buffer.writeInt(numberOfRotations);
|
||||
buffer.writeInt(completedRotations);
|
||||
buffer.writeInt(maxTicks);
|
||||
buffer.writeInt(ownerEntityId);
|
||||
buffer.writeInt(targetEntityId);
|
||||
buffer.writeFloat(currentAngle);
|
||||
buffer.writeFloat(baseYaw);
|
||||
buffer.writeFloat(damage);
|
||||
buffer.writeInt(damageInterval);
|
||||
buffer.writeBoolean(piercing);
|
||||
buffer.writeBoolean(lockOnTarget);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
this.beamLength = buffer.readFloat();
|
||||
this.beamWidth = buffer.readFloat();
|
||||
this.beamHeight = buffer.readFloat();
|
||||
this.innerColor = buffer.readInt();
|
||||
this.outerColor = buffer.readInt();
|
||||
this.outerColorEnabled = buffer.readBoolean();
|
||||
this.outerColorWidth = buffer.readFloat();
|
||||
this.sweepSpeed = buffer.readFloat();
|
||||
this.numberOfRotations = buffer.readInt();
|
||||
this.completedRotations = buffer.readInt();
|
||||
this.maxTicks = buffer.readInt();
|
||||
this.ownerEntityId = buffer.readInt();
|
||||
this.targetEntityId = buffer.readInt();
|
||||
this.currentAngle = buffer.readFloat();
|
||||
this.baseYaw = buffer.readFloat();
|
||||
this.damage = buffer.readFloat();
|
||||
this.damageInterval = buffer.readInt();
|
||||
this.piercing = buffer.readBoolean();
|
||||
this.lockOnTarget = buffer.readBoolean();
|
||||
this.prevAngle = this.currentAngle;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,241 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
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 net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Universal base class for all energy ability entities (Projectiles, Barriers, Sweeper).
|
||||
* Provides shared visual data, owner tracking, charging state, and common entity properties.
|
||||
*/
|
||||
public abstract class EntityEnergyAbility extends Entity implements IEntityAdditionalSpawnData {
|
||||
|
||||
// ==================== VISUAL PROPERTIES ====================
|
||||
protected EnergyDisplayData displayData = new EnergyDisplayData();
|
||||
protected EnergyLightningData lightningData = new EnergyLightningData();
|
||||
|
||||
// Client-side lightning state (not saved to NBT)
|
||||
@SideOnly(Side.CLIENT)
|
||||
public transient Object lightningState; // Actually AttachedLightningRenderer.LightningState
|
||||
|
||||
// ==================== TRACKING ====================
|
||||
protected int ownerEntityId = -1;
|
||||
|
||||
// ==================== STATE ====================
|
||||
/** The ability that spawned this entity. Transient, not saved to NBT. */
|
||||
protected transient Ability sourceAbility = null;
|
||||
protected boolean previewMode = false;
|
||||
protected EntityLivingBase previewOwner = null;
|
||||
|
||||
// ==================== CHARGING STATE ====================
|
||||
protected boolean charging = false;
|
||||
protected int chargeDuration = 0;
|
||||
protected int chargeTick = 0;
|
||||
protected static final int DW_CHARGING = 20;
|
||||
|
||||
public EntityEnergyAbility(World world) {
|
||||
super(world);
|
||||
this.isImmuneToFire = true;
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
this.dataWatcher.addObject(DW_CHARGING, (byte) 0);
|
||||
}
|
||||
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
/**
|
||||
* Check if entity is in charging state (synced via data watcher).
|
||||
* In preview mode, uses local field since data watcher isn't synced.
|
||||
*/
|
||||
public boolean isCharging() {
|
||||
if (previewMode) return this.charging;
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set charging state (server only, synced to clients via data watcher).
|
||||
*/
|
||||
protected void setCharging(boolean value) {
|
||||
this.charging = value;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
public float getChargeProgress() {
|
||||
if (chargeDuration <= 0) return 1.0f;
|
||||
return Math.min(1.0f, (float) chargeTick / chargeDuration);
|
||||
}
|
||||
|
||||
public float getInterpolatedChargeProgress(float partialTicks) {
|
||||
if (chargeDuration <= 0) return 1.0f;
|
||||
float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration);
|
||||
float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration);
|
||||
return prevProgress + (currProgress - prevProgress) * partialTicks;
|
||||
}
|
||||
|
||||
// ==================== OWNER ====================
|
||||
|
||||
/**
|
||||
* Get the owner entity. In preview mode, returns the preview owner directly.
|
||||
*/
|
||||
public Entity getOwnerEntity() {
|
||||
if (previewMode && previewOwner != null) {
|
||||
return previewOwner;
|
||||
}
|
||||
if (ownerEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(ownerEntityId);
|
||||
}
|
||||
|
||||
public int getOwnerEntityId() { return ownerEntityId; }
|
||||
public void setOwnerEntityId(int id) { this.ownerEntityId = id; }
|
||||
|
||||
// ==================== SOURCE ABILITY ====================
|
||||
|
||||
public Ability getSourceAbility() { return sourceAbility; }
|
||||
public void setSourceAbility(Ability ability) { this.sourceAbility = ability; }
|
||||
|
||||
// ==================== PREVIEW MODE ====================
|
||||
|
||||
public boolean isPreviewMode() { return previewMode; }
|
||||
public void setPreviewMode(boolean preview) { this.previewMode = preview; }
|
||||
public void setPreviewOwner(EntityLivingBase owner) { this.previewOwner = owner; }
|
||||
|
||||
// ==================== DISPLAY GETTERS & SETTERS ====================
|
||||
|
||||
public EnergyDisplayData getDisplayData() { return displayData; }
|
||||
public EnergyLightningData getLightningData() { return lightningData; }
|
||||
|
||||
public int getInnerColor() { return displayData.getInnerColor(); }
|
||||
public void setInnerColor(int color) { displayData.setInnerColor(color); }
|
||||
|
||||
public float getInnerAlpha() { return displayData.getInnerAlpha(); }
|
||||
public void setInnerAlpha(float alpha) { displayData.setInnerAlpha(alpha); }
|
||||
|
||||
public int getOuterColor() { return displayData.getOuterColor(); }
|
||||
public void setOuterColor(int color) { displayData.setOuterColor(color); }
|
||||
|
||||
public boolean isOuterColorEnabled() { return displayData.isOuterColorEnabled(); }
|
||||
public void setOuterColorEnabled(boolean enabled) { displayData.setOuterColorEnabled(enabled); }
|
||||
|
||||
public float getOuterColorWidth() { return displayData.getOuterColorWidth(); }
|
||||
public void setOuterColorWidth(float width) { displayData.setOuterColorWidth(width); }
|
||||
|
||||
public float getOuterColorAlpha() { return displayData.getOuterColorAlpha(); }
|
||||
public void setOuterColorAlpha(float alpha) { displayData.setOuterColorAlpha(alpha); }
|
||||
|
||||
public float getRotationSpeed() { return displayData.getRotationSpeed(); }
|
||||
public void setRotationSpeed(float speed) { displayData.setRotationSpeed(speed); }
|
||||
|
||||
// ==================== LIGHTNING GETTERS & SETTERS ====================
|
||||
|
||||
public boolean hasLightningEffect() { return lightningData.isLightningEffect(); }
|
||||
public void setLightningEffect(boolean enabled) { lightningData.setLightningEffect(enabled); }
|
||||
|
||||
public float getLightningDensity() { return lightningData.getLightningDensity(); }
|
||||
public void setLightningDensity(float density) { lightningData.setLightningDensity(density); }
|
||||
|
||||
public float getLightningRadius() { return lightningData.getLightningRadius(); }
|
||||
public void setLightningRadius(float radius) { lightningData.setLightningRadius(radius); }
|
||||
|
||||
public int getLightningFadeTime() { return lightningData.getLightningFadeTime(); }
|
||||
public void setLightningFadeTime(int ticks) { lightningData.setLightningFadeTime(ticks); }
|
||||
|
||||
// ==================== BRIGHTNESS ====================
|
||||
|
||||
@Override
|
||||
public float getBrightness(float partialTicks) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float partialTicks) {
|
||||
return 0xF000F0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1; // Translucent pass
|
||||
}
|
||||
|
||||
// ==================== COLLISION SETTINGS ====================
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTriggerWalking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBurning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize() {
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// ==================== NBT HELPERS ====================
|
||||
|
||||
/**
|
||||
* Write shared energy base fields to NBT (owner, display, lightning).
|
||||
* Call from subclass NBT writers before writing type-specific fields.
|
||||
*/
|
||||
protected void writeEnergyBaseNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("OwnerId", ownerEntityId);
|
||||
displayData.writeNBT(nbt);
|
||||
lightningData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read shared energy base fields from NBT (owner, display, lightning).
|
||||
* Call from subclass NBT readers before reading type-specific fields.
|
||||
*/
|
||||
protected void readEnergyBaseNBT(NBTTagCompound nbt) {
|
||||
this.ownerEntityId = nbt.getInteger("OwnerId");
|
||||
displayData.readNBT(nbt);
|
||||
lightningData.readNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== SPAWN DATA ====================
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeEntityToNBT(compound);
|
||||
cpw.mods.fml.common.network.ByteBufUtils.writeTag(buffer, compound);
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error writing energy ability spawn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = cpw.mods.fml.common.network.ByteBufUtils.readTag(buffer);
|
||||
if (compound != null) {
|
||||
this.readEntityFromNBT(compound);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error reading energy ability spawn data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,269 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyBarrierData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyLightningData;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
/**
|
||||
* Base class for energy barrier entities (Dome, Panel).
|
||||
* Provides shared health, damage, hit flash, knockback target,
|
||||
* and barrier lifecycle management.
|
||||
* Extends EntityEnergyAbility for shared visual/owner/charging state.
|
||||
*/
|
||||
public abstract class EntityEnergyBarrier extends EntityEnergyAbility {
|
||||
|
||||
// ==================== BARRIER PROPERTIES ====================
|
||||
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
||||
protected float currentHealth;
|
||||
protected int ticksAlive = 0;
|
||||
|
||||
// ==================== DATA WATCHER INDICES ====================
|
||||
protected static final int DW_HEALTH_PERCENT = 21;
|
||||
protected static final int DW_HIT_FLASH = 22;
|
||||
|
||||
public EntityEnergyBarrier(World world) {
|
||||
super(world);
|
||||
this.noClip = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit(); // DW_CHARGING = 20
|
||||
this.dataWatcher.addObject(DW_HEALTH_PERCENT, 1.0f);
|
||||
this.dataWatcher.addObject(DW_HIT_FLASH, (byte) 0);
|
||||
}
|
||||
|
||||
// ==================== ABSTRACT METHODS ====================
|
||||
|
||||
/**
|
||||
* Check if a projectile is incoming toward this barrier.
|
||||
* Dome uses spherical check, Panel uses planar check.
|
||||
*/
|
||||
public abstract boolean isIncomingProjectile(EntityEnergyProjectile projectile);
|
||||
|
||||
/**
|
||||
* Setup charging state. Called during windup phase.
|
||||
*/
|
||||
public abstract void setupCharging(int duration);
|
||||
|
||||
/**
|
||||
* Finish charging — snap to full size and become active.
|
||||
*/
|
||||
public abstract void finishCharging();
|
||||
|
||||
/**
|
||||
* Push entities away from the barrier surface.
|
||||
*/
|
||||
protected abstract void knockbackEntities();
|
||||
|
||||
// ==================== PROJECTILE HIT ====================
|
||||
|
||||
/**
|
||||
* Apply damage to this barrier from a projectile.
|
||||
* Returns true if the barrier absorbed the hit (projectile should be destroyed).
|
||||
*/
|
||||
public boolean onProjectileHit(EntityEnergyProjectile projectile, float baseDamage) {
|
||||
// Get damage multiplier for this projectile type
|
||||
String typeId = "";
|
||||
if (projectile.getSourceAbility() != null) {
|
||||
typeId = projectile.getSourceAbility().getTypeId();
|
||||
}
|
||||
float multiplier = barrierData.getMultiplier(typeId);
|
||||
float damage = baseDamage * multiplier;
|
||||
|
||||
// Fire hit event (may cancel or modify damage)
|
||||
if (!worldObj.isRemote) {
|
||||
float eventDamage = EventHooks.onEnergyBarrierHit(this, ownerEntityId, projectile, damage);
|
||||
if (eventDamage < 0) return false; // Event cancelled — don't block
|
||||
damage = eventDamage;
|
||||
}
|
||||
|
||||
triggerHitFlash();
|
||||
|
||||
if (!barrierData.useHealth) {
|
||||
return true; // Duration-only mode: block but don't take damage
|
||||
}
|
||||
|
||||
currentHealth -= damage;
|
||||
syncHealthPercent();
|
||||
|
||||
if (currentHealth <= 0) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ==================== MELEE DAMAGE ====================
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return barrierData.meleeEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attackEntityFrom(DamageSource source, float amount) {
|
||||
if (worldObj.isRemote || !barrierData.meleeEnabled) return false;
|
||||
if (isCharging()) return false;
|
||||
|
||||
float damage = amount * barrierData.meleeDamageMultiplier;
|
||||
|
||||
// Fire hit event with null projectile (melee hit)
|
||||
float eventDamage = EventHooks.onEnergyBarrierHit(this, ownerEntityId, null, damage);
|
||||
if (eventDamage < 0) return false;
|
||||
damage = eventDamage;
|
||||
|
||||
triggerHitFlash();
|
||||
|
||||
if (!barrierData.useHealth) return true;
|
||||
|
||||
currentHealth -= damage;
|
||||
syncHealthPercent();
|
||||
|
||||
if (currentHealth <= 0) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ==================== SHARED UPDATE LOGIC ====================
|
||||
|
||||
/**
|
||||
* Shared barrier tick logic for onUpdate(). Handles spawned event, owner death,
|
||||
* duration check, hit flash decay, and tick event.
|
||||
* Call this after incrementing ticksAlive in subclass onUpdate().
|
||||
* @return true if barrier died this tick (caller should return early)
|
||||
*/
|
||||
protected boolean updateBarrierTick() {
|
||||
if (!worldObj.isRemote) {
|
||||
// Fire spawned event on first tick
|
||||
if (ticksAlive == 1) {
|
||||
EventHooks.onEnergyBarrierSpawned(this, ownerEntityId);
|
||||
}
|
||||
|
||||
// Check owner death
|
||||
if (ownerEntityId >= 0 && ticksAlive > 5) {
|
||||
Entity owner = worldObj.getEntityByID(ownerEntityId);
|
||||
if (owner != null) {
|
||||
if (owner.isDead) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
return true;
|
||||
}
|
||||
if (owner instanceof EntityNPCInterface && ((EntityNPCInterface) owner).isKilled()) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Duration check
|
||||
if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) {
|
||||
onBarrierDestroyed();
|
||||
this.setDead();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Reset hit flash
|
||||
if (getHitFlash() > 0) {
|
||||
setHitFlash((byte) (getHitFlash() - 1));
|
||||
}
|
||||
|
||||
// Fire tick event
|
||||
EventHooks.onEnergyBarrierTick(this, ownerEntityId);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// ==================== HELPERS ====================
|
||||
|
||||
protected void onBarrierDestroyed() {
|
||||
EventHooks.onEnergyBarrierDestroyed(this, ownerEntityId);
|
||||
}
|
||||
|
||||
protected void syncHealthPercent() {
|
||||
float percent = barrierData.useHealth && barrierData.maxHealth > 0
|
||||
? Math.max(0, currentHealth / barrierData.maxHealth)
|
||||
: 1.0f;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_HEALTH_PERCENT, percent);
|
||||
}
|
||||
}
|
||||
|
||||
protected void triggerHitFlash() {
|
||||
if (!worldObj.isRemote) {
|
||||
setHitFlash((byte) 4);
|
||||
}
|
||||
}
|
||||
|
||||
protected void setHitFlash(byte value) {
|
||||
this.dataWatcher.updateObject(DW_HIT_FLASH, value);
|
||||
}
|
||||
|
||||
public byte getHitFlash() {
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_HIT_FLASH);
|
||||
}
|
||||
|
||||
public float getHealthPercent() {
|
||||
return this.dataWatcher.getWatchableObjectFloat(DW_HEALTH_PERCENT);
|
||||
}
|
||||
|
||||
protected boolean isKnockbackTarget(EntityLivingBase entity) {
|
||||
switch (barrierData.knockbackTarget) {
|
||||
case 1: return entity instanceof EntityPlayer;
|
||||
case 2: return entity instanceof EntityNPCInterface;
|
||||
default: return entity instanceof EntityPlayer || entity instanceof EntityNPCInterface;
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
public EnergyBarrierData getBarrierData() { return barrierData; }
|
||||
public float getCurrentHealth() { return currentHealth; }
|
||||
public void setCurrentHealth(float health) { this.currentHealth = health; syncHealthPercent(); }
|
||||
public int getTicksAlive() { return ticksAlive; }
|
||||
|
||||
// ==================== NBT HELPERS ====================
|
||||
|
||||
/**
|
||||
* Write shared barrier base fields to NBT.
|
||||
* Call from subclass writeEntityToNBT() before writing type-specific fields.
|
||||
*/
|
||||
protected void writeBarrierBaseNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
nbt.setInteger("TicksAlive", ticksAlive);
|
||||
nbt.setFloat("CurrentHealth", currentHealth);
|
||||
nbt.setBoolean("Charging", charging);
|
||||
nbt.setInteger("ChargeTick", chargeTick);
|
||||
nbt.setInteger("ChargeDuration", chargeDuration);
|
||||
barrierData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read shared barrier base fields from NBT.
|
||||
* Call from subclass readEntityFromNBT() before reading type-specific fields.
|
||||
*/
|
||||
protected void readBarrierBaseNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
this.ticksAlive = nbt.getInteger("TicksAlive");
|
||||
this.currentHealth = nbt.getFloat("CurrentHealth");
|
||||
this.charging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||
this.chargeTick = nbt.getInteger("ChargeTick");
|
||||
this.chargeDuration = nbt.getInteger("ChargeDuration");
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (charging ? 1 : 0));
|
||||
barrierData.readNBT(nbt);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyBarrierData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyLightningData;
|
||||
@@ -13,7 +10,6 @@ import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -21,39 +17,18 @@ import java.util.List;
|
||||
* Energy Dome entity - a spherical barrier that blocks incoming energy projectiles.
|
||||
* Centered on the caster's position at time of casting.
|
||||
* Only blocks incoming attacks (not outgoing from allies inside).
|
||||
* Extends EntityEnergyBarrier for shared barrier logic.
|
||||
*/
|
||||
public class EntityEnergyDome extends Entity implements IEntityAdditionalSpawnData {
|
||||
public class EntityEnergyDome extends EntityEnergyBarrier {
|
||||
|
||||
// ==================== VISUAL PROPERTIES ====================
|
||||
protected EnergyDisplayData displayData = new EnergyDisplayData();
|
||||
protected EnergyLightningData lightningData = new EnergyLightningData();
|
||||
|
||||
// ==================== BARRIER PROPERTIES ====================
|
||||
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
||||
protected float currentHealth;
|
||||
// ==================== DOME-SPECIFIC PROPERTIES ====================
|
||||
protected float domeRadius = 5.0f;
|
||||
|
||||
// ==================== TRACKING ====================
|
||||
protected int ownerEntityId = -1;
|
||||
protected int ticksAlive = 0;
|
||||
|
||||
// ==================== STATE ====================
|
||||
protected transient Ability sourceAbility = null;
|
||||
|
||||
// ==================== DATA WATCHER INDICES ====================
|
||||
private static final int DW_HEALTH_PERCENT = 20;
|
||||
private static final int DW_HIT_FLASH = 21;
|
||||
|
||||
// ==================== CLIENT STATE ====================
|
||||
@SideOnly(Side.CLIENT)
|
||||
public transient Object lightningState;
|
||||
protected float targetDomeRadius = 5.0f;
|
||||
protected boolean followCaster = false;
|
||||
|
||||
public EntityEnergyDome(World world) {
|
||||
super(world);
|
||||
this.setSize(1.0f, 1.0f); // Hitbox doesn't really matter, we use radius checks
|
||||
this.noClip = true;
|
||||
this.isImmuneToFire = true;
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
public EntityEnergyDome(World world, EntityLivingBase owner, double x, double y, double z,
|
||||
@@ -69,12 +44,6 @@ public class EntityEnergyDome extends Entity implements IEntityAdditionalSpawnDa
|
||||
this.currentHealth = barrier.maxHealth;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
this.dataWatcher.addObject(DW_HEALTH_PERCENT, 1.0f);
|
||||
this.dataWatcher.addObject(DW_HIT_FLASH, (byte) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
this.prevPosX = this.posX;
|
||||
@@ -82,76 +51,51 @@ public class EntityEnergyDome extends Entity implements IEntityAdditionalSpawnDa
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
super.onUpdate();
|
||||
|
||||
// Follow caster: both sides for smooth interpolated rendering
|
||||
if (followCaster) {
|
||||
Entity owner = ownerEntityId >= 0 ? worldObj.getEntityByID(ownerEntityId) : null;
|
||||
if (owner != null) {
|
||||
this.setPosition(owner.posX, owner.posY, owner.posZ);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle charging animation (both sides for smooth rendering)
|
||||
if (isCharging()) {
|
||||
chargeTick++;
|
||||
float progress = getChargeProgress();
|
||||
this.domeRadius = targetDomeRadius * progress;
|
||||
return; // Don't tick duration/death during charging
|
||||
}
|
||||
|
||||
ticksAlive++;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
// Check owner death
|
||||
if (ownerEntityId >= 0 && ticksAlive > 5) {
|
||||
Entity owner = worldObj.getEntityByID(ownerEntityId);
|
||||
if (owner != null) {
|
||||
if (owner.isDead) { this.setDead(); return; }
|
||||
if (owner instanceof EntityNPCInterface && ((EntityNPCInterface) owner).isKilled()) {
|
||||
this.setDead(); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updateBarrierTick()) return;
|
||||
|
||||
// Duration check
|
||||
if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset hit flash
|
||||
if (getHitFlash() > 0) {
|
||||
setHitFlash((byte) (getHitFlash() - 1));
|
||||
}
|
||||
// Knockback entities inside the dome
|
||||
if (!worldObj.isRemote && barrierData.knockbackEnabled) {
|
||||
knockbackEntities();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply damage to this dome from a projectile.
|
||||
* Returns true if the dome absorbed the hit (projectile should be destroyed).
|
||||
*/
|
||||
public boolean onProjectileHit(EntityAbilityProjectile projectile, float baseDamage) {
|
||||
if (!barrierData.useHealth) {
|
||||
// Duration-only mode: block but don't take damage
|
||||
triggerHitFlash();
|
||||
return true;
|
||||
}
|
||||
|
||||
// Get damage multiplier for this projectile type
|
||||
String typeId = "";
|
||||
if (projectile.getSourceAbility() != null) {
|
||||
typeId = projectile.getSourceAbility().getTypeId();
|
||||
}
|
||||
float multiplier = barrierData.getMultiplier(typeId);
|
||||
float damage = baseDamage * multiplier;
|
||||
|
||||
currentHealth -= damage;
|
||||
syncHealthPercent();
|
||||
triggerHitFlash();
|
||||
|
||||
if (currentHealth <= 0) {
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// ==================== INCOMING CHECK ====================
|
||||
|
||||
/**
|
||||
* Check if a projectile at the given position is entering this dome from outside.
|
||||
* Only blocks incoming projectiles (dot product check).
|
||||
*/
|
||||
public boolean isIncomingProjectile(EntityAbilityProjectile projectile) {
|
||||
@Override
|
||||
public boolean isIncomingProjectile(EntityEnergyProjectile projectile) {
|
||||
// Don't block during charging phase
|
||||
if (isCharging()) return false;
|
||||
// Don't block projectiles from the dome's owner
|
||||
if (projectile.getOwnerEntityId() == this.ownerEntityId) return false;
|
||||
|
||||
// Don't block projectiles from same-faction NPCs
|
||||
Entity owner = getOwnerEntity();
|
||||
Entity projOwner = projectile.getOwnerEntity();
|
||||
if (owner instanceof EntityNPCInterface && projOwner instanceof EntityNPCInterface) {
|
||||
if (((EntityNPCInterface) owner).faction.id == ((EntityNPCInterface) projOwner).faction.id) {
|
||||
if (owner instanceof noppes.npcs.entity.EntityNPCInterface && projOwner instanceof noppes.npcs.entity.EntityNPCInterface) {
|
||||
if (((noppes.npcs.entity.EntityNPCInterface) owner).faction.id == ((noppes.npcs.entity.EntityNPCInterface) projOwner).faction.id) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -170,74 +114,77 @@ public class EntityEnergyDome extends Entity implements IEntityAdditionalSpawnDa
|
||||
return dot < 0;
|
||||
}
|
||||
|
||||
// ==================== HELPERS ====================
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
private void syncHealthPercent() {
|
||||
float percent = barrierData.useHealth && barrierData.maxHealth > 0
|
||||
? Math.max(0, currentHealth / barrierData.maxHealth)
|
||||
: 1.0f;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_HEALTH_PERCENT, percent);
|
||||
@Override
|
||||
public void setupCharging(int duration) {
|
||||
this.targetDomeRadius = this.domeRadius;
|
||||
this.domeRadius = 0.01f;
|
||||
this.chargeDuration = duration;
|
||||
this.chargeTick = 0;
|
||||
setCharging(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishCharging() {
|
||||
this.domeRadius = targetDomeRadius;
|
||||
setCharging(false);
|
||||
}
|
||||
|
||||
// ==================== KNOCKBACK ====================
|
||||
|
||||
/**
|
||||
* Push entities away from the dome surface.
|
||||
* Entities outside are pushed outward, entities inside are pushed inward (containment).
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void knockbackEntities() {
|
||||
float margin = 1.0f;
|
||||
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - domeRadius - margin, posY - domeRadius - margin, posZ - domeRadius - margin,
|
||||
posX + domeRadius + margin, posY + domeRadius + margin, posZ + domeRadius + margin
|
||||
);
|
||||
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox);
|
||||
for (EntityLivingBase ent : entities) {
|
||||
if (ent.getEntityId() == ownerEntityId) continue;
|
||||
if (!isKnockbackTarget(ent)) continue;
|
||||
|
||||
double dx = ent.posX - posX;
|
||||
double dy = (ent.posY + ent.height * 0.5) - posY;
|
||||
double dz = ent.posZ - posZ;
|
||||
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
if (dist < 0.01) continue;
|
||||
|
||||
// Only affect entities near the dome surface
|
||||
if (dist < domeRadius + margin && dist > domeRadius - margin) {
|
||||
double pushStrength = barrierData.knockbackStrength * 0.5;
|
||||
double pushDir = dist >= domeRadius ? 1.0 : -1.0; // Outside = outward, Inside = inward
|
||||
ent.addVelocity(
|
||||
(dx / dist) * pushStrength * pushDir,
|
||||
0.05 * pushDir,
|
||||
(dz / dist) * pushStrength * pushDir
|
||||
);
|
||||
ent.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void triggerHitFlash() {
|
||||
if (!worldObj.isRemote) {
|
||||
setHitFlash((byte) 4);
|
||||
// ==================== BOUNDING BOX ====================
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
if (barrierData.meleeEnabled) {
|
||||
return AxisAlignedBB.getBoundingBox(
|
||||
posX - domeRadius, posY - domeRadius, posZ - domeRadius,
|
||||
posX + domeRadius, posY + domeRadius, posZ + domeRadius
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setHitFlash(byte value) {
|
||||
this.dataWatcher.updateObject(DW_HIT_FLASH, value);
|
||||
}
|
||||
|
||||
public byte getHitFlash() {
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_HIT_FLASH);
|
||||
}
|
||||
|
||||
public float getHealthPercent() {
|
||||
return this.dataWatcher.getWatchableObjectFloat(DW_HEALTH_PERCENT);
|
||||
}
|
||||
|
||||
public Entity getOwnerEntity() {
|
||||
if (ownerEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(ownerEntityId);
|
||||
}
|
||||
|
||||
public int getOwnerEntityId() { return ownerEntityId; }
|
||||
public float getDomeRadius() { return domeRadius; }
|
||||
public EnergyDisplayData getDisplayData() { return displayData; }
|
||||
public EnergyLightningData getLightningData() { return lightningData; }
|
||||
public EnergyBarrierData getBarrierData() { return barrierData; }
|
||||
public float getCurrentHealth() { return currentHealth; }
|
||||
|
||||
public void setSourceAbility(Ability ability) { this.sourceAbility = ability; }
|
||||
public Ability getSourceAbility() { return sourceAbility; }
|
||||
|
||||
// ==================== VISUAL GETTERS ====================
|
||||
|
||||
public int getInnerColor() { return displayData.innerColor; }
|
||||
public int getOuterColor() { return displayData.outerColor; }
|
||||
public boolean isOuterColorEnabled() { return displayData.outerColorEnabled; }
|
||||
public float getOuterColorWidth() { return displayData.outerColorWidth; }
|
||||
public float getOuterColorAlpha() { return displayData.outerColorAlpha; }
|
||||
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
|
||||
public float getLightningDensity() { return lightningData.lightningDensity; }
|
||||
public float getLightningRadius() { return lightningData.lightningRadius; }
|
||||
public int getLightningFadeTime() { return lightningData.lightningFadeTime; }
|
||||
|
||||
// ==================== BRIGHTNESS ====================
|
||||
|
||||
@Override
|
||||
public float getBrightness(float partialTicks) { return 1.0f; }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float partialTicks) { return 0xF000F0; }
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) { return pass == 1; }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isInRangeToRenderDist(double distance) {
|
||||
@@ -246,69 +193,28 @@ public class EntityEnergyDome extends Entity implements IEntityAdditionalSpawnDa
|
||||
return distance < d * d;
|
||||
}
|
||||
|
||||
// ==================== COLLISION SETTINGS ====================
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() { return false; }
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() { return false; }
|
||||
|
||||
@Override
|
||||
protected boolean canTriggerWalking() { return false; }
|
||||
|
||||
@Override
|
||||
public boolean isBurning() { return false; }
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize() { return 0.0f; }
|
||||
public float getDomeRadius() { return domeRadius; }
|
||||
public void setDomeRadius(float radius) { this.domeRadius = Math.max(0.1f, radius); }
|
||||
public boolean isFollowCaster() { return followCaster; }
|
||||
public void setFollowCaster(boolean follow) { this.followCaster = follow; }
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
readBarrierBaseNBT(nbt);
|
||||
this.domeRadius = nbt.getFloat("DomeRadius");
|
||||
this.ownerEntityId = nbt.getInteger("OwnerId");
|
||||
this.ticksAlive = nbt.getInteger("TicksAlive");
|
||||
this.currentHealth = nbt.getFloat("CurrentHealth");
|
||||
displayData.readNBT(nbt);
|
||||
lightningData.readNBT(nbt);
|
||||
barrierData.readNBT(nbt);
|
||||
this.targetDomeRadius = nbt.hasKey("TargetDomeRadius") ? nbt.getFloat("TargetDomeRadius") : domeRadius;
|
||||
this.followCaster = nbt.hasKey("FollowCaster") && nbt.getBoolean("FollowCaster");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
writeBarrierBaseNBT(nbt);
|
||||
nbt.setFloat("DomeRadius", domeRadius);
|
||||
nbt.setInteger("OwnerId", ownerEntityId);
|
||||
nbt.setInteger("TicksAlive", ticksAlive);
|
||||
nbt.setFloat("CurrentHealth", currentHealth);
|
||||
displayData.writeNBT(nbt);
|
||||
lightningData.writeNBT(nbt);
|
||||
barrierData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== SPAWN DATA ====================
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeEntityToNBT(compound);
|
||||
cpw.mods.fml.common.network.ByteBufUtils.writeTag(buffer, compound);
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error writing energy dome spawn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = cpw.mods.fml.common.network.ByteBufUtils.readTag(buffer);
|
||||
if (compound != null) {
|
||||
this.readEntityFromNBT(compound);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error reading energy dome spawn data", e);
|
||||
}
|
||||
nbt.setFloat("TargetDomeRadius", targetDomeRadius);
|
||||
nbt.setBoolean("FollowCaster", followCaster);
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,29 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyBarrierData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyDisplayData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyLightningData;
|
||||
import kamkeel.npcs.controllers.data.ability.data.EnergyPanelData;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.NpcDamageSource;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Energy Panel entity - a flat rectangular barrier used by Wall and Shield abilities.
|
||||
* Supports three modes: PLACED (stationary), HELD (tracks caster), LAUNCHED (moves forward).
|
||||
* Extends EntityEnergyBarrier for shared barrier logic.
|
||||
*/
|
||||
public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnData {
|
||||
public class EntityEnergyPanel extends EntityEnergyBarrier {
|
||||
|
||||
public enum PanelMode {
|
||||
PLACED, // Stationary wall
|
||||
@@ -33,40 +31,18 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
LAUNCHED // Moves forward, deals damage/knockback on contact
|
||||
}
|
||||
|
||||
// ==================== VISUAL PROPERTIES ====================
|
||||
protected EnergyDisplayData displayData = new EnergyDisplayData();
|
||||
protected EnergyLightningData lightningData = new EnergyLightningData();
|
||||
|
||||
// ==================== BARRIER PROPERTIES ====================
|
||||
protected EnergyBarrierData barrierData = new EnergyBarrierData();
|
||||
// ==================== PANEL-SPECIFIC PROPERTIES ====================
|
||||
protected EnergyPanelData panelData = new EnergyPanelData();
|
||||
protected float currentHealth;
|
||||
|
||||
// ==================== PANEL STATE ====================
|
||||
protected PanelMode mode = PanelMode.PLACED;
|
||||
protected float panelYaw = 0.0f; // Rotation of the panel face (degrees)
|
||||
|
||||
// ==================== TRACKING ====================
|
||||
protected int ownerEntityId = -1;
|
||||
protected int ticksAlive = 0;
|
||||
|
||||
// ==================== STATE ====================
|
||||
protected transient Ability sourceAbility = null;
|
||||
|
||||
// ==================== DATA WATCHER INDICES ====================
|
||||
private static final int DW_HEALTH_PERCENT = 20;
|
||||
private static final int DW_HIT_FLASH = 21;
|
||||
|
||||
// ==================== CLIENT STATE ====================
|
||||
@SideOnly(Side.CLIENT)
|
||||
public transient Object lightningState;
|
||||
// ==================== CHARGING (panel-specific targets) ====================
|
||||
protected float targetPanelWidth;
|
||||
protected float targetPanelHeight;
|
||||
|
||||
public EntityEnergyPanel(World world) {
|
||||
super(world);
|
||||
this.setSize(0.5f, 0.5f);
|
||||
this.noClip = true;
|
||||
this.isImmuneToFire = true;
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
public EntityEnergyPanel(World world, EntityLivingBase owner, double x, double y, double z,
|
||||
@@ -93,12 +69,6 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
this.dataWatcher.addObject(DW_HEALTH_PERCENT, 1.0f);
|
||||
this.dataWatcher.addObject(DW_HIT_FLASH, (byte) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
this.prevPosX = this.posX;
|
||||
@@ -106,30 +76,28 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
this.prevPosZ = this.posZ;
|
||||
|
||||
super.onUpdate();
|
||||
|
||||
// Handle charging animation (both sides for smooth rendering)
|
||||
if (isCharging()) {
|
||||
chargeTick++;
|
||||
float progress = getChargeProgress();
|
||||
panelData.panelWidth = targetPanelWidth * progress;
|
||||
panelData.panelHeight = targetPanelHeight * progress;
|
||||
|
||||
// During charging, held panels still track owner
|
||||
if (mode == PanelMode.HELD) {
|
||||
updateHeld();
|
||||
}
|
||||
return; // Don't tick duration/death during charging
|
||||
}
|
||||
|
||||
ticksAlive++;
|
||||
|
||||
if (!worldObj.isRemote) {
|
||||
// Check owner death
|
||||
if (ownerEntityId >= 0 && ticksAlive > 5) {
|
||||
Entity owner = worldObj.getEntityByID(ownerEntityId);
|
||||
if (owner != null) {
|
||||
if (owner.isDead) { this.setDead(); return; }
|
||||
if (owner instanceof EntityNPCInterface && ((EntityNPCInterface) owner).isKilled()) {
|
||||
this.setDead(); return;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (updateBarrierTick()) return;
|
||||
|
||||
// Duration check
|
||||
if (barrierData.useDuration && ticksAlive >= barrierData.durationTicks) {
|
||||
this.setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset hit flash
|
||||
if (getHitFlash() > 0) {
|
||||
setHitFlash((byte) (getHitFlash() - 1));
|
||||
}
|
||||
// Knockback (not during launched mode)
|
||||
if (!worldObj.isRemote && barrierData.knockbackEnabled && mode != PanelMode.LAUNCHED) {
|
||||
knockbackEntities();
|
||||
}
|
||||
|
||||
// Mode-specific updates
|
||||
@@ -151,108 +119,90 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner == null) return;
|
||||
|
||||
// Update yaw BEFORE position calc to avoid 1-tick lag
|
||||
this.panelYaw = owner.rotationYaw;
|
||||
|
||||
// Follow owner position
|
||||
float frontDist = 1.5f;
|
||||
float yawRad = (float) Math.toRadians(owner.rotationYaw);
|
||||
float yawRad = (float) Math.toRadians(panelYaw);
|
||||
double newX = owner.posX + (-Math.sin(yawRad) * frontDist);
|
||||
double newY = owner.posY + panelData.heightOffset + (owner.height * 0.5f);
|
||||
double newZ = owner.posZ + (Math.cos(yawRad) * frontDist);
|
||||
|
||||
this.setPosition(newX, newY, newZ);
|
||||
this.panelYaw = owner.rotationYaw;
|
||||
}
|
||||
|
||||
private void updateLaunched() {
|
||||
if (worldObj.isRemote) return;
|
||||
|
||||
// Move forward
|
||||
// Move forward on both sides for smooth client rendering
|
||||
this.posX += motionX;
|
||||
this.posY += motionY;
|
||||
this.posZ += motionZ;
|
||||
this.setPosition(posX, posY, posZ);
|
||||
|
||||
// Check entity collision for damage
|
||||
float halfW = panelData.panelWidth * 0.5f;
|
||||
float halfH = panelData.panelHeight * 0.5f;
|
||||
AxisAlignedBB hitBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - halfW, posY - halfH, posZ - halfW,
|
||||
posX + halfW, posY + halfH, posZ + halfW
|
||||
);
|
||||
// Damage and knockback are server-only
|
||||
if (!worldObj.isRemote) {
|
||||
// Check entity collision for damage
|
||||
float halfW = panelData.panelWidth * 0.5f;
|
||||
float halfH = panelData.panelHeight * 0.5f;
|
||||
float halfD = 0.5f; // Panel collision depth
|
||||
float searchRadius = Math.max(halfW, halfD);
|
||||
AxisAlignedBB hitBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - searchRadius, posY - halfH, posZ - searchRadius,
|
||||
posX + searchRadius, posY + halfH, posZ + searchRadius
|
||||
);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, hitBox);
|
||||
Entity owner = getOwnerEntity();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, hitBox);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
// Apply damage
|
||||
if (panelData.launchDamage > 0) {
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), panelData.launchDamage);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), panelData.launchDamage);
|
||||
// Apply damage
|
||||
if (panelData.launchDamage > 0) {
|
||||
if (owner instanceof EntityNPCInterface) {
|
||||
target.attackEntityFrom(new NpcDamageSource("npc_ability", (EntityNPCInterface) owner), panelData.launchDamage);
|
||||
} else if (owner instanceof EntityPlayer) {
|
||||
target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) owner), panelData.launchDamage);
|
||||
}
|
||||
}
|
||||
|
||||
// Apply knockback
|
||||
if (panelData.launchKnockback > 0) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
double len = Math.sqrt(dx * dx + dz * dz);
|
||||
if (len > 0) {
|
||||
target.addVelocity(
|
||||
(dx / len) * panelData.launchKnockback * 0.5,
|
||||
0.1,
|
||||
(dz / len) * panelData.launchKnockback * 0.5
|
||||
);
|
||||
target.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Apply knockback
|
||||
if (panelData.launchKnockback > 0) {
|
||||
double dx = target.posX - posX;
|
||||
double dz = target.posZ - posZ;
|
||||
double len = Math.sqrt(dx * dx + dz * dz);
|
||||
if (len > 0) {
|
||||
target.addVelocity(
|
||||
(dx / len) * panelData.launchKnockback * 0.5,
|
||||
0.1,
|
||||
(dz / len) * panelData.launchKnockback * 0.5
|
||||
);
|
||||
target.velocityChanged = true;
|
||||
}
|
||||
// Max lifetime check
|
||||
if (ticksAlive > 200) {
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
// Max distance check (30 blocks)
|
||||
double distSq = (posX - prevPosX) * (posX - prevPosX) + (posZ - prevPosZ) * (posZ - prevPosZ);
|
||||
if (ticksAlive > 200) {
|
||||
this.setDead();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply damage to this panel from a projectile.
|
||||
*/
|
||||
public boolean onProjectileHit(EntityAbilityProjectile projectile, float baseDamage) {
|
||||
if (!barrierData.useHealth) {
|
||||
triggerHitFlash();
|
||||
return true;
|
||||
}
|
||||
|
||||
String typeId = "";
|
||||
if (projectile.getSourceAbility() != null) {
|
||||
typeId = projectile.getSourceAbility().getTypeId();
|
||||
}
|
||||
float multiplier = barrierData.getMultiplier(typeId);
|
||||
float damage = baseDamage * multiplier;
|
||||
|
||||
currentHealth -= damage;
|
||||
syncHealthPercent();
|
||||
triggerHitFlash();
|
||||
|
||||
if (currentHealth <= 0) {
|
||||
this.setDead();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
// ==================== INCOMING CHECK ====================
|
||||
|
||||
/**
|
||||
* Check if a projectile hits this panel surface.
|
||||
* Only blocks incoming projectiles (not from the panel's owner).
|
||||
*/
|
||||
public boolean isIncomingProjectile(EntityAbilityProjectile projectile) {
|
||||
@Override
|
||||
public boolean isIncomingProjectile(EntityEnergyProjectile projectile) {
|
||||
// Don't block during charging phase
|
||||
if (isCharging()) return false;
|
||||
if (projectile.getOwnerEntityId() == this.ownerEntityId) return false;
|
||||
|
||||
// Faction check
|
||||
@@ -292,85 +242,97 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
double dot = projectile.motionX * normalX + projectile.motionZ * normalZ;
|
||||
|
||||
// Determine which side of the panel the projectile is on
|
||||
// If on the front (localForward > 0), it must be moving backward (dot < 0) to be incoming
|
||||
// If on the back (localForward < 0), it must be moving forward (dot > 0) to be incoming
|
||||
if (localForward > 0 && dot >= 0) return false; // Moving away from front side
|
||||
if (localForward < 0 && dot <= 0) return false; // Moving away from back side
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// ==================== HELPERS ====================
|
||||
// ==================== CHARGING ====================
|
||||
|
||||
private void syncHealthPercent() {
|
||||
float percent = barrierData.useHealth && barrierData.maxHealth > 0
|
||||
? Math.max(0, currentHealth / barrierData.maxHealth)
|
||||
: 1.0f;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_HEALTH_PERCENT, percent);
|
||||
@Override
|
||||
public void setupCharging(int duration) {
|
||||
this.targetPanelWidth = panelData.panelWidth;
|
||||
this.targetPanelHeight = panelData.panelHeight;
|
||||
panelData.panelWidth = 0.01f;
|
||||
panelData.panelHeight = 0.01f;
|
||||
this.chargeDuration = duration;
|
||||
this.chargeTick = 0;
|
||||
setCharging(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finishCharging() {
|
||||
panelData.panelWidth = targetPanelWidth;
|
||||
panelData.panelHeight = targetPanelHeight;
|
||||
setCharging(false);
|
||||
}
|
||||
|
||||
// ==================== KNOCKBACK ====================
|
||||
|
||||
/**
|
||||
* Push entities away from the panel surface.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void knockbackEntities() {
|
||||
float halfW = panelData.panelWidth * 0.5f;
|
||||
float halfH = panelData.panelHeight * 0.5f;
|
||||
float margin = 1.0f;
|
||||
|
||||
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - halfW - margin, posY - halfH - margin, posZ - halfW - margin,
|
||||
posX + halfW + margin, posY + halfH + margin, posZ + halfW + margin
|
||||
);
|
||||
|
||||
List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, searchBox);
|
||||
float yawRad = (float) Math.toRadians(panelYaw);
|
||||
float normalX = -(float) Math.sin(yawRad);
|
||||
float normalZ = (float) Math.cos(yawRad);
|
||||
|
||||
for (EntityLivingBase ent : entities) {
|
||||
if (ent.getEntityId() == ownerEntityId) continue;
|
||||
if (!isKnockbackTarget(ent)) continue;
|
||||
|
||||
// Transform entity position to panel-local space
|
||||
double dx = ent.posX - posX;
|
||||
double dy = (ent.posY + ent.height * 0.5) - posY;
|
||||
double dz = ent.posZ - posZ;
|
||||
|
||||
// Check proximity to panel surface
|
||||
float localForward = (float) (dx * normalX + dz * normalZ);
|
||||
float localRight = (float) (dx * (-normalZ) + dz * normalX);
|
||||
|
||||
if (Math.abs(localForward) < margin && Math.abs(localRight) < halfW + margin && Math.abs(dy) < halfH + margin) {
|
||||
// Push entity away from the panel face
|
||||
float pushDir = localForward >= 0 ? 1.0f : -1.0f;
|
||||
double pushStrength = barrierData.knockbackStrength * 0.5;
|
||||
ent.addVelocity(
|
||||
normalX * pushDir * pushStrength,
|
||||
0.1,
|
||||
normalZ * pushDir * pushStrength
|
||||
);
|
||||
ent.velocityChanged = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void triggerHitFlash() {
|
||||
if (!worldObj.isRemote) {
|
||||
setHitFlash((byte) 4);
|
||||
// ==================== BOUNDING BOX ====================
|
||||
|
||||
@Override
|
||||
public AxisAlignedBB getBoundingBox() {
|
||||
if (barrierData.meleeEnabled) {
|
||||
float halfW = panelData.panelWidth * 0.5f;
|
||||
float halfH = panelData.panelHeight * 0.5f;
|
||||
float extent = Math.max(halfW, 0.5f);
|
||||
return AxisAlignedBB.getBoundingBox(
|
||||
posX - extent, posY - halfH, posZ - extent,
|
||||
posX + extent, posY + halfH, posZ + extent
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setHitFlash(byte value) {
|
||||
this.dataWatcher.updateObject(DW_HIT_FLASH, value);
|
||||
}
|
||||
|
||||
public byte getHitFlash() {
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_HIT_FLASH);
|
||||
}
|
||||
|
||||
public float getHealthPercent() {
|
||||
return this.dataWatcher.getWatchableObjectFloat(DW_HEALTH_PERCENT);
|
||||
}
|
||||
|
||||
public Entity getOwnerEntity() {
|
||||
if (ownerEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(ownerEntityId);
|
||||
}
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
public int getOwnerEntityId() { return ownerEntityId; }
|
||||
public PanelMode getMode() { return mode; }
|
||||
public float getPanelYaw() { return panelYaw; }
|
||||
public EnergyDisplayData getDisplayData() { return displayData; }
|
||||
public EnergyLightningData getLightningData() { return lightningData; }
|
||||
public EnergyBarrierData getBarrierData() { return barrierData; }
|
||||
public EnergyPanelData getPanelData() { return panelData; }
|
||||
public float getCurrentHealth() { return currentHealth; }
|
||||
|
||||
public void setSourceAbility(Ability ability) { this.sourceAbility = ability; }
|
||||
public Ability getSourceAbility() { return sourceAbility; }
|
||||
|
||||
// Visual getters
|
||||
public int getInnerColor() { return displayData.innerColor; }
|
||||
public int getOuterColor() { return displayData.outerColor; }
|
||||
public boolean isOuterColorEnabled() { return displayData.outerColorEnabled; }
|
||||
public float getOuterColorWidth() { return displayData.outerColorWidth; }
|
||||
public float getOuterColorAlpha() { return displayData.outerColorAlpha; }
|
||||
public boolean hasLightningEffect() { return lightningData.lightningEffect; }
|
||||
public float getLightningDensity() { return lightningData.lightningDensity; }
|
||||
public float getLightningRadius() { return lightningData.lightningRadius; }
|
||||
public int getLightningFadeTime() { return lightningData.lightningFadeTime; }
|
||||
|
||||
// ==================== BRIGHTNESS ====================
|
||||
|
||||
@Override
|
||||
public float getBrightness(float partialTicks) { return 1.0f; }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float partialTicks) { return 0xF000F0; }
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) { return pass == 1; }
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isInRangeToRenderDist(double distance) {
|
||||
@@ -379,73 +341,33 @@ public class EntityEnergyPanel extends Entity implements IEntityAdditionalSpawnD
|
||||
return distance < d * d;
|
||||
}
|
||||
|
||||
// ==================== COLLISION SETTINGS ====================
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() { return false; }
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() { return false; }
|
||||
|
||||
@Override
|
||||
protected boolean canTriggerWalking() { return false; }
|
||||
|
||||
@Override
|
||||
public boolean isBurning() { return false; }
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize() { return 0.0f; }
|
||||
public PanelMode getMode() { return mode; }
|
||||
public float getPanelYaw() { return panelYaw; }
|
||||
public EnergyPanelData getPanelData() { return panelData; }
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
this.ownerEntityId = nbt.getInteger("OwnerId");
|
||||
this.ticksAlive = nbt.getInteger("TicksAlive");
|
||||
this.currentHealth = nbt.getFloat("CurrentHealth");
|
||||
readBarrierBaseNBT(nbt);
|
||||
this.panelYaw = nbt.getFloat("PanelYaw");
|
||||
this.mode = PanelMode.values()[nbt.getInteger("PanelMode")];
|
||||
displayData.readNBT(nbt);
|
||||
lightningData.readNBT(nbt);
|
||||
barrierData.readNBT(nbt);
|
||||
int modeOrdinal = nbt.getInteger("PanelMode");
|
||||
this.mode = (modeOrdinal >= 0 && modeOrdinal < PanelMode.values().length)
|
||||
? PanelMode.values()[modeOrdinal] : PanelMode.PLACED;
|
||||
panelData.readNBT(nbt);
|
||||
this.targetPanelWidth = nbt.hasKey("TargetPanelWidth") ? nbt.getFloat("TargetPanelWidth") : panelData.panelWidth;
|
||||
this.targetPanelHeight = nbt.hasKey("TargetPanelHeight") ? nbt.getFloat("TargetPanelHeight") : panelData.panelHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeEntityToNBT(NBTTagCompound nbt) {
|
||||
nbt.setInteger("OwnerId", ownerEntityId);
|
||||
nbt.setInteger("TicksAlive", ticksAlive);
|
||||
nbt.setFloat("CurrentHealth", currentHealth);
|
||||
writeBarrierBaseNBT(nbt);
|
||||
nbt.setFloat("PanelYaw", panelYaw);
|
||||
nbt.setInteger("PanelMode", mode.ordinal());
|
||||
displayData.writeNBT(nbt);
|
||||
lightningData.writeNBT(nbt);
|
||||
barrierData.writeNBT(nbt);
|
||||
nbt.setFloat("TargetPanelWidth", targetPanelWidth);
|
||||
nbt.setFloat("TargetPanelHeight", targetPanelHeight);
|
||||
panelData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
// ==================== SPAWN DATA ====================
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeEntityToNBT(compound);
|
||||
cpw.mods.fml.common.network.ByteBufUtils.writeTag(buffer, compound);
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error writing energy panel spawn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = cpw.mods.fml.common.network.ByteBufUtils.readTag(buffer);
|
||||
if (compound != null) {
|
||||
this.readEntityFromNBT(compound);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error reading energy panel spawn data", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
-259
@@ -1,14 +1,10 @@
|
||||
package kamkeel.npcs.entity;
|
||||
|
||||
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.AbilityEffect;
|
||||
import kamkeel.npcs.controllers.data.ability.AnchorPoint;
|
||||
|
||||
import kamkeel.npcs.controllers.data.ability.data.*;
|
||||
import kamkeel.npcs.util.AnchorPointHelper;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -35,20 +31,21 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Base class for all ability projectiles (Orb, Disc, Beam, Laser).
|
||||
* Provides common functionality for visuals, combat, effects, and interpolation.
|
||||
* Base class for all ability projectiles (Orb, Disc, Beam, Laser, Slicer).
|
||||
* Provides common functionality for combat, effects, homing, and interpolation.
|
||||
* Extends EntityEnergyAbility for shared visual/owner/charging state.
|
||||
*
|
||||
* Design inspired by LouisXIV's energy attack system.
|
||||
*/
|
||||
public abstract class EntityAbilityProjectile extends Entity implements IEntityAdditionalSpawnData {
|
||||
public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
|
||||
|
||||
// ==================== ACTIVE PROJECTILE TRACKING ====================
|
||||
private static final Map<Integer, List<WeakReference<EntityAbilityProjectile>>> activeProjectiles = new HashMap<>();
|
||||
private static final Map<Integer, List<WeakReference<EntityEnergyProjectile>>> activeProjectiles = new HashMap<>();
|
||||
|
||||
public static void trackProjectile(EntityAbilityProjectile projectile) {
|
||||
public static void trackProjectile(EntityEnergyProjectile projectile) {
|
||||
int ownerId = projectile.getOwnerEntityId();
|
||||
if (ownerId < 0) return;
|
||||
List<WeakReference<EntityAbilityProjectile>> refs = activeProjectiles.get(ownerId);
|
||||
List<WeakReference<EntityEnergyProjectile>> refs = activeProjectiles.get(ownerId);
|
||||
if (refs == null) {
|
||||
refs = new ArrayList<>();
|
||||
activeProjectiles.put(ownerId, refs);
|
||||
@@ -56,13 +53,13 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
refs.add(new WeakReference<>(projectile));
|
||||
}
|
||||
|
||||
public static List<EntityAbilityProjectile> getActiveProjectiles(int ownerEntityId) {
|
||||
List<WeakReference<EntityAbilityProjectile>> refs = activeProjectiles.get(ownerEntityId);
|
||||
public static List<EntityEnergyProjectile> getActiveProjectiles(int ownerEntityId) {
|
||||
List<WeakReference<EntityEnergyProjectile>> refs = activeProjectiles.get(ownerEntityId);
|
||||
if (refs == null) return Collections.emptyList();
|
||||
List<EntityAbilityProjectile> result = new ArrayList<>();
|
||||
Iterator<WeakReference<EntityAbilityProjectile>> it = refs.iterator();
|
||||
List<EntityEnergyProjectile> result = new ArrayList<>();
|
||||
Iterator<WeakReference<EntityEnergyProjectile>> it = refs.iterator();
|
||||
while (it.hasNext()) {
|
||||
EntityAbilityProjectile p = it.next().get();
|
||||
EntityEnergyProjectile p = it.next().get();
|
||||
if (p == null || p.isDead) {
|
||||
it.remove();
|
||||
} else {
|
||||
@@ -82,16 +79,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
// ==================== EFFECT PROPERTIES ====================
|
||||
protected List<AbilityEffect> effects = new ArrayList<>();
|
||||
|
||||
// ==================== LIGHTNING EFFECT PROPERTIES ====================
|
||||
protected EnergyLightningData lightningData = new EnergyLightningData();
|
||||
|
||||
// Client-side lightning state (not saved to NBT)
|
||||
@cpw.mods.fml.relauncher.SideOnly(cpw.mods.fml.relauncher.Side.CLIENT)
|
||||
public transient Object lightningState; // Actually AttachedLightningRenderer.LightningState
|
||||
|
||||
// ==================== DISPLAY PROPERTIES ====================
|
||||
protected EnergyDisplayData displayData = new EnergyDisplayData();
|
||||
|
||||
// ==================== ANCHOR PROPERTIES ====================
|
||||
protected EnergyAnchorData anchorData = new EnergyAnchorData(AnchorPoint.FRONT);
|
||||
|
||||
@@ -108,23 +95,13 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
|
||||
// ==================== TRACKING ====================
|
||||
protected double startX, startY, startZ;
|
||||
protected int ownerEntityId = -1;
|
||||
protected int targetEntityId = -1;
|
||||
|
||||
// ==================== STATE ====================
|
||||
protected boolean hasHit = false;
|
||||
protected boolean previewMode = false; // Client-side preview mode (no damage/effects)
|
||||
protected EntityLivingBase previewOwner = null; // Direct reference for GUI preview (no world lookup)
|
||||
|
||||
/** The ability that spawned this projectile. Transient, not saved to NBT. */
|
||||
protected transient Ability sourceAbility = null;
|
||||
|
||||
// ==================== CHARGING STATE ====================
|
||||
protected boolean charging = false;
|
||||
protected int chargeDuration = 40;
|
||||
protected int chargeTick = 0;
|
||||
// ==================== CHARGING STATE (projectile-specific) ====================
|
||||
protected float targetSize = 1.0f;
|
||||
protected static final int DW_CHARGING = 20;
|
||||
|
||||
// ==================== ROTATION INTERPOLATION ====================
|
||||
public float prevRotationValX, prevRotationValY, prevRotationValZ;
|
||||
@@ -139,12 +116,10 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
protected double interpTargetMotionX, interpTargetMotionY, interpTargetMotionZ;
|
||||
protected int interpSteps;
|
||||
|
||||
public EntityAbilityProjectile(World world) {
|
||||
public EntityEnergyProjectile(World world) {
|
||||
super(world);
|
||||
this.setSize(0.5f, 0.5f);
|
||||
this.noClip = false;
|
||||
this.isImmuneToFire = true;
|
||||
this.ignoreFrustumCheck = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -177,11 +152,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
this.prevRenderSize = size;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
this.dataWatcher.addObject(DW_CHARGING, (byte) 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isInRangeToRenderDist(double distance) {
|
||||
@@ -190,11 +160,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
return distance < d1 * d1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldRenderInPass(int pass) {
|
||||
return pass == 1; // Translucent pass
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
// Store previous values for interpolation
|
||||
@@ -320,39 +285,24 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
// ==================== BARRIER COLLISION ====================
|
||||
|
||||
/**
|
||||
* Check for collision with energy barrier entities (Dome, Panel).
|
||||
* Check for collision with energy barrier entities.
|
||||
* Barriers only block incoming projectiles from enemies.
|
||||
* @return true if projectile was absorbed (caller should stop processing)
|
||||
*/
|
||||
protected boolean checkBarrierCollision() {
|
||||
// Search area for barriers - check a generous range
|
||||
double searchRange = 10.0;
|
||||
// Search area for barriers - must cover large domes (up to 30 radius)
|
||||
double searchRange = 32.0;
|
||||
AxisAlignedBB searchBox = AxisAlignedBB.getBoundingBox(
|
||||
posX - searchRange, posY - searchRange, posZ - searchRange,
|
||||
posX + searchRange, posY + searchRange, posZ + searchRange
|
||||
);
|
||||
|
||||
// Check domes
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityEnergyDome> domes = worldObj.getEntitiesWithinAABB(EntityEnergyDome.class, searchBox);
|
||||
for (EntityEnergyDome dome : domes) {
|
||||
if (dome.isDead) continue;
|
||||
if (dome.isIncomingProjectile(this)) {
|
||||
if (dome.onProjectileHit(this, getDamage())) {
|
||||
hasHit = true;
|
||||
this.setDead();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check panels
|
||||
@SuppressWarnings("unchecked")
|
||||
List<EntityEnergyPanel> panels = worldObj.getEntitiesWithinAABB(EntityEnergyPanel.class, searchBox);
|
||||
for (EntityEnergyPanel panel : panels) {
|
||||
if (panel.isDead) continue;
|
||||
if (panel.isIncomingProjectile(this)) {
|
||||
if (panel.onProjectileHit(this, getDamage())) {
|
||||
List<EntityEnergyBarrier> barriers = worldObj.getEntitiesWithinAABB(EntityEnergyBarrier.class, searchBox);
|
||||
for (EntityEnergyBarrier barrier : barriers) {
|
||||
if (barrier.isDead) continue;
|
||||
if (barrier.isIncomingProjectile(this)) {
|
||||
if (barrier.onProjectileHit(this, getDamage())) {
|
||||
hasHit = true;
|
||||
this.setDead();
|
||||
return true;
|
||||
@@ -406,23 +356,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== PREVIEW MODE ====================
|
||||
|
||||
/**
|
||||
* Set preview mode for GUI display.
|
||||
* In preview mode, no damage or world effects are applied.
|
||||
*/
|
||||
public void setPreviewMode(boolean preview) {
|
||||
this.previewMode = preview;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if entity is in preview mode.
|
||||
*/
|
||||
public boolean isPreviewMode() {
|
||||
return previewMode;
|
||||
}
|
||||
|
||||
// ==================== DAMAGE & EFFECTS ====================
|
||||
|
||||
protected void applyDamage(EntityLivingBase target) {
|
||||
@@ -495,21 +428,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
this.effects = effects != null ? effects : new ArrayList<>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the source ability that spawned this projectile.
|
||||
* Used by external damage handlers to access ability-specific data.
|
||||
*/
|
||||
public void setSourceAbility(Ability ability) {
|
||||
this.sourceAbility = ability;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the source ability that spawned this projectile.
|
||||
*/
|
||||
public Ability getSourceAbility() {
|
||||
return sourceAbility;
|
||||
}
|
||||
|
||||
protected void doExplosion() {
|
||||
if (previewMode) return; // Skip explosion in preview mode
|
||||
worldObj.playSoundEffect(posX, posY, posZ, "random.explode", 1.0f, 1.0f);
|
||||
@@ -566,38 +484,7 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
prevPosZ = newZ;
|
||||
}
|
||||
|
||||
// ==================== CHARGING METHODS ====================
|
||||
|
||||
/**
|
||||
* Check if entity is in charging state (synced via data watcher).
|
||||
* In preview mode, uses local field since data watcher isn't synced.
|
||||
*/
|
||||
public boolean isCharging() {
|
||||
if (previewMode) return this.charging;
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set charging state (server only, synced to clients via data watcher).
|
||||
*/
|
||||
protected void setCharging(boolean value) {
|
||||
this.charging = value;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
public float getChargeProgress() {
|
||||
if (chargeDuration <= 0) return 1.0f;
|
||||
return Math.min(1.0f, (float) chargeTick / chargeDuration);
|
||||
}
|
||||
|
||||
public float getInterpolatedChargeProgress(float partialTicks) {
|
||||
if (chargeDuration <= 0) return 1.0f;
|
||||
float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration);
|
||||
float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration);
|
||||
return prevProgress + (currProgress - prevProgress) * partialTicks;
|
||||
}
|
||||
// ==================== CHARGING METHODS (projectile-specific) ====================
|
||||
|
||||
/**
|
||||
* Setup this entity in charging mode (for windup phase).
|
||||
@@ -730,37 +617,12 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
|
||||
// ==================== ENTITY HELPERS ====================
|
||||
|
||||
public Entity getOwnerEntity() {
|
||||
// In preview mode, use direct reference (no world lookup)
|
||||
if (previewMode && previewOwner != null) {
|
||||
return previewOwner;
|
||||
}
|
||||
if (ownerEntityId == -1) return null;
|
||||
return worldObj.getEntityByID(ownerEntityId);
|
||||
}
|
||||
|
||||
public int getOwnerEntityId() {
|
||||
return ownerEntityId;
|
||||
}
|
||||
|
||||
public void setOwnerEntityId(int id) {
|
||||
this.ownerEntityId = id;
|
||||
}
|
||||
|
||||
public IEntity getOwner() {
|
||||
if (previewMode) return null;
|
||||
if (getOwnerEntity() == null) return null;
|
||||
return NpcAPI.Instance().getIEntity(getOwnerEntity());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the preview owner for GUI preview mode.
|
||||
* This allows anchor point calculations without world entity lookup.
|
||||
*/
|
||||
public void setPreviewOwner(EntityLivingBase owner) {
|
||||
this.previewOwner = owner;
|
||||
}
|
||||
|
||||
public int getTargetEntityId() {
|
||||
return targetEntityId;
|
||||
}
|
||||
@@ -794,8 +656,8 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
}
|
||||
|
||||
// Ignore other projectiles from the same caster (e.g. multi-projectile abilities)
|
||||
if (entity instanceof EntityAbilityProjectile) {
|
||||
EntityAbilityProjectile other = (EntityAbilityProjectile) entity;
|
||||
if (entity instanceof EntityEnergyProjectile) {
|
||||
EntityEnergyProjectile other = (EntityEnergyProjectile) entity;
|
||||
if (other.ownerEntityId == this.ownerEntityId) return true;
|
||||
}
|
||||
|
||||
@@ -821,24 +683,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
this.startZ = z;
|
||||
}
|
||||
|
||||
public int getInnerColor() { return displayData.getInnerColor(); }
|
||||
public void setInnerColor(int color) { displayData.setInnerColor(color); }
|
||||
|
||||
public int getOuterColor() { return displayData.getOuterColor(); }
|
||||
public void setOuterColor(int color) { displayData.setOuterColor(color); }
|
||||
|
||||
public boolean isOuterColorEnabled() { return displayData.isOuterColorEnabled(); }
|
||||
public void setOuterColorEnabled(boolean enabled) { displayData.setOuterColorEnabled(enabled); }
|
||||
|
||||
public float getOuterColorWidth() { return displayData.getOuterColorWidth(); }
|
||||
public void setOuterColorWidth(float width) { displayData.setOuterColorWidth(width); }
|
||||
|
||||
public float getOuterColorAlpha() { return displayData.getOuterColorAlpha(); }
|
||||
public void setOuterColorAlpha(float alpha) { displayData.setOuterColorAlpha(alpha); }
|
||||
|
||||
public float getRotationSpeed() { return displayData.getRotationSpeed(); }
|
||||
public void setRotationSpeed(float speed) { displayData.setRotationSpeed(speed); }
|
||||
|
||||
// ==================== ROTATION GETTERS ====================
|
||||
|
||||
public float getInterpolatedRotationX(float partialTicks) {
|
||||
@@ -857,20 +701,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
return this.prevRenderSize + (this.renderCurrentSize - this.prevRenderSize) * partialTicks;
|
||||
}
|
||||
|
||||
// ==================== LIGHTNING GETTERS & SETTERS ====================
|
||||
|
||||
public boolean hasLightningEffect() { return lightningData.isLightningEffect(); }
|
||||
public void setLightningEffect(boolean enabled) { lightningData.setLightningEffect(enabled); }
|
||||
|
||||
public float getLightningDensity() { return lightningData.getLightningDensity(); }
|
||||
public void setLightningDensity(float density) { lightningData.setLightningDensity(density); }
|
||||
|
||||
public float getLightningRadius() { return lightningData.getLightningRadius(); }
|
||||
public void setLightningRadius(float radius) { lightningData.setLightningRadius(radius); }
|
||||
|
||||
public int getLightningFadeTime() { return lightningData.getLightningFadeTime(); }
|
||||
public void setLightningFadeTime(int ticks) { lightningData.setLightningFadeTime(ticks); }
|
||||
|
||||
// ==================== LIFESPAN GETTERS & SETTERS ====================
|
||||
|
||||
public float getMaxDistance() { return lifespanData.getMaxDistance(); }
|
||||
@@ -932,19 +762,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
|
||||
public boolean getHasHit() { return hasHit; }
|
||||
|
||||
// ==================== BRIGHTNESS ====================
|
||||
|
||||
@Override
|
||||
public float getBrightness(float partialTicks) {
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public int getBrightnessForRender(float partialTicks) {
|
||||
return 0xF000F0;
|
||||
}
|
||||
|
||||
// ==================== NBT ====================
|
||||
|
||||
@Override
|
||||
@@ -963,6 +780,8 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
* Read base projectile properties from NBT.
|
||||
*/
|
||||
protected void readBaseNBT(NBTTagCompound nbt) {
|
||||
readEnergyBaseNBT(nbt);
|
||||
|
||||
this.size = nbt.getFloat("Size");
|
||||
|
||||
// Read effects list
|
||||
@@ -980,7 +799,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
this.startY = nbt.getDouble("StartY");
|
||||
this.startZ = nbt.getDouble("StartZ");
|
||||
|
||||
this.ownerEntityId = nbt.getInteger("OwnerId");
|
||||
this.targetEntityId = nbt.getInteger("TargetId");
|
||||
|
||||
this.motionX = nbt.getDouble("MotionX");
|
||||
@@ -994,10 +812,8 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
|
||||
anchorData.readNBT(nbt);
|
||||
combatData.readNBT(nbt);
|
||||
displayData.readNBT(nbt);
|
||||
homingData.readNBT(nbt);
|
||||
lifespanData.readNBT(nbt);
|
||||
lightningData.readNBT(nbt);
|
||||
trajectoryData.readNBT(nbt);
|
||||
}
|
||||
|
||||
@@ -1005,6 +821,8 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
* Write base projectile properties to NBT.
|
||||
*/
|
||||
protected void writeBaseNBT(NBTTagCompound nbt) {
|
||||
writeEnergyBaseNBT(nbt);
|
||||
|
||||
nbt.setFloat("Size", size);
|
||||
|
||||
// Write effects list
|
||||
@@ -1022,7 +840,6 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
nbt.setDouble("StartY", startY);
|
||||
nbt.setDouble("StartZ", startZ);
|
||||
|
||||
nbt.setInteger("OwnerId", ownerEntityId);
|
||||
nbt.setInteger("TargetId", targetEntityId);
|
||||
|
||||
nbt.setDouble("MotionX", motionX);
|
||||
@@ -1031,10 +848,8 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
|
||||
anchorData.writeNBT(nbt);
|
||||
combatData.writeNBT(nbt);
|
||||
displayData.writeNBT(nbt);
|
||||
homingData.writeNBT(nbt);
|
||||
lifespanData.writeNBT(nbt);
|
||||
lightningData.writeNBT(nbt);
|
||||
trajectoryData.writeNBT(nbt);
|
||||
}
|
||||
|
||||
@@ -1048,55 +863,10 @@ public abstract class EntityAbilityProjectile extends Entity implements IEntityA
|
||||
*/
|
||||
protected abstract void writeProjectileNBT(NBTTagCompound nbt);
|
||||
|
||||
// ==================== SPAWN DATA ====================
|
||||
|
||||
@Override
|
||||
public void writeSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
this.writeEntityToNBT(compound);
|
||||
cpw.mods.fml.common.network.ByteBufUtils.writeTag(buffer, compound);
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error writing ability projectile spawn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSpawnData(ByteBuf buffer) {
|
||||
try {
|
||||
NBTTagCompound compound = cpw.mods.fml.common.network.ByteBufUtils.readTag(buffer);
|
||||
if (compound != null) {
|
||||
this.readEntityFromNBT(compound);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
noppes.npcs.LogWriter.error("Error reading ability projectile spawn data", e);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== COLLISION SETTINGS ====================
|
||||
|
||||
@Override
|
||||
public boolean canBeCollidedWith() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBePushed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canTriggerWalking() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBurning() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public float getShadowSize() {
|
||||
return 0.0f;
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,9 @@ import java.util.List;
|
||||
/**
|
||||
* Energy Slicer entity - a thin, wide blade projectile that flies in a straight line.
|
||||
* JJK Cleave/Dismantle inspired. Piercing by default (passes through entities).
|
||||
* Extends EntityAbilityProjectile to leverage the existing projectile infrastructure.
|
||||
* Extends EntityEnergyAbility to leverage the existing projectile infrastructure.
|
||||
*/
|
||||
public class EntityEnergySlicer extends EntityAbilityProjectile {
|
||||
public class EntityEnergySlicer extends EntityEnergyProjectile {
|
||||
|
||||
private float sliceWidth = 3.0f;
|
||||
private float sliceThickness = 0.15f;
|
||||
@@ -50,17 +50,6 @@ public class EntityEnergySlicer extends EntityAbilityProjectile {
|
||||
calculateInitialVelocity(owner, target, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup in charging mode (windup phase).
|
||||
*/
|
||||
public void setupCharging(EnergyAnchorData anchor, int chargeDuration, float width, float thickness) {
|
||||
this.sliceWidth = 0.01f;
|
||||
this.sliceThickness = 0.01f;
|
||||
super.setupCharging(anchor, chargeDuration);
|
||||
// Store target dimensions
|
||||
this.targetSize = width; // Re-use base field for width
|
||||
}
|
||||
|
||||
// Targets stored during charging for grow animation
|
||||
private float targetSliceWidth = 3.0f;
|
||||
private float targetSliceThickness = 0.15f;
|
||||
|
||||
Reference in new issue
Block a user