mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-22 01:32:19 +00:00
Ability Preview GUI
This commit is contained in:
1 parent
216a3dbbf8
commit
55658a7956
37 files changed
+2396
-162
No files matched your search
@@ -83,8 +83,12 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
|
||||
/**
|
||||
* Check if beam is in charging state (synced via data watcher).
|
||||
* In preview mode, uses local field since data watcher isn't synced.
|
||||
*/
|
||||
public boolean isCharging() {
|
||||
if (previewMode) {
|
||||
return this.charging;
|
||||
}
|
||||
return this.dataWatcher.getWatchableObjectByte(DW_CHARGING) == 1;
|
||||
}
|
||||
|
||||
@@ -264,6 +268,103 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
return beam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a beam in preview mode for GUI display.
|
||||
* Follows anchor point and animations like in the real game.
|
||||
* Can be fired when transitioning to active phase.
|
||||
*/
|
||||
public static EntityAbilityBeam createPreview(World world, EntityNPCInterface owner,
|
||||
float beamWidth, float headSize, int innerColor, int outerColor,
|
||||
boolean outerColorEnabled, float outerColorWidth, float rotationSpeed,
|
||||
boolean lightningEffect, float lightningDensity, float lightningRadius,
|
||||
AnchorPoint anchorPoint, int chargeDuration, float chargeOffsetDistance) {
|
||||
EntityAbilityBeam beam = new EntityAbilityBeam(world);
|
||||
beam.setPreviewMode(true);
|
||||
beam.setPreviewOwner(owner);
|
||||
|
||||
// Set visual properties
|
||||
beam.beamWidth = beamWidth;
|
||||
beam.headSize = headSize;
|
||||
beam.size = headSize;
|
||||
beam.innerColor = innerColor;
|
||||
beam.outerColor = outerColor;
|
||||
beam.outerColorEnabled = outerColorEnabled;
|
||||
beam.outerColorWidth = outerColorWidth;
|
||||
beam.rotationSpeed = rotationSpeed;
|
||||
beam.lightningEffect = lightningEffect;
|
||||
beam.lightningDensity = lightningDensity;
|
||||
beam.lightningRadius = lightningRadius;
|
||||
|
||||
// Set charging state
|
||||
beam.setCharging(true);
|
||||
beam.chargeDuration = chargeDuration;
|
||||
beam.chargeTick = 0;
|
||||
beam.chargeOffsetDistance = chargeOffsetDistance;
|
||||
beam.anchorPoint = anchorPoint;
|
||||
|
||||
// Initial position at anchor point
|
||||
Vec3 pos = AnchorPointHelper.calculateAnchorPosition(owner, anchorPoint, chargeOffsetDistance);
|
||||
beam.setPosition(pos.xCoord, pos.yCoord, pos.zCoord);
|
||||
beam.prevPosX = pos.xCoord;
|
||||
beam.prevPosY = pos.yCoord;
|
||||
beam.prevPosZ = pos.zCoord;
|
||||
beam.startX = pos.xCoord;
|
||||
beam.startY = pos.yCoord;
|
||||
beam.startZ = pos.zCoord;
|
||||
|
||||
// Initialize head offsets
|
||||
beam.headOffsetX = 0;
|
||||
beam.headOffsetY = 0;
|
||||
beam.headOffsetZ = 0;
|
||||
beam.prevHeadOffsetX = 0;
|
||||
beam.prevHeadOffsetY = 0;
|
||||
beam.prevHeadOffsetZ = 0;
|
||||
|
||||
// Attach to owner for anchor following
|
||||
beam.attachedToOwner = true;
|
||||
beam.renderTailOrb = true;
|
||||
|
||||
// Clear motion while charging
|
||||
beam.motionX = 0;
|
||||
beam.motionY = 0;
|
||||
beam.motionZ = 0;
|
||||
|
||||
return beam;
|
||||
}
|
||||
|
||||
/**
|
||||
* Start preview firing (simulates firing toward a point in front of NPC).
|
||||
*/
|
||||
public void startPreviewFiring() {
|
||||
if (!isCharging()) return;
|
||||
|
||||
setCharging(false);
|
||||
|
||||
// Update start position to current position
|
||||
startX = posX;
|
||||
startY = posY;
|
||||
startZ = posZ;
|
||||
|
||||
// Sync prev position to prevent visual jump on first frame
|
||||
prevPosX = posX;
|
||||
prevPosY = posY;
|
||||
prevPosZ = posZ;
|
||||
|
||||
// Fire forward based on owner facing direction
|
||||
Entity owner = getOwner();
|
||||
if (owner != null) {
|
||||
float yaw = (float) Math.toRadians(owner.rotationYaw);
|
||||
float pitch = 0; // Fire horizontally
|
||||
motionX = -Math.sin(yaw) * Math.cos(pitch) * speed;
|
||||
motionY = -Math.sin(pitch) * speed;
|
||||
motionZ = Math.cos(yaw) * Math.cos(pitch) * speed;
|
||||
} else {
|
||||
motionX = speed;
|
||||
motionY = 0;
|
||||
motionZ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the beam firing (exit charging mode).
|
||||
* Called by ability when windup ends.
|
||||
@@ -361,6 +462,12 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
ageTrailPoints();
|
||||
}
|
||||
|
||||
// In preview mode, run movement on client (no server)
|
||||
if (previewMode) {
|
||||
updatePreviewMovement();
|
||||
return;
|
||||
}
|
||||
|
||||
if (worldObj.isRemote) {
|
||||
// Client: interpolate entity position
|
||||
handleClientInterpolation();
|
||||
@@ -510,6 +617,37 @@ public class EntityAbilityBeam extends EntityAbilityProjectile {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update movement in preview mode (client-side only, no damage).
|
||||
*/
|
||||
private void updatePreviewMovement() {
|
||||
// Move head offset
|
||||
headOffsetX += motionX;
|
||||
headOffsetY += motionY;
|
||||
headOffsetZ += motionZ;
|
||||
|
||||
// Update origin if attached to owner
|
||||
if (attachedToOwner) {
|
||||
Entity owner = getOwner();
|
||||
if (owner != null) {
|
||||
startX = owner.posX;
|
||||
startY = owner.posY + owner.getEyeHeight() * 0.7;
|
||||
startZ = owner.posZ;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate world position of head
|
||||
double headWorldX = startX + headOffsetX;
|
||||
double headWorldY = startY + headOffsetY;
|
||||
double headWorldZ = startZ + headOffsetZ;
|
||||
|
||||
// Update entity position to head
|
||||
this.setPosition(headWorldX, headWorldY, headWorldZ);
|
||||
|
||||
// Add trail point
|
||||
addTrailPoint();
|
||||
}
|
||||
|
||||
private void updateHoming() {
|
||||
if (!homing) return;
|
||||
|
||||
|
||||
Reference in new issue
Block a user