Merge branch 'dev' into syntax-highlighter-unified

This commit is contained in:
Kam committed 2026-02-26 19:27:42 -05:00
commit 6a10a25389
11 files changed
+424 -344

No files matched your search

@@ -55,7 +55,8 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
RIGHT(-90),
DIAGONAL_BACK_LEFT(135),
DIAGONAL_BACK_RIGHT(-135),
BACK(180);
BACK(180),
CUSTOM(0);
private final float angleOffset;
@@ -66,6 +67,40 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
public float getAngleOffset() {
return angleOffset;
}
@Override
public String toString() {
switch (this) {
case FORWARD:
return "ability.dash.forward";
case DIAGONAL_FORWARD_LEFT:
return "ability.dash.diagonalForwardLeft";
case DIAGONAL_FORWARD_RIGHT:
return "ability.dash.diagonalForwardRight";
case LEFT:
return "ability.dash.left";
case RIGHT:
return "ability.dash.right";
case DIAGONAL_BACK_LEFT:
return "ability.dash.diagonalBackLeft";
case DIAGONAL_BACK_RIGHT:
return "ability.dash.diagonalBackRight";
case BACK:
return "ability.dash.back";
case CUSTOM:
return "ability.dash.custom";
default:
return name();
}
}
public static DashDirection fromOrdinal(int ordinal) {
DashDirection[] values = values();
if (ordinal >= 0 && ordinal < values.length) {
return values[ordinal];
}
return DashDirection.FORWARD;
}
}
private static final Random RANDOM = new Random();
@@ -86,8 +121,10 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
// Type-specific parameters
private DashMode dashMode = DashMode.DEFENSIVE;
private DashDirection dashDirection = DashDirection.FORWARD;
private float dashDistance = 4.0f;
private float dashSpeed = 0.5f;
private float dashAngle = 0.0f;
// Type-specific runtime state
private transient DashDirection chosenDirection;
@@ -107,7 +144,6 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
this.telegraphType = TelegraphType.NONE;
this.showTelegraph = false;
this.windUpSound = "mob.bat.takeoff";
this.activeSound = "mob.endermen.portal";
}
@Override
@@ -133,8 +169,11 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
if (dashMode == DashMode.DIRECTIONAL) {
// Dash straight in the caster's look direction
chosenDirection = DashDirection.FORWARD;
setDirectionFromYaw(caster.rotationYaw);
chosenDirection = dashDirection;
float baseYaw = getBaseYaw(caster, target);
float angleOffset = chosenDirection == DashDirection.CUSTOM ? dashAngle : chosenDirection.getAngleOffset();
float dashYaw = baseYaw + angleOffset;
setDirectionFromYaw(dashYaw);
} else {
// Choose random direction based on mode
DashDirection[] directions = dashMode == DashMode.AGGRESSIVE
@@ -241,8 +280,10 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
@Override
public void writeTypeNBT(NBTTagCompound nbt) {
nbt.setString("dashMode", dashMode.name());
nbt.setString("dashDirection", dashDirection.name());
nbt.setFloat("dashDistance", dashDistance);
nbt.setFloat("dashSpeed", dashSpeed);
nbt.setFloat("dashAngle", dashAngle);
}
@Override
@@ -252,8 +293,16 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
} catch (Exception e) {
this.dashMode = DashMode.DEFENSIVE;
}
try {
this.dashDirection = DashDirection.valueOf(nbt.getString("dashDirection"));
} catch (Exception e) {
this.dashDirection = DashDirection.FORWARD;
}
this.dashDistance = nbt.hasKey("dashDistance") ? nbt.getFloat("dashDistance") : 4.0f;
this.dashSpeed = nbt.hasKey("dashSpeed") ? Math.max(0.01f, nbt.getFloat("dashSpeed")) : 0.5f;
this.dashAngle = nbt.hasKey("dashAngle") ? Math.max(0.01f, nbt.getFloat("dashAngle")) : 0.0f;
}
// Getters & Setters
@@ -292,6 +341,34 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
this.dashSpeed = dashSpeed;
}
public float getDashAngle() {
return dashAngle;
}
public void setDashAngle(float dashAngle) {
this.dashAngle = dashAngle;
}
public DashDirection getDashDirectionEnum() {
return dashDirection;
}
public void setDashDirectionEnum(DashDirection dashDirection) {
this.dashDirection = dashDirection;
}
@Override
public int getDashDirection() {
return dashDirection.ordinal();
}
@Override
public void setDashDirection(int mode) {
DashDirection[] values = DashDirection.values();
this.dashDirection = mode >= 0 && mode < values.length ? values[mode] : DashDirection.FORWARD;
}
public DashDirection getChosenDirection() {
return chosenDirection;
}
@@ -313,7 +390,12 @@ public class AbilityDash extends AbilityMovement implements IAbilityDash {
FieldDef.row(
FieldDef.floatField("ability.dashDistance", this::getDashDistance, this::setDashDistance),
FieldDef.floatField("ability.dashSpeed", this::getDashSpeed, this::setDashSpeed)
)
),
FieldDef.row(
FieldDef.enumField("ability.dashDirection", DashDirection.class, this::getDashDirectionEnum, this::setDashDirectionEnum),
FieldDef.floatField("ability.dashAngle", this::getDashAngle, this::setDashAngle)
.visibleWhen(() -> getDashDirectionEnum() == DashDirection.CUSTOM)
).visibleWhen(() -> this.getDashModeEnum() == DashMode.DIRECTIONAL)
));
}
}
@@ -13,6 +13,9 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class EnergyChargePreviewManager {
/** Hard age cap for preview entities — last-resort safety net (60 seconds). */
private static final int MAX_PREVIEW_AGE = 1200;
public static EnergyChargePreviewManager ClientInstance;
private final ConcurrentHashMap<String, EntityEnergyProjectile> previews = new ConcurrentHashMap<String, EntityEnergyProjectile>();
@@ -59,6 +62,14 @@ public class EnergyChargePreviewManager {
iterator.remove();
continue;
}
// Hard age cap: remove previews that have existed far too long
if (entity.ticksExisted > MAX_PREVIEW_AGE) {
entity.setDead();
iterator.remove();
continue;
}
entity.onUpdate();
if (entity.isDead) {
iterator.remove();
@@ -21,6 +21,7 @@ public abstract class EntityEnergyAbility extends Entity implements IEntityAddit
// ==================== SAFETY CONSTANTS ====================
protected static final int CHARGE_TIMEOUT_GRACE = 60; // Ticks of grace after charge should have ended
protected static final int PREVIEW_CHARGE_GRACE = 3; // Ticks of grace for client-only charge previews
protected static final int HARD_LIFETIME_CAP = 1200; // 60 seconds absolute max for projectiles/sweepers
protected static final int BARRIER_HARD_LIFETIME_CAP = 12000; // 10 minutes absolute max for barriers
protected static final float MAX_ENTITY_SIZE = 100.0f; // Max size/width/length for any energy entity
@@ -94,7 +95,7 @@ public abstract class EntityEnergyAbility extends Entity implements IEntityAddit
public float getInterpolatedChargeProgress(float partialTicks) {
if (chargeDuration <= 0) return 1.0f;
float prevProgress = Math.max(0, (float) (chargeTick - 1) / chargeDuration);
float prevProgress = Math.min(1.0f, Math.max(0, (float) (chargeTick - 1) / chargeDuration));
float currProgress = Math.min(1.0f, (float) chargeTick / chargeDuration);
return prevProgress + (currProgress - prevProgress) * partialTicks;
}
@@ -232,6 +232,18 @@ public abstract class EntityEnergyProjectile extends EntityEnergyAbility {
// Preview entities skip super.onUpdate() but still need ticksExisted
// for renderer pulsing effects (e.g., sin(ticksExisted + partialTicks)).
this.ticksExisted++;
// Preview-specific safety: self-destruct if charging has exceeded duration + grace
if (isCharging() && chargeDuration > 0 && chargeTick > chargeDuration + PREVIEW_CHARGE_GRACE) {
this.setDead();
return;
}
// Preview hard lifetime cap (mirrors real entity HARD_LIFETIME_CAP)
if (ticksExisted > HARD_LIFETIME_CAP) {
this.setDead();
return;
}
}
if (!previewMode) {
@@ -54,6 +54,9 @@ public class AnchorPointHelper {
private static final float FALLBACK_FORWARD = 0.1f; // Slight forward offset
private static final float FALLBACK_ARM_HEIGHT = 0.45f; // Hand height when arms hang down (near hip)
// Default arm scale (no scaling)
private static final ModelScalePart DEFAULT_ARM_SCALE = new ModelScalePart();
/**
* Calculate world position for an anchor point on an entity.
*/
@@ -75,10 +78,11 @@ public class AnchorPointHelper {
float anchorZ = anchorData.anchorOffsetZ;
double x = entity.posX;
double y = entity.posY + getClientPlayerYCorrection(entity);
// EYE uses getEyeHeight() which already gives the correct offset from posY,
// so the client player correction would double-subtract and place it at feet level
double y = entity.posY + (anchor == AnchorPoint.EYE ? 0 : getClientPlayerYCorrection(entity));
double z = entity.posZ;
float headYaw = (float) Math.toRadians(entity.rotationYawHead);
float bodyYaw = (float) Math.toRadians(entity.renderYawOffset);
switch (anchor) {
@@ -108,8 +112,7 @@ public class AnchorPointHelper {
break;
case EYE:
y += entity.getEyeHeight();
break;
return calculateEyePosition(entity, anchorData, scale);
}
// Rotate offsets relative to entity's body yaw
@@ -136,6 +139,88 @@ public class AnchorPointHelper {
return Vec3.createVectorHelper(x, y, z);
}
private static Vec3 calculateEyePosition(EntityLivingBase entity, EnergyAnchorData anchorData, float scale) {
double pivotWorldX = entity.posX;
double pivotWorldY = entity.posY + entity.getEyeHeight();
double pivotWorldZ = entity.posZ;
float bodyYaw = (float) Math.toRadians(entity.renderYawOffset);
float[] rotations = getHeadBoneRotations(entity);
double ox = -anchorData.anchorOffsetX * scale;
double oy = -anchorData.anchorOffsetY * scale;
double oz = -anchorData.anchorOffsetZ * scale;
// X rotation
double cosX = Math.cos(rotations[0]);
double sinX = Math.sin(rotations[0]);
double ry = oy * cosX - oz * sinX;
double rz = oy * sinX + oz * cosX;
double rx = ox;
oy = ry; oz = rz;
// Y rotation
double cosY = Math.cos(rotations[1]);
double sinY = Math.sin(rotations[1]);
double rx2 = rx * cosY + oz * sinY;
double rz2 = -rx * sinY + oz * cosY;
rx = rx2; oz = rz2;
// Z rotation
double cosZ = Math.cos(rotations[2]);
double sinZ = Math.sin(rotations[2]);
double rx3 = rx * cosZ - oy * sinZ;
double ry3 = rx * sinZ + oy * cosZ;
rx = rx3; oy = ry3;
double cosYaw = Math.cos(bodyYaw);
double sinYaw = Math.sin(bodyYaw);
double worldOffsetX = rx * cosYaw + oz * sinYaw;
double worldOffsetZ = rx * sinYaw - oz * cosYaw;
double worldOffsetY = -oy; // model Y-down → world Y-up
double x = pivotWorldX + worldOffsetX;
double y = pivotWorldY + worldOffsetY;
double z = pivotWorldZ + worldOffsetZ;
FramePart fullModel = getFullModelPart(entity);
if (fullModel != null) {
double dx = x - entity.posX;
double dy = y - entity.posY;
double dz = z - entity.posZ;
Vec3 rotatedFull = applyFullModelToWorldOffset(fullModel, entity, dx, dy, dz, bodyYaw, scale);
return Vec3.createVectorHelper(
entity.posX + rotatedFull.xCoord,
entity.posY + rotatedFull.yCoord,
entity.posZ + rotatedFull.zCoord
);
}
return Vec3.createVectorHelper(x, y, z);
}
private static float[] getHeadBoneRotations(EntityLivingBase entity) {
// Try animated HEAD part first
AnimationData animData = AnimationData.getData(entity);
if (animData != null && animData.isActive() && animData.animation != null) {
Frame frame = (Frame) animData.animation.currentFrame();
if (frame != null) {
FramePart headPart = frame.frameParts.get(EnumAnimationPart.HEAD);
if (headPart != null) {
return getRotations(headPart, entity);
}
}
}
// Fallback: live head angles
float pitch = (float) Math.toRadians(entity.rotationPitch);
float yawDelta = (float) Math.toRadians(entity.rotationYawHead - entity.renderYawOffset);
return new float[]{ pitch, yawDelta, 0f };
}
/**
* Get model scale factor for an entity.
* NPCs have configurable model size, players use default scale.
@@ -160,9 +245,6 @@ public class AnchorPointHelper {
return 0.0;
}
// Default arm scale (no scaling)
private static final ModelScalePart DEFAULT_ARM_SCALE = new ModelScalePart();
/**
* Get arm scale for an entity.
* EntityCustomNpc has per-part scaling, others use default (1,1,1).
@@ -65,6 +65,11 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
EntityAbilityOrb orb = (EntityAbilityOrb) entity;
if (orb.getChargeProgress() < 1.0f) {
orb.setDead();
return;
}
orb.startMoving(null);
world.playSoundAtEntity(
@@ -127,7 +132,7 @@ public class ItemStaff extends ItemNpcInterface implements IProjectileCallback {
);
orb.setupCharging(
new EnergyAnchorData(AnchorPoint.FRONT, 0, -1, 0),
new EnergyAnchorData(AnchorPoint.EYE, 0, 0, 1),
chargeTime
);