Fixes #3 - Use WrapWithCondition to improve compatibility with other mods

This commit is contained in:
MrMelon54 committed 2024-01-30 10:19:34 +00:00
1 parent 4377c5f9f4
commit be1ec18a31
11 files changed
+50 -66

No files matched your search

@@ -11,15 +11,9 @@ import java.util.function.Supplier;
public class DraggableLists { public class DraggableLists {
public static final String MOD_ID = "draggable_lists"; public static final String MOD_ID = "draggable_lists";
private static ConfigStructure config; public static final ConfigStructure CONFIG = AutoConfig.register(ConfigStructure.class, JanksonConfigSerializer::new).get();
public static ConfigStructure getConfig() {
return config;
}
public static void init() { public static void init() {
AutoConfig.register(ConfigStructure.class, JanksonConfigSerializer::new);
config = AutoConfig.getConfigHolder(ConfigStructure.class).getConfig();
} }
public static Supplier<Screen> createConfigScreen(Screen screen) { public static Supplier<Screen> createConfigScreen(Screen screen) {
@@ -7,7 +7,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(PackSelectionModel.class) @Mixin(PackSelectionModel.class)
public abstract class MixinPackSelectionModel implements ResourcePackOrganizerDuckProvider { public abstract class PackSelectionModelMixin implements ResourcePackOrganizerDuckProvider {
@Shadow @Shadow
@Final @Final
Runnable onListChanged; Runnable onListChanged;
@@ -1,6 +1,5 @@
package com.mrmelon54.DraggableLists.mixin.packs; package com.mrmelon54.DraggableLists.mixin.packs;
import com.mrmelon54.DraggableLists.DraggableLists;
import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider; import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider;
import com.mrmelon54.DraggableLists.duck.ResourcePackOrganizerDuckProvider; import com.mrmelon54.DraggableLists.duck.ResourcePackOrganizerDuckProvider;
import net.minecraft.client.gui.screens.packs.PackSelectionModel; import net.minecraft.client.gui.screens.packs.PackSelectionModel;
@@ -14,7 +13,7 @@ import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
@Mixin(PackSelectionModel.EntryBase.class) @Mixin(PackSelectionModel.EntryBase.class)
public abstract class MixinPackSelectionModel_EntryBase implements AbstractPackDuckProvider { public abstract class PackSelectionModel_EntryBaseMixin implements AbstractPackDuckProvider {
@Shadow @Shadow
protected abstract List<Pack> getSelfList(); protected abstract List<Pack> getSelfList();
@@ -8,14 +8,14 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@Mixin(PackSelectionScreen.class) @Mixin(PackSelectionScreen.class)
public class MixinPackSelectionScreen extends Screen { public class PackSelectionScreenMixin extends Screen {
@Shadow @Shadow
private TransferableSelectionList selectedPackList; private TransferableSelectionList selectedPackList;
@Shadow @Shadow
private TransferableSelectionList availablePackList; private TransferableSelectionList availablePackList;
protected MixinPackSelectionScreen(Component component) { protected PackSelectionScreenMixin(Component component) {
super(component); super(component);
} }
@@ -1,6 +1,5 @@
package com.mrmelon54.DraggableLists.mixin.packs; package com.mrmelon54.DraggableLists.mixin.packs;
import com.mrmelon54.DraggableLists.DraggableLists;
import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider; import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider;
import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider; import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
@@ -18,7 +17,7 @@ import org.spongepowered.asm.mixin.Unique;
@Mixin(TransferableSelectionList.class) @Mixin(TransferableSelectionList.class)
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public abstract class MixinTransferableSelectionList extends ObjectSelectionList<TransferableSelectionList.PackEntry> { public abstract class TransferableSelectionListMixin extends ObjectSelectionList<TransferableSelectionList.PackEntry> {
@Unique @Unique
private TransferableSelectionList.PackEntry draggable_lists$draggingObject = null; private TransferableSelectionList.PackEntry draggable_lists$draggingObject = null;
@Unique @Unique
@@ -34,7 +33,7 @@ public abstract class MixinTransferableSelectionList extends ObjectSelectionList
@Unique @Unique
private double draggable_lists$softScrollingOrigin = 0; private double draggable_lists$softScrollingOrigin = 0;
public MixinTransferableSelectionList(Minecraft minecraft, int i, int j, int k, int l, int m) { public TransferableSelectionListMixin(Minecraft minecraft, int i, int j, int k, int l, int m) {
super(minecraft, i, j, k, l); super(minecraft, i, j, k, l);
} }
@@ -1,5 +1,6 @@
package com.mrmelon54.DraggableLists.mixin.packs; package com.mrmelon54.DraggableLists.mixin.packs;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mrmelon54.DraggableLists.DraggableLists; import com.mrmelon54.DraggableLists.DraggableLists;
import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider; import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider;
@@ -14,12 +15,11 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(TransferableSelectionList.PackEntry.class) @Mixin(TransferableSelectionList.PackEntry.class)
public abstract class MixinTransferableSelectionList_PackEntry extends ObjectSelectionList.Entry<TransferableSelectionList.PackEntry> implements ResourcePackEntryDuckProvider { public abstract class TransferableSelectionList_PackEntryMixin extends ObjectSelectionList.Entry<TransferableSelectionList.PackEntry> implements ResourcePackEntryDuckProvider {
@Shadow @Shadow
@Final @Final
private PackSelectionModel.Entry pack; private PackSelectionModel.Entry pack;
@@ -40,33 +40,29 @@ public abstract class MixinTransferableSelectionList_PackEntry extends ObjectSel
ci.cancel(); ci.cancel();
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 4)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 4))
public void removeOnUpArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeOnUpArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableResourcePackArrows) return; return !DraggableLists.CONFIG.disableResourcePackArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 5)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 5))
public void removeOffUpArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeOffUpArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableResourcePackArrows) return; return !DraggableLists.CONFIG.disableResourcePackArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 6)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 6))
public void removeOnDownArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeOnDownArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableResourcePackArrows) return; return !DraggableLists.CONFIG.disableResourcePackArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 7)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 7))
public void removeOffDownArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeOffDownArrowButtons(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableResourcePackArrows) return; return !DraggableLists.CONFIG.disableResourcePackArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
public void removeMoveTowardEnd(double d, double e, int i, CallbackInfoReturnable<Boolean> cir) { public void removeMoveTowardEnd(double d, double e, int i, CallbackInfoReturnable<Boolean> cir) {
if (!DraggableLists.getConfig().disableResourcePackArrows) return; if (!DraggableLists.CONFIG.disableResourcePackArrows) return;
if (d > getRectangle().width() / 2f) return; if (d > getRectangle().width() / 2f) return;
double f = d - (double) parent.getRowLeft(); double f = d - (double) parent.getRowLeft();
@@ -14,14 +14,14 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(JoinMultiplayerScreen.class) @Mixin(JoinMultiplayerScreen.class)
public abstract class MixinJoinMultiplayerScreen extends Screen implements MultiplayerScreenDuckProvider { public abstract class JoinMultiplayerScreenMixin extends Screen implements MultiplayerScreenDuckProvider {
@Shadow @Shadow
protected ServerSelectionList serverSelectionList; protected ServerSelectionList serverSelectionList;
@Shadow @Shadow
public abstract ServerList getServers(); public abstract ServerList getServers();
protected MixinJoinMultiplayerScreen(Component component) { protected JoinMultiplayerScreenMixin(Component component) {
super(component); super(component);
} }
@@ -1,5 +1,6 @@
package com.mrmelon54.DraggableLists.mixin.server; package com.mrmelon54.DraggableLists.mixin.server;
import com.llamalad7.mixinextras.injector.WrapWithCondition;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.mrmelon54.DraggableLists.DraggableLists; import com.mrmelon54.DraggableLists.DraggableLists;
import com.mrmelon54.DraggableLists.duck.ServerEntryDuckProvider; import com.mrmelon54.DraggableLists.duck.ServerEntryDuckProvider;
@@ -14,12 +15,11 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(ServerSelectionList.OnlineServerEntry.class) @Mixin(ServerSelectionList.OnlineServerEntry.class)
public abstract class MixinOnlineServerEntry extends ObjectSelectionList.Entry<ServerSelectionList.Entry> implements ServerEntryDuckProvider { public abstract class OnlineServerEntryMixin extends ObjectSelectionList.Entry<ServerSelectionList.Entry> implements ServerEntryDuckProvider {
@Shadow @Shadow
@Final @Final
private ServerData serverData; private ServerData serverData;
@@ -68,28 +68,24 @@ public abstract class MixinOnlineServerEntry extends ObjectSelectionList.Entry<S
draggable_lists$isBeingDragged = v; draggable_lists$isBeingDragged = v;
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 3))
public void removeUpOnButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeUpOnButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableServerArrows) return; return !DraggableLists.CONFIG.disableServerArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 4)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 4))
public void removeUpButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeUpButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableServerArrows) return; return !DraggableLists.CONFIG.disableServerArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 5)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 5))
public void removeDownOnButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeDownOnButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableServerArrows) return; return !DraggableLists.CONFIG.disableServerArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 6)) @WrapWithCondition(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;blitSprite(Lnet/minecraft/resources/ResourceLocation;IIII)V", ordinal = 6))
public void removeDownButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) { public boolean removeDownButton(GuiGraphics instance, ResourceLocation resourceLocation, int i, int j, int k, int l) {
if (DraggableLists.getConfig().disableServerArrows) return; return !DraggableLists.CONFIG.disableServerArrows;
instance.blitSprite(resourceLocation, i, j, k, l);
} }
@Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true) @Inject(method = "mouseClicked", at = @At("HEAD"), cancellable = true)
@@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.Shadow;
import java.util.List; import java.util.List;
@Mixin(ServerList.class) @Mixin(ServerList.class)
public class MixinServerList implements ServerListDuckProvider { public class ServerListMixin implements ServerListDuckProvider {
@Shadow @Shadow
@Final @Final
private List<ServerData> serverList; private List<ServerData> serverList;
@@ -22,7 +22,7 @@ import org.spongepowered.asm.mixin.Unique;
import java.util.List; import java.util.List;
@Mixin(ServerSelectionList.class) @Mixin(ServerSelectionList.class)
public abstract class MixinServerSelectionList extends ObjectSelectionList<ServerSelectionList.Entry> { public abstract class ServerSelectionListMixin extends ObjectSelectionList<ServerSelectionList.Entry> {
@Shadow @Shadow
@Final @Final
private JoinMultiplayerScreen screen; private JoinMultiplayerScreen screen;
@@ -52,7 +52,7 @@ public abstract class MixinServerSelectionList extends ObjectSelectionList<Serve
@Unique @Unique
private double draggable_lists$softScrollingOrigin = 0; private double draggable_lists$softScrollingOrigin = 0;
public MixinServerSelectionList(Minecraft minecraftClient, int i, int j, int k, int l, int m) { public ServerSelectionListMixin(Minecraft minecraftClient, int i, int j, int k, int l, int m) {
super(minecraftClient, i, j, k, l); super(minecraftClient, i, j, k, l);
} }
@@ -4,15 +4,15 @@
"compatibilityLevel": "JAVA_17", "compatibilityLevel": "JAVA_17",
"minVersion": "0.8", "minVersion": "0.8",
"client": [ "client": [
"packs.MixinPackSelectionModel", "packs.PackSelectionModelMixin",
"packs.MixinPackSelectionModel_EntryBase", "packs.PackSelectionModel_EntryBaseMixin",
"packs.MixinPackSelectionScreen", "packs.PackSelectionScreenMixin",
"packs.MixinTransferableSelectionList", "packs.TransferableSelectionListMixin",
"packs.MixinTransferableSelectionList_PackEntry", "packs.TransferableSelectionList_PackEntryMixin",
"server.MixinJoinMultiplayerScreen", "server.JoinMultiplayerScreenMixin",
"server.MixinOnlineServerEntry", "server.OnlineServerEntryMixin",
"server.MixinServerList", "server.ServerListMixin",
"server.MixinServerSelectionList" "server.ServerSelectionListMixin"
], ],
"mixins": [ "mixins": [
], ],