Files
SoundPadMod/src/main/java/com/example/soundmod/net/packet/S2CStopSoundPacket.java
T

42 lines
1.2 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* net.minecraft.network.PacketBuffer
* net.minecraftforge.fml.network.NetworkEvent$Context
*/
package com.example.soundmod.net.packet;
import com.example.soundmod.client.audio.AudioPlaybackService;
import java.util.function.Supplier;
import net.minecraft.network.PacketBuffer;
import net.minecraftforge.fml.network.NetworkEvent;
public class S2CStopSoundPacket {
private final String sourceId;
public S2CStopSoundPacket(String sourceId) {
this.sourceId = sourceId;
}
public static void encode(S2CStopSoundPacket msg, PacketBuffer buf) {
buf.writeUtf(msg.sourceId);
}
public static S2CStopSoundPacket decode(PacketBuffer buf) {
return new S2CStopSoundPacket(buf.readUtf(256));
}
public static void handle(S2CStopSoundPacket msg, Supplier<NetworkEvent.Context> ctx) {
ctx.get().enqueueWork(() -> {
if (msg.sourceId == null || msg.sourceId.isEmpty() || "*".equals(msg.sourceId)) {
AudioPlaybackService.get().stopAll();
} else {
AudioPlaybackService.get().stop(msg.sourceId);
}
});
ctx.get().setPacketHandled(true);
}
}