Skip to content

Commit

Permalink
Merge branch '1.20.x' into LootTableLoadEventFix-1.20.4
Browse files Browse the repository at this point in the history
  • Loading branch information
GirafiStudios authored Dec 14, 2023
2 parents afcd01a + 70cbb5b commit 673ccfa
Show file tree
Hide file tree
Showing 28 changed files with 379 additions and 396 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ java_version=17
minecraft_version=1.20.4
neoform_version=20231207.154220

spi_version=8.0.0
spi_version=9.0.1
mergetool_version=2.0.0
accesstransformers_version=10.0.1
coremods_version=6.0.2
Expand All @@ -30,7 +30,7 @@ jetbrains_annotations_version=24.0.1
slf4j_api_version=2.0.7
apache_maven_artifact_version=3.8.5
jarjar_version=0.4.0
fancy_mod_loader_version=2.0.0
fancy_mod_loader_version=2.0.1
mojang_logging_version=1.1.1
log4j_version=2.19.0
guava_version=31.1.2-jre
Expand Down
9 changes: 9 additions & 0 deletions patches/net/minecraft/client/Options.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@
&& !Minecraft.getInstance().getSoundManager().getAvailableSoundDevices().contains(p_232011_)
? Optional.empty()
: Optional.of(p_232011_),
@@ -787,7 +_,7 @@
this.incompatibleResourcePacks.clear();

for(Pack pack : p_275268_.getSelectedPacks()) {
- if (!pack.isFixedPosition()) {
+ if (!pack.isFixedPosition() && !pack.isHidden()) {
this.resourcePacks.add(pack.getId());
if (!pack.getCompatibility().isCompatible()) {
this.incompatibleResourcePacks.add(pack.getId());
@@ -1058,6 +_,7 @@
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
--- a/net/minecraft/client/gui/screens/packs/PackSelectionModel.java
+++ b/net/minecraft/client/gui/screens/packs/PackSelectionModel.java
@@ -106,6 +_,8 @@
boolean canMoveUp();

boolean canMoveDown();
+
+ default boolean notHidden() { return true; }
}

@OnlyIn(Dist.CLIENT)
@@ -205,6 +_,11 @@
@Override
public void moveDown() {
this.move(1);
+ }
+
+ @Override
+ public boolean notHidden() {
+ return !pack.isHidden();
}
}

@@ -31,7 +_,7 @@
this.onListChanged = p_99909_;
this.iconGetter = p_99910_;
this.repository = p_99911_;
- this.selected = Lists.newArrayList(p_99911_.getSelectedPacks());
+ this.selected = Lists.newArrayList(p_99911_.getSelectedPacks().stream().filter(p -> !p.isHidden()).toList());
Collections.reverse(this.selected);
this.unselected = Lists.newArrayList(p_99911_.getAvailablePacks());
this.unselected.removeAll(this.selected);

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
if (path != null) {
if (this.tempDataPackRepository == null) {
this.tempDataPackRepository = ServerPacksSource.createPackRepository(path, this.packValidator);
+ net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(this.tempDataPackRepository, net.neoforged.neoforge.server.ServerLifecycleHooks::buildPackFinder);
+ net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(this.tempDataPackRepository, map -> net.neoforged.neoforge.resource.ResourcePackLoader.buildPackFinder(map, net.minecraft.server.packs.PackType.SERVER_DATA));
this.tempDataPackRepository.reload();
}

10 changes: 5 additions & 5 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,15 @@
public static WorldDataConfiguration configurePackRepository(
PackRepository p_248681_, DataPackConfig p_248920_, boolean p_249869_, FeatureFlagSet p_251243_
) {
+ net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(p_248681_, net.neoforged.neoforge.server.ServerLifecycleHooks::buildPackFinder);
+ net.neoforged.neoforge.resource.ResourcePackLoader.loadResourcePacks(p_248681_, map -> net.neoforged.neoforge.resource.ResourcePackLoader.buildPackFinder(map, PackType.SERVER_DATA));
p_248681_.reload();
+ DataPackConfig.DEFAULT.addModPacks(net.neoforged.neoforge.common.CommonHooks.getModPacks());
+ p_248920_.addModPacks(net.neoforged.neoforge.common.CommonHooks.getModPacks());
+ DataPackConfig.DEFAULT.addModPacks(net.neoforged.neoforge.common.CommonHooks.getModDataPacks());
+ p_248920_.addModPacks(net.neoforged.neoforge.common.CommonHooks.getModDataPacks());
if (p_249869_) {
- p_248681_.setSelected(Collections.singleton("vanilla"));
- return WorldDataConfiguration.DEFAULT;
+ p_248681_.setSelected(net.neoforged.neoforge.common.CommonHooks.getModPacksWithVanilla());
+ return new WorldDataConfiguration(new DataPackConfig(net.neoforged.neoforge.common.CommonHooks.getModPacksWithVanilla(), ImmutableList.of()), FeatureFlags.DEFAULT_FLAGS);
+ p_248681_.setSelected(net.neoforged.neoforge.common.CommonHooks.getModDataPacksWithVanilla());
+ return new WorldDataConfiguration(new DataPackConfig(net.neoforged.neoforge.common.CommonHooks.getModDataPacksWithVanilla(), ImmutableList.of()), FeatureFlags.DEFAULT_FLAGS);
} else {
Set<String> set = Sets.newLinkedHashSet();

Expand Down
11 changes: 11 additions & 0 deletions patches/net/minecraft/server/commands/DataPackCommand.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/net/minecraft/server/commands/DataPackCommand.java
+++ b/net/minecraft/server/commands/DataPackCommand.java
@@ -183,7 +_,7 @@
private static int listEnabledPacks(CommandSourceStack p_136866_) {
PackRepository packrepository = p_136866_.getServer().getPackRepository();
packrepository.reload();
- Collection<? extends Pack> collection = packrepository.getSelectedPacks();
+ Collection<? extends Pack> collection = packrepository.getSelectedPacks().stream().filter(p -> !p.isHidden()).toList();
if (collection.isEmpty()) {
p_136866_.sendSuccess(() -> Component.translatable("commands.datapack.list.enabled.none"), false);
} else {
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());
+ }
}
81 changes: 65 additions & 16 deletions patches/net/minecraft/server/packs/repository/Pack.java.patch
Original file line number Diff line number Diff line change
@@ -1,48 +1,97 @@
--- a/net/minecraft/server/packs/repository/Pack.java
+++ b/net/minecraft/server/packs/repository/Pack.java
@@ -29,6 +_,7 @@
@@ -29,6 +_,8 @@
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; // Neo: Allow packs to be hidden from the UI entirely
+ private final List<Pack> children; // Neo: Allows packs to specify packs which will always be placed beneath them; must be hidden
private final PackSource packSource;

@Nullable
@@ -77,6 +_,7 @@
this.defaultPosition = p_251298_;
this.fixedPosition = p_249753_;
this.packSource = p_251608_;
@@ -69,6 +_,33 @@
boolean p_249753_,
PackSource p_251608_
) {
+ this(p_252218_, p_248829_, p_249377_, p_251718_, p_250162_, p_251298_, p_249753_, p_251608_, List.of());
+ }
+
+ private Pack(
+ String p_252218_,
+ boolean p_248829_,
+ Pack.ResourcesSupplier p_249377_,
+ Component p_251718_,
+ Pack.Info p_250162_,
+ Pack.Position p_251298_,
+ boolean p_249753_,
+ PackSource p_251608_,
+ List<Pack> children
+ ) {
+ List<Pack> flattenedChildren = new java.util.ArrayList<>();
+ List<Pack> remainingChildren = children;
+ // recursively flatten children
+ while (!remainingChildren.isEmpty()) {
+ List<Pack> oldChildren = remainingChildren;
+ remainingChildren = new java.util.ArrayList<>();
+ for (Pack child : oldChildren) {
+ flattenedChildren.add(child.withChildren(List.of()).hidden());
+ remainingChildren.addAll(child.getChildren());
+ }
+ }
+ this.children = List.copyOf(flattenedChildren);
+ this.hidden = p_250162_.isHidden();
}

@Nullable
this.id = p_252218_;
this.resources = p_249377_;
this.title = p_251718_;
@@ -96,7 +_,7 @@
PackCompatibility packcompatibility = PackCompatibility.forVersion(inclusiverange, p_294759_);
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;
@@ -172,6 +_,8 @@
@@ -172,6 +_,33 @@
return this.packSource;
}

+ public boolean isHidden() { return hidden; }
+
+ public List<Pack> getChildren() { return children; }
+
+ /**
+ * {@return a copy of the pack with the provided children in place of any children this pack currently has}
+ */
+ public Pack withChildren(List<Pack> children) {
+ return new Pack(this.id, this.required, this.resources, this.title, this.info, this.defaultPosition, this.fixedPosition, this.packSource, children);
+ }
+
+ /**
+ * {@return a copy of the pack that is hidden}
+ */
+ public Pack hidden() {
+ return new Pack(
+ this.id, this.required, this.resources, this.title,
+ new Info(
+ this.info.description(),
+ info.compatibility(),
+ info.requestedFeatures(),
+ info.overlays(),
+ true
+ ),
+ this.defaultPosition, this.fixedPosition, this.packSource, this.children);
+ }
+
@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 {
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,30 @@
}

public void reload() {
@@ -71,11 +_,12 @@
}

private List<Pack> rebuildSelected(Collection<String> p_10518_) {
- List<Pack> list = this.getAvailablePacks(p_10518_).collect(Collectors.toList());
+ List<Pack> list = this.getAvailablePacks(p_10518_).flatMap(p -> Stream.concat(Stream.of(p), p.getChildren().stream())).collect(Collectors.toList());

for(Pack pack : this.available.values()) {
if (pack.isRequired() && !list.contains(pack)) {
- pack.getDefaultPosition().insert(list, pack, Functions.identity(), false);
+ int i = pack.getDefaultPosition().insert(list, pack, Functions.identity(), false);
+ list.addAll(i + 1, pack.getChildren());
}
}

@@ -95,7 +_,7 @@
}

public Collection<String> getSelectedIds() {
- return this.selected.stream().map(Pack::getId).collect(ImmutableSet.toImmutableSet());
+ return this.selected.stream().filter(p -> !p.isHidden()).map(Pack::getId).collect(ImmutableSet.toImmutableSet());
}

public FeatureFlagSet getRequestedFeatureFlags() {
@@ -109,6 +_,10 @@
@Nullable
public Pack getPack(String p_10508_) {
Expand Down

This file was deleted.

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 @@ -34,6 +34,7 @@
import net.minecraft.network.chat.Style;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.resources.IoSupplier;
import net.minecraft.util.FormattedCharSequence;
import net.neoforged.fml.ModContainer;
Expand Down Expand Up @@ -379,11 +380,11 @@ private void updateCache() {
@SuppressWarnings("resource")
Pair<ResourceLocation, Size2i> logoData = selectedMod.getLogoFile().map(logoFile -> {
TextureManager tm = this.minecraft.getTextureManager();
final PackResources resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId())
final Pack.ResourcesSupplier resourcePack = ResourcePackLoader.getPackFor(selectedMod.getModId())
.orElse(ResourcePackLoader.getPackFor("neoforge").orElseThrow(() -> new RuntimeException("Can't find neoforge, WHAT!")));
try {
try (PackResources packResources = resourcePack.openPrimary("mod:" + selectedMod.getModId())) {
NativeImage logo = null;
IoSupplier<InputStream> logoResource = resourcePack.getRootResource(logoFile.split("[/\\\\]"));
IoSupplier<InputStream> logoResource = packResources.getRootResource(logoFile.split("[/\\\\]"));
if (logoResource != null)
logo = NativeImage.read(logoResource.get());
if (logo != null) {
Expand Down
Loading

0 comments on commit 673ccfa

Please sign in to comment.