mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-19 00:19:05 +00:00
Update Abilities to Support Player Casting (Part 1)
This commit is contained in:
1 parent
c05b6e60b8
commit
2387ece1ff
14 files changed
+259
-117
No files matched your search
@@ -392,6 +392,18 @@ public abstract class Ability implements IAbility {
|
||||
return 45.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the caster is a player (not an NPC).
|
||||
* Use this instead of checking {@code target != null} to make NPC/Player
|
||||
* code paths explicit and readable.
|
||||
* <p>
|
||||
* NPCs always have an aggro target passed to ability methods.
|
||||
* Players never do — they use look direction for aiming instead.
|
||||
*/
|
||||
protected final boolean isPlayerCaster(EntityLivingBase caster) {
|
||||
return caster instanceof EntityPlayer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this ability controls NPC movement during ACTIVE phase.
|
||||
* When true, AI pathfinding will be blocked during ability execution.
|
||||
|
||||
@@ -164,6 +164,11 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
|
||||
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create beam entities.
|
||||
* NPC: target is the aggro target — beams will home toward it.
|
||||
* Player: target is null — beams fire in caster's look direction.
|
||||
*/
|
||||
private EntityAbilityBeam[] createBeamEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
EntityAbilityBeam[] entities = new EntityAbilityBeam[projectileCount];
|
||||
float offsetDist = 1.0f;
|
||||
@@ -294,7 +299,9 @@ public class AbilityBeam extends Ability implements IAbilityEnergyBeam {
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
|
||||
// NPC: telegraph on aggro target position
|
||||
// Player: no telegraph (beam fires in look direction, no fixed position to mark)
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,11 +87,13 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
|
||||
}
|
||||
|
||||
/**
|
||||
* Locks the charge direction based on current target position.
|
||||
* Called once at windup start - direction won't change even if target moves.
|
||||
* Locks the charge direction. Called once at windup start — direction won't change even if target moves.
|
||||
* NPC: charges toward aggro target.
|
||||
* Player: charges in look direction.
|
||||
*/
|
||||
private void lockChargeDirection(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (target != null) {
|
||||
if (!isPlayerCaster(caster) && target != null) {
|
||||
// NPC: charge toward aggro target
|
||||
double dx = target.posX - caster.posX;
|
||||
double dz = target.posZ - caster.posZ;
|
||||
double len = Math.sqrt(dx * dx + dz * dz);
|
||||
@@ -102,6 +104,7 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
|
||||
chargeDirection = Vec3.createVectorHelper(-Math.sin(yaw), 0, Math.cos(yaw));
|
||||
}
|
||||
} else {
|
||||
// Player: charge in look direction
|
||||
float yaw = (float) Math.toRadians(caster.rotationYaw);
|
||||
chargeDirection = Vec3.createVectorHelper(-Math.sin(yaw), 0, Math.cos(yaw));
|
||||
}
|
||||
@@ -258,9 +261,10 @@ public class AbilityCharge extends Ability implements IAbilityCharge {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Calculate direction to target at this moment (locked)
|
||||
// NPC: telegraph points toward aggro target
|
||||
// Player: telegraph points in look direction
|
||||
float yaw;
|
||||
if (target != null) {
|
||||
if (!isPlayerCaster(caster) && target != null) {
|
||||
double dx = target.posX - caster.posX;
|
||||
double dz = target.posZ - caster.posZ;
|
||||
yaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
|
||||
|
||||
@@ -149,9 +149,10 @@ public class AbilityDash extends Ability implements IAbilityDash {
|
||||
: DEFENSIVE_DIRECTIONS;
|
||||
chosenDirection = directions[RANDOM.nextInt(directions.length)];
|
||||
|
||||
// Calculate dash direction relative to target
|
||||
// NPC: dash direction is relative to aggro target facing
|
||||
// Player: dash direction is relative to look direction
|
||||
float baseYaw;
|
||||
if (target != null) {
|
||||
if (!isPlayerCaster(caster) && target != null) {
|
||||
double dx = target.posX - caster.posX;
|
||||
double dz = target.posZ - caster.posZ;
|
||||
baseYaw = (float) Math.toDegrees(Math.atan2(-dx, dz));
|
||||
|
||||
@@ -169,6 +169,11 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
|
||||
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create disc entities.
|
||||
* NPC: target is the aggro target — discs will home toward it.
|
||||
* Player: target is null — discs fire in caster's look direction.
|
||||
*/
|
||||
private EntityAbilityDisc[] createDiscEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
EntityAbilityDisc[] entities = new EntityAbilityDisc[projectileCount];
|
||||
for (int i = 0; i < projectileCount; i++) {
|
||||
@@ -301,7 +306,9 @@ public class AbilityDisc extends Ability implements IAbilityDisc {
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
|
||||
// NPC: telegraph on aggro target position
|
||||
// Player: no telegraph (discs fire in look direction, no fixed position to mark)
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -111,6 +112,7 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
|
||||
this.cooldownTicks = 0;
|
||||
this.windUpTicks = 30;
|
||||
this.telegraphType = TelegraphType.CIRCLE;
|
||||
this.allowedBy = UserType.NPC_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -202,14 +204,12 @@ public class AbilityHazard extends Ability implements IAbilityHazard {
|
||||
}
|
||||
break;
|
||||
case AT_TARGET:
|
||||
// Use telegraph position if available, apply offset
|
||||
if (telegraph != null) {
|
||||
double[] pos = Ability.calculateOffsetPosition(telegraph.getX(), telegraph.getY(), telegraph.getZ(),
|
||||
minOffset, maxOffset, randomOffset, RANDOM);
|
||||
zoneX = pos[0];
|
||||
zoneY = pos[1];
|
||||
zoneZ = pos[2];
|
||||
// Update telegraph to show actual hazard position
|
||||
telegraph.setX(zoneX);
|
||||
telegraph.setY(zoneY);
|
||||
telegraph.setZ(zoneZ);
|
||||
|
||||
@@ -88,6 +88,11 @@ public class AbilityLaserShot extends Ability implements IAbilityLaserShot {
|
||||
return laserWidth * 2.0f; // Make telegraph slightly wider for visibility
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn laser entity.
|
||||
* NPC: target is the aggro target — laser expands toward it.
|
||||
* Player: target is null — laser expands in caster's look direction.
|
||||
*/
|
||||
private EntityAbilityLaser spawnLaserEntity(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
Vec3 spawnPos = AnchorPointHelper.calculateAnchorPosition(caster, anchorData);
|
||||
EntityAbilityLaser entity = new EntityAbilityLaser(
|
||||
|
||||
@@ -172,6 +172,11 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
return new TargetingMode[]{TargetingMode.AGGRO_TARGET};
|
||||
}
|
||||
|
||||
/**
|
||||
* Create orb entities.
|
||||
* NPC: target is the aggro target — orbs will home toward it.
|
||||
* Player: target is null — orbs fire in caster's look direction.
|
||||
*/
|
||||
private EntityAbilityOrb[] createOrbEntities(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
EntityAbilityOrb[] entities = new EntityAbilityOrb[projectileCount];
|
||||
for (int i = 0; i < projectileCount; i++) {
|
||||
@@ -302,7 +307,9 @@ public class AbilityOrb extends Ability implements IAbilityOrb {
|
||||
|
||||
@Override
|
||||
public TelegraphInstance createTelegraph(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || target == null) {
|
||||
// NPC: telegraph on aggro target position
|
||||
// Player: no telegraph (orbs fire in look direction, no fixed position to mark)
|
||||
if (!showTelegraph || telegraphType == TelegraphType.NONE || isPlayerCaster(caster) || target == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import noppes.npcs.entity.EntityNPCInterface;
|
||||
|
||||
@@ -67,68 +68,131 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
|
||||
|
||||
@Override
|
||||
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
if ((world.isRemote && !isPreview()) || target == null) {
|
||||
if (world.isRemote && !isPreview()) {
|
||||
signalCompletion();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isPreview()) {
|
||||
// Calculate direction to target
|
||||
double dx = target.posX - caster.posX;
|
||||
double dy = (target.posY + target.height / 2) - (caster.posY + caster.getEyeHeight());
|
||||
double dz = target.posZ - caster.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
|
||||
if (len > 0) {
|
||||
dx /= len;
|
||||
dy /= len;
|
||||
dz /= len;
|
||||
}
|
||||
|
||||
// Deal instant damage with scripted event support
|
||||
// TODO: Use custom EntityAbilityProjectile for actual tracking
|
||||
applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz);
|
||||
|
||||
// Play sound
|
||||
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
||||
|
||||
// Handle splash damage for explosive projectiles
|
||||
if (explosive && explosionRadius > 0) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(target,
|
||||
target.boundingBox.expand(explosionRadius, explosionRadius, explosionRadius));
|
||||
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof EntityLivingBase && entity != caster) {
|
||||
EntityLivingBase living = (EntityLivingBase) entity;
|
||||
float dist = target.getDistanceToEntity(living);
|
||||
if (dist < explosionRadius) {
|
||||
float falloff = 1.0f - (dist / explosionRadius);
|
||||
// Apply splash damage with scripted event support (no knockback)
|
||||
applyAbilityDamage(caster, living, damage * falloff * 0.5f, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Explosion particles
|
||||
world.playSoundAtEntity(target, "random.explode", 0.5f, 1.0f);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
world.spawnParticle("explode",
|
||||
target.posX + (world.rand.nextDouble() - 0.5) * explosionRadius,
|
||||
target.posY + world.rand.nextDouble() * target.height,
|
||||
target.posZ + (world.rand.nextDouble() - 0.5) * explosionRadius,
|
||||
0, 0.1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn projectile particles (visual trail)
|
||||
spawnProjectileParticles(world, caster, target);
|
||||
if (isPlayerCaster(caster)) {
|
||||
// Player: instant hit-scan in look direction
|
||||
executePlayerProjectile(caster, world);
|
||||
} else if (target != null) {
|
||||
// NPC: instant hit-scan on aggro target
|
||||
executeNpcProjectile(caster, target, world);
|
||||
}
|
||||
|
||||
// Projectile is instant
|
||||
signalCompletion();
|
||||
}
|
||||
|
||||
/**
|
||||
* NPC projectile: instant hit-scan damage on the aggro target.
|
||||
*/
|
||||
private void executeNpcProjectile(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
if (isPreview()) return;
|
||||
|
||||
double dx = target.posX - caster.posX;
|
||||
double dy = (target.posY + target.height / 2) - (caster.posY + caster.getEyeHeight());
|
||||
double dz = target.posZ - caster.posZ;
|
||||
double len = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (len > 0) { dx /= len; dy /= len; dz /= len; }
|
||||
|
||||
applyAbilityDamageWithDirection(caster, target, damage, knockback, dx, dz);
|
||||
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
||||
|
||||
if (explosive && explosionRadius > 0) {
|
||||
applyExplosionDamage(caster, target, world, target.posX, target.posY, target.posZ);
|
||||
}
|
||||
|
||||
spawnProjectileParticles(world, caster, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Player projectile: fires instant hit-scan in look direction.
|
||||
* Raycasts for the first entity in range and applies damage.
|
||||
*/
|
||||
private void executePlayerProjectile(EntityLivingBase caster, World world) {
|
||||
if (isPreview()) return;
|
||||
|
||||
Vec3 look = caster.getLookVec();
|
||||
double eyeX = caster.posX;
|
||||
double eyeY = caster.posY + caster.getEyeHeight();
|
||||
double eyeZ = caster.posZ;
|
||||
|
||||
// Raycast: find the closest entity along look direction
|
||||
EntityLivingBase hitTarget = null;
|
||||
double closestDist = maxRange;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Entity> candidates = world.getEntitiesWithinAABBExcludingEntity(caster,
|
||||
caster.boundingBox.expand(maxRange, maxRange, maxRange));
|
||||
|
||||
for (Entity entity : candidates) {
|
||||
if (!(entity instanceof EntityLivingBase)) continue;
|
||||
if (entity.isDead) continue;
|
||||
|
||||
// Check if entity is roughly along look direction
|
||||
double dx = entity.posX - eyeX;
|
||||
double dy = (entity.posY + entity.height / 2) - eyeY;
|
||||
double dz = entity.posZ - eyeZ;
|
||||
double dist = Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||
if (dist > maxRange || dist < 0.5) continue;
|
||||
|
||||
// Dot product to check alignment with look vector
|
||||
double dot = (dx * look.xCoord + dy * look.yCoord + dz * look.zCoord) / dist;
|
||||
if (dot < 0.95) continue; // Must be within ~18 degree cone
|
||||
|
||||
if (dist < closestDist) {
|
||||
closestDist = dist;
|
||||
hitTarget = (EntityLivingBase) entity;
|
||||
}
|
||||
}
|
||||
|
||||
world.playSoundAtEntity(caster, "random.bow", 1.0f, 0.8f);
|
||||
|
||||
if (hitTarget != null) {
|
||||
applyAbilityDamageWithDirection(caster, hitTarget, damage, knockback, look.xCoord, look.zCoord);
|
||||
|
||||
if (explosive && explosionRadius > 0) {
|
||||
applyExplosionDamage(caster, hitTarget, world, hitTarget.posX, hitTarget.posY, hitTarget.posZ);
|
||||
}
|
||||
|
||||
spawnProjectileParticles(world, caster, hitTarget);
|
||||
} else {
|
||||
// No hit — spawn particles along look direction anyway
|
||||
spawnProjectileParticlesInDirection(world, caster, look);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply explosion splash damage around a point.
|
||||
*/
|
||||
private void applyExplosionDamage(EntityLivingBase caster, EntityLivingBase primaryTarget, World world,
|
||||
double x, double y, double z) {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(primaryTarget,
|
||||
primaryTarget.boundingBox.expand(explosionRadius, explosionRadius, explosionRadius));
|
||||
|
||||
for (Entity entity : entities) {
|
||||
if (entity instanceof EntityLivingBase && entity != caster) {
|
||||
EntityLivingBase living = (EntityLivingBase) entity;
|
||||
float dist = primaryTarget.getDistanceToEntity(living);
|
||||
if (dist < explosionRadius) {
|
||||
float falloff = 1.0f - (dist / explosionRadius);
|
||||
applyAbilityDamage(caster, living, damage * falloff * 0.5f, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
world.playSoundAtEntity(primaryTarget, "random.explode", 0.5f, 1.0f);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
world.spawnParticle("explode",
|
||||
x + (world.rand.nextDouble() - 0.5) * explosionRadius,
|
||||
y + world.rand.nextDouble() * 2,
|
||||
z + (world.rand.nextDouble() - 0.5) * explosionRadius,
|
||||
0, 0.1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnProjectileParticles(World world, EntityLivingBase caster, EntityLivingBase target) {
|
||||
double startX = caster.posX;
|
||||
double startY = caster.posY + caster.getEyeHeight();
|
||||
@@ -160,6 +224,31 @@ public class AbilityProjectile extends Ability implements IAbilityProjectile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Spawn projectile particles along a direction (player miss — no entity hit).
|
||||
*/
|
||||
private void spawnProjectileParticlesInDirection(World world, EntityLivingBase caster, Vec3 look) {
|
||||
double startX = caster.posX;
|
||||
double startY = caster.posY + caster.getEyeHeight();
|
||||
double startZ = caster.posZ;
|
||||
|
||||
String particle = "flame";
|
||||
if (projectileType.equals("arrow")) {
|
||||
particle = "crit";
|
||||
} else if (projectileType.equals("magic")) {
|
||||
particle = "witchMagic";
|
||||
}
|
||||
|
||||
int steps = (int) Math.max(5, maxRange * 2);
|
||||
for (int i = 0; i < steps; i++) {
|
||||
double progress = (double) i / steps * maxRange;
|
||||
double px = startX + look.xCoord * progress;
|
||||
double py = startY + look.yCoord * progress;
|
||||
double pz = startZ + look.zCoord * progress;
|
||||
world.spawnParticle(particle, px, py, pz, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActiveTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
|
||||
// Projectile is instant, nothing to do per-tick
|
||||
|
||||
@@ -85,51 +85,74 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
|
||||
|
||||
@Override
|
||||
public void onWindUpTick(EntityLivingBase caster, EntityLivingBase target, World world, int tick) {
|
||||
// Update target position during windup
|
||||
if (targetingMode == TargetingMode.AOE_SELF) {
|
||||
// AOE_SELF: slam at caster's current position
|
||||
if (isPlayerCaster(caster)) {
|
||||
// Player: slam will launch from current position, no target tracking needed
|
||||
targetX = caster.posX;
|
||||
targetY = caster.posY;
|
||||
targetZ = caster.posZ;
|
||||
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
|
||||
// AOE_TARGET: telegraph follows target via setEntityIdToFollow
|
||||
targetX = target.posX;
|
||||
targetY = target.posY;
|
||||
targetZ = target.posZ;
|
||||
} else {
|
||||
// NPC: update target position during windup for telegraph tracking
|
||||
if (targetingMode == TargetingMode.AOE_SELF) {
|
||||
targetX = caster.posX;
|
||||
targetY = caster.posY;
|
||||
targetZ = caster.posZ;
|
||||
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
|
||||
targetX = target.posX;
|
||||
targetY = target.posY;
|
||||
targetZ = target.posZ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExecute(EntityLivingBase caster, EntityLivingBase target, World world) {
|
||||
// Lock in the destination at moment of launch
|
||||
hasLaunched = false;
|
||||
hasLanded = false;
|
||||
airTicks = 0;
|
||||
caster.fallDistance = 0;
|
||||
|
||||
if (isPlayerCaster(caster)) {
|
||||
executePlayerSlam(caster);
|
||||
} else {
|
||||
executeNpcSlam(caster, target);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NPC slam: Lock destination based on targeting mode, then launch in a ballistic arc toward it.
|
||||
*/
|
||||
private void executeNpcSlam(EntityLivingBase caster, EntityLivingBase target) {
|
||||
if (targetingMode == TargetingMode.AOE_SELF) {
|
||||
// AOE_SELF: slam in place (just jump up)
|
||||
targetX = caster.posX;
|
||||
targetY = caster.posY;
|
||||
targetZ = caster.posZ;
|
||||
} else if (targetingMode == TargetingMode.AOE_TARGET && target != null && !target.isDead) {
|
||||
// AOE_TARGET: leap to target's current position
|
||||
targetX = target.posX;
|
||||
targetY = target.posY;
|
||||
targetZ = target.posZ;
|
||||
} else {
|
||||
// Fallback: slam in place
|
||||
targetX = caster.posX;
|
||||
targetY = caster.posY;
|
||||
targetZ = caster.posZ;
|
||||
}
|
||||
|
||||
hasLaunched = false;
|
||||
hasLanded = false;
|
||||
airTicks = 0;
|
||||
|
||||
// Reset fall distance to prevent fall damage during slam
|
||||
caster.fallDistance = 0;
|
||||
|
||||
// Calculate and apply leap velocity
|
||||
launchTowardTarget(caster);
|
||||
}
|
||||
|
||||
/**
|
||||
* Player slam: Launch straight up. Player controls horizontal movement via WASD.
|
||||
* AOE damage triggers wherever the player lands.
|
||||
*/
|
||||
private void executePlayerSlam(EntityLivingBase caster) {
|
||||
targetX = caster.posX;
|
||||
targetY = caster.posY;
|
||||
targetZ = caster.posZ;
|
||||
|
||||
double vy = calculateLaunchVelocity(Math.max(1.0, leapHeight));
|
||||
caster.motionY = vy;
|
||||
hasLaunched = true;
|
||||
caster.velocityChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the initial vertical velocity needed to reach a target height
|
||||
* in Minecraft's physics (gravity=0.08, vertical drag=0.98).
|
||||
@@ -273,8 +296,9 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
|
||||
return;
|
||||
}
|
||||
|
||||
// While in air, face toward target
|
||||
if (!isPreview()) {
|
||||
// NPC: face toward target destination while in air
|
||||
// Player: free look — player controls their own camera
|
||||
if (!isPreview() && !isPlayerCaster(caster)) {
|
||||
double dx = targetX - caster.posX;
|
||||
double dz = targetZ - caster.posZ;
|
||||
float targetYaw = (float) (Math.atan2(-dx, dz) * 180.0D / Math.PI);
|
||||
@@ -441,11 +465,11 @@ public class AbilitySlam extends Ability implements IAbilitySlam {
|
||||
TelegraphInstance instance = new TelegraphInstance(telegraph, targetX, groundY, targetZ, caster.rotationYaw);
|
||||
instance.setCasterEntityId(caster.getEntityId());
|
||||
|
||||
// AOE_TARGET: telegraph follows target during windup
|
||||
if (targetingMode == TargetingMode.AOE_TARGET && target != null) {
|
||||
// NPC AOE_TARGET: telegraph follows target during windup
|
||||
// Player: telegraph stays at caster position (no target to follow)
|
||||
if (!isPlayerCaster(caster) && targetingMode == TargetingMode.AOE_TARGET && target != null) {
|
||||
instance.setEntityIdToFollow(target.getEntityId());
|
||||
}
|
||||
// AOE_SELF: telegraph stays at caster position, no follow
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,9 @@ public class AbilitySweeper extends Ability implements IAbilitySweeper {
|
||||
return;
|
||||
}
|
||||
|
||||
// Spawn the entity that handles BOTH visuals AND damage
|
||||
// Spawn the sweeper entity that handles BOTH visuals AND damage.
|
||||
// NPC: target is the aggro target — lockOnTarget tracks it during sweep.
|
||||
// Player: target is null — sweep rotates around caster's facing direction, lockOnTarget has no effect.
|
||||
activeEntity = new EntityAbilitySweeper(world, caster, target,
|
||||
beamLength, beamWidth, beamHeight,
|
||||
colorData,
|
||||
|
||||
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
@@ -72,6 +73,7 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
|
||||
this.typeId = "ability.cnpc.teleport";
|
||||
this.name = "Teleport";
|
||||
this.targetingMode = TargetingMode.AGGRO_TARGET;
|
||||
this.allowedBy = UserType.NPC_ONLY;
|
||||
this.maxRange = 30.0f;
|
||||
this.minRange = 5.0f;
|
||||
this.cooldownTicks = 0;
|
||||
@@ -228,26 +230,8 @@ public class AbilityTeleport extends Ability implements IAbilityTeleport {
|
||||
}
|
||||
}
|
||||
|
||||
// No target (player use) - teleport in caster's look direction
|
||||
Vec3 look = caster.getLookVec();
|
||||
switch (mode) {
|
||||
case BEHIND:
|
||||
// Teleport forward in look direction by behindDistance
|
||||
newX = caster.posX + look.xCoord * behindDistance;
|
||||
newZ = caster.posZ + look.zCoord * behindDistance;
|
||||
newY = caster.posY;
|
||||
return Vec3.createVectorHelper(newX, newY, newZ);
|
||||
case SINGLE:
|
||||
case BLINK:
|
||||
default:
|
||||
// Teleport forward in look direction within blinkRadius
|
||||
double dist = Math.min(blinkRadius, maxRange);
|
||||
double offset = (RANDOM.nextDouble() * 0.5 + 0.5) * dist; // 50-100% of max distance
|
||||
newX = caster.posX + look.xCoord * offset;
|
||||
newZ = caster.posZ + look.zCoord * offset;
|
||||
newY = caster.posY;
|
||||
return Vec3.createVectorHelper(newX, newY, newZ);
|
||||
}
|
||||
// NPC-only ability — should not reach here
|
||||
return null;
|
||||
}
|
||||
|
||||
private Vec3 findSafeDestination(World world, double oldX, double oldY, double oldZ,
|
||||
|
||||
@@ -3,6 +3,7 @@ package kamkeel.npcs.controllers.data.ability.type;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.LockMovementType;
|
||||
import kamkeel.npcs.controllers.data.ability.TargetingMode;
|
||||
import kamkeel.npcs.controllers.data.ability.UserType;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphInstance;
|
||||
import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@@ -83,6 +84,7 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
|
||||
this.cooldownTicks = 0;
|
||||
this.windUpTicks = 20;
|
||||
this.telegraphType = TelegraphType.CIRCLE;
|
||||
this.allowedBy = UserType.NPC_ONLY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -128,7 +130,6 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
|
||||
}
|
||||
break;
|
||||
case AT_TARGET:
|
||||
// Telegraph follows target during windup, locks on execute
|
||||
if (target != null) {
|
||||
instance.setEntityIdToFollow(target.getEntityId());
|
||||
}
|
||||
@@ -154,14 +155,12 @@ public class AbilityTrap extends Ability implements IAbilityTrap {
|
||||
trapZ = caster.posZ;
|
||||
break;
|
||||
case AT_TARGET:
|
||||
// Use telegraph position with offset
|
||||
if (telegraph != null) {
|
||||
double[] pos = Ability.calculateOffsetPosition(telegraph.getX(), telegraph.getY(), telegraph.getZ(),
|
||||
minOffset, maxOffset, randomOffset, RANDOM);
|
||||
trapX = pos[0];
|
||||
trapY = pos[1];
|
||||
trapZ = pos[2];
|
||||
// Update telegraph to show actual trap position
|
||||
telegraph.setX(trapX);
|
||||
telegraph.setY(trapY);
|
||||
telegraph.setZ(trapZ);
|
||||
|
||||
@@ -103,8 +103,9 @@ public class AbilityVortex extends Ability implements IAbilityVortex {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Single target mode - still check pullRadius
|
||||
if (target != null && !target.isDead) {
|
||||
// NPC single-target mode: pull the aggro target
|
||||
// Player: single-target mode has no effect (no target to pull — use AOE mode instead)
|
||||
if (!isPlayerCaster(caster) && target != null && !target.isDead) {
|
||||
double dist = caster.getDistanceToEntity(target);
|
||||
if (dist <= pullRadius) {
|
||||
getPulledEntities().add(target.getUniqueID());
|
||||
|
||||
Reference in new issue
Block a user