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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@Mixin(IdRegistry.class) @Mixin(IdRegistry.class)
public abstract class MixinIdRegistry<T> implements RemappableRegistry, ListenableRegistry<T>, RegistryListener<T> { public abstract class MixinIdRegistry<T> implements RemappableRegistry, ListenableRegistry<T>, RegistryListener<T> {
@Shadow @Shadow
@ -135,7 +139,10 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
idStore.clear(); idStore.clear();
nextId = 0; 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); int id = idMap.getInt(identifier);
T object = objectMap.get(identifier); T object = objectMap.get(identifier);
if (object == null) { if (object == null) {

View file

@ -51,12 +51,14 @@ public final class RegistrySyncManager {
public static void receivePacket(PacketContext context, PacketByteBuf buf) { public static void receivePacket(PacketContext context, PacketByteBuf buf) {
CompoundTag compound = buf.readCompoundTag(); CompoundTag compound = buf.readCompoundTag();
try { context.getTaskQueue().execute(() -> {
apply(compound, false); try {
} catch (RemapException e) { apply(compound, false);
// TODO: log error properly } catch (RemapException e) {
e.printStackTrace(); // TODO: log error properly
} e.printStackTrace();
}
});
} }
public static CompoundTag toTag(boolean isClientSync) { public static CompoundTag toTag(boolean isClientSync) {