Skip to content

Commit

Permalink
[1.20.4] Fixed NeoForge pack version and description (Attempt 2) (#365)
Browse files Browse the repository at this point in the history
This is a **breaking change** because we are removing the obsolete server/resource pack numbers because vanilla allows us to specify version ranges. Mods can just say they can run on all versions and avoid the red highlighting in pack screens entirely.
  • Loading branch information
TelepathicGrunt authored Dec 14, 2023
1 parent 84d25b7 commit f7049ed
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 76 deletions.
Original file line number Diff line number Diff line change
@@ -1,64 +1,11 @@
--- a/net/minecraft/server/packs/metadata/pack/PackMetadataSection.java
+++ b/net/minecraft/server/packs/metadata/pack/PackMetadataSection.java
@@ -9,14 +_,59 @@
import net.minecraft.server.packs.metadata.MetadataSectionType;
import net.minecraft.util.InclusiveRange;

-public record PackMetadataSection(Component description, int packFormat, Optional<InclusiveRange<Integer>> supportedFormats) {
+public record PackMetadataSection(Component description, @Deprecated int packFormat, Optional<InclusiveRange<Integer>> supportedFormats, Optional<NeoForgeData> neoForgeData) {
public static final Codec<PackMetadataSection> CODEC = RecordCodecBuilder.create(
p_304321_ -> p_304321_.group(
ComponentSerialization.CODEC.fieldOf("description").forGetter(PackMetadataSection::description),
Codec.INT.fieldOf("pack_format").forGetter(PackMetadataSection::packFormat),
- InclusiveRange.codec(Codec.INT).optionalFieldOf("supported_formats").forGetter(PackMetadataSection::supportedFormats)
+ InclusiveRange.codec(Codec.INT).optionalFieldOf("supported_formats").forGetter(PackMetadataSection::supportedFormats),
+ NeoForgeData.CODEC.optionalFieldOf("neoforge").forGetter(PackMetadataSection::neoForgeData)
)
@@ -19,4 +_,8 @@
.apply(p_304321_, PackMetadataSection::new)
);
public static final MetadataSectionType<PackMetadataSection> TYPE = MetadataSectionType.fromCodec("pack", CODEC);
+
+ @Deprecated
+ public PackMetadataSection(Component description, int packFormat, Optional<InclusiveRange<Integer>> supportedFormats) {
+ this(description, packFormat, supportedFormats, Optional.empty());
+ }
+
+ public PackMetadataSection(Component description, int packFormat, InclusiveRange<Integer> supportedFormats) {
+ this(description, packFormat, Optional.of(supportedFormats), Optional.empty());
+ }
+
+ public PackMetadataSection(Component description, int packFormat, NeoForgeData neoForgeData) {
+ this(description, packFormat, Optional.empty(), Optional.of(neoForgeData));
+ }
+
+ public <R> PackMetadataSection(Component p_10371_, int p_10372_, java.util.Map<net.minecraft.server.packs.PackType, Integer> packTypeVersions) {
+ this(p_10371_, p_10372_, new NeoForgeData(packTypeVersions));
+ }
+
+ public PackMetadataSection(Component description, int packVersion) {
+ this(description, packVersion, Optional.empty(), Optional.empty());
+ }
+
+ public int packFormat(net.minecraft.server.packs.PackType packType) {
+ return neoForgeData().flatMap(d -> d.packFormat(packType)).orElse(packFormat());
+ }
+
+ public record NeoForgeData(Optional<java.util.Map<net.minecraft.server.packs.PackType, Integer>> formatPerPackType) {
+
+ private static final Codec<NeoForgeData> CODEC = RecordCodecBuilder.create(builder -> builder.group(
+ Codec.simpleMap(
+ net.minecraft.util.StringRepresentable.fromEnum(net.minecraft.server.packs.PackType::values),
+ Codec.INT,
+ com.mojang.serialization.Keyable.forStrings(() -> java.util.Arrays.stream(net.minecraft.server.packs.PackType.values()).map(net.minecraft.util.StringRepresentable::getSerializedName))
+ ).codec().optionalFieldOf("versions").forGetter(NeoForgeData::formatPerPackType)
+ ).apply(builder, NeoForgeData::new));
+
+ public NeoForgeData(java.util.Map<net.minecraft.server.packs.PackType, Integer> supportedFormats) {
+ this(Optional.of(supportedFormats));
+ }
+
+ public Optional<Integer> packFormat(net.minecraft.server.packs.PackType packType) {
+ return formatPerPackType.map(p -> p.get(packType));
+ }
+ this(description, packVersion, Optional.empty());
+ }
}
11 changes: 4 additions & 7 deletions patches/net/minecraft/server/packs/repository/Pack.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
private final Pack.Position defaultPosition;
private final boolean required;
private final boolean fixedPosition;
+ private final boolean hidden; // Forge: Allow packs to be hidden from the UI entirely
+ private final boolean hidden; // NeoForge: Allow packs to be hidden from the UI entirely
private final PackSource packSource;

@Nullable
Expand All @@ -21,7 +21,7 @@
OverlayMetadataSection overlaymetadatasection = packresources.getMetadataSection(OverlayMetadataSection.TYPE);
List<String> list = overlaymetadatasection != null ? overlaymetadatasection.overlaysForVersion(p_294759_) : List.of();
- pack$info = new Pack.Info(packmetadatasection.description(), packcompatibility, featureflagset, list);
+ pack$info = new Pack.Info(packmetadatasection.description(), packmetadatasection.packFormat(PackType.SERVER_DATA), packmetadatasection.packFormat(PackType.CLIENT_RESOURCES), packcompatibility, featureflagset, list, packresources.isHidden());
+ pack$info = new Pack.Info(packmetadatasection.description(), packcompatibility, featureflagset, list, packresources.isHidden());
}

return pack$info;
Expand All @@ -34,15 +34,12 @@
@Override
public boolean equals(Object p_10448_) {
if (this == p_10448_) {
@@ -189,7 +_,10 @@
@@ -189,7 +_,7 @@
return this.id.hashCode();
}

- public static record Info(Component description, PackCompatibility compatibility, FeatureFlagSet requestedFeatures, List<String> overlays) {
+ public static record Info(Component description, int dataFormat, int resourceFormat, PackCompatibility compatibility, FeatureFlagSet requestedFeatures, List<String> overlays, boolean isHidden) {
+ public int getFormat(PackType type) {
+ return type == PackType.SERVER_DATA ? this.dataFormat : this.resourceFormat;
+ }
+ public static record Info(Component description, PackCompatibility compatibility, FeatureFlagSet requestedFeatures, List<String> overlays, boolean isHidden) {
}

public static enum Position {
12 changes: 5 additions & 7 deletions src/generated/resources/pack.mcmeta
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
"description": {
"translate": "pack.neoforge.description"
},
"neoforge": {
"versions": {
"client_resources": 22,
"server_data": 26
}
},
"pack_format": 26
"pack_format": 26,
"supported_formats": [
0,
2147483647
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.concurrent.*;
import java.util.function.Consumer;
import net.minecraft.SharedConstants;
Expand All @@ -22,6 +23,7 @@
import net.minecraft.server.packs.resources.PreparableReloadListener;
import net.minecraft.server.packs.resources.ReloadableResourceManager;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.InclusiveRange;
import net.minecraft.util.profiling.ProfilerFiller;
import net.minecraft.world.level.DataPackConfig;
import net.neoforged.api.distmarker.Dist;
Expand Down Expand Up @@ -172,7 +174,8 @@ private static void clientPackFinder(Map<IModFile, ? extends PackResources> modR
id -> new DelegatingPackResources(id, false,
new PackMetadataSection(
Component.translatable("fml.resources.modresources", hiddenPacks.size()),
SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES)),
SharedConstants.getCurrentVersion().getPackVersion(PackType.CLIENT_RESOURCES),
Optional.of(new InclusiveRange<>(0, Integer.MAX_VALUE))),
hiddenPacks)),
PackType.CLIENT_RESOURCES, Pack.Position.BOTTOM, PackSource.DEFAULT);
packAcceptor.accept(modResourcesPack);
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/net/neoforged/neoforge/common/NeoForgeMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import net.minecraft.DetectedVersion;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BiomeColors;
Expand All @@ -45,6 +44,7 @@
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.util.InclusiveRange;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.ai.attributes.Attribute;
Expand Down Expand Up @@ -533,9 +533,8 @@ public void gatherData(GatherDataEvent event) {
gen.addProvider(true, new PackMetadataGenerator(packOutput)
.add(PackMetadataSection.TYPE, new PackMetadataSection(
Component.translatable("pack.neoforge.description"),
DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES),
Optional.empty(),
Optional.of(new PackMetadataSection.NeoForgeData(Optional.of(Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion))))))));
DetectedVersion.BUILT_IN.getPackVersion(PackType.SERVER_DATA),
Optional.of(new InclusiveRange<>(0, Integer.MAX_VALUE)))));
NeoForgeBlockTagsProvider blockTags = new NeoForgeBlockTagsProvider(packOutput, lookupProvider, existingFileHelper);
gen.addProvider(event.includeServer(), blockTags);
gen.addProvider(event.includeServer(), new NeoForgeItemTagsProvider(packOutput, lookupProvider, blockTags.contentsGetter(), existingFileHelper));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -47,6 +46,7 @@
import net.minecraft.sounds.SoundEvents;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.InclusiveRange;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemDisplayContext;
Expand Down Expand Up @@ -106,7 +106,7 @@ public static void gatherData(GatherDataEvent event) {
.add(PackMetadataSection.TYPE, new PackMetadataSection(
Component.literal("NeoForge tests resource pack"),
DetectedVersion.BUILT_IN.getPackVersion(PackType.CLIENT_RESOURCES),
Arrays.stream(PackType.values()).collect(Collectors.toMap(Function.identity(), DetectedVersion.BUILT_IN::getPackVersion)))));
Optional.of(new InclusiveRange<>(0, Integer.MAX_VALUE)))));
gen.addProvider(event.includeClient(), new Lang(packOutput));
// Let blockstate provider see generated item models by passing its existing file helper
ItemModelProvider itemModels = new ItemModels(packOutput, event.getExistingFileHelper());
Expand Down

0 comments on commit f7049ed

Please sign in to comment.