Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 29 additions & 0 deletions src/main/java/cam72cam/mod/input/Clipboard.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
19 changes: 18 additions & 1 deletion src/main/java/cam72cam/mod/input/Keyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

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;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;

@SideOnly(Side.CLIENT)
public class Keyboard {
private static final Int2ObjectArrayMap<KeyCode> keycodes = new Int2ObjectArrayMap<>();

Expand Down Expand Up @@ -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);
Expand All @@ -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();
}
}
58 changes: 47 additions & 11 deletions src/main/java/cam72cam/mod/input/Mouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Player.Hand, Boolean> 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
Expand Down Expand Up @@ -50,6 +91,9 @@ public static void registerClientEvents() {
});
}

/**
* Internal, don't use
*/
public static class MousePressPacket extends Packet {
@TagField
private Player.Hand hand;
Expand Down Expand Up @@ -77,12 +121,4 @@ public void handle() {
}
}
}

public static void registerDragHandler(Function<Player.Hand, Boolean> handler) {
ClientEvents.DRAG.subscribe(handler);
}

public static Vec3d getDrag() {
return ClientEvents.ClientEventBus.getDragPos();
}
}