mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-21 04:32:15 +00:00
change the AdvancementProvider to make it possabible for mods to hook into it (#7488)
* back Port changes from #8120
This commit is contained in:
1 parent
111d3ec5d5
commit
6568649965
5 files changed
+225
No files matched your search
@@ -1,5 +1,14 @@
|
||||
--- a/net/minecraft/advancements/Advancement.java
|
||||
+++ b/net/minecraft/advancements/Advancement.java
|
||||
@@ -130,7 +_,7 @@
|
||||
return this.field_193125_h;
|
||||
}
|
||||
|
||||
- public static class Builder {
|
||||
+ public static class Builder implements net.minecraftforge.common.extensions.IForgeAdvancementBuilder {
|
||||
private ResourceLocation field_192061_a;
|
||||
private Advancement field_192062_b;
|
||||
private DisplayInfo field_192063_c;
|
||||
@@ -309,6 +_,7 @@
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/net/minecraft/data/AdvancementProvider.java
|
||||
+++ b/net/minecraft/data/AdvancementProvider.java
|
||||
@@ -24,11 +_,18 @@
|
||||
private static final Gson field_204024_b = (new GsonBuilder()).setPrettyPrinting().create();
|
||||
private final DataGenerator field_204025_c;
|
||||
private final List<Consumer<Consumer<Advancement>>> field_204283_d = ImmutableList.of(new EndAdvancements(), new HusbandryAdvancements(), new AdventureAdvancements(), new NetherAdvancements(), new StoryAdvancements());
|
||||
+ protected net.minecraftforge.common.data.ExistingFileHelper fileHelper;
|
||||
|
||||
+ @Deprecated
|
||||
public AdvancementProvider(DataGenerator p_i48869_1_) {
|
||||
this.field_204025_c = p_i48869_1_;
|
||||
}
|
||||
|
||||
+ public AdvancementProvider(DataGenerator generatorIn, net.minecraftforge.common.data.ExistingFileHelper fileHelperIn) {
|
||||
+ this.field_204025_c = generatorIn;
|
||||
+ this.fileHelper = fileHelperIn;
|
||||
+ }
|
||||
+
|
||||
public void func_200398_a(DirectoryCache p_200398_1_) throws IOException {
|
||||
Path path = this.field_204025_c.func_200391_b();
|
||||
Set<ResourceLocation> set = Sets.newHashSet();
|
||||
@@ -47,6 +_,16 @@
|
||||
}
|
||||
};
|
||||
|
||||
+ registerAdvancements(consumer, fileHelper);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Override this method for registering and generating custom {@link Advancement}s. <p>
|
||||
+ * Just use {@link Advancement.Builder} to build your Advancements, you don't need an extra consumer like the vanilla classes.
|
||||
+ * @param consumer used for the register function from {@link Advancement.Builder}
|
||||
+ * @param fileHelper used for the register function from {@link Advancement.Builder}
|
||||
+ */
|
||||
+ protected void registerAdvancements(Consumer<Advancement> consumer, net.minecraftforge.common.data.ExistingFileHelper fileHelper) {
|
||||
for(Consumer<Consumer<Advancement>> consumer1 : this.field_204283_d) {
|
||||
consumer1.accept(consumer);
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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 com.google.common.collect.Maps;
|
||||
import net.minecraft.advancements.Advancement;
|
||||
import net.minecraft.advancements.AdvancementRewards;
|
||||
import net.minecraft.resources.ResourcePackType;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.common.data.ExistingFileHelper;
|
||||
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
public interface IForgeAdvancementBuilder
|
||||
{
|
||||
|
||||
default Advancement.Builder self()
|
||||
{
|
||||
return (Advancement.Builder) this;
|
||||
}
|
||||
|
||||
/**
|
||||
* save function for the {@link Advancement.Builder} which uses the {@link ExistingFileHelper} to check if the parent is already known
|
||||
* @param consumer A {@link Consumer} which the build {@link Advancement} is passed to
|
||||
* @param id The {@link ResourceLocation} for the new {@link Advancement}
|
||||
* @param fileHelper The {@link ExistingFileHelper} where all known {@link Advancement}s are registered
|
||||
* @return The build {@link Advancement}
|
||||
* @throws IllegalStateException is thrown if the parent of the {@link Advancement} is not known
|
||||
*/
|
||||
default Advancement save(Consumer<Advancement> consumer , ResourceLocation id, ExistingFileHelper fileHelper)
|
||||
{
|
||||
boolean canBuild = self().canBuild((advancementId) ->
|
||||
{
|
||||
if (fileHelper.exists(advancementId, ResourcePackType.SERVER_DATA, ".json", "advancements"))
|
||||
{
|
||||
return new Advancement(advancementId, null, null, AdvancementRewards.EMPTY, Maps.newHashMap(), null);
|
||||
}
|
||||
return null;
|
||||
});
|
||||
if (!canBuild)
|
||||
{
|
||||
throw new IllegalStateException("Tried to build Advancement without valid Parent!");
|
||||
}
|
||||
|
||||
Advancement advancement = self().build(id);
|
||||
consumer.accept(advancement);
|
||||
return advancement;
|
||||
}
|
||||
}
|
||||
@@ -40,8 +40,10 @@ import java.util.stream.Stream;
|
||||
|
||||
import com.google.gson.JsonNull;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import net.minecraft.advancements.criterion.InventoryChangeTrigger;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.util.SoundEvents;
|
||||
import net.minecraft.util.text.TranslationTextComponent;
|
||||
import net.minecraftforge.common.data.SoundDefinition;
|
||||
import net.minecraftforge.common.data.SoundDefinitionsProvider;
|
||||
import org.apache.commons.lang3.tuple.Triple;
|
||||
@@ -67,6 +69,7 @@ import net.minecraft.client.renderer.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.model.ItemTransformVec3f;
|
||||
import net.minecraft.client.renderer.model.Variant;
|
||||
import net.minecraft.client.renderer.model.BlockModel.GuiLight;
|
||||
import net.minecraft.data.AdvancementProvider;
|
||||
import net.minecraft.data.BlockTagsProvider;
|
||||
import net.minecraft.data.DataGenerator;
|
||||
import net.minecraft.data.DirectoryCache;
|
||||
@@ -135,6 +138,7 @@ public class DataGeneratorTest
|
||||
{
|
||||
gen.addProvider(new Recipes(gen));
|
||||
gen.addProvider(new Tags(gen, event.getExistingFileHelper()));
|
||||
gen.addProvider(new Advancements(gen, event.getExistingFileHelper()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,6 +886,78 @@ public class DataGeneratorTest
|
||||
}
|
||||
}
|
||||
|
||||
public static class Advancements extends AdvancementProvider
|
||||
{
|
||||
|
||||
public Advancements(DataGenerator generatorIn, ExistingFileHelper fileHelper)
|
||||
{
|
||||
super(generatorIn, fileHelper);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void registerAdvancements(Consumer<Advancement> consumer, ExistingFileHelper fileHelper)
|
||||
{
|
||||
Advancement.Builder.advancement().display(Items.DIRT,
|
||||
new TranslationTextComponent(Items.DIRT.getDescriptionId()),
|
||||
new TranslationTextComponent("dirt_description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("has_dirt", InventoryChangeTrigger.Instance.hasItems(Items.DIRT))
|
||||
.save(consumer, new ResourceLocation(MODID, "obtain_dirt"), fileHelper);
|
||||
|
||||
Advancement.Builder.advancement().display(Items.DIAMOND_BLOCK,
|
||||
new TranslationTextComponent(Items.DIAMOND_BLOCK.getDescriptionId()),
|
||||
new StringTextComponent("You obtained a DiamondBlock"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.CHALLENGE,
|
||||
true,
|
||||
true,
|
||||
false)
|
||||
.addCriterion("obtained_diamond_block", InventoryChangeTrigger.Instance.hasItems(Items.DIAMOND_BLOCK))
|
||||
.save(consumer, new ResourceLocation("obtain_diamond_block"), fileHelper);
|
||||
|
||||
Advancement.Builder.advancement()
|
||||
.display(Blocks.GRASS_BLOCK,
|
||||
new TranslationTextComponent("advancements.story.root.title"),
|
||||
new StringTextComponent("Changed Description"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("crafting_table", InventoryChangeTrigger.Instance.hasItems(Blocks.CRAFTING_TABLE))
|
||||
.save(consumer, new ResourceLocation("story/root"), fileHelper);
|
||||
|
||||
// This should cause an error because of the parent not existing
|
||||
/* Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
new TranslationTextComponent(Items.COBBLESTONE.getDescriptionId()),
|
||||
new StringTextComponent("You got cobblestone"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("get_cobbleStone", InventoryChangeTrigger.Instance.hasItems(Items.COBBLESTONE))
|
||||
.parent(new ResourceLocation("not_there/not_here"))
|
||||
.save(consumer, new ResourceLocation("illegalParent"), fileHelper);*/
|
||||
|
||||
Advancement.Builder.advancement().display(Blocks.COBBLESTONE,
|
||||
new TranslationTextComponent(Items.COBBLESTONE.getDescriptionId()),
|
||||
new StringTextComponent("You got cobblestone"),
|
||||
new ResourceLocation("textures/gui/advancements/backgrounds/stone.png"),
|
||||
FrameType.TASK,
|
||||
false,
|
||||
false,
|
||||
false)
|
||||
.addCriterion("get_cobbleStone", InventoryChangeTrigger.Instance.hasItems(Items.COBBLESTONE))
|
||||
.parent(new ResourceLocation("forge", "dummy_parent"))
|
||||
.save(consumer, new ResourceLocation("good_parent"), fileHelper);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T extends ModelBuilder<T>> List<String> testModelResults(Map<ResourceLocation, T> models, ExistingFileHelper existingFileHelper, Set<ResourceLocation> toIgnore) {
|
||||
List<String> ret = new ArrayList<>();
|
||||
models.forEach((loc, model) -> {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"display": {
|
||||
"icon": {
|
||||
"item": "minecraft:dirt"
|
||||
},
|
||||
"title": {
|
||||
"translate": "block.minecraft.dirt"
|
||||
},
|
||||
"description": {
|
||||
"translate": "dirt_description"
|
||||
},
|
||||
"frame": "task",
|
||||
"show_toast": true,
|
||||
"announce_to_chat": true,
|
||||
"hidden": false,
|
||||
"background": "minecraft:textures/gui/advancements/backgrounds/stone.png"
|
||||
},
|
||||
"criteria": {
|
||||
"has_dirt": {
|
||||
"trigger": "minecraft:inventory_changed",
|
||||
"conditions": {
|
||||
"items": [
|
||||
{
|
||||
"item": "minecraft:dirt"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"requirements": [
|
||||
[
|
||||
"has_dirt"
|
||||
]
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user