diff --git a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java index 5dca012cc..f05f2e35d 100644 --- a/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java +++ b/src/main/java/dan200/computercraft/shared/network/NetworkHandler.java @@ -9,6 +9,8 @@ import dan200.computercraft.ComputerCraft; import dan200.computercraft.api.ComputerCraftAPI; import dan200.computercraft.shared.network.client.*; import dan200.computercraft.shared.network.server.*; +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; @@ -26,7 +28,8 @@ import java.util.function.Function; public final class NetworkHandler { - public static SimpleChannel network; + private static SimpleChannel network; + private static final IntSet usedIds = new IntOpenHashSet(); private NetworkHandler() { @@ -100,6 +103,7 @@ public final class NetworkHandler */ private static void registerMainThread( int id, NetworkDirection direction, Class type, Function decoder ) { + if( !usedIds.add( id ) ) throw new IllegalStateException( "Duplicate message kind for for id " + id ); network.messageBuilder( type, id, direction ) .encoder( NetworkMessage::toBytes ) .decoder( decoder )