Files
CustomNPC-Plus/src/main/java/noppes/npcs/scripted/entity/ScriptEnergyProjectile.java
T
2026-02-18 05:13:51 -05:00

308 lines
8.1 KiB
Java

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;
import noppes.npcs.api.entity.IEntity;
import noppes.npcs.api.entity.IEntityLivingBase;
import noppes.npcs.scripted.constants.EntityType;
public class ScriptEnergyProjectile<T extends EntityEnergyProjectile> extends ScriptEnergyAbility<T> implements IEnergyProjectile {
public ScriptEnergyProjectile(T entity) {
super(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 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 (PROJECTILE-SPECIFIC) ====================
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);
}
// ==================== 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();
}
// ==================== 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);
}
}
}
}