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": [