From cc64c7ab4e5d5438aa2d81279978a54bf6109770 Mon Sep 17 00:00:00 2001 From: MisterJulsen Date: Tue, 17 Oct 2023 18:26:45 +0200 Subject: [PATCH] Networking system rewritten --- .../mineify/network/NetworkManager.java | 59 ++++++++++--------- .../packets/DefaultServerResponsePacket.java | 13 ++-- .../network/packets/DownloadSoundPacket.java | 22 ++++--- .../network/packets/ErrorMessagePacket.java | 15 +++-- .../mineify/network/packets/IPacketBase.java | 12 ++++ .../packets/NextSoundDataRequestPacket.java | 17 ++++-- .../packets/NextSoundDataResponsePacket.java | 22 ++++--- .../network/packets/PlaySoundPacket.java | 26 ++++---- .../packets/PlaySoundRequestPacket.java | 30 ++++++---- .../network/packets/SetCooldownPacket.java | 19 +++--- .../packets/SoundDeleteRequestPacket.java | 23 +++++--- .../packets/SoundFilesCountRequestPacket.java | 19 +++--- .../SoundFilesCountResponsePacket.java | 17 ++++-- .../packets/SoundFilesSizeRequestPacket.java | 19 +++--- .../packets/SoundListRequestPacket.java | 21 ++++--- .../packets/SoundListResponsePacket.java | 17 ++++-- .../packets/SoundModificationPacket.java | 25 ++++---- .../SoundModificationWithPathPacket.java | 27 +++++---- .../packets/SoundPlayerBlockEntityPacket.java | 29 +++++---- .../network/packets/StopSoundPacket.java | 15 +++-- .../packets/StopSoundWithPathPacket.java | 15 +++-- .../packets/UploadSoundCompletionPacket.java | 23 +++++--- .../network/packets/UploadSoundPacket.java | 19 +++--- 23 files changed, 312 insertions(+), 192 deletions(-) create mode 100644 src/main/java/de/mrjulsen/mineify/network/packets/IPacketBase.java diff --git a/src/main/java/de/mrjulsen/mineify/network/NetworkManager.java b/src/main/java/de/mrjulsen/mineify/network/NetworkManager.java index 0622f0b..f9b2b01 100644 --- a/src/main/java/de/mrjulsen/mineify/network/NetworkManager.java +++ b/src/main/java/de/mrjulsen/mineify/network/NetworkManager.java @@ -1,9 +1,14 @@ package de.mrjulsen.mineify.network; +import java.util.Optional; + +import javax.annotation.Nullable; + import de.mrjulsen.mineify.ModMain; import de.mrjulsen.mineify.network.packets.DefaultServerResponsePacket; import de.mrjulsen.mineify.network.packets.DownloadSoundPacket; import de.mrjulsen.mineify.network.packets.ErrorMessagePacket; +import de.mrjulsen.mineify.network.packets.IPacketBase; import de.mrjulsen.mineify.network.packets.NextSoundDataRequestPacket; import de.mrjulsen.mineify.network.packets.NextSoundDataResponsePacket; import de.mrjulsen.mineify.network.packets.PlaySoundPacket; @@ -27,47 +32,47 @@ import net.minecraftforge.network.NetworkDirection; import net.minecraftforge.network.NetworkRegistry; import net.minecraftforge.network.simple.SimpleChannel; -import net.minecraftforge.network.simple.SimpleChannel.MessageBuilder; public class NetworkManager { public static final String PROTOCOL_VERSION = String.valueOf(1); private static int currentId = 0; - public static final SimpleChannel MOD_CHANNEL = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(ModMain.MOD_ID, "mineify_channel")).networkProtocolVersion(() -> PROTOCOL_VERSION).clientAcceptedVersions(PROTOCOL_VERSION::equals).serverAcceptedVersions(PROTOCOL_VERSION::equals).simpleChannel(); + public static final SimpleChannel MOD_CHANNEL = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(ModMain.MOD_ID, "network")).networkProtocolVersion(() -> PROTOCOL_VERSION).clientAcceptedVersions(PROTOCOL_VERSION::equals).serverAcceptedVersions(PROTOCOL_VERSION::equals).simpleChannel(); public static void registerNetworkPackets() { - register(DownloadSoundPacket.class).encoder(DownloadSoundPacket::encode).decoder(DownloadSoundPacket::decode).consumerNetworkThread(DownloadSoundPacket::handle).add(); - register(UploadSoundPacket.class).encoder(UploadSoundPacket::encode).decoder(UploadSoundPacket::decode).consumerNetworkThread(UploadSoundPacket::handle).add(); - register(UploadSoundCompletionPacket.class).encoder(UploadSoundCompletionPacket::encode).decoder(UploadSoundCompletionPacket::decode).consumerNetworkThread(UploadSoundCompletionPacket::handle).add(); - register(SoundDeleteRequestPacket.class).encoder(SoundDeleteRequestPacket::encode).decoder(SoundDeleteRequestPacket::decode).consumerNetworkThread(SoundDeleteRequestPacket::handle).add(); - register(SoundListRequestPacket.class).encoder(SoundListRequestPacket::encode).decoder(SoundListRequestPacket::decode).consumerNetworkThread(SoundListRequestPacket::handle).add(); - register(SoundListResponsePacket.class).encoder(SoundListResponsePacket::encode).decoder(SoundListResponsePacket::decode).consumerNetworkThread(SoundListResponsePacket::handle).add(); - register(SoundPlayerBlockEntityPacket.class).encoder(SoundPlayerBlockEntityPacket::encode).decoder(SoundPlayerBlockEntityPacket::decode).consumerNetworkThread(SoundPlayerBlockEntityPacket::handle).add(); - register(StopSoundPacket.class).encoder(StopSoundPacket::encode).decoder(StopSoundPacket::decode).consumerNetworkThread(StopSoundPacket::handle).add(); - register(ErrorMessagePacket.class).encoder(ErrorMessagePacket::encode).decoder(ErrorMessagePacket::decode).consumerNetworkThread(ErrorMessagePacket::handle).add(); - register(NextSoundDataRequestPacket.class).encoder(NextSoundDataRequestPacket::encode).decoder(NextSoundDataRequestPacket::decode).consumerNetworkThread(NextSoundDataRequestPacket::handle).add(); - register(NextSoundDataResponsePacket.class).encoder(NextSoundDataResponsePacket::encode).decoder(NextSoundDataResponsePacket::decode).consumerNetworkThread(NextSoundDataResponsePacket::handle).add(); - register(PlaySoundPacket.class).encoder(PlaySoundPacket::encode).decoder(PlaySoundPacket::decode).consumerNetworkThread(PlaySoundPacket::handle).add(); - register(DefaultServerResponsePacket.class).encoder(DefaultServerResponsePacket::encode).decoder(DefaultServerResponsePacket::decode).consumerNetworkThread(DefaultServerResponsePacket::handle).add(); - register(SoundFilesCountRequestPacket.class).encoder(SoundFilesCountRequestPacket::encode).decoder(SoundFilesCountRequestPacket::decode).consumerNetworkThread(SoundFilesCountRequestPacket::handle).add(); - register(SoundFilesCountResponsePacket.class).encoder(SoundFilesCountResponsePacket::encode).decoder(SoundFilesCountResponsePacket::decode).consumerNetworkThread(SoundFilesCountResponsePacket::handle).add(); - register(SoundFilesSizeRequestPacket.class).encoder(SoundFilesSizeRequestPacket::encode).decoder(SoundFilesSizeRequestPacket::decode).consumerNetworkThread(SoundFilesSizeRequestPacket::handle).add(); - register(StopSoundWithPathPacket.class).encoder(StopSoundWithPathPacket::encode).decoder(StopSoundWithPathPacket::decode).consumerNetworkThread(StopSoundWithPathPacket::handle).add(); - register(SoundModificationPacket.class).encoder(SoundModificationPacket::encode).decoder(SoundModificationPacket::decode).consumerNetworkThread(SoundModificationPacket::handle).add(); - register(SoundModificationWithPathPacket.class).encoder(SoundModificationWithPathPacket::encode).decoder(SoundModificationWithPathPacket::decode).consumerNetworkThread(SoundModificationWithPathPacket::handle).add(); - register(PlaySoundRequestPacket.class).encoder(PlaySoundRequestPacket::encode).decoder(PlaySoundRequestPacket::decode).consumerNetworkThread(PlaySoundRequestPacket::handle).add(); - register(SetCooldownPacket.class).encoder(SetCooldownPacket::encode).decoder(SetCooldownPacket::decode).consumerNetworkThread(SetCooldownPacket::handle).add(); + registerPacket(UploadSoundPacket.class, new UploadSoundPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(UploadSoundCompletionPacket.class, new UploadSoundCompletionPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SoundDeleteRequestPacket.class, new SoundDeleteRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SoundListRequestPacket.class, new SoundListRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SoundPlayerBlockEntityPacket.class, new SoundPlayerBlockEntityPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(NextSoundDataRequestPacket.class, new NextSoundDataRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SoundFilesCountRequestPacket.class, new SoundFilesCountRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SoundFilesSizeRequestPacket.class, new SoundFilesSizeRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(PlaySoundRequestPacket.class, new PlaySoundRequestPacket(), NetworkDirection.PLAY_TO_SERVER); + registerPacket(SetCooldownPacket.class, new SetCooldownPacket(), NetworkDirection.PLAY_TO_SERVER); + + registerPacket(DownloadSoundPacket.class, new DownloadSoundPacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(SoundListResponsePacket.class, new SoundListResponsePacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(StopSoundPacket.class, new StopSoundPacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(ErrorMessagePacket.class, new ErrorMessagePacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(NextSoundDataResponsePacket.class, new NextSoundDataResponsePacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(PlaySoundPacket.class, new PlaySoundPacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(DefaultServerResponsePacket.class, new DefaultServerResponsePacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(SoundFilesCountResponsePacket.class, new SoundFilesCountResponsePacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(StopSoundWithPathPacket.class, new StopSoundWithPathPacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(SoundModificationPacket.class, new SoundModificationPacket(), NetworkDirection.PLAY_TO_CLIENT); + registerPacket(SoundModificationWithPathPacket.class, new SoundModificationWithPathPacket(), NetworkDirection.PLAY_TO_CLIENT); + + } public static SimpleChannel getPlayChannel() { return MOD_CHANNEL; } - private static MessageBuilder register(Class clazz) { - MessageBuilder mb = MOD_CHANNEL.messageBuilder(clazz, currentId); - currentId++; - return mb; + private static void registerPacket(Class clazz, IPacketBase packet, @Nullable NetworkDirection direction) { + MOD_CHANNEL.registerMessage(currentId++, clazz, packet::encode, packet::decode, packet::handle, Optional.of(direction)); } public static void sendToClient(Object o, ServerPlayer player) { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/DefaultServerResponsePacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/DefaultServerResponsePacket.java index f9def89..cc384e5 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/DefaultServerResponsePacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/DefaultServerResponsePacket.java @@ -8,25 +8,30 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class DefaultServerResponsePacket { +public class DefaultServerResponsePacket implements IPacketBase { public long requestId; + public DefaultServerResponsePacket() { } + public DefaultServerResponsePacket(long requestId) { this.requestId = requestId; } - public static void encode(DefaultServerResponsePacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(DefaultServerResponsePacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); } - public static DefaultServerResponsePacket decode(FriendlyByteBuf buffer) { + @Override + public DefaultServerResponsePacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); DefaultServerResponsePacket instance = new DefaultServerResponsePacket(requestId); return instance; } - public static void handle(DefaultServerResponsePacket packet, Supplier context) { + @Override + public void handle(DefaultServerResponsePacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/DownloadSoundPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/DownloadSoundPacket.java index 82fcbdc..1962bb9 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/DownloadSoundPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/DownloadSoundPacket.java @@ -9,13 +9,14 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class DownloadSoundPacket { - public final long requestId; - public final int dataOffset; - public final int maxLength; - public final EStreamingMode streamingMode; - public final byte[] data; +public class DownloadSoundPacket implements IPacketBase { + public long requestId; + public int dataOffset; + public int maxLength; + public EStreamingMode streamingMode; + public byte[] data; + public DownloadSoundPacket() { } public DownloadSoundPacket(long requestId, int dataOffset, byte[] data, int maxLength, EStreamingMode streamingMode) { this.data = data; @@ -25,7 +26,8 @@ public DownloadSoundPacket(long requestId, int dataOffset, byte[] data, int maxL this.maxLength = maxLength; } - public static void encode(DownloadSoundPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(DownloadSoundPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeInt(packet.dataOffset); buffer.writeInt(packet.maxLength); @@ -33,7 +35,8 @@ public static void encode(DownloadSoundPacket packet, FriendlyByteBuf buffer) { buffer.writeByteArray(packet.data); } - public static DownloadSoundPacket decode(FriendlyByteBuf buffer) { + @Override + public DownloadSoundPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int dataOffset = buffer.readInt(); int maxLength = buffer.readInt(); @@ -44,7 +47,8 @@ public static DownloadSoundPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(DownloadSoundPacket packet, Supplier context) { + @Override + public void handle(DownloadSoundPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/ErrorMessagePacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/ErrorMessagePacket.java index ca1327d..b2495dc 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/ErrorMessagePacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/ErrorMessagePacket.java @@ -9,24 +9,29 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class ErrorMessagePacket { - public final ToastMessage message; +public class ErrorMessagePacket implements IPacketBase { + public ToastMessage message; + + public ErrorMessagePacket() { } public ErrorMessagePacket(ToastMessage message) { this.message = message; } - public static void encode(ErrorMessagePacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(ErrorMessagePacket packet, FriendlyByteBuf buffer) { packet.message.serialize(buffer); } - public static ErrorMessagePacket decode(FriendlyByteBuf buffer) { + @Override + public ErrorMessagePacket decode(FriendlyByteBuf buffer) { ToastMessage message = ToastMessage.deserialize(buffer); ErrorMessagePacket instance = new ErrorMessagePacket(message); return instance; } - public static void handle(ErrorMessagePacket packet, Supplier context) { + @Override + public void handle(ErrorMessagePacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleErrorMessagePacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/IPacketBase.java b/src/main/java/de/mrjulsen/mineify/network/packets/IPacketBase.java new file mode 100644 index 0000000..5485cff --- /dev/null +++ b/src/main/java/de/mrjulsen/mineify/network/packets/IPacketBase.java @@ -0,0 +1,12 @@ +package de.mrjulsen.mineify.network.packets; + +import java.util.function.Supplier; + +import net.minecraft.network.FriendlyByteBuf; +import net.minecraftforge.network.NetworkEvent; + +public interface IPacketBase { + void encode(T message, FriendlyByteBuf buffer); + T decode(FriendlyByteBuf buffer); + void handle(T message, Supplier supplier); +} diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataRequestPacket.java index 0ef6fd1..6e840b0 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataRequestPacket.java @@ -8,21 +8,25 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class NextSoundDataRequestPacket { - private final long requestId; - private final int index; +public class NextSoundDataRequestPacket implements IPacketBase { + private long requestId; + private int index; + + public NextSoundDataRequestPacket() { } public NextSoundDataRequestPacket(long requestId, int index) { this.requestId = requestId; this.index = index; } - public static void encode(NextSoundDataRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(NextSoundDataRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeInt(packet.index); } - public static NextSoundDataRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public NextSoundDataRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int index = buffer.readInt(); @@ -30,7 +34,8 @@ public static NextSoundDataRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(NextSoundDataRequestPacket packet, Supplier context) { + @Override + public void handle(NextSoundDataRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { if (InstanceManager.Server.fileCache.containsKey(packet.requestId)) { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataResponsePacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataResponsePacket.java index 153dc8c..f770dbd 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataResponsePacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/NextSoundDataResponsePacket.java @@ -8,11 +8,13 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class NextSoundDataResponsePacket { - public final long requestId; - public final int index; - public final byte[] data; - public final boolean hasNext; +public class NextSoundDataResponsePacket implements IPacketBase { + public long requestId; + public int index; + public byte[] data; + public boolean hasNext; + + public NextSoundDataResponsePacket() { } public NextSoundDataResponsePacket(long requestId, byte[] data, boolean hasNext, int index) { this.requestId = requestId; @@ -21,14 +23,16 @@ public NextSoundDataResponsePacket(long requestId, byte[] data, boolean hasNext, this.index = index; } - public static void encode(NextSoundDataResponsePacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(NextSoundDataResponsePacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeInt(packet.index); buffer.writeBoolean(packet.hasNext); buffer.writeByteArray(packet.data); } - public static NextSoundDataResponsePacket decode(FriendlyByteBuf buffer) { + @Override + public NextSoundDataResponsePacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int index = buffer.readInt(); boolean hasNext = buffer.readBoolean(); @@ -38,10 +42,12 @@ public static NextSoundDataResponsePacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(NextSoundDataResponsePacket packet, Supplier context) { + @Override + public void handle(NextSoundDataResponsePacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleNextSoundDataResponsePacket(packet, context)); }); + context.get().setPacketHandled(true); } } diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundPacket.java index 52a8063..11a68c6 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundPacket.java @@ -10,14 +10,15 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class PlaySoundPacket { - public final BlockPos pos; - public final long requestId; - public final int attenuationDistance; - public final float pitch; - public final float volume; - public final String path; - +public class PlaySoundPacket implements IPacketBase { + public BlockPos pos; + public long requestId; + public int attenuationDistance; + public float pitch; + public float volume; + public String path; + + public PlaySoundPacket() { } public PlaySoundPacket(long requestId, BlockPos pos, int attenuationDistance, float volume, float pitch, String path) { this.pos = pos; @@ -28,7 +29,8 @@ public PlaySoundPacket(long requestId, BlockPos pos, int attenuationDistance, fl this.path = path; } - public static void encode(PlaySoundPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(PlaySoundPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeBlockPos(packet.pos); buffer.writeInt(packet.attenuationDistance); @@ -39,7 +41,8 @@ public static void encode(PlaySoundPacket packet, FriendlyByteBuf buffer) { buffer.writeUtf(packet.path); } - public static PlaySoundPacket decode(FriendlyByteBuf buffer) { + @Override + public PlaySoundPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); BlockPos pos = buffer.readBlockPos(); int attenuationDistance = buffer.readInt(); @@ -52,7 +55,8 @@ public static PlaySoundPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(PlaySoundPacket packet, Supplier context) { + @Override + public void handle(PlaySoundPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundRequestPacket.java index 33ffb14..828c04f 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/PlaySoundRequestPacket.java @@ -11,16 +11,17 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class PlaySoundRequestPacket { - public final BlockPos pos; - public final long requestId; - public final PlaybackArea area; - public final int attenuationDistance; - public final float volume; - public final float pitch; - public final String path; - public final ESoundCategory category; - +public class PlaySoundRequestPacket implements IPacketBase { + public BlockPos pos; + public long requestId; + public PlaybackArea area; + public int attenuationDistance; + public float volume; + public float pitch; + public String path; + public ESoundCategory category; + + public PlaySoundRequestPacket() { } public PlaySoundRequestPacket(long requestId, PlaybackArea area, BlockPos pos, int attenuationDistance, float volume, float pitch, String path, ESoundCategory category) { this.pos = pos; @@ -33,7 +34,8 @@ public PlaySoundRequestPacket(long requestId, PlaybackArea area, BlockPos pos, i this.category = category; } - public static void encode(PlaySoundRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(PlaySoundRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); packet.area.serialize(buffer); buffer.writeBlockPos(packet.pos); @@ -46,7 +48,8 @@ public static void encode(PlaySoundRequestPacket packet, FriendlyByteBuf buffer) buffer.writeEnum(packet.category); } - public static PlaySoundRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public PlaySoundRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); PlaybackArea area = PlaybackArea.deserialize(buffer); BlockPos pos = buffer.readBlockPos(); @@ -61,7 +64,8 @@ public static PlaySoundRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(PlaySoundRequestPacket packet, Supplier context) { + @Override + public void handle(PlaySoundRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { ServerApi.playSound(SoundFile.fromShortPath(packet.path, packet.category), packet.area, context.get().getSender().level, packet.pos, packet.attenuationDistance, packet.volume, packet.pitch); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SetCooldownPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SetCooldownPacket.java index ba627d4..c4a3365 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SetCooldownPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SetCooldownPacket.java @@ -6,21 +6,25 @@ import net.minecraft.world.item.ItemStack; import net.minecraftforge.network.NetworkEvent; -public class SetCooldownPacket { - public final ItemStack stack; - public final int ticks; +public class SetCooldownPacket implements IPacketBase { + public ItemStack stack; + public int ticks; + + public SetCooldownPacket() { } public SetCooldownPacket(ItemStack stack, int ticks) { this.stack = stack; this.ticks = ticks; } - public static void encode(SetCooldownPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SetCooldownPacket packet, FriendlyByteBuf buffer) { buffer.writeItemStack(packet.stack, true); buffer.writeInt(packet.ticks); } - public static SetCooldownPacket decode(FriendlyByteBuf buffer) { + @Override + public SetCooldownPacket decode(FriendlyByteBuf buffer) { ItemStack stack = buffer.readItem(); int ticks = buffer.readInt(); @@ -28,12 +32,13 @@ public static SetCooldownPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SetCooldownPacket packet, Supplier context) { + @Override + public void handle(SetCooldownPacket packet, Supplier context) { context.get().enqueueWork(() -> { context.get().getSender().getCooldowns().addCooldown(packet.stack.getItem(), packet.ticks); }); - context.get().setPacketHandled(true); + context.get().setPacketHandled(true); } } diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundDeleteRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundDeleteRequestPacket.java index 5b7567f..94b903c 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundDeleteRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundDeleteRequestPacket.java @@ -9,12 +9,14 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class SoundDeleteRequestPacket { - private final long requestId; - private final String filename; - private final String fileOwner; - private final ESoundVisibility visibility; - private final ESoundCategory category; +public class SoundDeleteRequestPacket implements IPacketBase { + private long requestId; + private String filename; + private String fileOwner; + private ESoundVisibility visibility; + private ESoundCategory category; + + public SoundDeleteRequestPacket() { } public SoundDeleteRequestPacket(long requestId, String filename, String fileOwner, ESoundVisibility visibility, ESoundCategory category) { this.filename = filename; @@ -24,7 +26,8 @@ public SoundDeleteRequestPacket(long requestId, String filename, String fileOwne this.category = category; } - public static void encode(SoundDeleteRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundDeleteRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeUtf(packet.filename); buffer.writeUtf(packet.fileOwner); @@ -32,7 +35,8 @@ public static void encode(SoundDeleteRequestPacket packet, FriendlyByteBuf buffe buffer.writeEnum(packet.category); } - public static SoundDeleteRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundDeleteRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); String filename = buffer.readUtf(); String fileOwner = buffer.readUtf(); @@ -43,7 +47,8 @@ public static SoundDeleteRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundDeleteRequestPacket packet, Supplier context) { + @Override + public void handle(SoundDeleteRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { ServerWrapper.deleteSound(packet.filename, packet.fileOwner, packet.visibility, packet.category, context.get().getSender(), () -> { ServerApi.sendResponse(context.get().getSender(), packet.requestId); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountRequestPacket.java index 1768e75..d0832af 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountRequestPacket.java @@ -12,10 +12,12 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class SoundFilesCountRequestPacket { - private final long requestID; - private final @NotNull ESoundVisibility[] visibilityWhitelist; - private final @NotNull String[] usersWhitelist; +public class SoundFilesCountRequestPacket implements IPacketBase { + private long requestID; + private @NotNull ESoundVisibility[] visibilityWhitelist; + private @NotNull String[] usersWhitelist; + + public SoundFilesCountRequestPacket() { } public SoundFilesCountRequestPacket(long requestId, @NotNull ESoundVisibility[] visibilityWhitelist, @NotNull String[] usersWhitelist) { this.requestID = requestId; @@ -23,7 +25,8 @@ public SoundFilesCountRequestPacket(long requestId, @NotNull ESoundVisibility[] this.usersWhitelist = usersWhitelist == null ? new String[0] : usersWhitelist; } - public static void encode(SoundFilesCountRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundFilesCountRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestID); buffer.writeInt(packet.visibilityWhitelist.length); for (int i = 0; i < packet.visibilityWhitelist.length; i++) { @@ -37,7 +40,8 @@ public static void encode(SoundFilesCountRequestPacket packet, FriendlyByteBuf b } } - public static SoundFilesCountRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundFilesCountRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int n = buffer.readInt(); ESoundVisibility[] visibilityWhitelist = new ESoundVisibility[n]; @@ -55,7 +59,8 @@ public static SoundFilesCountRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundFilesCountRequestPacket packet, Supplier context) { + @Override + public void handle(SoundFilesCountRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { new Thread(() -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountResponsePacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountResponsePacket.java index 1048ee2..54d14dc 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountResponsePacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesCountResponsePacket.java @@ -8,21 +8,25 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class SoundFilesCountResponsePacket { - public final long requestId; - public final long count; +public class SoundFilesCountResponsePacket implements IPacketBase { + public long requestId; + public long count; + + public SoundFilesCountResponsePacket() { } public SoundFilesCountResponsePacket(long requestId, long count) { this.requestId = requestId; this.count = count; } - public static void encode(SoundFilesCountResponsePacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundFilesCountResponsePacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeLong(packet.count); } - public static SoundFilesCountResponsePacket decode(FriendlyByteBuf buffer) { + @Override + public SoundFilesCountResponsePacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); long count = buffer.readLong(); @@ -30,7 +34,8 @@ public static SoundFilesCountResponsePacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundFilesCountResponsePacket packet, Supplier context) { + @Override + public void handle(SoundFilesCountResponsePacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleSoundFilesCountResponsePacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesSizeRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesSizeRequestPacket.java index d087a96..8a8566a 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesSizeRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundFilesSizeRequestPacket.java @@ -13,10 +13,12 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class SoundFilesSizeRequestPacket { - private final long requestID; - private final @NotNull ESoundVisibility[] visibilityWhitelist; - private final @NotNull String[] usersWhitelist; +public class SoundFilesSizeRequestPacket implements IPacketBase { + private long requestID; + private @NotNull ESoundVisibility[] visibilityWhitelist; + private @NotNull String[] usersWhitelist; + + public SoundFilesSizeRequestPacket() { } public SoundFilesSizeRequestPacket(long requestId, @NotNull ESoundVisibility[] visibilityWhitelist, @NotNull String[] usersWhitelist) { this.requestID = requestId; @@ -24,7 +26,8 @@ public SoundFilesSizeRequestPacket(long requestId, @NotNull ESoundVisibility[] v this.usersWhitelist = usersWhitelist == null ? new String[0] : usersWhitelist; } - public static void encode(SoundFilesSizeRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundFilesSizeRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestID); buffer.writeInt(packet.visibilityWhitelist.length); for (int i = 0; i < packet.visibilityWhitelist.length; i++) { @@ -38,7 +41,8 @@ public static void encode(SoundFilesSizeRequestPacket packet, FriendlyByteBuf bu } } - public static SoundFilesSizeRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundFilesSizeRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int n = buffer.readInt(); ESoundVisibility[] visibilityWhitelist = new ESoundVisibility[n]; @@ -56,7 +60,8 @@ public static SoundFilesSizeRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundFilesSizeRequestPacket packet, Supplier context) { + @Override + public void handle(SoundFilesSizeRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { new Thread(() -> { ModMain.LOGGER.debug("Reading sound files size..."); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundListRequestPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundListRequestPacket.java index bb0609f..1214c82 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundListRequestPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundListRequestPacket.java @@ -14,11 +14,13 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class SoundListRequestPacket { - private final long requestID; - private final @NotNull ESoundCategory[] categoryWhitelist; - private final @NotNull ESoundVisibility[] visibilityWhitelist; - private final @NotNull String[] usersWhitelist; +public class SoundListRequestPacket implements IPacketBase { + private long requestID; + private @NotNull ESoundCategory[] categoryWhitelist; + private @NotNull ESoundVisibility[] visibilityWhitelist; + private @NotNull String[] usersWhitelist; + + public SoundListRequestPacket() { } public SoundListRequestPacket(long requestId, @NotNull ESoundVisibility[] visibilityWhitelist, @NotNull String[] usersWhitelist, @NotNull ESoundCategory[] categoryWhitelist) { this.requestID = requestId; @@ -27,7 +29,8 @@ public SoundListRequestPacket(long requestId, @NotNull ESoundVisibility[] visibi this.categoryWhitelist = categoryWhitelist == null ? new ESoundCategory[0] : categoryWhitelist; } - public static void encode(SoundListRequestPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundListRequestPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestID); buffer.writeInt(packet.visibilityWhitelist.length); for (int i = 0; i < packet.visibilityWhitelist.length; i++) { @@ -45,7 +48,8 @@ public static void encode(SoundListRequestPacket packet, FriendlyByteBuf buffer) } } - public static SoundListRequestPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundListRequestPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int n = buffer.readInt(); ESoundVisibility[] visibilityWhitelist = new ESoundVisibility[n]; @@ -68,7 +72,8 @@ public static SoundListRequestPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundListRequestPacket packet, Supplier context) { + @Override + public void handle(SoundListRequestPacket packet, Supplier context) { context.get().enqueueWork(() -> { new Thread(() -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundListResponsePacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundListResponsePacket.java index a28c1d3..1941292 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundListResponsePacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundListResponsePacket.java @@ -9,16 +9,19 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class SoundListResponsePacket { - public final long requestId; - public final SoundFile[] soundFiles; +public class SoundListResponsePacket implements IPacketBase { + public long requestId; + public SoundFile[] soundFiles; + + public SoundListResponsePacket() { } public SoundListResponsePacket(long requestId, SoundFile[] soundFiles) { this.requestId = requestId; this.soundFiles = soundFiles; } - public static void encode(SoundListResponsePacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundListResponsePacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeInt(packet.soundFiles.length); for (int i = 0; i < packet.soundFiles.length; i++) { @@ -26,7 +29,8 @@ public static void encode(SoundListResponsePacket packet, FriendlyByteBuf buffer } } - public static SoundListResponsePacket decode(FriendlyByteBuf buffer) { + @Override + public SoundListResponsePacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int l = buffer.readInt(); SoundFile[] soundFiles = new SoundFile[l]; @@ -38,7 +42,8 @@ public static SoundListResponsePacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundListResponsePacket packet, Supplier context) { + @Override + public void handle(SoundListResponsePacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleSoundListResponsePacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationPacket.java index 9cab29f..926ff26 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationPacket.java @@ -10,13 +10,15 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class SoundModificationPacket { - public final long soundId; - public final @Nullable Integer attenuationDistance; - public final @Nullable Float pitch; - public final @Nullable Double x; - public final @Nullable Double y; - public final @Nullable Double z; +public class SoundModificationPacket implements IPacketBase { + public long soundId; + public @Nullable Integer attenuationDistance; + public @Nullable Float pitch; + public @Nullable Double x; + public @Nullable Double y; + public @Nullable Double z; + + public SoundModificationPacket() { } public SoundModificationPacket(long soundId, @Nullable Integer attenuationDistance, @Nullable Float pitch, @Nullable Double x, @Nullable Double y, @Nullable Double z) { this.soundId = soundId; @@ -27,7 +29,8 @@ public SoundModificationPacket(long soundId, @Nullable Integer attenuationDistan this.z = z; } - public static void encode(SoundModificationPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundModificationPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.soundId); boolean b; @@ -52,7 +55,8 @@ public static void encode(SoundModificationPacket packet, FriendlyByteBuf buffer if (b) buffer.writeDouble(packet.y); } - public static SoundModificationPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundModificationPacket decode(FriendlyByteBuf buffer) { long id = buffer.readLong(); @Nullable Integer attenuationDistance = null; @@ -71,7 +75,8 @@ public static SoundModificationPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundModificationPacket packet, Supplier context) { + @Override + public void handle(SoundModificationPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleSoundModificationPacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationWithPathPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationWithPathPacket.java index 14d1407..4f5198f 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationWithPathPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundModificationWithPathPacket.java @@ -11,14 +11,16 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class SoundModificationWithPathPacket { - public final String shortPath; - public final @Nullable Integer attenuationDistance; - public final @Nullable Float pitch; - public final @Nullable Float volume; - public final @Nullable Double x; - public final @Nullable Double y; - public final @Nullable Double z; +public class SoundModificationWithPathPacket implements IPacketBase { + public String shortPath; + public @Nullable Integer attenuationDistance; + public @Nullable Float pitch; + public @Nullable Float volume; + public @Nullable Double x; + public @Nullable Double y; + public @Nullable Double z; + + public SoundModificationWithPathPacket() { } public SoundModificationWithPathPacket(String shortPath, @Nullable Integer attenuationDistance, @Nullable Float volume, @Nullable Float pitch, @Nullable Double x, @Nullable Double y, @Nullable Double z) { this.shortPath = shortPath; @@ -30,7 +32,8 @@ public SoundModificationWithPathPacket(String shortPath, @Nullable Integer atten this.z = z; } - public static void encode(SoundModificationWithPathPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundModificationWithPathPacket packet, FriendlyByteBuf buffer) { if (packet.shortPath == null) { buffer.writeInt(0); } else { @@ -64,7 +67,8 @@ public static void encode(SoundModificationWithPathPacket packet, FriendlyByteBu if (b) buffer.writeDouble(packet.z); } - public static SoundModificationWithPathPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundModificationWithPathPacket decode(FriendlyByteBuf buffer) { int l = buffer.readInt(); String shortPath = null; if (l > 0) { @@ -89,7 +93,8 @@ public static SoundModificationWithPathPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundModificationWithPathPacket packet, Supplier context) { + @Override + public void handle(SoundModificationWithPathPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleSoundModificationWithPathPacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/SoundPlayerBlockEntityPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/SoundPlayerBlockEntityPacket.java index 2fdaf10..0427bce 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/SoundPlayerBlockEntityPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/SoundPlayerBlockEntityPacket.java @@ -11,16 +11,18 @@ import net.minecraft.world.level.Level; import net.minecraftforge.network.NetworkEvent; -public class SoundPlayerBlockEntityPacket { - private final BlockPos pos; - private final SimplePlaylist playlist; - private final PlaybackArea playbackArea; - private final float volume; - private final float pitch; - private final boolean locked; - private final ETrigger trigger; +public class SoundPlayerBlockEntityPacket implements IPacketBase { + private BlockPos pos; + private SimplePlaylist playlist; + private PlaybackArea playbackArea; + private float volume; + private float pitch; + private boolean locked; + private ETrigger trigger; - public SoundPlayerBlockEntityPacket(BlockPos pos, SimplePlaylist playlist, float volume, float pitch, PlaybackArea playbackArea, boolean locked, ETrigger trigger) { + public SoundPlayerBlockEntityPacket() { } + + public SoundPlayerBlockEntityPacket(BlockPos pos, SimplePlaylist playlist, float volume, float pitch, PlaybackArea playbackArea, boolean locked, ETrigger trigger) { this.pos = pos; this.playlist = playlist; this.playbackArea = playbackArea; @@ -30,7 +32,8 @@ public SoundPlayerBlockEntityPacket(BlockPos pos, SimplePlaylist playlist, float this.pitch = pitch; } - public static void encode(SoundPlayerBlockEntityPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(SoundPlayerBlockEntityPacket packet, FriendlyByteBuf buffer) { buffer.writeBlockPos(packet.pos); buffer.writeBoolean(packet.locked); buffer.writeByte(packet.trigger.getIndex()); @@ -40,7 +43,8 @@ public static void encode(SoundPlayerBlockEntityPacket packet, FriendlyByteBuf b packet.playbackArea.serialize(buffer); } - public static SoundPlayerBlockEntityPacket decode(FriendlyByteBuf buffer) { + @Override + public SoundPlayerBlockEntityPacket decode(FriendlyByteBuf buffer) { BlockPos pos = buffer.readBlockPos(); boolean locked = buffer.readBoolean(); ETrigger trigger = ETrigger.getTriggerByIndex(buffer.readByte()); @@ -53,7 +57,8 @@ public static SoundPlayerBlockEntityPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(SoundPlayerBlockEntityPacket packet, Supplier context) { + @Override + public void handle(SoundPlayerBlockEntityPacket packet, Supplier context) { context.get().enqueueWork(() -> { Level level = context.get().getSender().getLevel(); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundPacket.java index e458e94..2fdc835 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundPacket.java @@ -8,25 +8,30 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class StopSoundPacket { - public final long soundId; +public class StopSoundPacket implements IPacketBase { + public long soundId; + + public StopSoundPacket() { } public StopSoundPacket(long soundId) { this.soundId = soundId; } - public static void encode(StopSoundPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(StopSoundPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.soundId); } - public static StopSoundPacket decode(FriendlyByteBuf buffer) { + @Override + public StopSoundPacket decode(FriendlyByteBuf buffer) { long soundId = buffer.readLong(); StopSoundPacket instance = new StopSoundPacket(soundId); return instance; } - public static void handle(StopSoundPacket packet, Supplier context) { + @Override + public void handle(StopSoundPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleStopSoundPacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundWithPathPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundWithPathPacket.java index d876dea..0519804 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundWithPathPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/StopSoundWithPathPacket.java @@ -9,14 +9,17 @@ import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; -public class StopSoundWithPathPacket { - public final String shortPath; +public class StopSoundWithPathPacket implements IPacketBase { + public String shortPath; + + public StopSoundWithPathPacket() { } public StopSoundWithPathPacket(String shortPath) { this.shortPath = shortPath; } - public static void encode(StopSoundWithPathPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(StopSoundWithPathPacket packet, FriendlyByteBuf buffer) { if (packet.shortPath == null) { buffer.writeInt(0); } else { @@ -25,7 +28,8 @@ public static void encode(StopSoundWithPathPacket packet, FriendlyByteBuf buffer } } - public static StopSoundWithPathPacket decode(FriendlyByteBuf buffer) { + @Override + public StopSoundWithPathPacket decode(FriendlyByteBuf buffer) { int l = buffer.readInt(); String shortPath = null; if (l > 0) { @@ -36,7 +40,8 @@ public static StopSoundWithPathPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(StopSoundWithPathPacket packet, Supplier context) { + @Override + public void handle(StopSoundWithPathPacket packet, Supplier context) { context.get().enqueueWork(() -> { DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> ClientWrapper.handleStopSoundWithPathPacket(packet, context)); diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundCompletionPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundCompletionPacket.java index d4b52ef..1fe2fb7 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundCompletionPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundCompletionPacket.java @@ -20,12 +20,14 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class UploadSoundCompletionPacket { - private final long requestId; - private final UUID uploaderUUID; - private final EUserSoundVisibility visibility; - private final ESoundCategory category; - private final String filename; +public class UploadSoundCompletionPacket implements IPacketBase { + private long requestId; + private UUID uploaderUUID; + private EUserSoundVisibility visibility; + private ESoundCategory category; + private String filename; + + public UploadSoundCompletionPacket() { } public UploadSoundCompletionPacket(long requestId, UUID uploader, EUserSoundVisibility visibility, String filename, ESoundCategory category) { this.uploaderUUID = uploader; @@ -35,7 +37,8 @@ public UploadSoundCompletionPacket(long requestId, UUID uploader, EUserSoundVisi this.category = category; } - public static void encode(UploadSoundCompletionPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(UploadSoundCompletionPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeUUID(packet.uploaderUUID); buffer.writeEnum(packet.visibility); @@ -43,7 +46,8 @@ public static void encode(UploadSoundCompletionPacket packet, FriendlyByteBuf bu buffer.writeUtf(packet.filename); } - public static UploadSoundCompletionPacket decode(FriendlyByteBuf buffer) { + @Override + public UploadSoundCompletionPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); UUID uploader = buffer.readUUID(); EUserSoundVisibility visibility = buffer.readEnum(EUserSoundVisibility.class); @@ -54,7 +58,8 @@ public static UploadSoundCompletionPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(UploadSoundCompletionPacket packet, Supplier context) { + @Override + public void handle(UploadSoundCompletionPacket packet, Supplier context) { context.get().enqueueWork(() -> { new Thread(() -> { diff --git a/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundPacket.java b/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundPacket.java index 1d0f0fd..efb5d14 100644 --- a/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundPacket.java +++ b/src/main/java/de/mrjulsen/mineify/network/packets/UploadSoundPacket.java @@ -8,10 +8,12 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.network.NetworkEvent; -public class UploadSoundPacket { - private final long requestId; - private final int maxSize; - private final byte[] data; +public class UploadSoundPacket implements IPacketBase { + private long requestId; + private int maxSize; + private byte[] data; + + public UploadSoundPacket() { } public UploadSoundPacket(long requestId, byte[] data, int maxSize) { this.data = data; @@ -19,13 +21,15 @@ public UploadSoundPacket(long requestId, byte[] data, int maxSize) { this.requestId = requestId; } - public static void encode(UploadSoundPacket packet, FriendlyByteBuf buffer) { + @Override + public void encode(UploadSoundPacket packet, FriendlyByteBuf buffer) { buffer.writeLong(packet.requestId); buffer.writeInt(packet.maxSize); buffer.writeByteArray(packet.data); } - public static UploadSoundPacket decode(FriendlyByteBuf buffer) { + @Override + public UploadSoundPacket decode(FriendlyByteBuf buffer) { long requestId = buffer.readLong(); int maxSize = buffer.readInt(); byte[] data = buffer.readByteArray(); @@ -34,7 +38,8 @@ public static UploadSoundPacket decode(FriendlyByteBuf buffer) { return instance; } - public static void handle(UploadSoundPacket packet, Supplier context) { + @Override + public void handle(UploadSoundPacket packet, Supplier context) { context.get().enqueueWork(() -> { if (!InstanceManager.Server.streamCache.containsKey(packet.requestId)) { InstanceManager.Server.streamCache.put(packet.requestId, new ByteArrayOutputStream(packet.maxSize));