Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor resource loader internals #3473

Merged
merged 24 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.resource.loader.client;

import java.util.ArrayList;
import java.util.List;

import com.llamalad7.mixinextras.sugar.Local;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

import net.minecraft.client.MinecraftClient;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProfile;

/**
* Mixins to the anonymous class in #write method.
*/
@Mixin(targets = "net/minecraft/client/option/GameOptions$3")
public class GameOptionsWriteVisitorMixin {
@Unique
private static List<String> toPackListString(List<String> packs) {
List<String> copy = new ArrayList<>(packs.size());
ResourcePackManager manager = MinecraftClient.getInstance().getResourcePackManager();

for (String pack : packs) {
ResourcePackProfile profile = manager.getProfile(pack);

// Nonexistent pack profiles should be handled in the same way as vanilla
if (profile == null || !profile.isHidden()) copy.add(pack);
}

return copy;
}

@SuppressWarnings("unchecked")
@ModifyArg(method = "visitObject", at = @At(value = "INVOKE", target = "Ljava/util/function/Function;apply(Ljava/lang/Object;)Ljava/lang/Object;"))
private <T> T skipHiddenPacks(T value, @Local String key) {
Copy link
Contributor Author

@apple502j apple502j Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Injecting here is much easier than maintaining the ordinals among the visitObject calls in accept.

if ("resourcePacks".equals(key) && value instanceof List) {
return (T) toPackListString((List<String>) value);
}

return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.mixin.resource.loader.client;

import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProfile;

@Mixin(ResourcePackOrganizer.class)
public class ResourcePackOrganizerMixin {
@Shadow
@Final
List<ResourcePackProfile> enabledPacks;

@Shadow
@Final
List<ResourcePackProfile> disabledPacks;

/**
* Do not list hidden packs in either enabledPacks or disabledPacks.
* They are managed entirely by ResourcePackManager on save, and are invisible to client.
*/
@Inject(method = "<init>", at = @At("TAIL"))
private void removeHiddenPacksInit(Runnable updateCallback, Function iconIdSupplier, ResourcePackManager resourcePackManager, Consumer applier, CallbackInfo ci) {
this.enabledPacks.removeIf(ResourcePackProfile::isHidden);
this.disabledPacks.removeIf(ResourcePackProfile::isHidden);
}

@Inject(method = "refresh", at = @At("TAIL"))
private void removeHiddenPacksRefresh(CallbackInfo ci) {
this.enabledPacks.removeIf(ResourcePackProfile::isHidden);
this.disabledPacks.removeIf(ResourcePackProfile::isHidden);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"package": "net.fabricmc.fabric.mixin.resource.loader.client",
"compatibilityLevel": "JAVA_17",
"client": [
"VanillaResourcePackProviderMixin",
"DefaultClientResourcePackProviderMixin",
"CreateWorldScreenMixin",
"FontManagerMixin",
"GameOptionsMixin",
"KeyedResourceReloadListenerClientMixin"
"KeyedResourceReloadListenerClientMixin",
"ResourcePackOrganizerMixin",
"VanillaResourcePackProviderMixin",
"GameOptionsWriteVisitorMixin"
],
"injectors": {
"defaultRequire": 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ public interface ModResourcePack extends ResourcePack {
* resource pack.
*/
ModMetadata getFabricModMetadata();

ModResourcePack createOverlay(String overlay);
}

This file was deleted.

Loading
Loading