From 9d17f137143cd20745eb2298e2ca57a32b0c8759 Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Fri, 14 Dec 2018 19:43:10 +0100 Subject: [PATCH] ensure deterministic registry population order, fixes blockstate ID desync --- .../fabric/mixin/registry/MixinIdRegistry.java | 9 ++++++++- .../fabric/registry/RegistrySyncManager.java | 14 ++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/fabricmc/fabric/mixin/registry/MixinIdRegistry.java b/src/main/java/net/fabricmc/fabric/mixin/registry/MixinIdRegistry.java index 49a151653..07c4a72ea 100644 --- a/src/main/java/net/fabricmc/fabric/mixin/registry/MixinIdRegistry.java +++ b/src/main/java/net/fabricmc/fabric/mixin/registry/MixinIdRegistry.java @@ -35,6 +35,10 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; + @Mixin(IdRegistry.class) public abstract class MixinIdRegistry implements RemappableRegistry, ListenableRegistry, RegistryListener { @Shadow @@ -135,7 +139,10 @@ public abstract class MixinIdRegistry implements RemappableRegistry, Listenab idStore.clear(); nextId = 0; - for (Identifier identifier : idMap.keySet()) { + List idsInOrder = new ArrayList<>(idMap.keySet()); + idsInOrder.sort(Comparator.comparingInt(idMap::getInt)); + + for (Identifier identifier : idsInOrder) { int id = idMap.getInt(identifier); T object = objectMap.get(identifier); if (object == null) { diff --git a/src/main/java/net/fabricmc/fabric/registry/RegistrySyncManager.java b/src/main/java/net/fabricmc/fabric/registry/RegistrySyncManager.java index 4ad94af29..1002efd79 100644 --- a/src/main/java/net/fabricmc/fabric/registry/RegistrySyncManager.java +++ b/src/main/java/net/fabricmc/fabric/registry/RegistrySyncManager.java @@ -51,12 +51,14 @@ public final class RegistrySyncManager { public static void receivePacket(PacketContext context, PacketByteBuf buf) { CompoundTag compound = buf.readCompoundTag(); - try { - apply(compound, false); - } catch (RemapException e) { - // TODO: log error properly - e.printStackTrace(); - } + context.getTaskQueue().execute(() -> { + try { + apply(compound, false); + } catch (RemapException e) { + // TODO: log error properly + e.printStackTrace(); + } + }); } public static CompoundTag toTag(boolean isClientSync) {