From adc897458b0656a54fdebfaf92b9c33d0fa412a1 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Thu, 5 Dec 2024 21:34:49 +0200 Subject: [PATCH] Implement synced registry check in holder stream codec (#974) --- .../network/codec/ByteBufCodecs.java.patch | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/patches/net/minecraft/network/codec/ByteBufCodecs.java.patch b/patches/net/minecraft/network/codec/ByteBufCodecs.java.patch index ac8e4a2731d..0ae4bbce318 100644 --- a/patches/net/minecraft/network/codec/ByteBufCodecs.java.patch +++ b/patches/net/minecraft/network/codec/ByteBufCodecs.java.patch @@ -1,19 +1,37 @@ --- a/net/minecraft/network/codec/ByteBufCodecs.java +++ b/net/minecraft/network/codec/ByteBufCodecs.java -@@ -487,7 +_,11 @@ +@@ -487,7 +_,7 @@ ) { return new StreamCodec() { private IdMap getRegistryOrThrow(RegistryFriendlyByteBuf p_362297_) { - return p_320353_.apply(p_362297_.registryAccess().lookupOrThrow(p_319942_)); -+ var registry = p_362297_.registryAccess().lookupOrThrow(p_319942_); -+ if (net.neoforged.neoforge.registries.RegistryManager.isNonSyncedBuiltInRegistry(registry)) { -+ throw new IllegalStateException("Cannot use ID syncing for non-synced built-in registry: " + registry.key()); -+ } -+ return p_320353_.apply(registry); ++ return p_320353_.apply(getSyncableRegistryOrThrow(p_362297_, p_319942_)); } public R decode(RegistryFriendlyByteBuf p_340887_) { -@@ -544,8 +_,25 @@ +@@ -517,7 +_,7 @@ + private static final int DIRECT_HOLDER_ID = 0; + + private IdMap> getRegistryOrThrow(RegistryFriendlyByteBuf p_376392_) { +- return p_376392_.registryAccess().lookupOrThrow(p_320391_).asHolderIdMap(); ++ return getSyncableRegistryOrThrow(p_376392_, p_320391_).asHolderIdMap(); + } + + public Holder decode(RegistryFriendlyByteBuf p_363509_) { +@@ -539,13 +_,38 @@ + }; + } + ++ private static Registry getSyncableRegistryOrThrow(RegistryFriendlyByteBuf buffer, ResourceKey> registryKey) { ++ var registry = buffer.registryAccess().lookupOrThrow(registryKey); ++ if (net.neoforged.neoforge.registries.RegistryManager.isNonSyncedBuiltInRegistry(registry)) { ++ throw new io.netty.handler.codec.CodecException("Cannot use ID syncing for non-synced built-in registry: " + registry.key()); ++ } ++ return registry; ++ } ++ + static StreamCodec> holderSet(final ResourceKey> p_332137_) { + return new StreamCodec>() { private static final int NAMED_SET = -1; private final StreamCodec> holderCodec = ByteBufCodecs.holderRegistry(p_332137_);