Add energy projectile types and events: implement IEnergyOrb, IEnergyBeam, IEnergyDisc, and IEnergyLaser interfaces, along with their respective script handlers and event hooks

This commit is contained in:
Kam committed 2026-02-16 01:03:05 -05:00
1 parent 1ed012331b
commit 071d89cc15
23 files changed
+1363 -94

No files matched your search

@@ -0,0 +1,69 @@
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 {
public ScriptEnergyBeam(T entity) {
super(entity);
}
@Override
public int getType() {
return EntityType.ENERGY_BEAM;
}
@Override
public boolean typeOf(int type) {
return type == EntityType.ENERGY_BEAM || super.typeOf(type);
}
@Override
public int getEnergyType() {
return 1;
}
// ==================== BEAM-SPECIFIC ====================
public float getBeamWidth() { return entity.getBeamWidth(); }
public void setBeamWidth(float width) { entity.setBeamWidth(width); }
public float getHeadSize() { return entity.getHeadSize(); }
public void setHeadSize(float size) { entity.setHeadSize(size); }
public boolean isAttachedToOwner() { return entity.isAttachedToOwner(); }
public void setAttachedToOwner(boolean attached) { entity.setAttachedToOwner(attached); }
public boolean shouldRenderTailOrb() { return entity.shouldRenderTailOrb(); }
// ==================== FIRE ====================
@Override
public void fire(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startFiring(mcTarget);
}
@Override
public void fire(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);
}
}
@@ -0,0 +1,75 @@
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 {
public ScriptEnergyDisc(T entity) {
super(entity);
}
@Override
public int getType() {
return EntityType.ENERGY_DISC;
}
@Override
public boolean typeOf(int type) {
return type == EntityType.ENERGY_DISC || super.typeOf(type);
}
@Override
public int getEnergyType() {
return 2;
}
// ==================== DISC-SPECIFIC ====================
public float getDiscRadius() { return entity.getDiscRadius(); }
public void setDiscRadius(float radius) { entity.setDiscRadius(radius); }
public float getDiscThickness() { return entity.getDiscThickness(); }
public void setDiscThickness(float thickness) { entity.setDiscThickness(thickness); }
public boolean isVertical() { return entity.isVertical(); }
public void setVertical(boolean vertical) { entity.setVertical(vertical); }
public boolean isBoomerang() { return entity.isBoomerang(); }
public void setBoomerang(boolean boomerang) { entity.setBoomerang(boomerang); }
public int getBoomerangDelay() { return entity.getBoomerangDelay(); }
public void setBoomerangDelay(int ticks) { entity.setBoomerangDelay(ticks); }
public boolean isReturning() { return entity.isReturning(); }
// ==================== FIRE ====================
@Override
public void fire(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fire(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);
}
}
@@ -0,0 +1,82 @@
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 {
public ScriptEnergyLaser(T entity) {
super(entity);
}
@Override
public int getType() {
return EntityType.ENERGY_LASER;
}
@Override
public boolean typeOf(int type) {
return type == EntityType.ENERGY_LASER || super.typeOf(type);
}
@Override
public int getEnergyType() {
return 3;
}
// ==================== LASER-SPECIFIC ====================
public float getLaserWidth() { return entity.getLaserWidth(); }
public void setLaserWidth(float width) { entity.setLaserWidth(width); }
public float getExpansionSpeed() { return entity.getExpansionSpeed(); }
public void setExpansionSpeed(float speed) { entity.setExpansionSpeed(speed); }
public int getLingerTicks() { return entity.getLingerTicks(); }
public void setLingerTicks(int ticks) { entity.setLingerTicks(ticks); }
public float getCurrentLength() { return entity.getCurrentLength(); }
public boolean isFullyExtended() { return entity.isFullyExtended(); }
public double getDirX() { return entity.getDirX(); }
public double getDirY() { return entity.getDirY(); }
public double getDirZ() { return entity.getDirZ(); }
public void setDirection(double x, double y, double z) { entity.setDirection(x, y, z); }
public double getEndX() { return entity.getEndX(); }
public double getEndY() { return entity.getEndY(); }
public double getEndZ() { return entity.getEndZ(); }
public float getLingerAlpha() { return entity.getLingerAlpha(); }
public boolean isLockVerticalDirection() { return entity.isLockVerticalDirection(); }
public void setLockVerticalDirection(boolean lock) { entity.setLockVerticalDirection(lock); }
// ==================== FIRE ====================
@Override
public void fire(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fire(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.setDirection(dx / len, dy / len, dz / len);
}
entity.startMoving(null);
}
}
@@ -0,0 +1,53 @@
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 {
public ScriptEnergyOrb(T entity) {
super(entity);
}
@Override
public int getType() {
return EntityType.ENERGY_ORB;
}
@Override
public boolean typeOf(int type) {
return type == EntityType.ENERGY_ORB || super.typeOf(type);
}
@Override
public int getEnergyType() {
return 0;
}
@Override
public void fire(IEntity target) {
ensureSpawned();
EntityLivingBase mcTarget = null;
if (target != null && target.getMCEntity() instanceof EntityLivingBase) {
mcTarget = (EntityLivingBase) target.getMCEntity();
}
entity.startMoving(mcTarget);
}
@Override
public void fire(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();
}
}
}
@@ -0,0 +1,252 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import noppes.npcs.api.entity.IEnergyProjectile;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.EventHooks;
import noppes.npcs.scripted.NpcAPI;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyProjectile<T extends EntityAbilityProjectile> extends ScriptEntity<T> implements IEnergyProjectile {
protected T entity;
public ScriptEnergyProjectile(T entity) {
super(entity);
this.entity = entity;
}
// ==================== TYPE ====================
@Override
public int getType() {
return EntityType.ENERGY_PROJECTILE;
}
@Override
public boolean typeOf(int type) {
return type == EntityType.ENERGY_PROJECTILE || super.typeOf(type);
}
public int getEnergyType() {
return -1;
}
// ==================== OWNER & TARGET ====================
public int getOwnerEntityId() {
return entity.getOwnerEntityId();
}
public IEntity getOwner() {
return entity.getOwner();
}
public void setOwner(IEntity owner) {
if (owner != null) {
entity.setOwnerEntityId(owner.getMCEntity().getEntityId());
}
}
public int getTargetEntityId() {
return entity.getTargetEntityId();
}
public IEntity getTarget() {
return entity.getTarget();
}
public void setTarget(IEntity target) {
if (target != null) {
entity.setTargetEntityId(target.getMCEntity().getEntityId());
} else {
entity.setTargetEntityId(-1);
}
}
// ==================== SIZE ====================
public float getSize() {
return entity.getSize();
}
public void setSize(float size) {
entity.setProjectileSize(size);
}
// ==================== DISPLAY ====================
public int getInnerColor() { return entity.getInnerColor(); }
public void setInnerColor(int color) { entity.setInnerColor(color); }
public int getOuterColor() { return entity.getOuterColor(); }
public void setOuterColor(int color) { entity.setOuterColor(color); }
public boolean isOuterColorEnabled() { return entity.isOuterColorEnabled(); }
public void setOuterColorEnabled(boolean enabled) { entity.setOuterColorEnabled(enabled); }
public float getOuterColorWidth() { return entity.getOuterColorWidth(); }
public void setOuterColorWidth(float width) { entity.setOuterColorWidth(width); }
public float getOuterColorAlpha() { return entity.getOuterColorAlpha(); }
public void setOuterColorAlpha(float alpha) { entity.setOuterColorAlpha(alpha); }
public float getRotationSpeed() { return entity.getRotationSpeed(); }
public void setRotationSpeed(float speed) { entity.setRotationSpeed(speed); }
// ==================== INTERPOLATION ====================
public float getInterpolatedRotationX(float partialTicks) { return entity.getInterpolatedRotationX(partialTicks); }
public float getInterpolatedRotationY(float partialTicks) { return entity.getInterpolatedRotationY(partialTicks); }
public float getInterpolatedRotationZ(float partialTicks) { return entity.getInterpolatedRotationZ(partialTicks); }
public float getInterpolatedSize(float partialTicks) { return entity.getInterpolatedSize(partialTicks); }
// ==================== LIGHTNING ====================
public boolean hasLightningEffect() { return entity.hasLightningEffect(); }
public void setLightningEffect(boolean enabled) { entity.setLightningEffect(enabled); }
public float getLightningDensity() { return entity.getLightningDensity(); }
public void setLightningDensity(float density) { entity.setLightningDensity(density); }
public float getLightningRadius() { return entity.getLightningRadius(); }
public void setLightningRadius(float radius) { entity.setLightningRadius(radius); }
public int getLightningFadeTime() { return entity.getLightningFadeTime(); }
public void setLightningFadeTime(int ticks) { entity.setLightningFadeTime(ticks); }
// ==================== LIFESPAN ====================
public float getMaxDistance() { return entity.getMaxDistance(); }
public void setMaxDistance(float distance) { entity.setMaxDistance(distance); }
public int getMaxLifetime() { return entity.getMaxLifetime(); }
public void setMaxLifetime(int ticks) { entity.setMaxLifetime(ticks); }
// ==================== COMBAT ====================
public float getDamage() { return entity.getDamage(); }
public void setDamage(float damage) { entity.setCombatDamage(damage); }
public float getKnockback() { return entity.getKnockback(); }
public void setKnockback(float knockback) { entity.setCombatKnockback(knockback); }
public float getKnockbackUp() { return entity.getKnockbackUp(); }
public void setKnockbackUp(float knockbackUp) { entity.setCombatKnockbackUp(knockbackUp); }
public boolean isExplosive() { return entity.isExplosive(); }
public void setExplosive(boolean explosive) { entity.setExplosive(explosive); }
public float getExplosionRadius() { return entity.getExplosionRadius(); }
public void setExplosionRadius(float radius) { entity.setExplosionRadius(radius); }
public float getExplosionDamageFalloff() { return entity.getExplosionDamageFalloff(); }
public void setExplosionDamageFalloff(float falloff) { entity.setExplosionDamageFalloff(falloff); }
// ==================== MOVEMENT ====================
public float getSpeed() { return entity.getSpeed(); }
public void setSpeed(float speed) { entity.setSpeed(speed); }
public boolean isHoming() { return entity.isHoming(); }
public void setHoming(boolean homing) { entity.setHomingEnabled(homing); }
public float getHomingStrength() { return entity.getHomingStrength(); }
public void setHomingStrength(float strength) { entity.setHomingStrength(strength); }
public float getHomingRange() { return entity.getHomingRange(); }
public void setHomingRange(float range) { entity.setHomingRange(range); }
// ==================== ANCHOR ====================
public int getAnchor() { return entity.getAnchor(); }
public float getAnchorOffsetX() { return entity.getAnchorOffsetX(); }
public float getAnchorOffsetY() { return entity.getAnchorOffsetY(); }
public float getAnchorOffsetZ() { return entity.getAnchorOffsetZ(); }
// ==================== POSITION ====================
public double getStartX() { return entity.getStartX(); }
public double getStartY() { return entity.getStartY(); }
public double getStartZ() { return entity.getStartZ(); }
// ==================== STATE ====================
public boolean hasHit() { return entity.getHasHit(); }
public boolean isCharging() { return entity.isCharging(); }
public float getChargeProgress() { return entity.getChargeProgress(); }
// ==================== FIRE ====================
public void fire(IEntity target) {
if (target != null) {
Entity mcTarget = target.getMCEntity();
setMotionToward(mcTarget.posX, mcTarget.posY + mcTarget.getEyeHeight(), mcTarget.posZ);
}
ensureSpawned();
}
public void fire(double x, double y, double z) {
setMotionToward(x, y, z);
ensureSpawned();
}
public void fire(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();
ensureSpawned();
}
public void fire(IEntityLivingBase caster) {
if (caster == null) return;
initFromCaster(caster);
fire(caster.getRotation(), caster.getPitch());
}
public void fire(IEntityLivingBase caster, IEntity target) {
if (caster == null) return;
initFromCaster(caster);
fire(target);
}
/**
* Sets owner from caster and positions projectile at caster's eye level.
*/
private void initFromCaster(IEntityLivingBase caster) {
EntityLivingBase mc = (EntityLivingBase) caster.getMCEntity();
entity.setOwnerEntityId(mc.getEntityId());
double eyeY = mc.posY + mc.getEyeHeight();
entity.setPosition(mc.posX, eyeY, mc.posZ);
entity.setStartPosition(mc.posX, eyeY, mc.posZ);
}
/**
* Calculates and sets motion from the projectile's current position toward a target point.
*/
private void setMotionToward(double x, double y, double z) {
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();
}
}
protected void ensureSpawned() {
if (!entity.addedToChunk && entity.worldObj != null) {
entity.worldObj.spawnEntityInWorld(entity);
if (!entity.worldObj.isRemote) {
EventHooks.onEnergyProjectileFired(entity);
}
}
}
}
@@ -1,5 +1,10 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.entity.EntityAbilityBeam;
import kamkeel.npcs.entity.EntityAbilityDisc;
import kamkeel.npcs.entity.EntityAbilityLaser;
import kamkeel.npcs.entity.EntityAbilityOrb;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -526,6 +531,16 @@ public class ScriptEntity<T extends Entity> implements IEntity {
cls = EntityMob.class;
else if (type == EntityType.NPC)
cls = EntityNPCInterface.class;
else if (type == EntityType.ENERGY_PROJECTILE)
cls = EntityAbilityProjectile.class;
else if (type == EntityType.ENERGY_ORB)
cls = EntityAbilityOrb.class;
else if (type == EntityType.ENERGY_BEAM)
cls = EntityAbilityBeam.class;
else if (type == EntityType.ENERGY_DISC)
cls = EntityAbilityDisc.class;
else if (type == EntityType.ENERGY_LASER)
cls = EntityAbilityLaser.class;
List<Entity> entities = entity.worldObj.getEntitiesWithinAABB(cls, entity.boundingBox.expand(range, range, range));
List<IEntity> list = new ArrayList<IEntity>();
@@ -7,6 +7,7 @@ import noppes.npcs.api.IPos;
import noppes.npcs.api.ITimers;
import noppes.npcs.api.ability.IDataAbilities;
import noppes.npcs.api.entity.ICustomNpc;
import noppes.npcs.api.entity.IEnergyProjectile;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.entity.data.IModelData;
@@ -28,6 +29,7 @@ import noppes.npcs.constants.EnumMovingType;
import noppes.npcs.constants.EnumNavType;
import noppes.npcs.constants.EnumRoleType;
import noppes.npcs.constants.EnumStandingType;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import noppes.npcs.controllers.FactionController;
import noppes.npcs.controllers.data.DialogOption;
import noppes.npcs.controllers.data.Line;
@@ -1463,4 +1465,13 @@ public class ScriptNpc<T extends EntityNPCInterface> extends ScriptLiving<T> imp
public IDataAbilities getAbilityData() {
return new ScriptDataAbilities(npc);
}
public IEnergyProjectile[] getActiveEnergyProjectiles() {
java.util.List<EntityAbilityProjectile> entities = EntityAbilityProjectile.getActiveProjectiles(npc.getEntityId());
IEnergyProjectile[] result = new IEnergyProjectile[entities.size()];
for (int i = 0; i < entities.size(); i++) {
result[i] = (IEnergyProjectile) NpcAPI.Instance().getIEntity(entities.get(i));
}
return result;
}
}
@@ -1,6 +1,7 @@
package noppes.npcs.scripted.entity;
import kamkeel.npcs.controllers.AttributeController;
import kamkeel.npcs.entity.EntityAbilityProjectile;
import kamkeel.npcs.network.PacketHandler;
import kamkeel.npcs.network.packets.data.AchievementPacket;
import kamkeel.npcs.network.packets.data.ChatAlertPacket;
@@ -31,6 +32,7 @@ import noppes.npcs.api.IPos;
import noppes.npcs.api.IScreenSize;
import noppes.npcs.api.ITimers;
import noppes.npcs.api.IWorld;
import noppes.npcs.api.entity.IEnergyProjectile;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IPlayer;
import noppes.npcs.api.gui.ICustomGui;
@@ -933,4 +935,13 @@ public class ScriptPlayer<T extends EntityPlayerMP> extends ScriptLivingBase<T>
public String getFormattedCurrencyBalance() {
return getData().tradeData.formatBalance();
}
public IEnergyProjectile[] getActiveEnergyProjectiles() {
List<EntityAbilityProjectile> entities = EntityAbilityProjectile.getActiveProjectiles(player.getEntityId());
IEnergyProjectile[] result = new IEnergyProjectile[entities.size()];
for (int i = 0; i < entities.size(); i++) {
result[i] = (IEnergyProjectile) NpcAPI.Instance().getIEntity(entities.get(i));
}
return result;
}
}