This commit is contained in:
LZX committed 2026-09-04 22:11:49 +08:00
1 parent 8773e8d4a1
commit 7af612a373
3 files changed
+81 -25

No files matched your search

@@ -151,7 +151,7 @@ public class BejeweledStaff extends MagicWeapon {
CompoundTag projData = new CompoundTag(); CompoundTag projData = new CompoundTag();
projData.putInt("skill", skill); projData.putInt("skill", skill);
projData.putUUID("playerUUID", player.getUUID()); projData.putUUID("playerUUID", player.getUUID());
projData.putFloat("damage", DAMAGE.get()); projData.putFloat("damage", DAMAGE.get() / 3.0F);
projData.putFloat("knockback", 0.5F); projData.putFloat("knockback", 0.5F);
projData.putFloat("colorR", color.x); projData.putFloat("colorR", color.x);
projData.putFloat("colorG", color.y); projData.putFloat("colorG", color.y);
@@ -56,9 +56,9 @@ public abstract class GemStaff extends MagicWeapon {
public static final double BURST_OFFSET = -1.2D; public static final double BURST_OFFSET = -1.2D;
public static final int LIFETIME = 50; public static final int LIFETIME = 50;
public static final double TURN_RATE = 0.35D; public static final double INITIAL_TURN_ANGLE = Math.toRadians(5.0D);
public static final double CLOSE_TARGET_RANGE = 5.0D; public static final double DASHED_TURN_ANGLE = Math.toRadians(30.0D);
public static final double CLOSE_TURN_RATE = 0.75D; public static final int DASH_TICKS = 1;
public static final double DEFAULT_HITBOX_INFLATE = 0.35D; public static final double DEFAULT_HITBOX_INFLATE = 0.35D;
/** /**
@@ -75,28 +75,53 @@ public abstract class GemStaff extends MagicWeapon {
boolean emerald = (skill & SKILL_EMERALD) != 0; boolean emerald = (skill & SKILL_EMERALD) != 0;
boolean amber = (skill & SKILL_AMBER) != 0; boolean amber = (skill & SKILL_AMBER) != 0;
Vec3 currentDir = summon.getLookAngle().normalize(); //Vec3 currentDir = summon.getLookAngle().lengthSqr() > 1.0E-6D ? summon.getLookAngle().normalize() :
// (summon.getDeltaMovement().lengthSqr() > 1.0E-6D ? summon.getDeltaMovement().normalize() : new Vec3(0, 0, 1));
Vec3 currentDir = summon.getDeltaMovement().normalize();
Vec3 nextDir = currentDir; Vec3 nextDir = currentDir;
// 紫晶追踪
if(amethyst) {
double targetRange = AmethystStaff.TARGET_RANGE.get();
Entity target = findTarget(summon, targetRange);
if(target != null) {
Vec3 targetCenter = target.getBoundingBox().getCenter();
Vec3 targetDir = targetCenter.subtract(summon.position()).normalize();
double turnRate = targetCenter.distanceTo(summon.position()) <= CLOSE_TARGET_RANGE ? CLOSE_TURN_RATE : TURN_RATE;
if (hasLineOfSight(summon.level(), summon, summon.position(), targetCenter)) {
nextDir = steer(currentDir, targetDir, turnRate);
}
}
}
double speed = summon.getDeltaMovement().length(); double speed = summon.getDeltaMovement().length();
if(emerald) { if(emerald) {
speed *= EmeraldStaff.DRAG.get(); speed *= EmeraldStaff.DRAG.get();
if(customData.contains("stop")) speed = 0; if(customData.contains("stop")) speed = 0;
} }
// 紫晶追踪(参考夜光逻辑:在快要到达时锁定直线冲刺一段距离,穿过实体形成平滑自然轨迹)
if(amethyst) {
int dashTime = customData.getInt("dashTime");
if(dashTime > 0) {
// 处于直线冲刺状态:保持当前直线方向不进行转向,直到穿过实体
nextDir = currentDir;
customData.putInt("dashTime", dashTime - 1);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
} else {
double targetRange = AmethystStaff.TARGET_RANGE.get();
Entity target = findTarget(summon, targetRange);
if(target != null) {
Vec3 targetCenter = target.getBoundingBox().getCenter();
Vec3 toTarget = targetCenter.subtract(summon.position());
double dist = toTarget.length();
boolean hasDashed = customData.getBoolean("hasDashed");
double turnAngle = hasDashed ? DASHED_TURN_ANGLE : INITIAL_TURN_ANGLE;
if(dist < speed) {
// 距离小于阈值(快要到达时):按角速度平滑对准并设置 dashTime 保持直线冲刺穿透实体
nextDir = MathUtil.rotateTowards(currentDir, toTarget, turnAngle);
customData.putInt("dashTime", DASH_TICKS);
customData.putBoolean("hasDashed", true);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
} else {
// 距离较远时:使用 MathUtil.rotateTowards 沿球面按固定角速度平滑追击,避免反向拉扯
Vec3 targetDir = toTarget.normalize();
if (hasLineOfSight(summon.level(), summon, summon.position(), targetCenter)) {
nextDir = MathUtil.rotateTowards(currentDir, targetDir, turnAngle);
}
}
}
}
}
Vec3 motion = nextDir.normalize().scale(speed); Vec3 motion = nextDir.normalize().scale(speed);
summon.setDeltaMovement(motion); summon.setDeltaMovement(motion);
@@ -126,6 +151,7 @@ public abstract class GemStaff extends MagicWeapon {
int hitCount = customData.getInt("hitCount") + 1; int hitCount = customData.getInt("hitCount") + 1;
customData.putInt("hitCount", hitCount); customData.putInt("hitCount", hitCount);
customData.putInt("dashTime", 0);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
if(hitCount >= AmberStaff.MAX_HIT_COUNT.get()) { if(hitCount >= AmberStaff.MAX_HIT_COUNT.get()) {
onDied(summon); onDied(summon);
@@ -138,10 +164,10 @@ public abstract class GemStaff extends MagicWeapon {
} }
int hitCount = customData.getInt("hitCount") + 1; int hitCount = customData.getInt("hitCount") + 1;
customData.putInt("hitCount", hitCount); customData.putInt("hitCount", hitCount);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
//翡翠停止 //翡翠停止
customData.putBoolean("stop", true); customData.putBoolean("stop", true);
customData.putInt("dashTime", 0);
summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData); summon.getEntityData().set(StaticSummon.CUSTOM_DATA, customData);
summon.setPos(blockHitResult.getLocation().add(Vec3.atLowerCornerOf(blockHitResult.getDirection().getNormal()).scale(0.05D))); summon.setPos(blockHitResult.getLocation().add(Vec3.atLowerCornerOf(blockHitResult.getDirection().getNormal()).scale(0.05D)));
updateRotation(summon, nextDir); updateRotation(summon, nextDir);
@@ -585,11 +611,6 @@ public abstract class GemStaff extends MagicWeapon {
)).getType() == HitResult.Type.MISS; )).getType() == HitResult.Type.MISS;
} }
private static Vec3 steer(Vec3 currentDir, Vec3 desiredDir, double turnRate) {
Vec3 steered = currentDir.scale(1.0D - turnRate).add(desiredDir.normalize().scale(turnRate));
if (steered.lengthSqr() < 1.0E-7D) return desiredDir.normalize();
return steered.normalize();
}
private static void updateRotation(StaticSummon summon, Vec3 motion) { private static void updateRotation(StaticSummon summon, Vec3 motion) {
float[] xyRot = MathUtil.computeXYRot(motion.toVector3f()); float[] xyRot = MathUtil.computeXYRot(motion.toVector3f());
@@ -167,4 +167,39 @@ public class MathUtil {
public static Vec3 toVec3(Vector3f vector3f) { public static Vec3 toVec3(Vector3f vector3f) {
return new Vec3(vector3f.x, vector3f.y, vector3f.z); return new Vec3(vector3f.x, vector3f.y, vector3f.z);
} }
/**
* 将当前方向沿着球面朝着目标方向平滑旋转,单刻最大旋转角为 maxAngleRadians(弧度)
* 解决了两向量相反(180度)时 lerp 产生共线拉扯的对跖奇点问题,能划出优美真实的圆弧
*/
public static Vec3 rotateTowards(Vec3 current, Vec3 target, double maxAngleRadians) {
if(current.lengthSqr() < 1.0E-7D) return target.normalize();
if(target.lengthSqr() < 1.0E-7D) return current.normalize();
Vec3 from = current.normalize();
Vec3 to = target.normalize();
double dot = Mth.clamp(from.dot(to), -1.0D, 1.0D);
double angle = Math.acos(dot);
// 夹角小于单刻最大角,直接返回目标方向
if(angle <= maxAngleRadians) {
return to;
}
// 旋转轴 = from x to
Vec3 axis = from.cross(to);
// 处理 180 度反向奇点:叉积接近 0 时,选取与 from 垂直的参考轴
if(axis.lengthSqr() < 1.0E-6D) {
axis = Math.abs(from.y) < 0.9D ? from.cross(new Vec3(0, 1, 0)) : from.cross(new Vec3(1, 0, 0));
}
axis = axis.normalize();
// 罗德里格旋转公式:沿 axis 旋转 maxAngleRadians 弧度
Vec3 ortho = axis.cross(from);
return from.scale(Math.cos(maxAngleRadians)).add(ortho.scale(Math.sin(maxAngleRadians))).normalize();
}
public static Vec3 rotateTowardsDegrees(Vec3 current, Vec3 target, double maxAngleDegrees) {
return rotateTowards(current, target, Math.toRadians(maxAngleDegrees));
}
} }