-
-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.20.4] Fix grouped mod datapacks being dropped when reloading data (#…
- Loading branch information
Showing
4 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ated/resources/data/neotests_mod_datapack/advancements/recipes/misc/test_advancement.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{ | ||
"parent": "minecraft:recipes/root", | ||
"criteria": { | ||
"has_scute": { | ||
"conditions": { | ||
"items": [ | ||
{ | ||
"items": [ | ||
"minecraft:scute" | ||
] | ||
} | ||
] | ||
}, | ||
"trigger": "minecraft:inventory_changed" | ||
} | ||
}, | ||
"requirements": [ | ||
[ | ||
"has_scute" | ||
] | ||
], | ||
"rewards": { | ||
"recipes": [ | ||
"minecraft:turtle_helmet" | ||
] | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/src/main/java/net/neoforged/neoforge/debug/resources/ModDatapackTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) NeoForged and contributors | ||
* SPDX-License-Identifier: LGPL-2.1-only | ||
*/ | ||
|
||
package net.neoforged.neoforge.debug.resources; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import net.minecraft.advancements.Advancement; | ||
import net.minecraft.advancements.AdvancementRewards; | ||
import net.minecraft.advancements.CriteriaTriggers; | ||
import net.minecraft.advancements.critereon.InventoryChangeTrigger; | ||
import net.minecraft.advancements.critereon.ItemPredicate; | ||
import net.minecraft.data.recipes.RecipeBuilder; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Items; | ||
import net.neoforged.neoforge.common.data.AdvancementProvider; | ||
import net.neoforged.neoforge.event.OnDatapackSyncEvent; | ||
import net.neoforged.testframework.DynamicTest; | ||
import net.neoforged.testframework.annotation.ForEachTest; | ||
import net.neoforged.testframework.annotation.TestHolder; | ||
|
||
@ForEachTest(groups = ModDatapackTest.GROUP) | ||
public class ModDatapackTest { | ||
public static final String GROUP = "resources"; | ||
|
||
@TestHolder(description = "Tests that mod datapacks are loaded properly on initial load and reload", enabledByDefault = true) | ||
static void modDatapack(final DynamicTest test) { | ||
final ResourceLocation testAdvancement = new ResourceLocation(test.createModId(), "recipes/misc/test_advancement"); | ||
|
||
test.registrationHelper().addProvider(event -> { | ||
List<AdvancementProvider.AdvancementGenerator> generators = List.of((registries, saver, existingFileHelper) -> Advancement.Builder.recipeAdvancement() | ||
.parent(RecipeBuilder.ROOT_RECIPE_ADVANCEMENT) | ||
.addCriterion("has_scute", CriteriaTriggers.INVENTORY_CHANGED.createCriterion( | ||
new InventoryChangeTrigger.TriggerInstance( | ||
Optional.empty(), InventoryChangeTrigger.TriggerInstance.Slots.ANY, List.of( | ||
ItemPredicate.Builder.item().of(Items.SCUTE).build())))) | ||
.rewards(AdvancementRewards.Builder.recipe(new ResourceLocation("minecraft:turtle_helmet"))) | ||
.save(saver, testAdvancement, existingFileHelper)); | ||
return new AdvancementProvider(event.getGenerator().getPackOutput(), event.getLookupProvider(), event.getExistingFileHelper(), generators); | ||
}); | ||
|
||
test.eventListeners().forge().addListener((OnDatapackSyncEvent event) -> { | ||
if (event.getPlayerList().getServer().getAdvancements().get(testAdvancement) != null) { | ||
test.pass(); | ||
} else { | ||
test.fail("Test advancement not loaded"); | ||
} | ||
}); | ||
} | ||
} |