| 1 | package nicotine.mixin;
|
| 2 |
|
| 3 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 4 | import net.minecraft.client.player.AbstractClientPlayer;
|
| 5 | import net.minecraft.core.Holder;
|
| 6 | import net.minecraft.sounds.SoundEvent;
|
| 7 | import net.minecraft.sounds.SoundEvents;
|
| 8 | import net.minecraft.sounds.SoundSource;
|
| 9 | import net.minecraft.world.entity.Entity;
|
| 10 | import nicotine.events.CaughtFishEvent;
|
| 11 | import nicotine.events.ClientLevelTickEvent;
|
| 12 | import nicotine.events.TotemPopEvent;
|
| 13 | import nicotine.util.EventBus;
|
| 14 | import org.jspecify.annotations.Nullable;
|
| 15 | import org.spongepowered.asm.mixin.Mixin;
|
| 16 | import org.spongepowered.asm.mixin.injection.At;
|
| 17 | import org.spongepowered.asm.mixin.injection.Inject;
|
| 18 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
| 19 |
|
| 20 | import java.util.function.BooleanSupplier;
|
| 21 |
|
| 22 | import static nicotine.util.Common.*;
|
| 23 |
|
| 24 | @Mixin(ClientLevel.class)
|
| 25 | public class ClientLevelMixin {
|
| 26 |
|
| 27 | @Inject(at = @At("TAIL"), method = "tick")
|
| 28 | public void tick(BooleanSupplier shouldKeepTicking, CallbackInfo info) {
|
| 29 | EventBus.post(new ClientLevelTickEvent());
|
| 30 | }
|
| 31 |
|
| 32 | @Inject(at = @At("HEAD"), method = "Lnet/minecraft/client/multiplayer/ClientLevel;playLocalSound(DDDLnet/minecraft/sounds/SoundEvent;Lnet/minecraft/sounds/SoundSource;FFZ)V")
|
| 33 | public void playLocalSound(double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, boolean useDistance, CallbackInfo info) {
|
| 34 | if (SoundEvents.TOTEM_USE == sound) {
|
| 35 | for (AbstractClientPlayer player : mc.level.players()) {
|
| 36 | if (player.position().distanceToSqr(x, y, z) <= 0) {
|
| 37 | EventBus.post(new TotemPopEvent(player));
|
| 38 | }
|
| 39 | }
|
| 40 | }
|
| 41 | }
|
| 42 |
|
| 43 | @Inject(at = @At("HEAD"), method = "Lnet/minecraft/client/multiplayer/ClientLevel;playSeededSound(Lnet/minecraft/world/entity/Entity;DDDLnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V")
|
| 44 | public void playSeededSound(@Nullable Entity entity, double d, double e, double f, Holder<SoundEvent> holder, SoundSource soundSource, float g, float h, long l, CallbackInfo info) {
|
| 45 | if (SoundEvents.FISHING_BOBBER_SPLASH == holder.value()) {
|
| 46 | if (mc.player.fishing != null) {
|
| 47 | if (entity == mc.player) {
|
| 48 | EventBus.post(new CaughtFishEvent());
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 | }
|
| 53 |
|
| 54 | }
|
| 55 |
|