mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-25 06:24:43 +00:00
Add support for custom tag types (#7289)
This commit is contained in:
1 parent
43391c009c
commit
45f8dc5245
27 files changed
+1059
-24
No files matched your search
@@ -21,6 +21,7 @@ package net.minecraftforge.common.extensions;
|
||||
|
||||
import net.minecraft.data.TagsProvider;
|
||||
import net.minecraft.tags.ITag;
|
||||
import net.minecraft.util.RegistryKey;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
//TODO, Tag removal support.
|
||||
@@ -40,6 +41,14 @@ public interface IForgeTagBuilder<T>
|
||||
return builder;
|
||||
}
|
||||
|
||||
default TagsProvider.Builder<T> add(RegistryKey<T>... keys) {
|
||||
TagsProvider.Builder<T> builder = getBuilder();
|
||||
for (RegistryKey<T> key : keys) {
|
||||
builder.getInternalBuilder().func_232961_a_(key.func_240901_a_(), getBuilder().getModID());
|
||||
}
|
||||
return builder;
|
||||
}
|
||||
|
||||
default TagsProvider.Builder<T> replace() {
|
||||
return replace(true);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2020.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation version 2.1
|
||||
* of the License.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
package net.minecraftforge.common.extensions;
|
||||
|
||||
import java.util.Map;
|
||||
import net.minecraft.tags.ITagCollection;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.ForgeTagHandler;
|
||||
import net.minecraftforge.registries.IForgeRegistry;
|
||||
import net.minecraftforge.registries.IForgeRegistryEntry;
|
||||
|
||||
public interface IForgeTagCollectionSupplier
|
||||
{
|
||||
/**
|
||||
* Gets the tag map of registry names to tag collections for the various custom tag types.
|
||||
*
|
||||
* @apiNote Prefer using one of the getCustomTypeCollection methods
|
||||
*/
|
||||
default Map<ResourceLocation, ITagCollection<?>> getCustomTagTypes()
|
||||
{
|
||||
return ForgeTagHandler.getCustomTagTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ITagCollection} for a forge registry with the given name, or throws an exception if the registry doesn't support custom tag types.
|
||||
* @param regName Name of the forge registry
|
||||
* @return The tag collection
|
||||
*/
|
||||
default ITagCollection<?> getCustomTypeCollection(ResourceLocation regName)
|
||||
{
|
||||
if (!ForgeTagHandler.getCustomTagTypeNames().contains(regName)) throw new IllegalArgumentException("Registry " + regName + ", does not support custom tag types");
|
||||
return getCustomTagTypes().get(regName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the {@link ITagCollection} for a forge registry, or throws an exception if the registry doesn't support custom tag types.
|
||||
* @param reg Forge registry
|
||||
* @return The tag collection
|
||||
*/
|
||||
default <T extends IForgeRegistryEntry<T>> ITagCollection<T> getCustomTypeCollection(IForgeRegistry<T> reg)
|
||||
{
|
||||
return (ITagCollection<T>) getCustomTypeCollection(reg.getRegistryName());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user