Fix registry replacement
This commit is contained in:
parent
6665db3a69
commit
c0c789f29c
|
|
@ -73,13 +73,14 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public V put(@Nullable Integer key, @Nullable V value) {
|
public V put(@Nullable Integer key, @Nullable V value) {
|
||||||
ensureArrayCanFitId(key);
|
RegistryValueData data = infoByValue.get(value);
|
||||||
V oldValue = valuesById.get(key);
|
int unboxedKey = key;
|
||||||
if(oldValue != null)
|
if(data != null && data.id != -1 && data.id != unboxedKey)
|
||||||
throw new IllegalArgumentException("Existing mapping");
|
throw new IllegalArgumentException("Existing mapping for ID " + data.id + " value " + value + " when new ID " + unboxedKey + " was requested");
|
||||||
valuesById.set(key, value);
|
ensureArrayCanFitId(unboxedKey);
|
||||||
storeId(value, key);
|
V oldValue = valuesById.set(unboxedKey, value);
|
||||||
return null;
|
storeId(value, unboxedKey);
|
||||||
|
return oldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|
@ -305,14 +306,16 @@ public class FastForgeRegistry<V extends IForgeRegistryEntry<V>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private V forcePut(@Nullable K key, @Nullable V value, boolean throwOnExisting) {
|
private V forcePut(@Nullable K key, @Nullable V value, boolean throwOnExisting) {
|
||||||
|
if(throwOnExisting) {
|
||||||
|
RegistryValueData dataForValue = infoByValue.get(value);
|
||||||
|
// null check could be wrong if null is a valid value but doesn't matter in Forge's use
|
||||||
|
if(dataForValue != null && getter.apply(dataForValue) != null && !Objects.equals(getter.apply(dataForValue), key)) {
|
||||||
|
throw new IllegalArgumentException("Existing mapping for key " + key + " value " + value);
|
||||||
|
}
|
||||||
|
}
|
||||||
V oldValue = valuesByKey.put(key, value);
|
V oldValue = valuesByKey.put(key, value);
|
||||||
if(oldValue != null) {
|
if(oldValue != null) {
|
||||||
if(throwOnExisting) {
|
updateInfoPairAndClearIfNull(oldValue, p -> setter.accept(p, null));
|
||||||
valuesByKey.put(key, oldValue);
|
|
||||||
throw new IllegalArgumentException("Existing mapping");
|
|
||||||
} else {
|
|
||||||
updateInfoPairAndClearIfNull(oldValue, p -> setter.accept(p, null));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
updateInfoPairAndClearIfNull(value, p -> setter.accept(p, key));
|
updateInfoPairAndClearIfNull(value, p -> setter.accept(p, key));
|
||||||
return oldValue;
|
return oldValue;
|
||||||
|
|
@ -590,7 +593,7 @@ 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 int id;
|
public int id = -1;
|
||||||
public Object overrideOwner;
|
public Object overrideOwner;
|
||||||
|
|
||||||
boolean isEmpty() {
|
boolean isEmpty() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user