[1.18.2] Fix tags for custom forge registries. (#8495)

Tag-enabled registries must now be registered to vanilla's root registry. See RegistryBuilder#hasTags.
Modded tag-enabled registries have to use the format `data/<namespace>/tags/<registrynamespace>/<registryname>/<tag>.json`
This format is to prevent conflicts for registries with the same path but different namespaces
EX: Registry name `examplemod:shoe`, tag name `blue_shoes` would be `data/<namespace>/tags/examplemod/shoe/blue_shoes.json`
RegistryEvent.NewRegistry has been moved and renamed to NewRegistryEvent.
RegistryBuilder#create has been made private. See NewRegistryEvent#create
Created new ITagManager system for looking up Forge tags. See IForgeRegistry#tags.
Add lookup methods for Holders from forge registries. See IForgeRegistry#getHolder.
This commit is contained in:
SizableShrimp authored and GitHub committed 2022-03-16 13:36:00 -07:00
1 parent 30f3a7dbba
commit ad75cb8644
51 files changed
+1621 -531

No files matched your search

@@ -38,8 +38,6 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
private boolean allowOverrides = true;
private boolean allowModifications = false;
private boolean hasWrapper = false;
@Nullable
private String tagFolder;
private DummyFactory<T> dummyFactory;
private MissingFactory<T> missingFactory;
private Set<ResourceLocation> legacyNames = new HashSet<>();
@@ -201,15 +199,6 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
return this;
}
public RegistryBuilder<T> tagFolder(String tagFolder)
{
if (tagFolder == null || !tagFolder.matches("[a-z_/]+")) throw new IllegalArgumentException("Non [a-z_/] character in tag folder " + tagFolder);
this.tagFolder = tagFolder;
//Also mark this registry as having a wrapper to a vanilla registry so that it can be used in data generators properly
hasWrapper();
return this;
}
public RegistryBuilder<T> legacyName(String name)
{
return legacyName(new ResourceLocation(name));
@@ -227,7 +216,24 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
return this;
}
public IForgeRegistry<T> create()
/**
* Enables tags for this registry if not already.
* All forge registries with wrappers inherently support tags.
*
* @return this builder
* @see RegistryBuilder#hasWrapper()
*/
public RegistryBuilder<T> hasTags()
{
// Tag system heavily relies on Registry<?> objects, so we need a wrapper for this registry to take advantage
this.hasWrapper();
return this;
}
/**
* Modders: Use {@link NewRegistryEvent#create(RegistryBuilder)} instead
*/
IForgeRegistry<T> create()
{
if (hasWrapper)
{
@@ -345,12 +351,6 @@ public class RegistryBuilder<T extends IForgeRegistryEntry<T>>
return allowModifications;
}
@Nullable
public String getTagFolder()
{
return tagFolder;
}
@Nullable
public DummyFactory<T> getDummyFactory()
{