diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java index 050936631..9f30298ed 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/vehicle/Bmp2Entity.java @@ -16,6 +16,7 @@ import com.atsuishio.superbwarfare.entity.vehicle.weapon.WgMissileWeapon; import com.atsuishio.superbwarfare.event.ClientMouseHandler; import com.atsuishio.superbwarfare.init.ModDamageTypes; import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModParticleTypes; import com.atsuishio.superbwarfare.init.ModSounds; import com.atsuishio.superbwarfare.network.message.receive.ShakeClientMessage; import com.atsuishio.superbwarfare.tools.*; @@ -32,6 +33,7 @@ import net.minecraft.network.syncher.EntityDataSerializers; import net.minecraft.network.syncher.SynchedEntityData; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; +import net.minecraft.server.level.ServerPlayer; import net.minecraft.sounds.SoundEvent; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; @@ -67,7 +69,10 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit public static final EntityDataAccessor CANNON_FIRE_TIME = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor LOADED_MISSILE = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT); public static final EntityDataAccessor MISSILE_COUNT = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.INT); + + public static final EntityDataAccessor TURRET_DAMAGED = SynchedEntityData.defineId(Bmp2Entity.class, EntityDataSerializers.BOOLEAN); private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this); + public int reloadCoolDown; public OBB obb; @@ -82,7 +87,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.BODY); this.obb4 = new OBB(this.position().toVector3f(), new Vector3f(0.375f, 0.78125f, 3.46875f), new Quaternionf(), OBB.Part.BODY); - this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(1.5f, 0.34375f, 1.5f), new Quaternionf(), OBB.Part.BODY); + this.obbTurret = new OBB(this.position().toVector3f(), new Vector3f(1.5f, 0.34375f, 1.5f), new Quaternionf(), OBB.Part.TURRET); } @Override @@ -130,7 +135,8 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit super.defineSynchedData(builder); builder.define(CANNON_FIRE_TIME, 0) .define(LOADED_MISSILE, 0) - .define(MISSILE_COUNT, 0); + .define(MISSILE_COUNT, 0) + .define(TURRET_DAMAGED, false); } @Override @@ -211,7 +217,22 @@ public class Bmp2Entity extends ContainerMobileVehicleEntity implements GeoEntit sendParticle(serverLevel, ParticleTypes.BUBBLE_COLUMN_UP, this.getX() + 0.5 * this.getDeltaMovement().x, this.getY() + getSubmergedHeight(this) - 0.2, this.getZ() + 0.5 * this.getDeltaMovement().z, (int) (2 + 10 * this.getDeltaMovement().length()), 0.65, 0, 0.65, 0, true); } - turretAngle(10, 12.5f); + if (entityData.get(TURRET_DAMAGED)) { + List entities = getPlayer(level()); + for (var e : entities) { + if (e instanceof ServerPlayer player) { + if (player.level() instanceof ServerLevel serverLevel) { + Matrix4f transformT = getTurretTransform(1); + Vector4f worldPositionT = transformPosition(transformT, 0, 0.56875f, 0f); + sendParticle(serverLevel, ModParticleTypes.FIRE_STAR.get(), worldPositionT.x, worldPositionT.y, worldPositionT.z, 5, 0.25, 0.25, 0.25, 0.2, true); + } + } + } + turretAngle(1, 1.25f); + } else { + turretAngle(10, 12.5f); + } + this.terrainCompact(4f, 5f); inertiaRotate(1); diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java index a2cf73d41..449e32e72 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/ProjectileUtilMixin.java @@ -1,8 +1,10 @@ package com.atsuishio.superbwarfare.mixins; import com.atsuishio.superbwarfare.entity.OBBEntity; +import com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity; import com.atsuishio.superbwarfare.init.ModParticleTypes; import com.atsuishio.superbwarfare.init.ModSounds; +import com.atsuishio.superbwarfare.tools.OBB; import net.minecraft.core.BlockPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; @@ -23,6 +25,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import java.util.Optional; import java.util.function.Predicate; +import static com.atsuishio.superbwarfare.entity.vehicle.Bmp2Entity.TURRET_DAMAGED; import static com.atsuishio.superbwarfare.tools.ParticleTool.sendParticle; @Mixin(ProjectileUtil.class) @@ -52,6 +55,9 @@ public class ProjectileUtilMixin { sendParticle(serverLevel, ParticleTypes.SMOKE, hitPos.x, hitPos.y, hitPos.z, 2, 0, 0, 0, 0.01, false); } } + if (obbEntity instanceof Bmp2Entity bmp2 && obb.part() == OBB.Part.TURRET) { + bmp2.getEntityData().set(TURRET_DAMAGED, true); + } } } } diff --git a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java index e968754a7..9374fc8d9 100644 --- a/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java +++ b/src/main/java/com/atsuishio/superbwarfare/tools/OBB.java @@ -227,6 +227,10 @@ 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内部 * @@ -253,7 +257,8 @@ public record OBB(Vector3f center, Vector3f extents, Quaternionf rotation, Part } public enum Part { - WHEEL(), + WHEEL_LEFT(), + WHEEL_RIGHT(), TURRET(), ENGINE(), BODY();