diff --git a/src/main/java/cam72cam/mod/input/Clipboard.java b/src/main/java/cam72cam/mod/input/Clipboard.java new file mode 100644 index 000000000..49850a1a7 --- /dev/null +++ b/src/main/java/cam72cam/mod/input/Clipboard.java @@ -0,0 +1,29 @@ +package cam72cam.mod.input; + +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** + * Utility class to interact with the system clipboard. + */ +@SideOnly(Side.CLIENT) +public class Clipboard { + /** + * Retrieves the current text content of the system clipboard. + * + * @return the clipboard string, or {@code ""} if the clipboard is empty or inaccessible + */ + public static String getClipboard() { + return GuiScreen.getClipboardString(); + } + + /** + * Sets the system clipboard to the given text. + * + * @param newText the text to place on the clipboard + */ + public static void setClipboard(String newText) { + GuiScreen.setClipboardString(newText); + } +} \ No newline at end of file diff --git a/src/main/java/cam72cam/mod/input/Keyboard.java b/src/main/java/cam72cam/mod/input/Keyboard.java index 8ecda2ef1..311b13a35 100644 --- a/src/main/java/cam72cam/mod/input/Keyboard.java +++ b/src/main/java/cam72cam/mod/input/Keyboard.java @@ -2,6 +2,7 @@ import cam72cam.mod.event.ClientEvents; import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.settings.KeyBinding; import net.minecraftforge.fml.client.registry.ClientRegistry; import net.minecraftforge.fml.relauncher.Side; @@ -9,6 +10,7 @@ import javax.annotation.Nullable; +@SideOnly(Side.CLIENT) public class Keyboard { private static final Int2ObjectArrayMap keycodes = new Int2ObjectArrayMap<>(); @@ -135,7 +137,6 @@ public enum KeyCode { } /** Registers a keybind */ - @SideOnly(Side.CLIENT) public static void registerKey(String name, KeyCode keyCode, String category, Runnable handler) { KeyBinding key = new KeyBinding(name, keyCode.code, category); ClientRegistry.registerKeyBinding(key); @@ -145,4 +146,20 @@ public static void registerKey(String name, KeyCode keyCode, String category, Ru } }); } + + public static boolean isKeyDown(KeyCode keyCode) { + return org.lwjgl.input.Keyboard.isKeyDown(keyCode.code); + } + + public static boolean isCtrlKeyDown() { + return GuiScreen.isCtrlKeyDown(); + } + + public static boolean isShiftKeyDown() { + return GuiScreen.isShiftKeyDown(); + } + + public static boolean isAltKeyDown() { + return GuiScreen.isAltKeyDown(); + } } diff --git a/src/main/java/cam72cam/mod/input/Mouse.java b/src/main/java/cam72cam/mod/input/Mouse.java index 47ce14a34..d2d636434 100644 --- a/src/main/java/cam72cam/mod/input/Mouse.java +++ b/src/main/java/cam72cam/mod/input/Mouse.java @@ -6,7 +6,6 @@ import cam72cam.mod.entity.Player; import cam72cam.mod.entity.custom.IClickable; import cam72cam.mod.event.ClientEvents; -import cam72cam.mod.event.Event; import cam72cam.mod.item.ClickResult; import cam72cam.mod.math.Vec3d; import cam72cam.mod.net.Packet; @@ -17,9 +16,51 @@ import java.util.function.Function; -/** Only used for MC bugfixes, don't use directly */ +@SideOnly(Side.CLIENT) public class Mouse { - @SideOnly(Side.CLIENT) + /** + * Checks if the left mouse button is currently pressed. + */ + public static boolean isLMBDown() { + return org.lwjgl.input.Mouse.isButtonDown(0); + } + + /** + * Checks if the right mouse button is currently pressed. + */ + public static boolean isRMBDown() { + return org.lwjgl.input.Mouse.isButtonDown(1); + } + + /** + * Checks if the middle mouse button exists and is currently pressed. + */ + public static boolean isMMBDown() { + return org.lwjgl.input.Mouse.getButtonCount() >= 3 && org.lwjgl.input.Mouse.isButtonDown(2); + } + + /** + * Registers a 3D space dragging handler. + * + * @param handler receives the pressing key ({@link cam72cam.mod.entity.Player.Hand#PRIMARY} as LMB, {@link cam72cam.mod.entity.Player.Hand#SECONDARY} for others) + * and returns a boolean indicating whether the event should be passed down or not + */ + public static void registerDragHandler(Function handler) { + ClientEvents.DRAG.subscribe(handler); + } + + /** + * Get the screen space mouse position. + * + * @return the screen space mouse position from the start point of dragging, or {@code null} if the mouse is not pressed. + */ + public static Vec3d getDrag() { + return ClientEvents.ClientEventBus.getDragPos(); + } + + /** + * Internal, don't use + */ public static void registerClientEvents() { ClientEvents.CLICK.subscribe(button -> { // So it turns out that the client sends mouse click packets to the server regardless of @@ -50,6 +91,9 @@ public static void registerClientEvents() { }); } + /** + * Internal, don't use + */ public static class MousePressPacket extends Packet { @TagField private Player.Hand hand; @@ -77,12 +121,4 @@ public void handle() { } } } - - public static void registerDragHandler(Function handler) { - ClientEvents.DRAG.subscribe(handler); - } - - public static Vec3d getDrag() { - return ClientEvents.ClientEventBus.getDragPos(); - } }