Fix some Firing Script Behavior for Energy Projectiles

This commit is contained in:
Kam committed 2026-03-07 15:30:11 -05:00
1 parent ee7e8c17e8
commit 393abc08ed
7 files changed
+56 -113

No files matched your search

+1 -1
Submodule src/api updated: 5eb98d172e...6faa544f6f.
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityBeam;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyBeam;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyProjectile<T> implements IEnergyBeam {
@@ -60,27 +59,7 @@ public class ScriptEnergyBeam<T extends EntityAbilityBeam> extends ScriptEnergyP
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startFiring(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startFiring(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startFiring(target);
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityDisc;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyDisc;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyProjectile<T> implements IEnergyDisc {
@@ -76,27 +75,7 @@ public class ScriptEnergyDisc<T extends EntityAbilityDisc> extends ScriptEnergyP
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityLaser;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyLaser;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnergyProjectile<T> implements IEnergyLaser {
@@ -92,18 +91,12 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
@@ -111,6 +104,6 @@ public class ScriptEnergyLaser<T extends EntityAbilityLaser> extends ScriptEnerg
if (len > 0) {
entity.setDirection(dx / len, dy / len, dz / len);
}
entity.startMoving(null);
ensureSpawned();
}
}
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityOrb;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyOrb;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyOrb<T extends EntityAbilityOrb> extends ScriptEnergyProjectile<T> implements IEnergyOrb {
@@ -28,27 +27,7 @@ public class ScriptEnergyOrb<T extends EntityAbilityOrb> extends ScriptEnergyPro
}
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}
@@ -1,7 +1,6 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityEnergyProjectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.EventHooks;
import noppes.npcs.api.entity.IEnergyProjectile;
@@ -261,8 +260,14 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
public void fireAt(IEntity target) {
if (target != null) {
Entity mcTarget = target.getMCEntity();
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
EntityLivingBase living = resolveLivingTarget(target);
if (living != null) {
entity.setTargetEntityId(living.getEntityId());
setMotionToward(living.posX, living.posY + living.getEyeHeight(), living.posZ);
} else {
net.minecraft.entity.Entity mcTarget = target.getMCEntity();
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
}
}
ensureSpawned();
}
@@ -273,24 +278,22 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
}
public void fireDirection(float yaw, float pitch) {
float yawRad = (float) Math.toRadians(yaw);
float pitchRad = (float) Math.toRadians(pitch);
entity.motionX = -Math.sin(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
entity.motionY = -Math.sin(pitchRad) * entity.getSpeed();
entity.motionZ = Math.cos(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
setMotionFromDirection(yaw, pitch);
ensureSpawned();
}
public void fireFrom(IEntityLivingBase caster) {
if (caster == null) return;
initFromCaster(caster);
fireDirection(caster.getRotation(), caster.getPitch());
launchFromOwner(null);
ensureSpawned();
}
public void fireFrom(IEntityLivingBase caster, IEntity target) {
if (caster == null) return;
initFromCaster(caster);
fireAt(target);
launchFromOwner(resolveLivingTarget(target));
ensureSpawned();
}
/**
@@ -304,6 +307,37 @@ public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends Sc
entity.setStartPosition(mc.posX, eyeY, mc.posZ);
}
/**
* Hook for subclasses to call their entity's full launch sequence (startMoving/startFiring).
* Called by fireFrom methods — handles look-vector snap, charge exit, homing init, etc.
* Default: sets motion toward target, or along owner's look direction if target is null.
*/
protected void launchFromOwner(EntityLivingBase target) {
if (target != null) {
setMotionToward(target.posX, target.posY + target.getEyeHeight(), target.posZ);
} else {
net.minecraft.entity.Entity owner = entity.getOwnerEntity();
if (owner != null) {
setMotionFromDirection(owner.rotationYaw, owner.rotationPitch);
}
}
}
private void setMotionFromDirection(float yaw, float pitch) {
float yawRad = (float) Math.toRadians(yaw);
float pitchRad = (float) Math.toRadians(pitch);
entity.motionX = -Math.sin(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
entity.motionY = -Math.sin(pitchRad) * entity.getSpeed();
entity.motionZ = Math.cos(yawRad) * Math.cos(pitchRad) * entity.getSpeed();
}
protected static EntityLivingBase resolveLivingTarget(IEntity target) {
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
return (EntityLivingBase) target.getMCEntity();
}
return null;
}
/**
* Calculates and sets motion from the projectile's current position toward a target point.
*/
@@ -3,7 +3,6 @@ package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityEnergySlicer;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergySlicer;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergySlicer<T extends EntityEnergySlicer> extends ScriptEnergyProjectile<T> implements IEnergySlicer {
@@ -48,27 +47,7 @@ public class ScriptEnergySlicer<T extends EntityEnergySlicer> extends ScriptEner
// ==================== FIRE ====================
@Override
public void fireAt(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fireAt(double x, double y, double z) {
ensureSpawned();
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
if (len > 0) {
entity.motionX = (dx / len) * entity.getSpeed();
entity.motionY = (dy / len) * entity.getSpeed();
entity.motionZ = (dz / len) * entity.getSpeed();
}
entity.startMoving(null);
protected void launchFromOwner(EntityLivingBase target) {
entity.startMoving(target);
}
}