94 lines
4.1 KiB
Diff
94 lines
4.1 KiB
Diff
--- a/net/minecraft/data/TagsProvider.java
|
|
+++ b/net/minecraft/data/TagsProvider.java
|
|
@@ -28,10 +28,18 @@
|
|
protected final DataGenerator field_200433_a;
|
|
protected final Registry<T> field_200435_c;
|
|
protected final Map<ResourceLocation, ITag.Builder> field_200434_b = Maps.newLinkedHashMap();
|
|
+ protected final String modId;
|
|
+ protected final net.minecraftforge.common.data.ExistingFileHelper existingFileHelper;
|
|
|
|
+ @Deprecated//Forge, Use ModID version.
|
|
protected TagsProvider(DataGenerator p_i49827_1_, Registry<T> p_i49827_2_) {
|
|
+ this(p_i49827_1_, p_i49827_2_, "vanilla", null);
|
|
+ }
|
|
+ protected TagsProvider(DataGenerator p_i49827_1_, Registry<T> p_i49827_2_, String modId, @javax.annotation.Nullable net.minecraftforge.common.data.ExistingFileHelper existingFileHelper) {
|
|
this.field_200433_a = p_i49827_1_;
|
|
this.field_200435_c = p_i49827_2_;
|
|
+ this.modId = modId;
|
|
+ this.existingFileHelper = existingFileHelper;
|
|
}
|
|
|
|
protected abstract void func_200432_c();
|
|
@@ -47,12 +55,14 @@
|
|
return this.field_200435_c.func_241873_b(p_240527_1_).orElse((T)null);
|
|
};
|
|
this.field_200434_b.forEach((p_240524_4_, p_240524_5_) -> {
|
|
- List<ITag.Proxy> list = p_240524_5_.func_232963_b_(function, function1).collect(Collectors.toList());
|
|
+ // FORGE: Add validation via existing resources
|
|
+ List<ITag.Proxy> list = p_240524_5_.func_232963_b_(function, function1).filter(this::missing).collect(Collectors.toList());
|
|
if (!list.isEmpty()) {
|
|
throw new IllegalArgumentException(String.format("Couldn't define tag %s as it is missing following references: %s", p_240524_4_, list.stream().map(Objects::toString).collect(Collectors.joining(","))));
|
|
} else {
|
|
JsonObject jsonobject = p_240524_5_.func_232965_c_();
|
|
Path path = this.func_200431_a(p_240524_4_);
|
|
+ if (path == null) return; //Forge: Allow running this data provider without writing it. Recipe provider needs valid tags.
|
|
|
|
try {
|
|
String s = field_200437_e.toJson((JsonElement)jsonobject);
|
|
@@ -74,11 +84,26 @@
|
|
});
|
|
}
|
|
|
|
+ private boolean missing(ITag.Proxy reference) {
|
|
+ ITag.ITagEntry entry = reference.func_232968_a_();
|
|
+ // We only care about non-optional tag entries, this is the only type that can reference a resource and needs validation
|
|
+ // Optional tags should not be validated
|
|
+ if (entry instanceof ITag.TagEntry) {
|
|
+ return existingFileHelper == null || !existingFileHelper.exists(((ITag.TagEntry)entry).getId(), net.minecraft.resources.ResourcePackType.SERVER_DATA, ".json", "tags/" + getTagFolder());
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings({ "unchecked", "rawtypes" })
|
|
+ protected String getTagFolder() {
|
|
+ return ((Registry)Registry.field_212617_f).func_177774_c(field_200435_c).func_110623_a() + "s";
|
|
+ }
|
|
+
|
|
protected abstract Path func_200431_a(ResourceLocation p_200431_1_);
|
|
|
|
protected TagsProvider.Builder<T> func_240522_a_(ITag.INamedTag<T> p_240522_1_) {
|
|
ITag.Builder itag$builder = this.func_240525_b_(p_240522_1_);
|
|
- return new TagsProvider.Builder<>(itag$builder, this.field_200435_c, "vanilla");
|
|
+ return new TagsProvider.Builder<>(itag$builder, this.field_200435_c, modId);
|
|
}
|
|
|
|
protected ITag.Builder func_240525_b_(ITag.INamedTag<T> p_240525_1_) {
|
|
@@ -87,7 +112,7 @@
|
|
});
|
|
}
|
|
|
|
- public static class Builder<T> {
|
|
+ public static class Builder<T> implements net.minecraftforge.common.extensions.IForgeTagBuilder<T> {
|
|
private final ITag.Builder field_240528_a_;
|
|
private final Registry<T> field_240529_b_;
|
|
private final String field_240530_c_;
|
|
@@ -115,5 +140,18 @@
|
|
});
|
|
return this;
|
|
}
|
|
+
|
|
+ public TagsProvider.Builder<T> add(ITag.ITagEntry tag) {
|
|
+ field_240528_a_.func_232955_a_(tag, field_240530_c_);
|
|
+ return this;
|
|
+ }
|
|
+
|
|
+ public ITag.Builder getInternalBuilder() {
|
|
+ return field_240528_a_;
|
|
+ }
|
|
+
|
|
+ public String getModID() {
|
|
+ return field_240530_c_;
|
|
+ }
|
|
}
|
|
}
|