YX100添加引擎损毁

This commit is contained in:
Atsuishio 2025-06-22 01:02:57 +08:00 committed by Light_Quanta
parent 422a2aaae8
commit c7b8a07eff
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
3 changed files with 109 additions and 54 deletions

View file

@ -223,7 +223,12 @@ public class VehicleHudOverlay implements LayeredDraw.Layer {
//引擎 //引擎
ResourceLocation engine; ResourceLocation engine;
if (mobileVehicle.getEntityData().get(ENGINE_DAMAGED)) {
engine = Mod.loc("textures/screens/land/engine_damaged.png");
} else {
engine = Mod.loc("textures/screens/land/engine.png"); engine = Mod.loc("textures/screens/land/engine.png");
}
poseStack.rotateAround(Axis.ZP.rotationDegrees(Mth.lerp(partialTick, iLand.turretYRotO(), iLand.turretYRot())), w / 2f + 112, h - 56, 0); poseStack.rotateAround(Axis.ZP.rotationDegrees(Mth.lerp(partialTick, iLand.turretYRotO(), iLand.turretYRot())), w / 2f + 112, h - 56, 0);

View file

@ -89,6 +89,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
public OBB obb2; public OBB obb2;
public OBB obb3; public OBB obb3;
public OBB obb4; public OBB obb4;
public OBB obb5;
public OBB obbTurret; public OBB obbTurret;
public OBB obbTurret2; public OBB obbTurret2;
@ -98,6 +99,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.obb2 = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.59375f, 0.65625f), new Quaternionf(), OBB.Part.BODY); this.obb2 = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.59375f, 0.65625f), new Quaternionf(), OBB.Part.BODY);
this.obb3 = new OBB(this.position().toVector3f(), new Vector3f(0.625f, 0.84375f, 3.875f), new Quaternionf(), OBB.Part.WHEEL_LEFT); this.obb3 = new OBB(this.position().toVector3f(), new Vector3f(0.625f, 0.84375f, 3.875f), new Quaternionf(), OBB.Part.WHEEL_LEFT);
this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.625f, 0.84375f, 3.875f), new Quaternionf(), OBB.Part.WHEEL_RIGHT); this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.625f, 0.84375f, 3.875f), new Quaternionf(), OBB.Part.WHEEL_RIGHT);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(2.0625f, 0.59375f, 0.625f), new Quaternionf(), OBB.Part.ENGINE);
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.5625f, 2.1875f), new Quaternionf(), OBB.Part.TURRET); this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(2.375f, 0.5625f, 2.1875f), new Quaternionf(), OBB.Part.TURRET);
this.obbTurret2 = new OBB(this.position().toVector3f(), new Vector3f(1.625f, 0.40625f, 0.59375f), new Quaternionf(), OBB.Part.TURRET); this.obbTurret2 = new OBB(this.position().toVector3f(), new Vector3f(1.625f, 0.40625f, 0.59375f), new Quaternionf(), OBB.Part.TURRET);
} }
@ -331,34 +333,6 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.refreshDimensions(); this.refreshDimensions();
} }
@Override
public void partDamaged() {
if (entityData.get(TURRET_HEALTH) < 0) {
entityData.set(TURRET_DAMAGED, true);
}
if (entityData.get(TURRET_HEALTH) > 80) {
entityData.set(TURRET_DAMAGED, false);
}
if (entityData.get(L_WHEEL_HEALTH) < 0) {
entityData.set(L_WHEEL_DAMAGED, true);
}
if (entityData.get(L_WHEEL_HEALTH) > 80) {
entityData.set(L_WHEEL_DAMAGED, false);
}
if (entityData.get(R_WHEEL_HEALTH) < 0) {
entityData.set(R_WHEEL_DAMAGED, true);
}
if (entityData.get(R_WHEEL_HEALTH) > 80) {
entityData.set(R_WHEEL_DAMAGED, false);
}
entityData.set(TURRET_HEALTH, Math.min(entityData.get(TURRET_HEALTH) + 0.5f, 100));
entityData.set(L_WHEEL_HEALTH, Math.min(entityData.get(L_WHEEL_HEALTH) + 0.5f, 100));
entityData.set(R_WHEEL_HEALTH, Math.min(entityData.get(R_WHEEL_HEALTH) + 0.5f, 100));
}
@Override @Override
public void terrainCompact(float w, float l) { public void terrainCompact(float w, float l) {
if (onGround()) { if (onGround()) {
@ -764,6 +738,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
i = 0; i = 0;
} }
if (entityData.get(ENGINE_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.875f);
}
this.setYRot((float) (this.getYRot() - (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT) - i * s0)); this.setYRot((float) (this.getYRot() - (isInWater() && !onGround() ? 2.5 : 6) * entityData.get(DELTA_ROT) - i * s0));
if (this.isInWater() || onGround()) { if (this.isInWater() || onGround()) {
float power = this.entityData.get(POWER) * Mth.clamp(1 + (s0 > 0 ? 1 : -1) * getXRot() / 35, 0, 2); float power = this.entityData.get(POWER) * Mth.clamp(1 + (s0 > 0 ? 1 : -1) * getXRot() / 35, 0, 2);
@ -1328,21 +1306,24 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
return Mod.loc("textures/gui/vehicle/type/land.png"); return Mod.loc("textures/gui/vehicle/type/land.png");
} }
@Override
public float getTurretMaxHealth() { public float getTurretMaxHealth() {
return 100; return 100;
} }
public float getLeftWheelMaxHealth() { @Override
public float getWheelMaxHealth() {
return 100; return 100;
} }
public float getRightWheelMaxHealth() { @Override
public float getEngineMaxHealth() {
return 100; return 100;
} }
@Override @Override
public List<OBB> getOBBs() { public List<OBB> getOBBs() {
return List.of(this.obb, this.obb2, this.obb3, this.obb4, this.obbTurret, this.obbTurret2); return List.of(this.obb, this.obb2, this.obb3, this.obb4, this.obb5, this.obbTurret, this.obbTurret2);
} }
@Override @Override
@ -1365,6 +1346,10 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
this.obb4.center().set(new Vector3f(worldPosition4.x, worldPosition4.y, worldPosition4.z)); this.obb4.center().set(new Vector3f(worldPosition4.x, worldPosition4.y, worldPosition4.z));
this.obb4.setRotation(VectorTool.combineRotations(1, this)); this.obb4.setRotation(VectorTool.combineRotations(1, this));
Vector4f worldPosition5 = transformPosition(transform, 0, 1.65625f, -3.9375f);
this.obb5.center().set(new Vector3f(worldPosition5.x, worldPosition5.y, worldPosition5.z));
this.obb5.setRotation(VectorTool.combineRotations(1, this));
Matrix4f transformT = getTurretTransform(1); Matrix4f transformT = getTurretTransform(1);
Vector4f worldPositionT = transformPosition(transformT, 0, 0.5625f, -1.125f); Vector4f worldPositionT = transformPosition(transformT, 0, 0.5625f, -1.125f);

View file

@ -76,7 +76,6 @@ import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit; import static com.atsuishio.superbwarfare.client.RenderHelper.preciseBlit;
import static com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity.getPlayer;
import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle;
public abstract class VehicleEntity extends Entity { public abstract class VehicleEntity extends Entity {
@ -93,10 +92,12 @@ public abstract class VehicleEntity extends Entity {
public static final EntityDataAccessor<Float> TURRET_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> TURRET_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> L_WHEEL_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> L_WHEEL_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> R_WHEEL_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT); public static final EntityDataAccessor<Float> R_WHEEL_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Float> ENGINE_HEALTH = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.FLOAT);
public static final EntityDataAccessor<Boolean> TURRET_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> TURRET_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> L_WHEEL_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> L_WHEEL_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> R_WHEEL_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN); public static final EntityDataAccessor<Boolean> R_WHEEL_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> ENGINE_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public VehicleWeapon[][] availableWeapons; public VehicleWeapon[][] availableWeapons;
@ -309,11 +310,13 @@ public abstract class VehicleEntity extends Entity {
.define(MOUSE_SPEED_Y, 0f) .define(MOUSE_SPEED_Y, 0f)
.define(HEAT, 0) .define(HEAT, 0)
.define(TURRET_HEALTH, getTurretMaxHealth()) .define(TURRET_HEALTH, getTurretMaxHealth())
.define(L_WHEEL_HEALTH, getLeftWheelMaxHealth()) .define(L_WHEEL_HEALTH, getWheelMaxHealth())
.define(R_WHEEL_HEALTH, getRightWheelMaxHealth()) .define(R_WHEEL_HEALTH, getWheelMaxHealth())
.define(ENGINE_HEALTH, getEngineMaxHealth())
.define(TURRET_DAMAGED, false) .define(TURRET_DAMAGED, false)
.define(L_WHEEL_DAMAGED, false) .define(L_WHEEL_DAMAGED, false)
.define(R_WHEEL_DAMAGED, false) .define(R_WHEEL_DAMAGED, false)
.define(ENGINE_DAMAGED, false)
.define(SELECTED_WEAPON, IntList.of(new int[this.getMaxPassengers()])); .define(SELECTED_WEAPON, IntList.of(new int[this.getMaxPassengers()]));
// 怎么还不给玩动态注册了 // 怎么还不给玩动态注册了
} }
@ -339,10 +342,12 @@ public abstract class VehicleEntity extends Entity {
this.entityData.set(TURRET_HEALTH, compound.getFloat("TurretHealth")); this.entityData.set(TURRET_HEALTH, compound.getFloat("TurretHealth"));
this.entityData.set(L_WHEEL_HEALTH, compound.getFloat("LeftWheelHealth")); this.entityData.set(L_WHEEL_HEALTH, compound.getFloat("LeftWheelHealth"));
this.entityData.set(R_WHEEL_HEALTH, compound.getFloat("RightWheelHealth")); this.entityData.set(R_WHEEL_HEALTH, compound.getFloat("RightWheelHealth"));
this.entityData.set(ENGINE_HEALTH, compound.getFloat("EngineHealth"));
this.entityData.set(TURRET_DAMAGED, compound.getBoolean("TurretDamaged")); this.entityData.set(TURRET_DAMAGED, compound.getBoolean("TurretDamaged"));
this.entityData.set(L_WHEEL_DAMAGED, compound.getBoolean("LeftDamaged")); this.entityData.set(L_WHEEL_DAMAGED, compound.getBoolean("LeftDamaged"));
this.entityData.set(R_WHEEL_DAMAGED, compound.getBoolean("RightDamaged")); this.entityData.set(R_WHEEL_DAMAGED, compound.getBoolean("RightDamaged"));
this.entityData.set(ENGINE_DAMAGED, compound.getBoolean("EngineDamaged"));
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) { if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
var selected = compound.getIntArray("SelectedWeapon"); var selected = compound.getIntArray("SelectedWeapon");
@ -365,10 +370,12 @@ public abstract class VehicleEntity extends Entity {
compound.putFloat("TurretHealth", this.entityData.get(TURRET_HEALTH)); compound.putFloat("TurretHealth", this.entityData.get(TURRET_HEALTH));
compound.putFloat("LeftWheelHealth", this.entityData.get(L_WHEEL_HEALTH)); compound.putFloat("LeftWheelHealth", this.entityData.get(L_WHEEL_HEALTH));
compound.putFloat("RightWheelHealth", this.entityData.get(R_WHEEL_HEALTH)); compound.putFloat("RightWheelHealth", this.entityData.get(R_WHEEL_HEALTH));
compound.putFloat("EngineHealth", this.entityData.get(ENGINE_HEALTH));
compound.putBoolean("TurretDamaged", this.entityData.get(TURRET_DAMAGED)); compound.putBoolean("TurretDamaged", this.entityData.get(TURRET_DAMAGED));
compound.putBoolean("LeftWheelDamaged", this.entityData.get(L_WHEEL_DAMAGED)); compound.putBoolean("LeftWheelDamaged", this.entityData.get(L_WHEEL_DAMAGED));
compound.putBoolean("RightWheelDamaged", this.entityData.get(R_WHEEL_DAMAGED)); compound.putBoolean("RightWheelDamaged", this.entityData.get(R_WHEEL_DAMAGED));
compound.putBoolean("EngineDamaged", this.entityData.get(ENGINE_DAMAGED));
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) { if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
compound.putIntArray("SelectedWeapon", this.entityData.get(SELECTED_WEAPON)); compound.putIntArray("SelectedWeapon", this.entityData.get(SELECTED_WEAPON));
@ -479,6 +486,10 @@ public abstract class VehicleEntity extends Entity {
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.WHEEL_RIGHT) { if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.WHEEL_RIGHT) {
entityData.set(R_WHEEL_HEALTH, entityData.get(R_WHEEL_HEALTH) - computedAmount); entityData.set(R_WHEEL_HEALTH, entityData.get(R_WHEEL_HEALTH) - computedAmount);
} }
//引擎损伤
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.ENGINE) {
entityData.set(ENGINE_HEALTH, entityData.get(ENGINE_HEALTH) - computedAmount);
}
// System.out.println(accessor.sbw$getCurrentHitPart()); // System.out.println(accessor.sbw$getCurrentHitPart());
} }
@ -551,11 +562,12 @@ public abstract class VehicleEntity extends Entity {
return 50; return 50;
} }
public float getLeftWheelMaxHealth() { public float getWheelMaxHealth() {
return 50; return 50;
} }
public float getRightWheelMaxHealth() {
public float getEngineMaxHealth() {
return 50; return 50;
} }
@ -696,6 +708,15 @@ public abstract class VehicleEntity extends Entity {
// 炮塔损毁特效 // 炮塔损毁特效
turretDamagedEffect(); turretDamagedEffect();
// 引擎损毁特效
engineDamagedEffect();
// 左轮损毁特效
leftWheelDamagedEffect();
// 右轮损毁特效
rightWheelDamagedEffect();
//部件血量 //部件血量
partDamaged(); partDamaged();
@ -706,43 +727,87 @@ public abstract class VehicleEntity extends Entity {
if (entityData.get(TURRET_HEALTH) < 0) { if (entityData.get(TURRET_HEALTH) < 0) {
entityData.set(TURRET_DAMAGED, true); entityData.set(TURRET_DAMAGED, true);
} }
if (entityData.get(TURRET_HEALTH) > 40) { if (entityData.get(TURRET_HEALTH) > 0.8 * getTurretMaxHealth()) {
entityData.set(TURRET_DAMAGED, false); entityData.set(TURRET_DAMAGED, false);
} }
if (entityData.get(L_WHEEL_HEALTH) < 0) { if (entityData.get(L_WHEEL_HEALTH) < 0) {
entityData.set(L_WHEEL_DAMAGED, true); entityData.set(L_WHEEL_DAMAGED, true);
} }
if (entityData.get(L_WHEEL_HEALTH) > 40) { if (entityData.get(L_WHEEL_HEALTH) > 0.8 * getWheelMaxHealth()) {
entityData.set(L_WHEEL_DAMAGED, false); entityData.set(L_WHEEL_DAMAGED, false);
} }
if (entityData.get(R_WHEEL_HEALTH) < 0) { if (entityData.get(R_WHEEL_HEALTH) < 0) {
entityData.set(R_WHEEL_DAMAGED, true); entityData.set(R_WHEEL_DAMAGED, true);
} }
if (entityData.get(R_WHEEL_HEALTH) > 40) { if (entityData.get(R_WHEEL_HEALTH) > 0.8 * getWheelMaxHealth()) {
entityData.set(R_WHEEL_DAMAGED, false); entityData.set(R_WHEEL_DAMAGED, false);
} }
entityData.set(TURRET_HEALTH, Math.min(entityData.get(TURRET_HEALTH) + 0.25f, 50)); if (entityData.get(ENGINE_HEALTH) < 0) {
entityData.set(L_WHEEL_HEALTH, Math.min(entityData.get(L_WHEEL_HEALTH) + 0.25f, 50)); entityData.set(ENGINE_DAMAGED, true);
entityData.set(R_WHEEL_HEALTH, Math.min(entityData.get(R_WHEEL_HEALTH) + 0.25f, 50)); }
if (entityData.get(ENGINE_HEALTH) > 0.8 * getEngineMaxHealth()) {
entityData.set(ENGINE_DAMAGED, false);
}
entityData.set(TURRET_HEALTH, Math.min(entityData.get(TURRET_HEALTH) + 0.003f * getTurretMaxHealth(), getTurretMaxHealth()));
entityData.set(L_WHEEL_HEALTH, Math.min(entityData.get(L_WHEEL_HEALTH) + 0.003f * getWheelMaxHealth(), getWheelMaxHealth()));
entityData.set(R_WHEEL_HEALTH, Math.min(entityData.get(R_WHEEL_HEALTH) + 0.003f * getWheelMaxHealth(), getWheelMaxHealth()));
entityData.set(ENGINE_HEALTH, Math.min(entityData.get(ENGINE_HEALTH) + 0.003f * getEngineMaxHealth(), getEngineMaxHealth()));
} }
public void turretDamagedEffect() { public void turretDamagedEffect() {
if (entityData.get(TURRET_DAMAGED)) { if (entityData.get(TURRET_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
List<Entity> entities = getPlayer(level()); var obbList = obbEntity.getOBBs();
for (var e : entities) { for (var obb : obbList) {
if (e instanceof ServerPlayer player) { if (obb.part() == OBB.Part.TURRET) {
if (player.level() instanceof ServerLevel serverLevel) { Vec3 pos = new Vec3(obb.center());
Matrix4f transformT = getTurretTransform(1); sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
Vector4f worldPositionT = transformPosition(transformT, 0, 0.5f, 0f); sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 1, 1, 0.5, 1, 0.01, true);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), worldPositionT.x, worldPositionT.y, worldPositionT.z, 5, 0.25, 0.25, 0.25, 0.25, true);
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, worldPositionT.x, worldPositionT.y, worldPositionT.z, 1, 1, 0.5, 1, 0.01, true);
} }
} }
} }
} }
public void engineDamagedEffect() {
if (entityData.get(ENGINE_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.ENGINE) {
Vec3 pos = new Vec3(obb.center());
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 1, 1, 0.5, 1, 0.01, true);
}
}
}
}
public void leftWheelDamagedEffect() {
if (entityData.get(L_WHEEL_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.WHEEL_LEFT) {
Vec3 pos = new Vec3(obb.center());
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 1, 1, 0.5, 1, 0.01, true);
}
}
}
}
public void rightWheelDamagedEffect() {
if (entityData.get(R_WHEEL_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.WHEEL_RIGHT) {
Vec3 pos = new Vec3(obb.center());
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 1, 1, 0.5, 1, 0.01, true);
}
}
}
} }
public void clearArrow() { public void clearArrow() {