From 99a2482f7f0a7b08ea0e34858a5524959a5f42da Mon Sep 17 00:00:00 2001 From: Light_Quanta Date: Mon, 23 Jun 2025 21:58:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=92=A2=E7=AE=A1=E8=90=BD?= =?UTF-8?q?=E5=9C=B0=E9=9F=B3=E6=95=88=E5=AE=9E=E7=8E=B0=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../event/LivingEventHandler.java | 10 ------- .../mixins/SteelPipeFallMixin.java | 29 +++++++++++++++++++ src/main/resources/mixins.superbwarfare.json | 1 + 3 files changed, 30 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/atsuishio/superbwarfare/mixins/SteelPipeFallMixin.java diff --git a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java index 5ce5a50ac..62d3c2f1a 100644 --- a/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java +++ b/src/main/java/com/atsuishio/superbwarfare/event/LivingEventHandler.java @@ -1,6 +1,5 @@ package com.atsuishio.superbwarfare.event; -import com.atsuishio.superbwarfare.Mod; import com.atsuishio.superbwarfare.api.event.PreKillEvent; import com.atsuishio.superbwarfare.component.ModDataComponents; import com.atsuishio.superbwarfare.config.common.GameplayConfig; @@ -46,7 +45,6 @@ import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.common.util.TriState; -import net.neoforged.neoforge.event.entity.item.ItemTossEvent; import net.neoforged.neoforge.event.entity.living.*; import net.neoforged.neoforge.event.entity.player.ItemEntityPickupEvent; import net.neoforged.neoforge.network.PacketDistributor; @@ -658,12 +656,4 @@ public class LivingEventHandler { event.setResult(MobEffectEvent.Applicable.Result.DO_NOT_APPLY); } } - - @SubscribeEvent - public static void onItemSpawned(ItemTossEvent event) { - if (event.getEntity().getItem().getItem() == ModItems.STEEL_PIPE.get()) { - Mod.queueServerWork(5, () -> - event.getEntity().level().playSound(null, event.getEntity().getOnPos(), ModSounds.STEEL_PIPE_DROP.get(), SoundSource.PLAYERS, 2, 1)); - } - } } diff --git a/src/main/java/com/atsuishio/superbwarfare/mixins/SteelPipeFallMixin.java b/src/main/java/com/atsuishio/superbwarfare/mixins/SteelPipeFallMixin.java new file mode 100644 index 000000000..beb06b538 --- /dev/null +++ b/src/main/java/com/atsuishio/superbwarfare/mixins/SteelPipeFallMixin.java @@ -0,0 +1,29 @@ +package com.atsuishio.superbwarfare.mixins; + +import com.atsuishio.superbwarfare.init.ModItems; +import com.atsuishio.superbwarfare.init.ModSounds; +import net.minecraft.sounds.SoundSource; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.phys.Vec3; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(Entity.class) +public abstract class SteelPipeFallMixin { + + @Shadow public abstract boolean onGround(); + + @Inject(method = "setOnGroundWithMovement", at = @At("HEAD")) + public void playSteelPipeDropSound(boolean onGround, Vec3 movement, CallbackInfo ci) { + if (!onGround || onGround()) return; + + var entity = (Entity) (Object) this; + if (entity instanceof ItemEntity itemEntity && itemEntity.getItem().getItem() == ModItems.STEEL_PIPE.get()) { + entity.level().playSound(null, entity.getOnPos(), ModSounds.STEEL_PIPE_DROP.get(), SoundSource.PLAYERS, 2, 1); + } + } +} diff --git a/src/main/resources/mixins.superbwarfare.json b/src/main/resources/mixins.superbwarfare.json index 1c8e5175c..7028ce509 100644 --- a/src/main/resources/mixins.superbwarfare.json +++ b/src/main/resources/mixins.superbwarfare.json @@ -12,6 +12,7 @@ "LivingEntityMixin", "PlayerMixin", "ProjectileUtilMixin", + "SteelPipeFallMixin", "VillagerMixin" ], "client": [