Skip to content

Commit

Permalink
[1.20.4] Fix grouped mod datapacks being dropped when reloading data (#…
Browse files Browse the repository at this point in the history
…403)

Fixes #402
  • Loading branch information
XFactHD authored Dec 18, 2023
1 parent f626071 commit ee686bb
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 1 deletion.
9 changes: 9 additions & 0 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@
}

public SystemReport fillSystemReport(SystemReport p_177936_) {
@@ -1379,7 +_,7 @@
public CompletableFuture<Void> reloadResources(Collection<String> p_129862_) {
RegistryAccess.Frozen registryaccess$frozen = this.registries.getAccessForLoading(RegistryLayer.RELOADABLE);
CompletableFuture<Void> completablefuture = CompletableFuture.<ImmutableList>supplyAsync(
- () -> p_129862_.stream().map(this.packRepository::getPack).filter(Objects::nonNull).map(Pack::open).collect(ImmutableList.toImmutableList()),
+ () -> p_129862_.stream().map(this.packRepository::getPack).filter(Objects::nonNull).flatMap(Pack::streamSelfAndChildren).map(Pack::open).collect(ImmutableList.toImmutableList()),
this
)
.thenCompose(
@@ -1416,6 +_,7 @@
this.getPlayerList().reloadResources();
this.functionManager.replaceLibrary(this.resources.managers.getFunctionLibrary());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,18 @@
}

return pack$info;
@@ -172,6 +_,33 @@
@@ -172,6 +_,37 @@
return this.packSource;
}

+ public boolean isHidden() { return hidden; }
+
+ public List<Pack> getChildren() { return children; }
+
+ public java.util.stream.Stream<Pack> streamSelfAndChildren() {
+ return java.util.stream.Stream.concat(java.util.stream.Stream.of(this), children.stream());
+ }
+
+ /**
+ * {@return a copy of the pack with the provided children in place of any children this pack currently has}
+ */
Expand Down
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"
]
}
}
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");
}
});
}
}

0 comments on commit ee686bb

Please sign in to comment.