Improve lang resource pack injection point (closes #532)
Previously we injected it as a regular builtin resource pack (like the Programmer Art pack) and hid it on the resource pack screen but this is bad for several reasons. The most significant one being that it can be re-ordered and makes the resource pack list ordering weird if you don't know that there is an invisible pack there. It also unnecessarily messes with other mods which make certain assumptions about configurable resource packs (e.g. EBE, though in that case, it merely triggers an existing bug in EBE). We now instead inject it into the final resource pack list which gets constructed from the configured packs, but never as a configurable pack itself.
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
//#if FABRIC>=1
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import net.minecraft.client.gui.screen.pack.PackListWidget;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
//#if MC>=11600
|
||||
import net.minecraft.client.gui.screen.pack.PackScreen;
|
||||
import net.minecraft.client.gui.screen.pack.ResourcePackOrganizer;
|
||||
//#else
|
||||
//$$ import net.minecraft.client.resource.ClientResourcePackProfile;
|
||||
//#endif
|
||||
|
||||
//#if MC>=11600
|
||||
@Mixin(PackScreen.class)
|
||||
//#else
|
||||
//$$ @Mixin(ResourcePackListWidget.class)
|
||||
//#endif
|
||||
public abstract class Mixin_HideDynamicResourcePacks {
|
||||
//#if MC>=11600
|
||||
@Inject(method = "method_29672", at = @At("HEAD"), cancellable = true)
|
||||
private void hideInternalPacks(PackListWidget packListWidget, ResourcePackOrganizer.Pack pack, CallbackInfo info) {
|
||||
//#else
|
||||
//$$ @Inject(method = "add", at = @At("HEAD"), cancellable = true)
|
||||
//$$ private void hideInternalPacks(ResourcePackListWidget.ResourcePackEntry entry, CallbackInfo info) {
|
||||
//$$ ClientResourcePackProfile pack = entry.getPack();
|
||||
//#endif
|
||||
String name = pack.getDisplayName().asString();
|
||||
if (name.equals("replaymod_lang") || name.equals("replaymod_jgui")) {
|
||||
info.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
@@ -0,0 +1,52 @@
|
||||
//#if FABRIC>=1
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.versions.LangResourcePack;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.stream.Collector;
|
||||
|
||||
|
||||
//#if MC>=11600
|
||||
@Mixin(net.minecraft.resource.ResourcePackManager.class)
|
||||
//#else
|
||||
//$$ @Mixin(net.minecraft.client.MinecraftClient.class)
|
||||
//#endif
|
||||
public class Mixin_InjectDynamicResourcePacks {
|
||||
@ModifyArg(
|
||||
//#if MC>=11600
|
||||
method = "createResourcePacks",
|
||||
//#elseif MC>=11500
|
||||
//$$ method = { "<init>", "reloadResources" },
|
||||
//#else
|
||||
//$$ method = { "init", "reloadResources" },
|
||||
//#endif
|
||||
at = @At(value = "INVOKE", target = "Ljava/util/stream/Stream;collect(Ljava/util/stream/Collector;)Ljava/lang/Object;")
|
||||
)
|
||||
private Collector<ResourcePack, ?, ?> injectReplayModPacks(Collector<ResourcePack, ?, ?> collector) {
|
||||
collector = append(collector, new LangResourcePack());
|
||||
if (ReplayMod.jGuiResourcePack != null) {
|
||||
collector = append(collector, ReplayMod.jGuiResourcePack);
|
||||
}
|
||||
return collector;
|
||||
}
|
||||
|
||||
private static <T, A, R> Collector<T, A, R> append(Collector<T, A, R> collector, T value) {
|
||||
BiConsumer<A, T> accumulator = collector.accumulator();
|
||||
return Collector.of(
|
||||
collector.supplier(),
|
||||
accumulator,
|
||||
collector.combiner(),
|
||||
result -> {
|
||||
accumulator.accept(result, value);
|
||||
return collector.finisher().apply(result);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
//#if FABRIC>=1
|
||||
package com.replaymod.core.mixin;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.versions.LangResourcePack;
|
||||
import net.minecraft.client.resource.ClientBuiltinResourcePackProvider;
|
||||
import net.minecraft.resource.ResourcePackProfile;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
|
||||
//#if MC>=11600
|
||||
import net.minecraft.resource.ResourcePackSource;
|
||||
//#else
|
||||
//$$ import java.util.Map;
|
||||
//#endif
|
||||
|
||||
@Mixin(ClientBuiltinResourcePackProvider.class)
|
||||
public class Mixin_RegisterDynamicResourcePacks {
|
||||
@Inject(method = "register", at = @At("RETURN"))
|
||||
//#if MC>=11600
|
||||
private void registerReplayMod(Consumer<ResourcePackProfile> consumer, ResourcePackProfile.Factory factory, CallbackInfo ci) {
|
||||
//#else
|
||||
//$$ private <T extends ResourcePackProfile> void registerReplayMod(Map<String, T> map, ResourcePackProfile.Factory<T> factory, CallbackInfo ci) {
|
||||
//$$ Consumer<T> consumer = (pack) -> map.put(pack.getName(), pack);
|
||||
//#endif
|
||||
|
||||
consumer.accept(ResourcePackProfile.of(
|
||||
LangResourcePack.NAME,
|
||||
true,
|
||||
LangResourcePack::new,
|
||||
factory,
|
||||
ResourcePackProfile.InsertionPosition.BOTTOM
|
||||
//#if MC>=11600
|
||||
, ResourcePackSource.PACK_SOURCE_BUILTIN
|
||||
//#endif
|
||||
));
|
||||
|
||||
if (ReplayMod.jGuiResourcePack != null) {
|
||||
consumer.accept(ResourcePackProfile.of(
|
||||
ReplayMod.JGUI_RESOURCE_PACK_NAME,
|
||||
true,
|
||||
() -> ReplayMod.jGuiResourcePack,
|
||||
factory,
|
||||
ResourcePackProfile.InsertionPosition.BOTTOM
|
||||
//#if MC>=11600
|
||||
, ResourcePackSource.PACK_SOURCE_BUILTIN
|
||||
//#endif
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
//#endif
|
||||
Reference in New Issue
Block a user