Remove forge optional tags in favor of Vanilla's new system. (#7246)
This commit is contained in:
parent
132cc3659d
commit
edca0c7293
|
@ -32,29 +32,16 @@
|
|||
list.forEach((p_232958_2_) -> {
|
||||
this.field_232953_a_.add(new ITag.Proxy(p_232958_2_, p_232956_2_));
|
||||
});
|
||||
@@ -135,11 +146,20 @@
|
||||
JsonArray jsonarray = new JsonArray();
|
||||
|
||||
for(ITag.Proxy itag$proxy : this.field_232953_a_) {
|
||||
+ if(!(itag$proxy.field_232966_a_ instanceof net.minecraftforge.common.data.IOptionalTagEntry))
|
||||
@@ -138,7 +149,7 @@
|
||||
itag$proxy.func_232968_a_().func_230237_a_(jsonarray);
|
||||
}
|
||||
|
||||
- jsonobject.addProperty("replace", false);
|
||||
+ JsonArray optopnals = new JsonArray();
|
||||
+ func_232962_b_()
|
||||
+ .map(e -> e.field_232966_a_)
|
||||
+ .filter(e -> e instanceof net.minecraftforge.common.data.IOptionalTagEntry)
|
||||
+ .forEach(e -> e.func_230237_a_(optopnals));
|
||||
+
|
||||
+ jsonobject.addProperty("replace", replace);
|
||||
jsonobject.add("values", jsonarray);
|
||||
+ if (optopnals.size() > 0)
|
||||
+ jsonobject.add("optional", optopnals);
|
||||
return jsonobject;
|
||||
}
|
||||
}
|
||||
@@ -178,6 +198,7 @@
|
||||
@@ -178,6 +189,7 @@
|
||||
public String toString() {
|
||||
return this.field_232969_a_.toString();
|
||||
}
|
||||
|
@ -62,7 +49,7 @@
|
|||
}
|
||||
|
||||
public static class OptionalItemEntry implements ITag.ITagEntry {
|
||||
@@ -278,5 +299,6 @@
|
||||
@@ -278,5 +290,6 @@
|
||||
public String toString() {
|
||||
return "#" + this.field_200163_a;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,14 @@
|
|||
"replace": false,
|
||||
"values": [
|
||||
"minecraft:diamond_block",
|
||||
"#minecraft:stone_bricks"
|
||||
],
|
||||
"optional": [
|
||||
"chisel:marble/raw",
|
||||
"#forge:storage_blocks/ruby"
|
||||
"#minecraft:stone_bricks",
|
||||
{
|
||||
"id": "chisel:marble/raw",
|
||||
"required": false
|
||||
},
|
||||
{
|
||||
"id": "#forge:storage_blocks/ruby",
|
||||
"required": false
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,12 +22,14 @@ package net.minecraftforge.debug;
|
|||
import static net.minecraftforge.debug.DataGeneratorTest.MODID;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
@ -179,6 +181,7 @@ public class DataGeneratorTest
|
|||
|
||||
public static class Tags extends BlockTagsProvider
|
||||
{
|
||||
private Set<ResourceLocation> filter;
|
||||
|
||||
public Tags(DataGenerator gen)
|
||||
{
|
||||
|
@ -188,6 +191,9 @@ public class DataGeneratorTest
|
|||
@Override
|
||||
protected void registerTags()
|
||||
{
|
||||
super.registerTags();
|
||||
filter = new HashSet<>(this.tagToBuilder.keySet()); // will copy all vanilla tags.
|
||||
|
||||
func_240522_a_(BlockTags.makeWrapperTag(new ResourceLocation(MODID, "test").toString()))
|
||||
.func_240532_a_(Blocks.DIAMOND_BLOCK)
|
||||
.func_240531_a_(BlockTags.STONE_BRICKS)
|
||||
|
@ -207,6 +213,12 @@ public class DataGeneratorTest
|
|||
.func_240532_a_(Blocks.DIORITE)
|
||||
.func_240532_a_(Blocks.ANDESITE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Path makePath(ResourceLocation id)
|
||||
{
|
||||
return filter != null && filter.contains(id) ? null : super.makePath(id); //To escape saving vanilla tags, but still register them.
|
||||
}
|
||||
}
|
||||
|
||||
public static class Lang extends LanguageProvider
|
||||
|
|
|
@ -74,8 +74,6 @@ license="LGPL v2.1"
|
|||
modId="raid_enum_test"
|
||||
[[mods]]
|
||||
modId="player_name_event_test"
|
||||
[[mods]]
|
||||
modId="modded_overworld_biomes_test"
|
||||
[[mods]]
|
||||
modId="tool_interact_test"
|
||||
[[mods]]
|
||||
|
|
Loading…
Reference in New Issue