generated from FabricMC/fabric-example-mod
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Some sounds are determined by the client, and these are not logged
- Loading branch information
Showing
13 changed files
with
218 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/io/github/misode/packtest/SoundListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package io.github.misode.packtest; | ||
|
||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.apache.commons.compress.utils.Lists; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
import java.util.function.Predicate; | ||
|
||
public class SoundListener { | ||
private static final List<SoundListener> listeners = Lists.newArrayList(); | ||
|
||
public static void broadcast(Player player, Vec3 pos, Holder<SoundEvent> holder) { | ||
String playerName = player == null ? null : player.getName().getString(); | ||
ResourceLocation sound = holder.value().getLocation(); | ||
SoundListener.Event message = new SoundListener.Event(playerName, pos, sound); | ||
SoundListener.listeners.forEach(l -> l.events.add(message)); | ||
} | ||
|
||
public SoundListener() { | ||
SoundListener.listeners.add(this); | ||
} | ||
|
||
public final List<SoundListener.Event> events = Lists.newArrayList(); | ||
|
||
public void stop() { | ||
SoundListener.listeners.remove(this); | ||
} | ||
|
||
public List<String> filter(Predicate<SoundListener.Event> predicate) { | ||
return this.events.stream() | ||
.filter(predicate) | ||
.map(m -> m.sound.toString()) | ||
.toList(); | ||
} | ||
|
||
public void reset() { | ||
this.events.clear(); | ||
} | ||
|
||
public record Event(@Nullable String player, Vec3 pos, ResourceLocation sound) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/io/github/misode/packtest/mixin/PlaySoundCommandMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import io.github.misode.packtest.SoundListener; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.commands.PlaySoundCommand; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Logs all sounds that are played | ||
*/ | ||
@Mixin(PlaySoundCommand.class) | ||
public class PlaySoundCommandMixin { | ||
|
||
@Inject(method = "playSound", at = @At(value = "NEW", target = "(Lnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;DDDFFJ)Lnet/minecraft/network/protocol/game/ClientboundSoundPacket;")) | ||
private static void playSound(CommandSourceStack commandSourceStack, Collection<ServerPlayer> players, ResourceLocation resourceLocation, SoundSource soundSource, Vec3 vec3, float f, float g, float h, CallbackInfoReturnable<Integer> cir, @Local(ordinal = 0) ServerPlayer player, @Local(ordinal = 1) Vec3 pos, @Local(ordinal = 0) Holder<SoundEvent> sound) { | ||
SoundListener.broadcast(player, pos, sound); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
src/main/java/io/github/misode/packtest/mixin/RaidMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import io.github.misode.packtest.SoundListener; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.world.entity.raid.Raid; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* Log raid horn sound | ||
*/ | ||
@Mixin(Raid.class) | ||
public class RaidMixin { | ||
@Inject(method = "playSound", at = @At(value = "NEW", target = "(Lnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;DDDFFJ)Lnet/minecraft/network/protocol/game/ClientboundSoundPacket;")) | ||
private void playSound(BlockPos blockPos, CallbackInfo ci, @Local(ordinal = 0) ServerPlayer player, @Local(ordinal = 1) double x, @Local(ordinal = 2) double z) { | ||
SoundListener.broadcast(player, new Vec3(x, player.getY(), z), SoundEvents.RAID_HORN); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/io/github/misode/packtest/mixin/ServerLevelMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import io.github.misode.packtest.SoundListener; | ||
import net.minecraft.core.Holder; | ||
import net.minecraft.server.level.ServerLevel; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* Logs all sounds that are played | ||
*/ | ||
@Mixin(ServerLevel.class) | ||
public class ServerLevelMixin { | ||
|
||
@Inject(method = "playSeededSound(Lnet/minecraft/world/entity/player/Player;DDDLnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V", at = @At("HEAD")) | ||
private void playSeededSound(Player player, double x, double y, double z, Holder<SoundEvent> holder, SoundSource soundSource, float volume, float pitch, long seed, CallbackInfo ci) { | ||
SoundListener.broadcast(player, new Vec3((float)x, (float)y, (float)z), holder); | ||
} | ||
|
||
@Inject(method = "playSeededSound(Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/entity/Entity;Lnet/minecraft/core/Holder;Lnet/minecraft/sounds/SoundSource;FFJ)V", at = @At("HEAD")) | ||
private void playSeededSound(Player player, Entity entity, Holder<SoundEvent> holder, SoundSource soundSource, float volume, float pitch, long seed, CallbackInfo ci) { | ||
SoundListener.broadcast(player, entity.position(), holder); | ||
} | ||
} |
15 changes: 13 additions & 2 deletions
15
src/main/java/io/github/misode/packtest/mixin/ServerPlayerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,32 @@ | ||
package io.github.misode.packtest.mixin; | ||
|
||
import io.github.misode.packtest.ChatListener; | ||
import io.github.misode.packtest.SoundListener; | ||
import net.minecraft.core.registries.BuiltInRegistries; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.entity.player.Player; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
/** | ||
* Logs all chat messages sent to players | ||
* Logs all chat messages sent to players. | ||
* Logs sounds that are played. | ||
*/ | ||
@Mixin(ServerPlayer.class) | ||
public class ServerPlayerMixin { | ||
|
||
@Inject(method = "sendSystemMessage(Lnet/minecraft/network/chat/Component;Z)V", at = @At("HEAD")) | ||
private void sendSystemMessage(Component message, boolean bl, CallbackInfo ci) { | ||
ChatListener.broadcast((ServerPlayer)(Object)this, message); | ||
ChatListener.broadcast((Player)(Object)this, message); | ||
} | ||
|
||
@Inject(method = "playNotifySound", at = @At("HEAD")) | ||
private void playNotifySound(SoundEvent soundEvent, SoundSource soundSource, float volume, float pitch, CallbackInfo ci) { | ||
SoundListener.broadcast((Player)(Object)this, ((Player)(Object)this).position(), BuiltInRegistries.SOUND_EVENT.wrapAsHolder(soundEvent)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters