mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 16:54:22 +00:00
Add support for forge's "remove" list to tag datagenerators (#7911)
This commit is contained in:
1 parent
bec9d6f534
commit
12d0f96fc2
9 files changed
+272
-6
No files matched your search
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
*
|
||||
* 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.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.Tag;
|
||||
|
||||
public interface IForgeRawTagBuilder
|
||||
{
|
||||
default Tag.Builder getRawBuilder()
|
||||
{
|
||||
return (Tag.Builder)this;
|
||||
}
|
||||
|
||||
/**
|
||||
* internal, called when a raw builder is written to json to add forge additions (e.g. the remove list)
|
||||
*/
|
||||
default void serializeTagAdditions(final JsonObject tagJson)
|
||||
{
|
||||
Tag.Builder rawBuilder = this.getRawBuilder();
|
||||
Stream<Tag.BuilderEntry> removeEntries = rawBuilder.getRemoveEntries();
|
||||
JsonArray removeEntriesAsJsonArray = new JsonArray();
|
||||
removeEntries.forEach(proxy ->proxy.getEntry().serializeTo(removeEntriesAsJsonArray));
|
||||
if (removeEntriesAsJsonArray.size() > 0)
|
||||
{
|
||||
tagJson.add("remove", removeEntriesAsJsonArray);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag entry to the remove list.
|
||||
* @param entry The tag entry to add to the remove list
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder remove(final Tag.Entry tagEntry, final String source)
|
||||
{
|
||||
return this.getRawBuilder().remove(new Tag.BuilderEntry(tagEntry,source));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single-element entry to the remove list.
|
||||
* @param elementID The ID of the element to add to the remove list
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder removeElement(final ResourceLocation elementID, final String source)
|
||||
{
|
||||
return this.remove(new Tag.ElementEntry(elementID), source);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a tag to the remove list.
|
||||
* @param tagID The ID of the tag to add to the remove list
|
||||
* @param source The source of the caller for logging purposes (generally a modid)
|
||||
* @return The builder for chaining purposes
|
||||
*/
|
||||
default Tag.Builder removeTag(final ResourceLocation tagID, final String source)
|
||||
{
|
||||
return this.remove(new Tag.TagEntry(tagID), source);
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,6 @@ import net.minecraft.tags.Tag;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
//TODO, Tag removal support.
|
||||
public interface IForgeTagAppender<T>
|
||||
{
|
||||
private TagsProvider.TagAppender<T> self() {
|
||||
@@ -66,4 +65,85 @@ public interface IForgeTagAppender<T>
|
||||
{
|
||||
return self().add(new Tag.OptionalTagEntry(location));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a registry entry to the tag json's remove list. Callable during datageneration.
|
||||
* @param element The entry to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
default TagsProvider.TagAppender<T> remove(final T entry)
|
||||
{
|
||||
return remove(this.self().registry.getKey(entry));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple registry entries to the tag json's remove list. Callable during datageneration.
|
||||
* @param entries The entries to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default TagsProvider.TagAppender<T> remove(final T first, final T...entries)
|
||||
{
|
||||
this.remove(first);
|
||||
for (T entry : entries)
|
||||
{
|
||||
this.remove(entry);
|
||||
}
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a single element's ID to the tag json's remove list. Callable during datageneration.
|
||||
* @param location The ID of the element to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
default TagsProvider.TagAppender<T> remove(final ResourceLocation location)
|
||||
{
|
||||
TagsProvider.TagAppender<T> builder = self();
|
||||
builder.getInternalBuilder().removeElement(location, builder.getModID());
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple elements' IDs to the tag json's remove list. Callable during datageneration.
|
||||
* @param locations The IDs of the elements to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
default TagsProvider.TagAppender<T> remove(final ResourceLocation first, final ResourceLocation... locations)
|
||||
{
|
||||
this.remove(first);
|
||||
for (ResourceLocation location : locations)
|
||||
{
|
||||
this.remove(location);
|
||||
}
|
||||
return self();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a tag to the tag json's remove list. Callable during datageneration.
|
||||
* @param tag The ID of the tag to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
default TagsProvider.TagAppender<T> remove(Tag.Named<T> tag)
|
||||
{
|
||||
TagsProvider.TagAppender<T> builder = self();
|
||||
builder.getInternalBuilder().removeTag(tag.getName(), builder.getModID());
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds multiple tags to the tag json's remove list. Callable during datageneration.
|
||||
* @param tags The IDs of the tags to remove
|
||||
* @return The builder for chaining
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
default TagsProvider.TagAppender<T> remove(Tag.Named<T> first, Tag.Named<T>...tags)
|
||||
{
|
||||
this.remove(first);
|
||||
for (Tag.Named<T> tag : tags)
|
||||
{
|
||||
this.remove(tag);
|
||||
}
|
||||
return self();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user