Skip to content

Commit

Permalink
Small tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeltumn committed Aug 6, 2023
1 parent d01001f commit 7b028fd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class NoxesiumPackets {
public static final PacketType<ClientboundServerInformationPacket> CLIENT_SERVER_INFO = client("server_info", ClientboundServerInformationPacket::new);

public static final PacketType<ServerboundClientInformationPacket> SERVER_CLIENT_INFO = server("client_info");
public static final PacketType<ServerboundClientInformationPacket> SERVER_CLIENT_SETTINGS = server("client_settings");
public static final PacketType<ServerboundClientSettingsPacket> SERVER_CLIENT_SETTINGS = server("client_settings");

/**
* Registers a new clientbound Noxesium packet.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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) {
Expand Down

0 comments on commit 7b028fd

Please sign in to comment.