载具在水面上会自动回正,微调汤姆操控,调整二次灾变上弹时间点

This commit is contained in:
Atsuishio 2025-04-15 22:47:15 +08:00 committed by Light_Quanta
parent 92c8838613
commit 986a385478
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 74 additions and 63 deletions

View file

@ -47,6 +47,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
public class Tom6Entity extends MobileVehicleEntity implements GeoEntity { public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> MELON = SynchedEntityData.defineId(Tom6Entity.class, EntityDataSerializers.BOOLEAN);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);
private float yRotSync;
public Tom6Entity(EntityType<Tom6Entity> type, Level world) { public Tom6Entity(EntityType<Tom6Entity> type, Level world) {
@ -182,10 +183,15 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
float addY = Mth.clamp(Math.min((this.onGround() ? 1.5f : 0.9f) * (float) Math.max(getDeltaMovement().length() - 0.06, 0.1), 0.9f) * diffY - 0.5f * this.entityData.get(DELTA_ROT), -3 * (roll + 1), 3 * (roll + 1)); float addY = Mth.clamp(Math.min((this.onGround() ? 1.5f : 0.9f) * (float) Math.max(getDeltaMovement().length() - 0.06, 0.1), 0.9f) * diffY - 0.5f * this.entityData.get(DELTA_ROT), -3 * (roll + 1), 3 * (roll + 1));
float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().length() - 0.1, 0.01), 0.9f) * diffX, -4, 4); float addX = Mth.clamp(Math.min((float) Math.max(getDeltaMovement().length() - 0.1, 0.01), 0.9f) * diffX, -4, 4);
float addZ = this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.01f) * diffY * (float) getDeltaMovement().length();
this.setYRot(this.getYRot() + addY); float i = getXRot() / 90;
yRotSync = addY * (1 - Mth.abs(i)) + addZ * i;
this.setYRot(this.getYRot() + yRotSync);
this.setXRot(Mth.clamp(this.getXRot() + addX, onGround() ? -12 : -120, onGround() ? 3 : 120)); this.setXRot(Mth.clamp(this.getXRot() + addX, onGround() ? -12 : -120, onGround() ? 3 : 120));
this.setZRot(this.getRoll() - this.entityData.get(DELTA_ROT) + (this.onGround() ? 0 : 0.01f) * diffY * (float) getDeltaMovement().length()); this.setZRot(this.getRoll() - addZ * (1 - Mth.abs(i)));
// 空格投掷西瓜炸弹 // 空格投掷西瓜炸弹
if (upInputDown && !onGround() && entityData.get(MELON)) { if (upInputDown && !onGround() && entityData.get(MELON)) {
@ -268,10 +274,12 @@ public class Tom6Entity extends MobileVehicleEntity implements GeoEntity {
} }
public void copyEntityData(Entity entity) { public void copyEntityData(Entity entity) {
float i = getXRot() / 90;
float f = Mth.wrapDegrees(entity.getYRot() - getYRot()); float f = Mth.wrapDegrees(entity.getYRot() - getYRot());
float g = Mth.clamp(f, -105.0f, 105.0f); float g = Mth.clamp(f, -105.0f, 105.0f);
entity.yRotO += g - f; entity.yRotO += g - f;
entity.setYRot(entity.getYRot() + g - f); entity.setYRot(entity.getYRot() + g - f + yRotSync * Mth.abs(i));
entity.setYHeadRot(entity.getYRot()); entity.setYHeadRot(entity.getYRot());
entity.setYBodyRot(getYRot()); entity.setYBodyRot(getYRot());
} }

View file

@ -288,55 +288,54 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
// 地形适应测试 // 地形适应测试
public void terrainCompat(float w, float l) { public void terrainCompat(float w, float l) {
if (!onGround()) return; if (onGround()) {
Matrix4f transform = this.getWheelsTransform(1);
Matrix4f transform = this.getWheelsTransform(1); // 点位
//
Vector4f positionF = transformPosition(transform, 0, 0, l / 2);
//
Vector4f positionB = transformPosition(transform, 0, 0, -l / 2);
//
Vector4f positionL = transformPosition(transform, -w / 2, 0, 0);
//
Vector4f positionR = transformPosition(transform, w / 2, 0, 0);
// 左前
Vector4f positionLF = transformPosition(transform, w / 2, 0, l / 2);
// 右前
Vector4f positionRF = transformPosition(transform, -w / 2, 0, l / 2);
// 左后
Vector4f positionLB = transformPosition(transform, w / 2, 0, -l / 2);
// 右后
Vector4f positionRB = transformPosition(transform, -w / 2, 0, -l / 2);
// 点位 Vec3 p1 = new Vec3(positionLF.x, positionLF.y, positionLF.z);
// Vec3 p2 = new Vec3(positionRF.x, positionRF.y, positionRF.z);
Vector4f positionF = transformPosition(transform, 0, 0, l / 2); Vec3 p3 = new Vec3(positionLB.x, positionLB.y, positionLB.z);
// Vec3 p4 = new Vec3(positionRB.x, positionRB.y, positionRB.z);
Vector4f positionB = transformPosition(transform, 0, 0, -l / 2);
//
Vector4f positionL = transformPosition(transform, -w / 2, 0, 0);
//
Vector4f positionR = transformPosition(transform, w / 2, 0, 0);
// 左前
Vector4f positionLF = transformPosition(transform, w / 2, 0, l / 2);
// 右前
Vector4f positionRF = transformPosition(transform, -w / 2, 0, l / 2);
// 左后
Vector4f positionLB = transformPosition(transform, w / 2, 0, -l / 2);
// 右后
Vector4f positionRB = transformPosition(transform, -w / 2, 0, -l / 2);
Vec3 p1 = new Vec3(positionLF.x, positionLF.y, positionLF.z); Vec3 p5 = new Vec3(positionF.x, positionF.y, positionF.z);
Vec3 p2 = new Vec3(positionRF.x, positionRF.y, positionRF.z); Vec3 p6 = new Vec3(positionB.x, positionB.y, positionB.z);
Vec3 p3 = new Vec3(positionLB.x, positionLB.y, positionLB.z); Vec3 p7 = new Vec3(positionL.x, positionL.y, positionL.z);
Vec3 p4 = new Vec3(positionRB.x, positionRB.y, positionRB.z); Vec3 p8 = new Vec3(positionR.x, positionR.y, positionR.z);
Vec3 p5 = new Vec3(positionF.x, positionF.y, positionF.z); // 确定点位是否在墙里来调整点位高度
Vec3 p6 = new Vec3(positionB.x, positionB.y, positionB.z); float p1y = (float) this.traceBlockY(p1, l);
Vec3 p7 = new Vec3(positionL.x, positionL.y, positionL.z); float p2y = (float) this.traceBlockY(p2, l);
Vec3 p8 = new Vec3(positionR.x, positionR.y, positionR.z); float p3y = (float) this.traceBlockY(p3, l);
float p4y = (float) this.traceBlockY(p4, l);
// 确定点位是否在墙里来调整点位高度 float p5y = (float) Mth.clamp(this.traceBlockY(p5, l), -l, l);
float p1y = (float) this.traceBlockY(p1, l); float p6y = (float) Mth.clamp(this.traceBlockY(p6, l), -l, l);
float p2y = (float) this.traceBlockY(p2, l); float p7y = (float) Mth.clamp(this.traceBlockY(p7, l), -l, l);
float p3y = (float) this.traceBlockY(p3, l); float p8y = (float) Mth.clamp(this.traceBlockY(p8, l), -l, l);
float p4y = (float) this.traceBlockY(p4, l);
float p5y = (float) Mth.clamp(this.traceBlockY(p5, l), -l, l); p1 = new Vec3(positionLF.x, p1y, positionLF.z);
float p6y = (float) Mth.clamp(this.traceBlockY(p6, l), -l, l); p2 = new Vec3(positionRF.x, p2y, positionRF.z);
float p7y = (float) Mth.clamp(this.traceBlockY(p7, l), -l, l); p3 = new Vec3(positionLB.x, p3y, positionLB.z);
float p8y = (float) Mth.clamp(this.traceBlockY(p8, l), -l, l); p4 = new Vec3(positionRB.x, p4y, positionRB.z);
p1 = new Vec3(positionLF.x, p1y, positionLF.z); // 测试用粒子效果用于确定点位位置
p2 = new Vec3(positionRF.x, p2y, positionRF.z);
p3 = new Vec3(positionLB.x, p3y, positionLB.z);
p4 = new Vec3(positionRB.x, p4y, positionRB.z);
// 测试用粒子效果用于确定点位位置
// var passenger = this.getFirstPassenger(); // var passenger = this.getFirstPassenger();
// //
// if (passenger != null) { // if (passenger != null) {
@ -348,27 +347,31 @@ public abstract class MobileVehicleEntity extends EnergyVehicleEntity implements
// } // }
// } // }
// 通过点位位置获取角度 // 通过点位位置获取角度
// 左后-左前 // 左后-左前
Vec3 v0 = p3.vectorTo(p1); Vec3 v0 = p3.vectorTo(p1);
// 右后-右前 // 右后-右前
Vec3 v1 = p4.vectorTo(p2); Vec3 v1 = p4.vectorTo(p2);
// 左前-右前 // 左前-右前
Vec3 v2 = p1.vectorTo(p2); Vec3 v2 = p1.vectorTo(p2);
// 左后-右后 // 左后-右后
Vec3 v3 = p3.vectorTo(p4); Vec3 v3 = p3.vectorTo(p4);
double x1 = getXRotFromVector(v0); double x1 = getXRotFromVector(v0);
double x2 = getXRotFromVector(v1); double x2 = getXRotFromVector(v1);
double z1 = getXRotFromVector(v2); double z1 = getXRotFromVector(v2);
double z2 = getXRotFromVector(v3); double z2 = getXRotFromVector(v3);
float diffX = Math.clamp(-90f, 90f, Mth.wrapDegrees((float) (-(x1 + x2)) - this.getXRot())); float diffX = Math.clamp(-90f, 90f, Mth.wrapDegrees((float) (-(x1 + x2)) - getXRot()));
this.setXRot(Mth.clamp(this.getXRot() + 0.075f * diffX, -90f, 90f)); setXRot(Mth.clamp(getXRot() + 0.075f * diffX, -90f, 90f));
float diffZ = Math.clamp(-90f, 90f, Mth.wrapDegrees((float) (-(z1 + z2)) - this.getRoll())); float diffZ = Math.clamp(-90f, 90f, Mth.wrapDegrees((float) (-(z1 + z2)) - getRoll()));
this.setZRot(Mth.clamp(this.getRoll() + 0.15f * diffZ, -90f, 90f)); setZRot(Mth.clamp(getRoll() + 0.15f * diffZ, -90f, 90f));
} else if (isInWater()) {
setXRot(getXRot() * 0.9f);
setZRot(getRoll() * 0.9f);
}
} }
public Matrix4f getWheelsTransform(float ticks) { public Matrix4f getWheelsTransform(float ticks) {

View file

@ -502,7 +502,7 @@ public class GunEventHandler {
singleLoad(player, data); singleLoad(player, data);
} }
if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && reload.iterativeLoadTimer.get() == 16) { if (stack.getItem() == ModItems.SECONDARY_CATACLYSM.get() && reload.iterativeLoadTimer.get() == 1) {
singleLoad(player, data); singleLoad(player, data);
} }