diff --git a/common/src/main/java/com/mrmelon54/DraggableLists/Cursor.java b/common/src/main/java/com/mrmelon54/DraggableLists/Cursor.java new file mode 100644 index 0000000..2934434 --- /dev/null +++ b/common/src/main/java/com/mrmelon54/DraggableLists/Cursor.java @@ -0,0 +1,19 @@ +package com.mrmelon54.DraggableLists; + +import net.minecraft.client.Minecraft; +import org.lwjgl.glfw.GLFW; + +public class Cursor { + private static boolean isDragging; + + public static void setDragging() { + isDragging = true; + GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_VRESIZE_CURSOR)); + } + + public static void reset() { + if (!isDragging) return; + isDragging = false; + GLFW.glfwSetCursor(Minecraft.getInstance().getWindow().getWindow(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR)); + } +} diff --git a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/MinecraftMixin.java b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/MinecraftMixin.java index bb0b61f..75fb835 100644 --- a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/MinecraftMixin.java +++ b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/MinecraftMixin.java @@ -1,23 +1,18 @@ package com.mrmelon54.DraggableLists.mixin; -import com.mojang.blaze3d.platform.Window; +import com.mrmelon54.DraggableLists.Cursor; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; -import org.lwjgl.glfw.GLFW; 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; @Mixin(Minecraft.class) public abstract class MinecraftMixin { - @Shadow - public abstract Window getWindow(); - @Inject(method = "setScreen", at = @At("HEAD")) private void injectedSetScreen(Screen screen, CallbackInfo ci) { // reset cursor when screen changes - GLFW.glfwSetCursor(getWindow().getWindow(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR)); + Cursor.reset(); } } diff --git a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/packs/TransferableSelectionListMixin.java b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/packs/TransferableSelectionListMixin.java index a604558..5837833 100644 --- a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/packs/TransferableSelectionListMixin.java +++ b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/packs/TransferableSelectionListMixin.java @@ -1,5 +1,6 @@ package com.mrmelon54.DraggableLists.mixin.packs; +import com.mrmelon54.DraggableLists.Cursor; import com.mrmelon54.DraggableLists.duck.AbstractPackDuckProvider; import com.mrmelon54.DraggableLists.duck.ResourcePackEntryDuckProvider; import net.fabricmc.api.EnvType; @@ -60,7 +61,7 @@ public abstract class TransferableSelectionListMixin extends ObjectSelectionList this.setFocused(draggable_lists$draggingObject); duckProvider.draggable_lists$setBeingDragged(true); draggable_lists$softScrollingTimer = 0; - GLFW.glfwSetCursor(minecraft.getWindow().getWindow(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_VRESIZE_CURSOR)); + Cursor.setDragging(); super.mouseClicked(mouseX, mouseY, button); this.setSelected(null); return true; @@ -73,7 +74,7 @@ public abstract class TransferableSelectionListMixin extends ObjectSelectionList public boolean mouseReleased(double mouseX, double mouseY, int button) { this.setDragging(false); if (draggable_lists$draggingObject != null) { - GLFW.glfwSetCursor(minecraft.getWindow().getWindow(), GLFW.glfwCreateStandardCursor(GLFW.GLFW_ARROW_CURSOR)); + Cursor.reset(); if (draggable_lists$draggingObject instanceof ResourcePackEntryDuckProvider duckProvider) duckProvider.draggable_lists$setBeingDragged(false); } diff --git a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/server/ServerSelectionListMixin.java b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/server/ServerSelectionListMixin.java index a2cb116..fdc2b08 100644 --- a/common/src/main/java/com/mrmelon54/DraggableLists/mixin/server/ServerSelectionListMixin.java +++ b/common/src/main/java/com/mrmelon54/DraggableLists/mixin/server/ServerSelectionListMixin.java @@ -1,5 +1,6 @@ package com.mrmelon54.DraggableLists.mixin.server; +import com.mrmelon54.DraggableLists.Cursor; import com.mrmelon54.DraggableLists.duck.MultiplayerScreenDuckProvider; import com.mrmelon54.DraggableLists.duck.ServerEntryDuckProvider; import com.mrmelon54.DraggableLists.duck.ServerListDuckProvider; @@ -78,7 +79,7 @@ public abstract class ServerSelectionListMixin extends ObjectSelectionList