From 7b028fd6b8ae00d0f9dacbd33f2854781c4ca26b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20Goossens?= Date: Sun, 6 Aug 2023 19:33:02 +0200 Subject: [PATCH] Small tweaks --- .../java/com/noxcrew/noxesium/network/NoxesiumPackets.java | 3 ++- .../clientbound/ClientboundChangeServerRulesPacket.java | 6 ++++-- .../clientbound/ClientboundServerInformationPacket.java | 1 - .../network/serverbound/ServerboundNoxesiumPacket.java | 6 +++++- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java b/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java index 59b02257..b3fdc55d 100644 --- a/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/NoxesiumPackets.java @@ -9,6 +9,7 @@ import com.noxcrew.noxesium.network.clientbound.ClientboundResetServerRulesPacket; import com.noxcrew.noxesium.network.clientbound.ClientboundServerInformationPacket; import com.noxcrew.noxesium.network.serverbound.ServerboundClientInformationPacket; +import com.noxcrew.noxesium.network.serverbound.ServerboundClientSettingsPacket; import com.noxcrew.noxesium.network.serverbound.ServerboundNoxesiumPacket; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking; import net.fabricmc.fabric.api.networking.v1.FabricPacket; @@ -43,7 +44,7 @@ public class NoxesiumPackets { public static final PacketType CLIENT_SERVER_INFO = client("server_info", ClientboundServerInformationPacket::new); public static final PacketType SERVER_CLIENT_INFO = server("client_info"); - public static final PacketType SERVER_CLIENT_SETTINGS = server("client_settings"); + public static final PacketType SERVER_CLIENT_SETTINGS = server("client_settings"); /** * Registers a new clientbound Noxesium packet. diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundChangeServerRulesPacket.java b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundChangeServerRulesPacket.java index aa4e8f40..7fe872fe 100644 --- a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundChangeServerRulesPacket.java +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundChangeServerRulesPacket.java @@ -9,7 +9,7 @@ import net.minecraft.network.FriendlyByteBuf; /** - * Resets the stored value for one or more server rules. + * Changes the stored value for one or more server rules. */ public class ClientboundChangeServerRulesPacket extends ClientboundNoxesiumPacket { @@ -26,7 +26,9 @@ public ClientboundChangeServerRulesPacket(FriendlyByteBuf buf) { public void receive(LocalPlayer player, PacketSender responseSender) { for (var index : indices) { var rule = ServerRuleModule.getInstance().getIndex(index); - if (rule == null) continue; + + // If we don't know one rule the whole packet is useless + if (rule == null) return; // TODO Can we do something that does not involve passing along the buffer? rule.setValueFromBuffer(buffer); diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundServerInformationPacket.java b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundServerInformationPacket.java index 478ff8b2..af586928 100644 --- a/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundServerInformationPacket.java +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/clientbound/ClientboundServerInformationPacket.java @@ -2,7 +2,6 @@ import com.noxcrew.noxesium.NoxesiumMod; import com.noxcrew.noxesium.network.NoxesiumPackets; -import com.noxcrew.noxesium.network.serverbound.ServerboundNoxesiumPacket; import net.fabricmc.fabric.api.networking.v1.PacketSender; import net.fabricmc.fabric.api.networking.v1.PacketType; import net.minecraft.client.player.LocalPlayer; diff --git a/fabric/src/main/java/com/noxcrew/noxesium/network/serverbound/ServerboundNoxesiumPacket.java b/fabric/src/main/java/com/noxcrew/noxesium/network/serverbound/ServerboundNoxesiumPacket.java index 500ef3eb..6e936c64 100644 --- a/fabric/src/main/java/com/noxcrew/noxesium/network/serverbound/ServerboundNoxesiumPacket.java +++ b/fabric/src/main/java/com/noxcrew/noxesium/network/serverbound/ServerboundNoxesiumPacket.java @@ -43,7 +43,7 @@ public final void write(FriendlyByteBuf buf) { * used by the server, e.g. if this is 3 and the packet being serialized * was v1 until protocol 4 and v2 after then this should return 1. */ - public int getVersion(int protocolVersion) { + public Integer getVersion(int protocolVersion) { return version; } @@ -68,6 +68,10 @@ public boolean send() { if (ClientPlayNetworking.canSend(getType()) && NoxesiumPackets.canSend(getType())) { var maxProtocol = NoxesiumMod.getMaxProtocolVersion(); var maxVersion = getVersion(maxProtocol); + if (maxVersion == null) { + // If the server does not know how to handle this packet we don't send it! + return false; + } var buffer = PacketByteBufs.create(); if (maxVersion >= version) {