Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/1.20.x' into 1.20.x
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD committed Dec 18, 2023
2 parents a54ac3a + 97f3373 commit 53678c6
Show file tree
Hide file tree
Showing 8 changed files with 231 additions and 19 deletions.
12 changes: 12 additions & 0 deletions patches/net/minecraft/gametest/framework/GameTestHelper.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--- a/net/minecraft/gametest/framework/GameTestHelper.java
+++ b/net/minecraft/gametest/framework/GameTestHelper.java
@@ -836,7 +_,8 @@

public void forEveryBlockInStructure(Consumer<BlockPos> p_177293_) {
AABB aabb = this.getRelativeBounds();
- BlockPos.MutableBlockPos.betweenClosedStream(aabb.move(0.0, 1.0, 0.0)).forEach(p_177293_);
+ // Neo: Shrink AABB by one as an aabb surrounding two blocks is increased by one compared to the actual positions
+ BlockPos.MutableBlockPos.betweenClosedStream(aabb.contract(1.0, 1.0, 1.0)).forEach(p_177293_);
}

public void onEachTick(Runnable p_177424_) {
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
113 changes: 95 additions & 18 deletions src/main/java/net/neoforged/neoforge/resource/ResourcePackLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
package net.neoforged.neoforge.resource;

import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.LinkedHashMap;
Expand All @@ -20,14 +23,22 @@
import java.util.stream.Collectors;
import net.minecraft.SharedConstants;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.ComponentSerialization;
import net.minecraft.server.packs.FeatureFlagsMetadataSection;
import net.minecraft.server.packs.OverlayMetadataSection;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.PathPackResources;
import net.minecraft.server.packs.metadata.MetadataSectionType;
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackCompatibility;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.repository.RepositorySource;
import net.neoforged.fml.Logging;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.util.InclusiveRange;
import net.minecraft.world.flag.FeatureFlagSet;
import net.neoforged.fml.ModList;
import net.neoforged.fml.ModLoader;
import net.neoforged.fml.ModLoadingStage;
Expand Down Expand Up @@ -76,30 +87,96 @@ private static void packFinder(Map<IModFile, Pack.ResourcesSupplier> modResource
if ("minecraft".equals(mod.getModId())) continue; // skip the minecraft "mod"
final String name = "mod:" + mod.getModId();
final String packName = mod.getOwningFile().getFile().getFileName();
Pack modPack = Pack.readMetaAndCreate(
name,
Component.literal(packName.isEmpty() ? "[unnamed]" : packName),
false,
e.getValue(),
packType,
Pack.Position.BOTTOM,
PackSource.DEFAULT);
if (modPack == null) {
// Vanilla only logs an error, instead of propagating, so handle null and warn that something went wrong

try {
final boolean isRequired = (packType == PackType.CLIENT_RESOURCES && mod.getOwningFile().showAsResourcePack()) || (packType == PackType.SERVER_DATA && mod.getOwningFile().showAsDataPack());
final Pack modPack;
// Packs displayed separately must be valid
if (isRequired) {
modPack = Pack.readMetaAndCreate(
name,
Component.literal(packName.isEmpty() ? "[unnamed]" : packName),
false,
e.getValue(),
packType,
Pack.Position.BOTTOM,
PackSource.DEFAULT);

if (modPack == null) {
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
continue;
}
} else {
modPack = readWithOptionalMeta(
name,
Component.literal(packName.isEmpty() ? "[unnamed]" : packName),
false,
e.getValue(),
packType,
Pack.Position.BOTTOM,
PackSource.DEFAULT);
}

if (isRequired) {
packAcceptor.accept(modPack);
} else {
hiddenPacks.add(modPack.hidden());
}
} catch (IOException exception) {
LOGGER.error("Failed to read pack.mcmeta file of mod {}", mod.getModId(), exception);
ModLoader.get().addWarning(new ModLoadingWarning(mod, ModLoadingStage.ERROR, "fml.modloading.brokenresources", e.getKey()));
continue;
}
LOGGER.debug(Logging.CORE, "Generating PackInfo named {} for mod file {}", name, e.getKey().getFilePath());
if ((packType == PackType.CLIENT_RESOURCES && mod.getOwningFile().showAsResourcePack()) || (packType == PackType.SERVER_DATA && mod.getOwningFile().showAsDataPack())) {
packAcceptor.accept(modPack);
} else {
hiddenPacks.add(modPack.hidden());
}
}

packAcceptor.accept(makePack(packType, hiddenPacks));
}

public static final MetadataSectionType<PackMetadataSection> OPTIONAL_FORMAT = MetadataSectionType.fromCodec("pack", RecordCodecBuilder.create(
in -> in.group(
ExtraCodecs.strictOptionalField(ComponentSerialization.CODEC, "description", Component.empty()).forGetter(PackMetadataSection::description),
ExtraCodecs.strictOptionalField(Codec.INT, "pack_format", -1).forGetter(PackMetadataSection::packFormat),
ExtraCodecs.strictOptionalField(InclusiveRange.codec(Codec.INT), "supported_formats").forGetter(PackMetadataSection::supportedFormats))
.apply(in, PackMetadataSection::new)));

public static Pack readWithOptionalMeta(
String id,
Component title,
boolean required,
Pack.ResourcesSupplier resources,
PackType type,
Pack.Position position,
PackSource source) throws IOException {
final Pack.Info packInfo = readInfo(type, resources, id, title);
return Pack.create(id, title, required, resources, packInfo, position, false, source);
}

private static Pack.Info readInfo(PackType type, Pack.ResourcesSupplier resources, String id, Component title) throws IOException {
final int currentVersion = SharedConstants.getCurrentVersion().getPackVersion(type);
try (final PackResources primaryResources = resources.openPrimary(id)) {
final PackMetadataSection metadata = primaryResources.getMetadataSection(OPTIONAL_FORMAT);

final FeatureFlagSet flags = Optional.ofNullable(primaryResources.getMetadataSection(FeatureFlagsMetadataSection.TYPE))
.map(FeatureFlagsMetadataSection::flags)
.orElse(FeatureFlagSet.of());

final List<String> overlays = Optional.ofNullable(primaryResources.getMetadataSection(OverlayMetadataSection.TYPE))
.map(section -> section.overlaysForVersion(currentVersion))
.orElse(List.of());

if (metadata == null) {
return new Pack.Info(title, PackCompatibility.COMPATIBLE, flags, overlays, primaryResources.isHidden());
}

final PackCompatibility compatibility;
if (metadata.packFormat() == -1 && metadata.supportedFormats().isEmpty()) {
compatibility = PackCompatibility.COMPATIBLE;
} else {
compatibility = PackCompatibility.forVersion(Pack.getDeclaredPackVersions(id, metadata), currentVersion);
}
return new Pack.Info(metadata.description(), compatibility, flags, overlays, primaryResources.isHidden());
}
}

private static Pack makePack(PackType packType, ArrayList<Pack> hiddenPacks) {
final String id = packType == PackType.CLIENT_RESOURCES ? MOD_RESOURCES_ID : MOD_DATA_ID;
final String name = packType == PackType.CLIENT_RESOURCES ? "Mod Resources" : "Mod Data";
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ public net.minecraft.server.packs.FilePackResources$SharedZipFileAccess
public net.minecraft.server.packs.FilePackResources$SharedZipFileAccess <init>(Ljava/io/File;)V # constructor
public net.minecraft.server.packs.repository.BuiltInPackSource fixedResources(Lnet/minecraft/server/packs/PackResources;)Lnet/minecraft/server/packs/repository/Pack$ResourcesSupplier; # fixedResources
public net.minecraft.server.packs.repository.ServerPacksSource createVanillaPackSource()Lnet/minecraft/server/packs/VanillaPackResources; # createVanillaPackSource
public net.minecraft.server.packs.repository.Pack getDeclaredPackVersions(Ljava/lang/String;Lnet/minecraft/server/packs/metadata/pack/PackMetadataSection;)Lnet/minecraft/util/InclusiveRange; # getDeclaredPackVersions
public net.minecraft.server.packs.resources.FallbackResourceManager fallbacks # fallbacks
public net.minecraft.util.ExtraCodecs$EitherCodec
public net.minecraft.util.datafix.fixes.StructuresBecomeConfiguredFix$Conversion
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");
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) NeoForged and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/

package net.neoforged.neoforge.debug.structure;

import net.minecraft.gametest.framework.GameTest;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.testframework.DynamicTest;
import net.neoforged.testframework.annotation.ForEachTest;
import net.neoforged.testframework.annotation.TestHolder;
import net.neoforged.testframework.gametest.StructureTemplateBuilder;

@ForEachTest(groups = StructureTests.GROUP)
public class StructureTests {
public static final String GROUP = "structure";

@GameTest
@TestHolder(description = "Tests that the structure bounds for use in Game Tests is correct")
static void everyBlockInStructure(final DynamicTest test) {
test.registerGameTestTemplate(() -> StructureTemplateBuilder.withSize(3, 3, 3)
.fill(0, 0, 0, 2, 2, 2, Blocks.DIAMOND_BLOCK));

test.onGameTest(helper -> helper.startSequence()
.thenWaitUntil(0, () -> helper.forEveryBlockInStructure(pos -> helper.assertBlockPresent(Blocks.DIAMOND_BLOCK, pos)))
.thenExecute(test::pass)
.thenSucceed());
}
}

0 comments on commit 53678c6

Please sign in to comment.