Add forge registries for most vanilla registries

Made all registry names consistent with their vanilla counterparts
Also added a system for legacy registry names, so no data will be lost
Cleaned up formatting in GameData and ForgeRegistries
This commit is contained in:
tterrag committed 2019-06-09 04:23:39 -04:00
1 parent 40f2276e88
commit 3385e62aa7
29 files changed
+523 -54

No files matched your search

@@ -21,6 +21,7 @@ package net.minecraftforge.registries;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -50,6 +51,7 @@ public class RegistryManager
private BiMap<Class<? extends IForgeRegistryEntry<?>>, ResourceLocation> superTypes = HashBiMap.create();
private Set<ResourceLocation> persisted = Sets.newHashSet();
private Set<ResourceLocation> synced = Sets.newHashSet();
private Map<ResourceLocation, ResourceLocation> legacyNames = new HashMap<>();
private final String name;
public RegistryManager(String name)
@@ -83,6 +85,19 @@ public class RegistryManager
{
return this.registries.inverse().get(reg);
}
public <V extends IForgeRegistryEntry<V>> ResourceLocation updateLegacyName(ResourceLocation legacyName)
{
while (getRegistry(legacyName) == null)
{
legacyName = legacyNames.get(legacyName);
if (legacyName == null)
{
return null;
}
}
return legacyName;
}
public <V extends IForgeRegistryEntry<V>> ForgeRegistry<V> getRegistry(ResourceLocation key, RegistryManager other)
{
@@ -97,6 +112,9 @@ public class RegistryManager
this.persisted.add(key);
if (other.synced.contains(key))
this.synced.add(key);
other.legacyNames.entrySet().stream()
.filter(e -> e.getValue().equals(key))
.forEach(e -> addLegacyName(e.getKey(), e.getValue()));
}
return getRegistry(key);
}
@@ -120,8 +138,19 @@ public class RegistryManager
this.persisted.add(name);
if (builder.getSync())
this.synced.add(name);
for (ResourceLocation legacyName : builder.getLegacyNames())
addLegacyName(legacyName, name);
return getRegistry(name);
}
private void addLegacyName(ResourceLocation legacyName, ResourceLocation name)
{
if (this.legacyNames.containsKey(legacyName))
{
throw new IllegalArgumentException("Legacy name conflict for registry " + name + ", upgrade path must be linear: " + legacyName);
}
this.legacyNames.put(legacyName, name);
}
private void findSuperTypes(Class<?> type, Set<Class<?>> types)
{