Unbox IDs

This commit is contained in:
embeddedt 2023-04-28 21:40:22 -04:00
parent c09c4ccf68
commit 8b71c823c4
No known key found for this signature in database
GPG Key ID: A69433EC199B5613

View File

@ -88,7 +88,7 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
ensureArrayCanFitId(key); ensureArrayCanFitId(key);
V oldValue = valuesById.set(key, value); V oldValue = valuesById.set(key, value);
if(oldValue != null) { if(oldValue != null) {
updateInfoPairAndClearIfNull(oldValue, pair -> pair.id = null); updateInfoPairAndClearIfNull(oldValue, pair -> pair.id = -1);
} }
storeId(value, key); storeId(value, key);
return oldValue; return oldValue;
@ -159,7 +159,7 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
RegistryValueData pair = infoByValue.get(key); RegistryValueData pair = infoByValue.get(key);
if(pair == null) if(pair == null)
return null; return null;
return pair.id; return pair.id == -1 ? null : pair.id;
} }
@Override @Override
@ -168,9 +168,10 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
if(pair == null) if(pair == null)
return null; return null;
int id = pair.id; int id = pair.id;
valuesById.set(id, null); if(id != -1)
updateInfoPairAndClearIfNull((V)key, p -> p.id = null); valuesById.set(id, null);
return id; updateInfoPairAndClearIfNull((V)key, p -> p.id = -1);
return id == -1 ? null : id;
} }
@Override @Override
@ -230,7 +231,7 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
public void clear() { public void clear() {
valuesById.clear(); valuesById.clear();
infoByValue.values().removeIf(pair -> { infoByValue.values().removeIf(pair -> {
pair.id = null; pair.id = -1;
return pair.isEmpty(); return pair.isEmpty();
}); });
} }
@ -589,11 +590,11 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
static class RegistryValueData { static class RegistryValueData {
public ResourceKey<?> key; public ResourceKey<?> key;
public ResourceLocation location; public ResourceLocation location;
public Integer id; public int id;
public Object overrideOwner; public Object overrideOwner;
boolean isEmpty() { boolean isEmpty() {
return key == null && location == null && id == null && overrideOwner == null; return key == null && location == null && id == -1 && overrideOwner == null;
} }
} }
} }