mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 14:19:13 +00:00
Refactoring for Code Cleanup and Projectile Abstract Class Handling
This commit is contained in:
1 parent
a1f3f5184b
commit
a23b199e7e
30 files changed
+1226
-2395
No files matched your search
@@ -20,47 +20,10 @@ import java.util.List;
|
||||
*/
|
||||
public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
|
||||
// Charging state (during windup)
|
||||
private boolean charging = false;
|
||||
private int chargeDuration = 40;
|
||||
private int chargeTick = 0;
|
||||
private float targetSize = 1.0f; // Full size to grow to during charging
|
||||
|
||||
// Data watcher index for charging state (synced to clients)
|
||||
private static final int DW_CHARGING = 20;
|
||||
|
||||
public EntityAbilityOrb(World world) {
|
||||
super(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit();
|
||||
// Register data watcher for charging state
|
||||
this.dataWatcher.addObject(DW_CHARGING, (byte) 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if orb 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).
|
||||
*/
|
||||
private void setCharging(boolean value) {
|
||||
this.charging = value;
|
||||
if (!worldObj.isRemote) {
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (value ? 1 : 0));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Full constructor using data classes for grouped parameters.
|
||||
*/
|
||||
@@ -77,43 +40,7 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
this.homingData = homing;
|
||||
|
||||
// Calculate initial velocity toward target
|
||||
if (target != null) {
|
||||
double dx = target.posX - x;
|
||||
double dy = (target.posY + target.getEyeHeight()) - y;
|
||||
double dz = target.posZ - z;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) {
|
||||
this.motionX = (dx / len) * homing.speed;
|
||||
this.motionY = (dy / len) * homing.speed;
|
||||
this.motionZ = (dz / len) * homing.speed;
|
||||
}
|
||||
} else {
|
||||
// Fire in NPC's facing direction
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = (float) Math.toRadians(owner.rotationPitch);
|
||||
this.motionX = -Math.sin(yaw) * Math.cos(pitch) * homing.speed;
|
||||
this.motionY = -Math.sin(pitch) * homing.speed;
|
||||
this.motionZ = Math.cos(yaw) * Math.cos(pitch) * homing.speed;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Setup this orb in charging mode (for windup phase).
|
||||
* The orb will grow from 0 to orbSize over chargeDuration ticks.
|
||||
* Position follows the owner based on anchor point.
|
||||
*/
|
||||
public void setupCharging(EnergyAnchorData anchor, int chargeDuration) {
|
||||
setCharging(true);
|
||||
this.chargeDuration = chargeDuration;
|
||||
this.chargeTick = 0;
|
||||
this.anchorData = anchor;
|
||||
this.targetSize = this.size;
|
||||
this.size = 0.01f;
|
||||
this.renderCurrentSize = 0.01f;
|
||||
this.prevRenderSize = 0.01f;
|
||||
this.motionX = 0;
|
||||
this.motionY = 0;
|
||||
this.motionZ = 0;
|
||||
calculateInitialVelocity(owner, target, x, y, z);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,8 +88,6 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
* Start preview firing (simulates firing toward a point in front of NPC).
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
if (!isCharging()) return;
|
||||
|
||||
setCharging(false);
|
||||
|
||||
// Update start position to current position
|
||||
@@ -196,8 +121,6 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
* Called by ability when windup ends.
|
||||
*/
|
||||
public void startMoving(EntityLivingBase target) {
|
||||
if (!isCharging()) return;
|
||||
|
||||
setCharging(false);
|
||||
|
||||
// For player casters, snap to look vector for crosshair-aligned launch
|
||||
@@ -302,47 +225,6 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateHoming() {
|
||||
if (!isHoming()) return;
|
||||
|
||||
Entity target = getTargetEntity();
|
||||
if (target == null || !target.isEntityAlive()) return;
|
||||
|
||||
double dx = target.posX - posX;
|
||||
double dy = (target.posY + target.getEyeHeight()) - posY;
|
||||
double dz = target.posZ - posZ;
|
||||
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
if (dist <= getHomingRange() && dist > 0) {
|
||||
// Calculate effective homing strength - increases when closer to commit to target
|
||||
// This prevents orbiting behavior at close range
|
||||
float effectiveStrength = getHomingStrength();
|
||||
if (dist < getHomingRange() * 0.3) {
|
||||
// Within 30% of homing range, dramatically increase strength to commit
|
||||
effectiveStrength = Math.min(1.0f, getHomingStrength() * 2.5f);
|
||||
} else if (dist < getHomingRange() * 0.6) {
|
||||
// Within 60% of homing range, moderately increase strength
|
||||
effectiveStrength = Math.min(0.8f, getHomingStrength() * 1.5f);
|
||||
}
|
||||
|
||||
double desiredVX = (dx / dist) * getSpeed();
|
||||
double desiredVY = (dy / dist) * getSpeed();
|
||||
double desiredVZ = (dz / dist) * getSpeed();
|
||||
|
||||
motionX += (desiredVX - motionX) * effectiveStrength;
|
||||
motionY += (desiredVY - motionY) * effectiveStrength;
|
||||
motionZ += (desiredVZ - motionZ) * effectiveStrength;
|
||||
|
||||
// Normalize to maintain speed
|
||||
double vLen = Math.sqrt(motionX * motionX + motionY * motionY + motionZ * motionZ);
|
||||
if (vLen > 0) {
|
||||
motionX = (motionX / vLen) * getSpeed();
|
||||
motionY = (motionY / vLen) * getSpeed();
|
||||
motionZ = (motionZ / vLen) * getSpeed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkBlockCollision() {
|
||||
Vec3 currentPos = Vec3.createVectorHelper(posX, posY, posZ);
|
||||
Vec3 nextPos = Vec3.createVectorHelper(posX + motionX, posY + motionY, posZ + motionZ);
|
||||
@@ -387,47 +269,6 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update during charging state - follow owner based on anchor point.
|
||||
*/
|
||||
private void updateCharging() {
|
||||
chargeTick++;
|
||||
|
||||
Entity owner = getOwnerEntity();
|
||||
if (owner == null || owner.isDead) {
|
||||
setDead();
|
||||
return;
|
||||
}
|
||||
|
||||
// Grow size based on charge progress
|
||||
float progress = getChargeProgress();
|
||||
this.size = targetSize * progress;
|
||||
|
||||
// Calculate position based on anchor point, offset downward by half size to center
|
||||
if (owner instanceof EntityLivingBase) {
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition((EntityLivingBase) owner, anchorData);
|
||||
setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the charge progress (0-1).
|
||||
*/
|
||||
public float getChargeProgress() {
|
||||
if (chargeDuration <= 0) return 1.0f;
|
||||
return Math.min(1.0f, (float) chargeTick / chargeDuration);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get interpolated charge progress for smooth rendering.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
// ==================== GETTERS ====================
|
||||
|
||||
// Legacy getter for renderer compatibility
|
||||
@@ -439,22 +280,11 @@ public class EntityAbilityOrb extends EntityAbilityProjectile {
|
||||
|
||||
@Override
|
||||
protected void readProjectileNBT(NBTTagCompound nbt) {
|
||||
// Charging state
|
||||
boolean isCharging = nbt.hasKey("Charging") && nbt.getBoolean("Charging");
|
||||
this.charging = isCharging;
|
||||
this.dataWatcher.updateObject(DW_CHARGING, (byte) (isCharging ? 1 : 0));
|
||||
this.chargeDuration = nbt.hasKey("ChargeDuration") ? nbt.getInteger("ChargeDuration") : 40;
|
||||
this.chargeTick = nbt.hasKey("ChargeTick") ? nbt.getInteger("ChargeTick") : 0;
|
||||
this.targetSize = nbt.hasKey("TargetSize") ? nbt.getFloat("TargetSize") : this.size;
|
||||
readChargingNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeProjectileNBT(NBTTagCompound nbt) {
|
||||
// Charging state
|
||||
nbt.setBoolean("Charging", isCharging());
|
||||
nbt.setInteger("ChargeDuration", chargeDuration);
|
||||
nbt.setInteger("ChargeTick", chargeTick);
|
||||
anchorData.writeNBT(nbt);
|
||||
nbt.setFloat("TargetSize", targetSize);
|
||||
writeChargingNBT(nbt);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user