mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2024-12-15 12:40:30 +00:00
Check for duplicate ids when registering channels
Should prevent #1130 occurring again. Possibly worth submitting a PR to Forge for this too.
This commit is contained in:
parent
954254e7e4
commit
be3a960273
@ -9,6 +9,8 @@ import dan200.computercraft.ComputerCraft;
|
|||||||
import dan200.computercraft.api.ComputerCraftAPI;
|
import dan200.computercraft.api.ComputerCraftAPI;
|
||||||
import dan200.computercraft.shared.network.client.*;
|
import dan200.computercraft.shared.network.client.*;
|
||||||
import dan200.computercraft.shared.network.server.*;
|
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.PlayerEntity;
|
||||||
import net.minecraft.entity.player.ServerPlayerEntity;
|
import net.minecraft.entity.player.ServerPlayerEntity;
|
||||||
import net.minecraft.network.PacketBuffer;
|
import net.minecraft.network.PacketBuffer;
|
||||||
@ -26,7 +28,8 @@ import java.util.function.Function;
|
|||||||
|
|
||||||
public final class NetworkHandler
|
public final class NetworkHandler
|
||||||
{
|
{
|
||||||
public static SimpleChannel network;
|
private static SimpleChannel network;
|
||||||
|
private static final IntSet usedIds = new IntOpenHashSet();
|
||||||
|
|
||||||
private NetworkHandler()
|
private NetworkHandler()
|
||||||
{
|
{
|
||||||
@ -100,6 +103,7 @@ public final class NetworkHandler
|
|||||||
*/
|
*/
|
||||||
private static <T extends NetworkMessage> void registerMainThread( int id, NetworkDirection direction, Class<T> type, Function<PacketBuffer, T> decoder )
|
private static <T extends NetworkMessage> void registerMainThread( int id, NetworkDirection direction, Class<T> type, Function<PacketBuffer, T> decoder )
|
||||||
{
|
{
|
||||||
|
if( !usedIds.add( id ) ) throw new IllegalStateException( "Duplicate message kind for for id " + id );
|
||||||
network.messageBuilder( type, id, direction )
|
network.messageBuilder( type, id, direction )
|
||||||
.encoder( NetworkMessage::toBytes )
|
.encoder( NetworkMessage::toBytes )
|
||||||
.decoder( decoder )
|
.decoder( decoder )
|
||||||
|
Loading…
Reference in New Issue
Block a user