Expose the data entry point and generate Forge's Tags using it.

This commit is contained in:
LexManos 2019-06-13 20:58:03 -07:00
parent c30b27fcfe
commit e1cdb2e558
114 changed files with 673 additions and 117 deletions

1
.gitignore vendored
View file

@ -28,6 +28,7 @@
/projects/**/*.launch
/repo/
/buildSrc
src/generated/resources/.cache/
#Patch rejects
/patches-/

View file

@ -130,7 +130,10 @@ project(':forge') {
srcDirs = ["$rootDir/src/main/java"]
}
resources {
srcDirs = ["$rootDir/src/main/resources"]
srcDirs = [
"$rootDir/src/main/resources",
"$rootDir/src/generated/resources"
]
}
}
test {
@ -268,6 +271,29 @@ project(':forge') {
TestMods { sources sourceSets.test }
}
}
forge_data {
taskName 'forge_data'
main 'net.minecraftforge.userdev.LaunchTesting'
workingDirectory project.file('run')
environment 'target', 'fmldevdata'
environment 'MC_VERSION', MC_VERSION
environment 'MCP_VERSION', MCP_VERSION
environment 'FORGE_GROUP', project.group
environment 'FORGE_SPEC', SPEC_VERSION
environment 'FORGE_VERSION', project.version.substring(MC_VERSION.length() + 1).toString()
environment 'LAUNCHER_VERSION', SPEC_VERSION
ideaModule "${rootProject.name}.${project.name}.userdev"
source sourceSets.main
source sourceSets.userdev
args '--mod', 'forge', '--all', '--output', rootProject.file('src/generated/resources/')
}
}
}

View file

@ -0,0 +1,22 @@
--- a/net/minecraft/data/DataGenerator.java
+++ b/net/minecraft/data/DataGenerator.java
@@ -19,7 +19,7 @@
public DataGenerator(Path p_i48266_1_, Collection<Path> p_i48266_2_) {
this.field_200395_c = p_i48266_1_;
- this.field_200394_b = p_i48266_2_;
+ this.field_200394_b = Lists.newArrayList(p_i48266_2_);
}
public Collection<Path> func_200389_a() {
@@ -53,6 +53,10 @@
this.field_200396_d.add(p_200390_1_);
}
+ public void addInput(Path value) {
+ this.field_200394_b.add(value);
+ }
+
static {
Bootstrap.func_151354_b();
}

View file

@ -0,0 +1,11 @@
--- a/net/minecraft/data/DirectoryCache.java
+++ b/net/minecraft/data/DirectoryCache.java
@@ -23,7 +23,7 @@
private final Path field_208326_c;
private int field_208327_d;
private final Map<Path, String> field_208328_e = Maps.newHashMap();
- private final Map<Path, String> field_208329_f = Maps.newHashMap();
+ private final Map<Path, String> field_208329_f = Maps.newTreeMap(); //Forge: TreeMap, makes the file output predictable/sorted.
private final Set<Path> field_218457_g = Sets.newHashSet();
public DirectoryCache(Path p_i49352_1_, String p_i49352_2_) throws IOException {

View file

@ -0,0 +1,51 @@
--- a/net/minecraft/data/Main.java
+++ b/net/minecraft/data/Main.java
@@ -1,5 +1,6 @@
package net.minecraft.data;
+import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -21,8 +22,12 @@
OptionSpec<Void> optionspec6 = optionparser.accepts("all", "Include all generators");
OptionSpec<String> optionspec7 = optionparser.accepts("output", "Output folder").withRequiredArg().defaultsTo("generated");
OptionSpec<String> optionspec8 = optionparser.accepts("input", "Input folder").withRequiredArg();
+ OptionSpec<File> gameDir = optionparser.accepts("gameDir").withRequiredArg().ofType(File.class).defaultsTo(new File("."));
+ OptionSpec<String> mod = optionparser.accepts("mod", "The mod to dump").withRequiredArg();
+ net.minecraft.util.registry.Bootstrap.func_151354_b();
+ net.minecraftforge.fml.ModLoader.get().loadMods();
OptionSet optionset = optionparser.parse(p_main_0_);
- if (!optionset.has(optionspec) && optionset.hasOptions()) {
+ if (!optionset.has(optionspec) && optionset.hasOptions() && !(optionset.specs().size() == 1 && optionset.has(gameDir))) {
Path path = Paths.get(optionspec7.value(optionset));
boolean flag = optionset.has(optionspec6);
boolean flag1 = flag || optionset.has(optionspec2);
@@ -30,10 +35,23 @@
boolean flag3 = flag || optionset.has(optionspec3);
boolean flag4 = flag || optionset.has(optionspec4);
boolean flag5 = flag || optionset.has(optionspec5);
- DataGenerator datagenerator = func_200264_a(path, optionset.valuesOf(optionspec8).stream().map((p_200263_0_) -> {
- return Paths.get(p_200263_0_);
- }).collect(Collectors.toList()), flag1, flag2, flag3, flag4, flag5);
- datagenerator.func_200392_c();
+ Collection<Path> inputs = optionset.valuesOf(optionspec8).stream().map(Paths::get).collect(Collectors.toList());
+ java.util.Set<String> mods = optionset.valuesOf(mod).stream().collect(Collectors.toSet());
+ net.minecraftforge.fml.ModList.get().forEachModContainer((modid, mc) -> {
+ try {
+ //We have to go to the subclass, as ModContainer doesn't have the event bus.
+ if (mods.contains(modid) && mc instanceof net.minecraftforge.fml.javafmlmod.FMLModContainer) {
+ DataGenerator gen = new DataGenerator(mods.size() == 1 ? path : path.resolve(modid), inputs);
+ ((net.minecraftforge.fml.javafmlmod.FMLModContainer)mc).getEventBus().post(new net.minecraftforge.event.GatherDataEvent(gen, flag2, flag1, flag3, flag4, flag5));
+ gen.func_200392_c();
+ }
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ });
+
+ if (mods.contains("minecraft") || mods.isEmpty())
+ func_200264_a(mods.isEmpty() ? path : path.resolve("minecraft"), inputs, flag1, flag2, flag3, flag4, flag5).func_200392_c();
} else {
optionparser.printHelpOn(System.out);
}

View file

@ -0,0 +1,47 @@
--- a/net/minecraft/data/TagsProvider.java
+++ b/net/minecraft/data/TagsProvider.java
@@ -41,17 +41,27 @@
return Optional.empty();
}, "", false, "generated");
- for(Entry<Tag<T>, Tag.Builder<T>> entry : this.field_200434_b.entrySet()) {
- ResourceLocation resourcelocation = entry.getKey().func_199886_b();
- if (!entry.getValue().func_200160_a(tagcollection::func_199910_a)) {
- throw new UnsupportedOperationException("Unsupported referencing of tags!");
+ //This does not support resolving nested tags of ResourceLocation type entries.
+ //So we must do this in multiple passes, and error if we have a pass that doesn't resolve anything.
+ java.util.Set<Tag<T>> pending = new java.util.HashSet<>(this.field_200434_b.keySet());
+ java.util.Set<Tag<?>> processed = new java.util.HashSet<>();
+
+ do {
+ pending.removeAll(processed);
+ processed.clear();
+ for (Tag<T> key : pending) {
+ Tag.Builder<T> value = this.field_200434_b.get(key);
+ ResourceLocation resourcelocation = key.func_199886_b();
+ if (!value.func_200160_a(tagcollection::func_199910_a)) {
+ continue;
}
- Tag<T> tag = entry.getValue().func_200051_a(resourcelocation);
+ Tag<T> tag = value.func_200051_a(resourcelocation);
JsonObject jsonobject = tag.func_200571_a(this.field_200435_c::func_177774_c);
Path path = this.func_200431_a(resourcelocation);
tagcollection.func_199912_a(tag);
this.func_200429_a(tagcollection);
+ processed.add(key);
try {
String s = field_200437_e.toJson((JsonElement)jsonobject);
@@ -69,7 +79,11 @@
field_200436_d.error("Couldn't save tags to {}", path, ioexception);
}
}
+ } while (!processed.isEmpty() && !pending.isEmpty());
+ if (!pending.isEmpty()) {
+ throw new UnsupportedOperationException("Failed to resolve tags: " + pending.stream().map(Tag::func_199886_b).map(Object::toString).sorted().collect(java.util.stream.Collectors.joining(", ")));
+ }
}
protected abstract void func_200429_a(TagCollection<T> p_200429_1_);

View file

@ -1,6 +1,73 @@
--- a/net/minecraft/tags/Tag.java
+++ b/net/minecraft/tags/Tag.java
@@ -147,8 +147,10 @@
@@ -21,6 +21,7 @@
private final ResourceLocation field_199888_a;
private final Set<T> field_199889_b;
private final Collection<Tag.ITagEntry<T>> field_200150_c;
+ private boolean replace = false;
public Tag(ResourceLocation p_i48236_1_) {
this.field_199888_a = p_i48236_1_;
@@ -29,6 +30,9 @@
}
public Tag(ResourceLocation p_i48224_1_, Collection<Tag.ITagEntry<T>> p_i48224_2_, boolean p_i48224_3_) {
+ this(p_i48224_1_, p_i48224_2_, p_i48224_3_, false);
+ }
+ private Tag(ResourceLocation p_i48224_1_, Collection<Tag.ITagEntry<T>> p_i48224_2_, boolean p_i48224_3_, boolean replace) {
this.field_199888_a = p_i48224_1_;
this.field_199889_b = (Set<T>)(p_i48224_3_ ? Sets.newLinkedHashSet() : Sets.newHashSet());
this.field_200150_c = p_i48224_2_;
@@ -47,7 +51,7 @@
itagentry.func_200576_a(jsonarray, p_200571_1_);
}
- jsonobject.addProperty("replace", false);
+ jsonobject.addProperty("replace", replace);
jsonobject.add("values", jsonarray);
return jsonobject;
}
@@ -76,6 +80,7 @@
public static class Builder<T> {
private final Set<Tag.ITagEntry<T>> field_200052_a = Sets.newLinkedHashSet();
private boolean field_200053_b;
+ private boolean replace = false;
public static <T> Tag.Builder<T> func_200047_a() {
return new Tag.Builder<>();
@@ -107,6 +112,22 @@
return this;
}
+ @SafeVarargs
+ public final Tag.Builder<T> add(Tag<T>... tags) {
+ for (Tag<T> tag : tags)
+ func_200574_a(tag);
+ return this;
+ }
+
+ public Tag.Builder<T> replace(boolean value) {
+ this.replace = value;
+ return this;
+ }
+
+ public Tag.Builder<T> replace() {
+ return replace(true);
+ }
+
public Tag.Builder<T> func_200045_a(boolean p_200045_1_) {
this.field_200053_b = p_200045_1_;
return this;
@@ -123,7 +144,7 @@
}
public Tag<T> func_200051_a(ResourceLocation p_200051_1_) {
- return new Tag<>(p_200051_1_, this.field_200052_a, this.field_200053_b);
+ return new Tag<>(p_200051_1_, this.field_200052_a, this.field_200053_b, this.replace);
}
public Tag.Builder<T> func_219783_a(Function<ResourceLocation, Optional<T>> p_219783_1_, JsonObject p_219783_2_) {
@@ -147,8 +168,10 @@
}
this.field_200052_a.addAll(list);
@ -11,7 +78,7 @@
}
public interface ITagEntry<T> {
@@ -187,6 +189,8 @@
@@ -187,6 +210,8 @@
public Collection<T> func_200578_a() {
return this.field_200165_a;
}
@ -20,7 +87,7 @@
}
public static class TagEntry<T> implements Tag.ITagEntry<T> {
@@ -233,5 +237,7 @@
@@ -233,5 +258,7 @@
public void func_200576_a(JsonArray p_200576_1_, Function<T, ResourceLocation> p_200576_2_) {
p_200576_1_.add("#" + this.func_200577_a());
}

View file

@ -5,4 +5,4 @@
"#forge:chests/trapped",
"#forge:chests/wooden"
]
}
}

View file

@ -5,4 +5,4 @@
"minecraft:infested_cobblestone",
"minecraft:mossy_cobblestone"
]
}
}

View file

@ -5,4 +5,4 @@
"minecraft:coarse_dirt",
"minecraft:podzol"
]
}
}

View file

@ -8,4 +8,4 @@
"minecraft:acacia_fence_gate",
"minecraft:dark_oak_fence_gate"
]
}
}

View file

@ -4,4 +4,4 @@
"#forge:fences/nether_brick",
"#forge:fences/wooden"
]
}
}

View file

@ -8,4 +8,4 @@
"minecraft:acacia_fence",
"minecraft:dark_oak_fence"
]
}
}

View file

@ -1,13 +1,13 @@
{
"replace": false,
"values": [
"#forge:ores/iron",
"#forge:ores/gold",
"#forge:ores/coal",
"#forge:ores/diamond",
"#forge:ores/emerald",
"#forge:ores/gold",
"#forge:ores/iron",
"#forge:ores/lapis",
"#forge:ores/redstone",
"#forge:ores/emerald",
"#forge:ores/diamond",
"#forge:ores/quartz"
]
}
}

View file

@ -10,4 +10,4 @@
"minecraft:polished_diorite",
"minecraft:polished_granite"
]
}
}

View file

@ -10,4 +10,4 @@
"#forge:storage_blocks/quartz",
"#forge:storage_blocks/redstone"
]
}
}

View file

@ -5,4 +5,4 @@
"#forge:chests/trapped",
"#forge:chests/wooden"
]
}
}

View file

@ -5,4 +5,4 @@
"minecraft:infested_cobblestone",
"minecraft:mossy_cobblestone"
]
}
}

View file

@ -1,8 +1,8 @@
{
"replace": false,
"values": [
"#forge:dusts/glowstone",
"#forge:dusts/prismarine",
"#forge:dusts/redstone",
"#forge:dusts/glowstone"
"#forge:dusts/redstone"
]
}
}

View file

@ -18,4 +18,4 @@
"#forge:dyes/orange",
"#forge:dyes/white"
]
}
}

View file

@ -8,4 +8,4 @@
"minecraft:acacia_fence_gate",
"minecraft:dark_oak_fence_gate"
]
}
}

View file

@ -4,4 +4,4 @@
"#forge:fences/nether_brick",
"#forge:fences/wooden"
]
}
}

View file

@ -8,4 +8,4 @@
"minecraft:acacia_fence",
"minecraft:dark_oak_fence"
]
}
}

View file

@ -3,8 +3,8 @@
"values": [
"#forge:gems/diamond",
"#forge:gems/emerald",
"#forge:gems/quartz",
"#forge:gems/lapis",
"#forge:gems/prismarine"
"#forge:gems/prismarine",
"#forge:gems/quartz"
]
}
}

View file

@ -6,4 +6,4 @@
"#forge:ingots/brick",
"#forge:ingots/nether_brick"
]
}
}

View file

@ -14,4 +14,4 @@
"minecraft:music_disc_11",
"minecraft:music_disc_wait"
]
}
}

View file

@ -4,4 +4,4 @@
"#forge:nuggets/iron",
"#forge:nuggets/gold"
]
}
}

View file

@ -1,13 +1,13 @@
{
"replace": false,
"values": [
"#forge:ores/iron",
"#forge:ores/gold",
"#forge:ores/coal",
"#forge:ores/diamond",
"#forge:ores/emerald",
"#forge:ores/gold",
"#forge:ores/iron",
"#forge:ores/lapis",
"#forge:ores/redstone",
"#forge:ores/emerald",
"#forge:ores/diamond",
"#forge:ores/quartz"
]
}
}

View file

@ -4,4 +4,4 @@
"#forge:rods/blaze",
"#forge:rods/wooden"
]
}
}

View file

@ -4,9 +4,10 @@
"minecraft:andesite",
"minecraft:diorite",
"minecraft:granite",
"minecraft:infested_stone",
"minecraft:stone",
"minecraft:polished_andesite",
"minecraft:polished_diorite",
"minecraft:polished_granite"
]
}
}

View file

@ -10,4 +10,4 @@
"#forge:storage_blocks/quartz",
"#forge:storage_blocks/redstone"
]
}
}

Some files were not shown because too many files have changed in this diff Show more