mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-12 06:07:27 +00:00
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:
1 parent
1ed012331b
commit
071d89cc15
23 files changed
+1363
-94
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user