调整部件损伤效果方法

This commit is contained in:
17146 2025-06-22 23:43:19 +08:00 committed by Light_Quanta
parent 1f72f49e30
commit 16807dda03
No known key found for this signature in database
GPG key ID: 11A39A1B8C890959
9 changed files with 118 additions and 169 deletions

View file

@ -224,7 +224,7 @@ public class VehicleHudOverlay implements LayeredDraw.Layer {
//引擎
ResourceLocation engine;
if (mobileVehicle.getEntityData().get(ENGINE_DAMAGED)) {
if (mobileVehicle.getEntityData().get(ENGINE1_DAMAGED)) {
engine = Mod.loc("textures/screens/land/engine_damaged.png");
} else {
engine = Mod.loc("textures/screens/land/engine.png");

View file

@ -105,8 +105,8 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(0.0625f, 1.09375f, 0.84375f), new Quaternionf(), OBB.Part.BODY);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(0.625f, 0.78125f, 1.09375f), new Quaternionf(), OBB.Part.BODY);
this.obb7 = new OBB(this.position().toVector3f(), new Vector3f(0.6875f, 0.75f, 2.9375f), new Quaternionf(), OBB.Part.BODY);
this.obb8 = new OBB(this.position().toVector3f(), new Vector3f(0.75f, 0.75f, 1.5625f), new Quaternionf(), OBB.Part.ENGINE);
this.obb9 = new OBB(this.position().toVector3f(), new Vector3f(0.75f, 0.75f, 1.5625f), new Quaternionf(), OBB.Part.ENGINE_LEFT);
this.obb8 = new OBB(this.position().toVector3f(), new Vector3f(0.75f, 0.75f, 1.5625f), new Quaternionf(), OBB.Part.ENGINE1);
this.obb9 = new OBB(this.position().toVector3f(), new Vector3f(0.75f, 0.75f, 1.5625f), new Quaternionf(), OBB.Part.ENGINE2);
this.obb10 = new OBB(this.position().toVector3f(), new Vector3f(0.34375f, 0.359375f, 1.78125f), new Quaternionf(), OBB.Part.BODY);
this.obb11 = new OBB(this.position().toVector3f(), new Vector3f(0.34375f, 0.359375f, 1.78125f), new Quaternionf(), OBB.Part.BODY);
}
@ -274,36 +274,21 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
releaseDecoy();
this.refreshDimensions();
}
@Override
public void engineDamagedEffect() {
if (entityData.get(ENGINE_DAMAGED) && level() instanceof ServerLevel serverLevel) {
var obbList = this.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.ENGINE) {
Vec3 position = new Vec3(obb.center());
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.FLAME, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0.25, true);
}
}
}
public void onEngine1Damaged(Vec3 pos, ServerLevel serverLevel) {
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.FLAME, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
}
@Override
public void leftEngineDamagedEffect() {
if (entityData.get(L_ENGINE_DAMAGED) && level() instanceof ServerLevel serverLevel) {
var obbList = this.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.ENGINE_LEFT) {
Vec3 position = new Vec3(obb.center());
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.FLAME, position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), position.x, position.y, position.z, 5, 0.25, 0.25, 0.25, 0.25, true);
}
}
}
public void onEngine2Damaged(Vec3 pos, ServerLevel serverLevel) {
sendParticle(serverLevel, ParticleTypes.LARGE_SMOKE, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.CAMPFIRE_COSY_SMOKE, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ParticleTypes.FLAME, pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0, true);
sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), pos.x, pos.y, pos.z, 5, 0.25, 0.25, 0.25, 0.25, true);
}
public void terrainCompactA10() {
@ -576,11 +561,11 @@ public class A10Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.entityData.set(DELTA_ROT, this.entityData.get(DELTA_ROT) * 0.85f);
this.entityData.set(PLANE_BREAK, this.entityData.get(PLANE_BREAK) * 0.8f);
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.96f);
}
if (entityData.get(L_ENGINE_DAMAGED)) {
if (entityData.get(ENGINE2_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.96f);
}

View file

@ -88,8 +88,8 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
this.obb3 = new OBB(this.position().toVector3f(), new Vector3f(0.25f, 0.3125f, 2.25f), new Quaternionf(), OBB.Part.BODY);
this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.0625f, 1.15625f, 0.40625f), new Quaternionf(), OBB.Part.BODY);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(1f, 0.25f, 0.21875f), new Quaternionf(), OBB.Part.BODY);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(0.3125f, 0.40625f, 0.84375f), new Quaternionf(), OBB.Part.ENGINE);
this.obb7 = new OBB(this.position().toVector3f(), new Vector3f(0.3125f, 0.40625f, 0.40625f), new Quaternionf(), OBB.Part.ENGINE_LEFT);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(0.3125f, 0.40625f, 0.84375f), new Quaternionf(), OBB.Part.ENGINE1);
this.obb7 = new OBB(this.position().toVector3f(), new Vector3f(0.3125f, 0.40625f, 0.40625f), new Quaternionf(), OBB.Part.ENGINE2);
}
@Override
@ -267,7 +267,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
}
delta_x = ((this.onGround()) ? 0 : 1.5f) * entityData.get(MOUSE_SPEED_Y) * this.entityData.get(PROPELLER_ROT);
delta_y = Mth.clamp((this.onGround() ? 0.1f : 2f) * entityData.get(MOUSE_SPEED_X) * this.entityData.get(PROPELLER_ROT) + (this.entityData.get(L_ENGINE_DAMAGED) ? 25 : 0) * this.entityData.get(PROPELLER_ROT), -10f, 10f);
delta_y = Mth.clamp((this.onGround() ? 0.1f : 2f) * entityData.get(MOUSE_SPEED_X) * this.entityData.get(PROPELLER_ROT) + (this.entityData.get(ENGINE2_DAMAGED) ? 25 : 0) * this.entityData.get(PROPELLER_ROT), -10f, 10f);
this.setYRot(this.getYRot() + delta_y);
this.setXRot(this.getXRot() + delta_x);
@ -335,7 +335,7 @@ public class Ah6Entity extends ContainerMobileVehicleEntity implements GeoEntity
setDeltaMovement(getDeltaMovement().add(0, -destroyRot * 0.004, 0));
}
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.98f);
}

View file

@ -85,7 +85,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
this.obb2 = new OBB(this.position().toVector3f(), new Vector3f(2.1875f, 0.5f, 0.65625f), new Quaternionf(), OBB.Part.BODY);
this.obb3 = new OBB(this.position().toVector3f(), new Vector3f(0.375f, 0.78125f, 3.46875f), new Quaternionf(), OBB.Part.WHEEL_LEFT);
this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.375f, 0.78125f, 3.46875f), new Quaternionf(), OBB.Part.WHEEL_RIGHT);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(1.15625f, 0.375f, 1.125f), new Quaternionf(), OBB.Part.ENGINE);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(1.15625f, 0.375f, 1.125f), new Quaternionf(), OBB.Part.ENGINE1);
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(1.5f, 0.34375f, 1.5f), new Quaternionf(), OBB.Part.TURRET);
}
@ -461,7 +461,7 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit
i = 0;
}
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.85f);
}

View file

@ -77,7 +77,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(1.3125f, 0.90625f, 2.4375f), new Quaternionf(), OBB.Part.BODY);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(1.3125f, 0.53125f, 0.34375f), new Quaternionf(), OBB.Part.BODY);
this.obb7 = new OBB(this.position().toVector3f(), new Vector3f(1.3125f, 0.625f, 0.53125f), new Quaternionf(), OBB.Part.BODY);
this.obb8 = new OBB(this.position().toVector3f(), new Vector3f(0.71875f, 0.46875f, 0.875f), new Quaternionf(), OBB.Part.ENGINE);
this.obb8 = new OBB(this.position().toVector3f(), new Vector3f(0.71875f, 0.46875f, 0.875f), new Quaternionf(), OBB.Part.ENGINE1);
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(0.875f, 0.3625f, 1.25f), new Quaternionf(), OBB.Part.TURRET);
}
@ -343,7 +343,7 @@ public class Lav150Entity extends ContainerMobileVehicleEntity implements GeoEnt
i = 0;
}
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.875f);
}

View file

@ -95,7 +95,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo
this.obb3 = new OBB(this.position().toVector3f(), new Vector3f(0.46875f, 0.78125f, 3.3125f), new Quaternionf(), OBB.Part.WHEEL_LEFT);
this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.46875f, 0.78125f, 3.3125f), new Quaternionf(), OBB.Part.WHEEL_RIGHT);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(1.375f, 0.28125f, 1.375f), new Quaternionf(), OBB.Part.BODY);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(2.0625f, 0.78125f, 0.8125f), new Quaternionf(), OBB.Part.ENGINE);
this.obb6 = new OBB(this.position().toVector3f(), new Vector3f(2.0625f, 0.78125f, 0.8125f), new Quaternionf(), OBB.Part.ENGINE1);
this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(0.4375f, 0.90625f, 1.21875f), new Quaternionf(), OBB.Part.TURRET);
}
@ -525,7 +525,7 @@ public class PrismTankEntity extends ContainerMobileVehicleEntity implements Geo
i = 0;
}
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.85f);
}

View file

@ -99,7 +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.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.obb5 = new OBB(this.position().toVector3f(), new Vector3f(2.0625f, 0.59375f, 0.625f), new Quaternionf(), OBB.Part.ENGINE);
this.obb5 = new OBB(this.position().toVector3f(), new Vector3f(2.0625f, 0.59375f, 0.625f), new Quaternionf(), OBB.Part.ENGINE1);
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);
}
@ -738,7 +738,7 @@ public class Yx100Entity extends ContainerMobileVehicleEntity implements GeoEnti
i = 0;
}
if (entityData.get(ENGINE_DAMAGED)) {
if (entityData.get(ENGINE1_DAMAGED)) {
this.entityData.set(POWER, this.entityData.get(POWER) * 0.85f);
}

View file

@ -11,7 +11,6 @@ import com.atsuishio.superbwarfare.init.*;
import com.atsuishio.superbwarfare.item.ContainerBlockItem;
import com.atsuishio.superbwarfare.network.message.receive.ClientIndicatorMessage;
import com.atsuishio.superbwarfare.tools.EntityFindUtil;
import com.atsuishio.superbwarfare.tools.OBB;
import com.atsuishio.superbwarfare.tools.ParticleTool;
import com.atsuishio.superbwarfare.tools.VectorTool;
import com.google.common.collect.ImmutableList;
@ -98,8 +97,8 @@ public abstract class VehicleEntity extends Entity {
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> R_WHEEL_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> ENGINE_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> L_ENGINE_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> ENGINE1_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public static final EntityDataAccessor<Boolean> ENGINE2_DAMAGED = SynchedEntityData.defineId(VehicleEntity.class, EntityDataSerializers.BOOLEAN);
public VehicleWeapon[][] availableWeapons;
@ -128,7 +127,6 @@ public abstract class VehicleEntity extends Entity {
public boolean cannotFire;
public void mouseInput(double x, double y) {
entityData.set(MOUSE_SPEED_X, (float) x);
entityData.set(MOUSE_SPEED_Y, (float) y);
@ -311,16 +309,19 @@ public abstract class VehicleEntity extends Entity {
.define(MOUSE_SPEED_X, 0f)
.define(MOUSE_SPEED_Y, 0f)
.define(HEAT, 0)
.define(TURRET_HEALTH, getTurretMaxHealth())
.define(L_WHEEL_HEALTH, getWheelMaxHealth())
.define(R_WHEEL_HEALTH, getWheelMaxHealth())
.define(ENGINE_HEALTH, getEngineMaxHealth())
.define(L_ENGINE_HEALTH, getEngineMaxHealth())
.define(TURRET_DAMAGED, false)
.define(L_WHEEL_DAMAGED, false)
.define(R_WHEEL_DAMAGED, false)
.define(ENGINE_DAMAGED, false)
.define(L_ENGINE_DAMAGED, false)
.define(ENGINE1_DAMAGED, false)
.define(ENGINE2_DAMAGED, false)
// 怎么还不给玩动态注册了
.define(SELECTED_WEAPON, IntList.of(new int[this.getMaxPassengers()]));
}
@ -352,8 +353,8 @@ public abstract class VehicleEntity extends Entity {
this.entityData.set(TURRET_DAMAGED, compound.getBoolean("TurretDamaged"));
this.entityData.set(L_WHEEL_DAMAGED, compound.getBoolean("LeftDamaged"));
this.entityData.set(R_WHEEL_DAMAGED, compound.getBoolean("RightDamaged"));
this.entityData.set(ENGINE_DAMAGED, compound.getBoolean("EngineDamaged"));
this.entityData.set(L_ENGINE_DAMAGED, compound.getBoolean("LeftEngineDamaged"));
this.entityData.set(ENGINE1_DAMAGED, compound.getBoolean("Engine1Damaged"));
this.entityData.set(ENGINE2_DAMAGED, compound.getBoolean("Engine2Damaged"));
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
var selected = compound.getIntArray("SelectedWeapon");
@ -382,8 +383,8 @@ public abstract class VehicleEntity extends Entity {
compound.putBoolean("TurretDamaged", this.entityData.get(TURRET_DAMAGED));
compound.putBoolean("LeftWheelDamaged", this.entityData.get(L_WHEEL_DAMAGED));
compound.putBoolean("RightWheelDamaged", this.entityData.get(R_WHEEL_DAMAGED));
compound.putBoolean("EngineDamaged", this.entityData.get(ENGINE_DAMAGED));
compound.putBoolean("LeftEngineDamaged", this.entityData.get(L_ENGINE_DAMAGED));
compound.putBoolean("Engine1Damaged", this.entityData.get(ENGINE1_DAMAGED));
compound.putBoolean("Engine2Damaged", this.entityData.get(ENGINE2_DAMAGED));
if (this instanceof WeaponVehicleEntity weaponVehicle && weaponVehicle.getAllWeapons().length > 0) {
compound.putIntArray("SelectedWeapon", this.entityData.get(SELECTED_WEAPON));
@ -479,30 +480,16 @@ public abstract class VehicleEntity extends Entity {
repairCoolDown = maxRepairCoolDown();
}
// TODO 这里可以获取击中的部位给需要的载具加一个部位受伤方法
if (source.getDirectEntity() instanceof Projectile projectile) {
if (source.getDirectEntity() instanceof Projectile projectile && this instanceof OBBEntity) {
OBBHitter accessor = OBBHitter.getInstance(projectile);
//炮塔损伤
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.TURRET) {
entityData.set(TURRET_HEALTH, entityData.get(TURRET_HEALTH) - computedAmount);
var part = accessor.sbw$getCurrentHitPart();
switch (part) {
case TURRET -> entityData.set(TURRET_HEALTH, entityData.get(TURRET_HEALTH) - computedAmount);
case WHEEL_LEFT -> entityData.set(L_WHEEL_HEALTH, entityData.get(L_WHEEL_HEALTH) - computedAmount);
case WHEEL_RIGHT -> entityData.set(R_WHEEL_HEALTH, entityData.get(R_WHEEL_HEALTH) - computedAmount);
case ENGINE1 -> entityData.set(ENGINE_HEALTH, entityData.get(ENGINE_HEALTH) - computedAmount);
case ENGINE2 -> entityData.set(L_ENGINE_HEALTH, entityData.get(L_ENGINE_HEALTH) - computedAmount);
}
//左轮损伤
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.WHEEL_LEFT) {
entityData.set(L_WHEEL_HEALTH, entityData.get(L_WHEEL_HEALTH) - computedAmount);
}
//右轮损伤
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.WHEEL_RIGHT) {
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);
}
if (this instanceof OBBEntity && accessor.sbw$getCurrentHitPart() == OBB.Part.ENGINE_LEFT) {
entityData.set(L_ENGINE_HEALTH, entityData.get(L_ENGINE_HEALTH) - computedAmount);
}
// System.out.println(accessor.sbw$getCurrentHitPart());
}
this.onHurt(computedAmount, source.getEntity(), true);
@ -578,7 +565,6 @@ public abstract class VehicleEntity extends Entity {
return 50;
}
public float getEngineMaxHealth() {
return 50;
}
@ -690,13 +676,13 @@ public abstract class VehicleEntity extends Entity {
prevRoll = deltaZ + getRoll();
}
handleClientSync();
this.handleClientSync();
if (this.level() instanceof ServerLevel && this.getHealth() <= 0) {
destroy();
}
travel();
this.travel();
Entity attacker = EntityFindUtil.findEntity(this.level(), this.entityData.get(LAST_ATTACKER_UUID));
@ -715,61 +701,83 @@ public abstract class VehicleEntity extends Entity {
this.entityData.set(LAST_DRIVER_UUID, getFirstPassenger().getStringUUID());
}
clearArrow();
this.clearArrow();
// 炮塔损毁特效
turretDamagedEffect();
if (this instanceof OBBEntity obbEntity) {
if (this.level() instanceof ServerLevel serverLevel) {
this.handlePartDamaged(obbEntity, serverLevel);
}
// 引擎损毁特效
engineDamagedEffect();
leftEngineDamagedEffect();
// 左轮损毁特效
leftWheelDamagedEffect();
// 右轮损毁特效
rightWheelDamagedEffect();
//部件血量
partDamaged();
// 处理部件血量
this.handlePartHealth();
}
this.refreshDimensions();
}
public void partDamaged() {
public void handlePartDamaged(OBBEntity obbEntity, ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
Vec3 pos = new Vec3(obb.center());
switch (obb.part()) {
case TURRET -> {
if (entityData.get(TURRET_DAMAGED)) {
this.onTurretDamaged(pos, serverLevel);
}
}
case WHEEL_LEFT -> {
if (entityData.get(L_WHEEL_DAMAGED)) {
this.onLeftWheelDamaged(pos, serverLevel);
}
}
case WHEEL_RIGHT -> {
if (entityData.get(R_WHEEL_DAMAGED)) {
this.onRightWheelDamaged(pos, serverLevel);
}
}
case ENGINE1 -> {
if (entityData.get(ENGINE1_DAMAGED)) {
this.onEngine1Damaged(pos, serverLevel);
}
}
case ENGINE2 -> {
if (entityData.get(ENGINE2_DAMAGED)) {
this.onEngine2Damaged(pos, serverLevel);
}
}
}
}
}
public void handlePartHealth() {
if (entityData.get(TURRET_HEALTH) < 0) {
entityData.set(TURRET_DAMAGED, true);
}
if (entityData.get(TURRET_HEALTH) > 0.95 * getTurretMaxHealth()) {
} else if (entityData.get(TURRET_HEALTH) > 0.95 * getTurretMaxHealth()) {
entityData.set(TURRET_DAMAGED, false);
}
if (entityData.get(L_WHEEL_HEALTH) < 0) {
entityData.set(L_WHEEL_DAMAGED, true);
}
if (entityData.get(L_WHEEL_HEALTH) > 0.95 * getWheelMaxHealth()) {
} else if (entityData.get(L_WHEEL_HEALTH) > 0.95 * getWheelMaxHealth()) {
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) > 0.95 * getWheelMaxHealth()) {
} else if (entityData.get(R_WHEEL_HEALTH) > 0.95 * getWheelMaxHealth()) {
entityData.set(R_WHEEL_DAMAGED, false);
}
if (entityData.get(ENGINE_HEALTH) < 0) {
entityData.set(ENGINE_DAMAGED, true);
}
if (entityData.get(ENGINE_HEALTH) > 0.95 * getEngineMaxHealth()) {
entityData.set(ENGINE_DAMAGED, false);
entityData.set(ENGINE1_DAMAGED, true);
} else if (entityData.get(ENGINE_HEALTH) > 0.95 * getEngineMaxHealth()) {
entityData.set(ENGINE1_DAMAGED, false);
}
if (entityData.get(L_ENGINE_HEALTH) < 0) {
entityData.set(L_ENGINE_DAMAGED, true);
}
if (entityData.get(L_ENGINE_HEALTH) > 0.95 * getEngineMaxHealth()) {
entityData.set(L_ENGINE_DAMAGED, false);
entityData.set(ENGINE2_DAMAGED, true);
} else if (entityData.get(L_ENGINE_HEALTH) > 0.95 * getEngineMaxHealth()) {
entityData.set(ENGINE2_DAMAGED, false);
}
entityData.set(TURRET_HEALTH, Math.min(entityData.get(TURRET_HEALTH) + 0.0025f * getTurretMaxHealth(), getTurretMaxHealth()));
@ -779,69 +787,29 @@ public abstract class VehicleEntity extends Entity {
entityData.set(L_ENGINE_HEALTH, Math.min(entityData.get(L_ENGINE_HEALTH) + 0.0025f * getEngineMaxHealth(), getEngineMaxHealth()));
}
public void turretDamagedEffect() {
if (entityData.get(TURRET_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.TURRET) {
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 defaultPartDamageEffect(Vec3 pos, ServerLevel serverLevel) {
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 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 onTurretDamaged(Vec3 pos, ServerLevel serverLevel) {
this.defaultPartDamageEffect(pos, serverLevel);
}
public void leftEngineDamagedEffect() {
if (entityData.get(L_ENGINE_DAMAGED) && this instanceof OBBEntity obbEntity && level() instanceof ServerLevel serverLevel) {
var obbList = obbEntity.getOBBs();
for (var obb : obbList) {
if (obb.part() == OBB.Part.ENGINE_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 onLeftWheelDamaged(Vec3 pos, ServerLevel serverLevel) {
this.defaultPartDamageEffect(pos, serverLevel);
}
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 onRightWheelDamaged(Vec3 pos, ServerLevel serverLevel) {
this.defaultPartDamageEffect(pos, serverLevel);
}
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 onEngine1Damaged(Vec3 pos, ServerLevel serverLevel) {
this.defaultPartDamageEffect(pos, serverLevel);
}
public void onEngine2Damaged(Vec3 pos, ServerLevel serverLevel) {
this.defaultPartDamageEffect(pos, serverLevel);
}
public void clearArrow() {

View file

@ -230,10 +230,6 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, Part
return new OBB(newCenter, extents, rotation, part);
}
public Part getPart(OBB obb) {
return obb.part;
}
/**
* 检查点是否在OBB内部
*
@ -447,8 +443,8 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, Part
WHEEL_LEFT,
WHEEL_RIGHT,
TURRET,
ENGINE,
ENGINE_LEFT,
ENGINE1,
ENGINE2,
BODY
}
}