ensure deterministic registry population order, fixes blockstate ID desync

This commit is contained in:
Adrian Siekierka 2018-12-14 19:43:10 +01:00
parent 5c23a10db1
commit 9d17f13714
2 changed files with 16 additions and 7 deletions

View file

@ -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<T> implements RemappableRegistry, ListenableRegistry<T>, RegistryListener<T> {
@Shadow
@ -135,7 +139,10 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
idStore.clear();
nextId = 0;
for (Identifier identifier : idMap.keySet()) {
List<Identifier> 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) {

View file

@ -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) {