Remove forge optional tags in favor of Vanilla's new system. (#7246)

This commit is contained in:
Cyborgmas authored and GitHub committed 2020-08-18 22:22:34 -07:00
1 parent 132cc3659d
commit edca0c7293
7 files changed
+31 -136

No files matched your search

@@ -23,16 +23,12 @@ import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.common.base.Throwables;
@@ -40,7 +36,6 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
@@ -109,7 +104,6 @@ import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.IWorldReader;
import net.minecraft.world.World;
import net.minecraftforge.common.data.IOptionalTagEntry;
import net.minecraftforge.common.loot.IGlobalLootModifier;
import net.minecraftforge.common.loot.LootModifierManager;
import net.minecraftforge.common.util.BlockSnapshot;
@@ -1080,15 +1074,16 @@ public class ForgeHooks
public static <T> void deserializeTagAdditions(List<ITag.ITagEntry> list, JsonObject json, List<ITag.Proxy> allList)
{
//TODO 1.17 remove parsing the forge added "optional" array. Still here for compatibility with previously created tags.
if (json.has("optional"))
{
for (JsonElement entry : JSONUtils.getJsonArray(json, "optional"))
{
String s = JSONUtils.getString(entry, "value");
if (!s.startsWith("#"))
list.add(ForgeHooks.makeOptionalTag(true, Collections.singleton(new ResourceLocation(s))));
list.add(new ITag.OptionalItemEntry(new ResourceLocation(s)));
else
list.add(ForgeHooks.makeOptionalTag(false, Collections.singleton(new ResourceLocation(s.substring(1)))));
list.add(new ITag.OptionalTagEntry(new ResourceLocation(s.substring(1))));
}
}
@@ -1181,64 +1176,6 @@ public class ForgeHooks
return list;
}
@Deprecated//INTERNAL
public static IOptionalTagEntry makeOptionalTag(boolean items, Collection<ResourceLocation> locations) {
return items ? new OptionalItemTarget(locations) : new OptionalTagTarget(locations);
}
private static class OptionalTagTarget implements IOptionalTagEntry
{
private final Collection<ResourceLocation> referents;
public OptionalTagTarget(Collection<ResourceLocation> referents)
{
this.referents = referents;
}
@Override
public <T> boolean func_230238_a_(Function<ResourceLocation, ITag<T>> tagLookup, Function<ResourceLocation, T> itemLookup, Consumer<T> collector)
{
referents.stream()
.map(tagLookup)
.filter(Objects::nonNull)
.map(ITag::func_230236_b_)
.flatMap(List::stream)
.forEach(collector);
return true;
}
@Override
public void func_230237_a_(JsonArray array)
{
referents.stream().map(e -> "#" + e).forEach(array::add);
}
}
private static class OptionalItemTarget implements IOptionalTagEntry
{
private final Collection<ResourceLocation> locations;
public OptionalItemTarget(Collection<ResourceLocation> locations)
{
this.locations = locations;
}
@Override
public <T> boolean func_230238_a_(Function<ResourceLocation, ITag<T>> tagLookup, Function<ResourceLocation, T> itemLookup, Consumer<T> collector)
{
locations.stream().map(itemLookup).filter(Objects::nonNull).forEach(collector);
return true;
}
@Override
public void func_230237_a_(JsonArray array)
{
locations.stream().map(ResourceLocation::toString).forEach(array::add);
}
}
public static List<String> getModPacks()
{
List<String> modpacks = ResourcePackLoader.getPackNames();
@@ -1,27 +0,0 @@
/*
* 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.data;
import net.minecraft.tags.ITag;
/**
* Marker class used by Forge to make a tag entry optional at runtime
*/
public interface IOptionalTagEntry extends ITag.ITagEntry {}
@@ -22,10 +22,6 @@ package net.minecraftforge.common.extensions;
import net.minecraft.data.TagsProvider;
import net.minecraft.tags.ITag;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeHooks;
import java.util.Arrays;
import java.util.Collection;
//TODO, Tag removal support.
public interface IForgeTagBuilder<T>
@@ -53,25 +49,13 @@ public interface IForgeTagBuilder<T>
return getBuilder();
}
default TagsProvider.Builder<T> addOptional(final ResourceLocation... locations)
default TagsProvider.Builder<T> addOptional(final ResourceLocation location)
{
return addOptional(Arrays.asList(locations));
return getBuilder().add(new ITag.OptionalItemEntry(location));
}
@SuppressWarnings("deprecation")
default TagsProvider.Builder<T> addOptional(final Collection<ResourceLocation> locations)
default TagsProvider.Builder<T> addOptionalTag(final ResourceLocation location)
{
return getBuilder().add(ForgeHooks.makeOptionalTag(true, locations));
}
default TagsProvider.Builder<T> addOptionalTag(final ResourceLocation... locations)
{
return addOptionalTag(Arrays.asList(locations));
}
@SuppressWarnings("deprecation")
default TagsProvider.Builder<T> addOptionalTag(final Collection<ResourceLocation> locations)
{
return getBuilder().add(ForgeHooks.makeOptionalTag(false, locations));
return getBuilder().add(new ITag.OptionalTagEntry(location));
}
}