mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-26 09:38:08 -05:00
Assign a new ID to client only registry entries when syncing. (#1179)
* Assign a new ID to client only registry entries when syncing. Fixes #1165 * Cleanup + review comments
This commit is contained in:
parent
cc3cc6c601
commit
1fec9da3c8
1 changed files with 15 additions and 13 deletions
|
@ -18,10 +18,8 @@ package net.fabricmc.fabric.mixin.registry.sync;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
|
@ -273,25 +271,29 @@ public abstract class MixinIdRegistry<T> extends Registry<T> implements Remappab
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case REMOTE: {
|
case REMOTE: {
|
||||||
// TODO: Is this what mods really want?
|
int maxId = -1;
|
||||||
Set<Identifier> droppedIds = new HashSet<>();
|
|
||||||
|
|
||||||
for (Identifier id : getIds()) {
|
for (Identifier id : getIds()) {
|
||||||
if (!remoteIndexedEntries.containsKey(id)) {
|
if (!remoteIndexedEntries.containsKey(id)) {
|
||||||
T object = get(id);
|
if (maxId < 0) {
|
||||||
int rid = getRawId(object);
|
for (int value : remoteIndexedEntries.values()) {
|
||||||
|
if (value > maxId) {
|
||||||
|
maxId = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
droppedIds.add(id);
|
if (maxId < 0) {
|
||||||
|
throw new RemapException("Failed to assign new id to client only registry entry");
|
||||||
|
}
|
||||||
|
|
||||||
// Emit RemoveObject events for removed objects.
|
maxId++;
|
||||||
fabric_getRemoveObjectEvent().invoker().onEntryRemoved(rid, id, object);
|
|
||||||
|
FABRIC_LOGGER.debug("An ID for {} was not sent by the server, assuming client only registry entry and assigning a new id ({}) in {}", id.toString(), maxId, getKey().getValue().toString());
|
||||||
|
remoteIndexedEntries.put(id, maxId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: indexedEntries cannot be safely remove()d from
|
|
||||||
idToEntry.keySet().removeAll(droppedIds);
|
|
||||||
keyToEntry.keySet().removeIf(registryKey -> droppedIds.contains(registryKey.getValue()));
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue