From 1e1b58ffba80a0904154d7e43f43b1017f016cde Mon Sep 17 00:00:00 2001 From: 17146 <1714673995@qq.com> Date: Mon, 12 May 2025 01:33:26 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E9=9F=B3=E6=95=88=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../projectile/AbstractLaserEntity.java | 17 +++---- .../entity/projectile/LaserEntity.java | 3 +- .../entity/projectile/RpgRocketEntity.java | 6 --- .../event/ClientSoundHandler.java | 44 ------------------- .../mixins/ClientPacketListenerMixin.java | 31 +++++++++++++ 5 files changed, 38 insertions(+), 63 deletions(-) delete mode 100644 src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AbstractLaserEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AbstractLaserEntity.java index cdf50c70c..eacef3474 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AbstractLaserEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/AbstractLaserEntity.java @@ -16,6 +16,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.phys.*; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; @@ -77,20 +78,12 @@ public abstract class AbstractLaserEntity extends Entity implements TraceableEnt this.on = false; } } - -// @Override -// public Packet getAddEntityPacket() { -// return NetworkHooks.getEntitySpawningPacket(this); -// } - @Override - protected void readAdditionalSaveData(CompoundTag pCompound) { - + protected void readAdditionalSaveData(@NotNull CompoundTag pCompound) { } @Override - protected void addAdditionalSaveData(CompoundTag pCompound) { - + protected void addAdditionalSaveData(@NotNull CompoundTag pCompound) { } protected void beamTick() { @@ -107,11 +100,11 @@ public abstract class AbstractLaserEntity extends Entity implements TraceableEnt } @Override - public void push(Entity entityIn) { + public void push(@NotNull Entity entityIn) { } @Override - public PushReaction getPistonPushReaction() { + public @NotNull PushReaction getPistonPushReaction() { return PushReaction.IGNORE; } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/LaserEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/LaserEntity.java index 6b0af21c4..be167e92f 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/LaserEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/LaserEntity.java @@ -9,6 +9,7 @@ import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; import java.util.Comparator; import java.util.List; @@ -111,7 +112,7 @@ public class LaserEntity extends AbstractLaserEntity { } @Override - protected void readAdditionalSaveData(CompoundTag compoundTag) { + protected void readAdditionalSaveData(@NotNull CompoundTag compoundTag) { if (this.caster == null) { discard(); } diff --git a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java index 62b9a3500..76d95bb04 100644 --- a/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java +++ b/src/main/java/com/atsuishio/superbwarfare/entity/projectile/RpgRocketEntity.java @@ -84,12 +84,6 @@ public class RpgRocketEntity extends FastThrowableProjectile implements GeoEntit this.monsterMultiplier = monsterMultiplier; } - // TOD AEP -// @Override -// public @NotNull Packet getAddEntityPacket() { -// return NetworkHooks.getEntitySpawningPacket(this); -// } - @Override protected @NotNull Item getDefaultItem() { return ModItems.ROCKET.get(); diff --git a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java deleted file mode 100644 index 7f5907fa6..000000000 --- a/src/main/java/com/atsuishio/superbwarfare/event/ClientSoundHandler.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.atsuishio.superbwarfare.event; - -import com.atsuishio.superbwarfare.client.LoudlyEntitySoundInstance; -import com.atsuishio.superbwarfare.client.VehicleFireSoundInstance; -import com.atsuishio.superbwarfare.client.VehicleSoundInstance; -import com.atsuishio.superbwarfare.entity.LoudlyEntity; -import com.atsuishio.superbwarfare.entity.vehicle.A10Entity; -import com.atsuishio.superbwarfare.entity.vehicle.Hpj11Entity; -import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; -import com.atsuishio.superbwarfare.entity.vehicle.base.TrackEntity; -import net.minecraft.client.Minecraft; -import net.neoforged.api.distmarker.Dist; -import net.neoforged.bus.api.SubscribeEvent; -import net.neoforged.fml.common.EventBusSubscriber; -import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent; - -@EventBusSubscriber(bus = EventBusSubscriber.Bus.GAME, value = Dist.CLIENT) -public class ClientSoundHandler { - - @SubscribeEvent - public static void handleJoinLevelEvent(EntityJoinLevelEvent event) { - if (event.getLevel().isClientSide) { - com.atsuishio.superbwarfare.Mod.queueClientWork(60, () -> { - if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle) { - Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.EngineSound(mobileVehicle, mobileVehicle.getEngineSound())); - Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.SwimSound(mobileVehicle)); - } - if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) { - Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle)); - } - if (event.getEntity() instanceof LoudlyEntity) { - Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(event.getEntity())); - Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(event.getEntity())); - } - if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof A10Entity) { - Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.A10FireSound(mobileVehicle)); - } - if (event.getEntity() instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof Hpj11Entity) { - Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.HPJ11CloseFireSound(mobileVehicle)); - } - }); - } - } -} diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/ClientPacketListenerMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/ClientPacketListenerMixin.java index ed753dabf..7d864a650 100644 --- a/src/main/java/com/atsuishio/superbwarfare/mixins/ClientPacketListenerMixin.java +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/ClientPacketListenerMixin.java @@ -1,5 +1,14 @@ package com.atsuishio.superbwarfare.mixins; +import com.atsuishio.superbwarfare.Mod; +import com.atsuishio.superbwarfare.client.LoudlyEntitySoundInstance; +import com.atsuishio.superbwarfare.client.VehicleFireSoundInstance; +import com.atsuishio.superbwarfare.client.VehicleSoundInstance; +import com.atsuishio.superbwarfare.entity.LoudlyEntity; +import com.atsuishio.superbwarfare.entity.vehicle.A10Entity; +import com.atsuishio.superbwarfare.entity.vehicle.Hpj11Entity; +import com.atsuishio.superbwarfare.entity.vehicle.base.MobileVehicleEntity; +import com.atsuishio.superbwarfare.entity.vehicle.base.TrackEntity; import com.atsuishio.superbwarfare.entity.vehicle.base.VehicleEntity; import com.atsuishio.superbwarfare.init.ModKeyMappings; import net.minecraft.client.Minecraft; @@ -69,4 +78,26 @@ public abstract class ClientPacketListenerMixin { vehicle.entityIndexOverride = null; } + @Inject(method = "postAddEntitySoundInstance(Lnet/minecraft/world/entity/Entity;)V", at = @At("RETURN")) + private void postAddEntitySoundInstance(Entity pEntity, CallbackInfo ci) { + Mod.queueClientWork(60, () -> { + if (pEntity instanceof MobileVehicleEntity mobileVehicle) { + Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.EngineSound(mobileVehicle, mobileVehicle.getEngineSound())); + Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.SwimSound(mobileVehicle)); + } + if (pEntity instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof TrackEntity) { + Minecraft.getInstance().getSoundManager().play(new VehicleSoundInstance.TrackSound(mobileVehicle)); + } + if (pEntity instanceof LoudlyEntity) { + Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySound(pEntity)); + Minecraft.getInstance().getSoundManager().play(new LoudlyEntitySoundInstance.EntitySoundClose(pEntity)); + } + if (pEntity instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof A10Entity) { + Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.A10FireSound(mobileVehicle)); + } + if (pEntity instanceof MobileVehicleEntity mobileVehicle && mobileVehicle instanceof Hpj11Entity) { + Minecraft.getInstance().getSoundManager().play(new VehicleFireSoundInstance.HPJ11CloseFireSound(mobileVehicle)); + } + }); + } }