Files
CraftingKeys/src/main/java/de/skate702/craftingkeys/util/InputUtil.java
T

57 lines
1.5 KiB
Java

package de.skate702.craftingkeys.util;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.world.inventory.Slot;
/**
* This class provides methods to interact with the Mouse and key input.
*/
public class InputUtil {
/**
* Saves the last Key that was Pressed
*/
private static int lastKeyDown = -1;
/**
* Private Constructor, Utility Class.
*/
private InputUtil() {
}
/**
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
*
* @param screen The (Inventory) Container to work with.
* @return Returns the slot (or null)
*/
public static Slot getSlotAtMousePosition(Screen screen) {
if (screen instanceof AbstractContainerScreen) {
return ((AbstractContainerScreen) screen).getSlotUnderMouse();
} else {
Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null");
return null;
}
}
/**
* Returns, if the current KeyValue is the same
*
* @param currentKey the new input value, saved in the method
* @return True, if these are the same keys
*/
public static boolean isSameKey(int currentKey) {
boolean returnValue = false;
if (lastKeyDown == currentKey && currentKey != -1) {
returnValue = true;
}
lastKeyDown = currentKey;
return returnValue;
}
}