Skip to content

Commit

Permalink
[1.20.4] Change how resource pack grouping works and group mod data p…
Browse files Browse the repository at this point in the history
…acks - take 2 (#367)
  • Loading branch information
lukebemish authored Dec 14, 2023
1 parent f7049ed commit 70cbb5b
Show file tree
Hide file tree
Showing 25 changed files with 364 additions and 325 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 {
72 changes: 62 additions & 10 deletions patches/net/minecraft/server/packs/repository/Pack.java.patch
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
--- 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; // NeoForge: 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);
Expand All @@ -25,11 +52,36 @@
}

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_) {
Expand Down
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.

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
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,14 @@
package net.neoforged.neoforge.client.loading;

import java.io.File;
import java.util.ArrayList;
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;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.server.packs.PackResources;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraft.server.packs.repository.*;
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 All @@ -37,11 +27,8 @@
import net.neoforged.neoforge.event.AddPackFindersEvent;
import net.neoforged.neoforge.internal.BrandingControl;
import net.neoforged.neoforge.logging.CrashReportExtender;
import net.neoforged.neoforge.resource.DelegatingPackResources;
import net.neoforged.neoforge.resource.ResourcePackLoader;
import net.neoforged.neoforge.server.LanguageHook;
import net.neoforged.neoforgespi.language.IModInfo;
import net.neoforged.neoforgespi.locating.IModFile;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

Expand All @@ -63,9 +50,9 @@ public static void begin(final Minecraft minecraft, final PackRepository default
LanguageHook.loadForgeAndMCLangs();
createRunnableWithCatch(() -> ModLoader.get().gatherAndInitializeMods(ModWorkManager.syncExecutor(), ModWorkManager.parallelExecutor(), ImmediateWindowHandler::renderTick)).run();
if (error == null) {
ResourcePackLoader.loadResourcePacks(defaultResourcePacks, ClientModLoader::buildPackFinder);
ResourcePackLoader.loadResourcePacks(defaultResourcePacks, map -> ResourcePackLoader.buildPackFinder(map, PackType.CLIENT_RESOURCES));
ModLoader.get().postEvent(new AddPackFindersEvent(PackType.CLIENT_RESOURCES, defaultResourcePacks::addPackFinder));
DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getPackNames());
DataPackConfig.DEFAULT.addModPacks(ResourcePackLoader.getDataPackNames());
mcResourceManager.registerReloadListener(ClientModLoader::onResourceReload);
mcResourceManager.registerReloadListener(BrandingControl.resourceManagerReloadListener());
}
Expand Down Expand Up @@ -144,40 +131,4 @@ public static boolean completeModLoading() {
public static boolean isLoading() {
return loading;
}

private static RepositorySource buildPackFinder(Map<IModFile, ? extends PackResources> modResourcePacks) {
return packAcceptor -> clientPackFinder(modResourcePacks, packAcceptor);
}

private static void clientPackFinder(Map<IModFile, ? extends PackResources> modResourcePacks, Consumer<Pack> packAcceptor) {
var hiddenPacks = new ArrayList<PackResources>();
for (Entry<IModFile, ? extends PackResources> e : modResourcePacks.entrySet()) {
IModInfo mod = e.getKey().getModInfos().get(0);
final String name = "mod:" + mod.getModId();
final Pack modPack = Pack.readMetaAndCreate(name, Component.literal(e.getValue().packId()), false, BuiltInPackSource.fixedResources(e.getValue()), PackType.CLIENT_RESOURCES, 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
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 (mod.getOwningFile().showAsResourcePack()) {
packAcceptor.accept(modPack);
} else {
hiddenPacks.add(e.getValue());
}
}

// Create a resource pack merging all mod resources that should be hidden
final Pack modResourcesPack = Pack.readMetaAndCreate("mod_resources", Component.literal("Mod Resources"), true,
BuiltInPackSource.fromName(
id -> new DelegatingPackResources(id, false,
new PackMetadataSection(
Component.translatable("fml.resources.modresources", hiddenPacks.size()),
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);
}
}
Loading

0 comments on commit 70cbb5b

Please sign in to comment.