mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-26 17:46:25 -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.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.BiMap;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
|
@ -273,25 +271,29 @@ public abstract class MixinIdRegistry<T> extends Registry<T> implements Remappab
|
|||
break;
|
||||
}
|
||||
case REMOTE: {
|
||||
// TODO: Is this what mods really want?
|
||||
Set<Identifier> droppedIds = new HashSet<>();
|
||||
int maxId = -1;
|
||||
|
||||
for (Identifier id : getIds()) {
|
||||
if (!remoteIndexedEntries.containsKey(id)) {
|
||||
T object = get(id);
|
||||
int rid = getRawId(object);
|
||||
if (maxId < 0) {
|
||||
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.
|
||||
fabric_getRemoveObjectEvent().invoker().onEntryRemoved(rid, id, object);
|
||||
maxId++;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue