Started refactoring. Added KeyBindings.
This commit is contained in:
@@ -1,10 +1,11 @@
|
|||||||
package de.skate702.craftingkeys;
|
package de.skate702.craftingkeys;
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
import de.skate702.craftingkeys.manager.ContainerManager;
|
||||||
|
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
||||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.common.Mod.EventHandler;
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
||||||
@@ -13,162 +14,158 @@ import net.minecraftforge.fml.common.SidedProxy;
|
|||||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||||
|
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
import net.minecraftforge.fml.common.gameevent.InputEvent;
|
||||||
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
||||||
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Main Class of the Mod with the important onTick-Method. Some Methods are
|
* The Main Class of the Mod with the important onTick-Method. Some Methods are
|
||||||
* base on the open-source Inventory Tweaks. Big Thanks for that!
|
* based on the open-source Inventory Tweaks. Big Thanks for that!
|
||||||
*
|
*
|
||||||
* @author skate702
|
* @author skate702
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@Mod(modid = "CraftingKeysID", name = "Crafting Keys", version = "1.0.0")
|
@Mod(modid = "craftingkeys", name = "Crafting Keys", version = "1.0.0")
|
||||||
public class CraftingKeys {
|
public class CraftingKeys {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Instance of CraftingKeys.
|
* Current Instance of CraftingKeys.
|
||||||
*/
|
*/
|
||||||
@Instance(value = "CraftingKeysID")
|
@Instance(value = "CraftingKeys")
|
||||||
public static CraftingKeys instance;
|
public static CraftingKeys instance;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Proxy (Common or Client)
|
* Current Proxy (Common or Client)
|
||||||
*/
|
*/
|
||||||
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy", serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
|
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy",
|
||||||
public static CraftingKeysProxy proxy;
|
serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
|
||||||
|
public static CraftingKeysProxy proxy;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method will be executed before Init.
|
* This method will be executed before Init.
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event Input Event from FML
|
||||||
* Input Event from FML
|
*/
|
||||||
*/
|
@EventHandler
|
||||||
@EventHandler
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
KeyBindings.init();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* This method will be executed while loading.
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
* Input Event from FML
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void load(FMLInitializationEvent event) {
|
|
||||||
|
|
||||||
// Regeistring
|
/**
|
||||||
proxy.registerRenderers();
|
* This method will be executed while loading.
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
*
|
||||||
|
* @param event Input Event from FML
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void load(FMLInitializationEvent event) {
|
||||||
|
|
||||||
Helper.debugPrint("load(): Loaded CraftingKeys successful");
|
// Registering
|
||||||
|
proxy.registerRenderers();
|
||||||
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
Helper.debugPrint("load(): Loaded CraftingKeys successful");
|
||||||
* This method will be executed after Init.
|
|
||||||
*
|
|
||||||
* @param event
|
|
||||||
* Input Event from FML
|
|
||||||
*/
|
|
||||||
@EventHandler
|
|
||||||
public void postInit(FMLPostInitializationEvent event) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
}
|
||||||
* To show a chat message at first start in minecraft.
|
|
||||||
*/
|
|
||||||
boolean firstInWorldTick = true;
|
|
||||||
|
|
||||||
/**
|
@SubscribeEvent
|
||||||
* This method will be executed every Ingame Tick.
|
public void onKeyInput(InputEvent.KeyInputEvent event) {
|
||||||
*
|
System.out.println(event.toString());
|
||||||
* @param tick
|
}
|
||||||
*/
|
|
||||||
@SubscribeEvent
|
|
||||||
public void onTick(TickEvent.ClientTickEvent tick) {
|
|
||||||
|
|
||||||
// Message
|
/**
|
||||||
if (Helper.client.theWorld != null && firstInWorldTick) {
|
* This method will be executed after Init.
|
||||||
|
*
|
||||||
|
* @param event Input Event from FML
|
||||||
|
*/
|
||||||
|
@EventHandler
|
||||||
|
public void postInit(FMLPostInitializationEvent event) {
|
||||||
|
}
|
||||||
|
|
||||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
/**
|
||||||
"Achtung: Crafting-Keys befindet sich in der Pre-Alpha!"));
|
* This method will be executed every Ingame Tick.
|
||||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
*
|
||||||
"Es gibt noch viele Fehler, und es fehlen noch einige Funktionen."));
|
* @param tick
|
||||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
*/
|
||||||
"Mehr Info's findest du auf: http://craftingkeys.codeplex.com!"));
|
@SubscribeEvent
|
||||||
|
public void onTick(TickEvent.ClientTickEvent tick) {
|
||||||
|
|
||||||
firstInWorldTick = !firstInWorldTick;
|
// Message
|
||||||
}
|
if(Helper.isFirstInWorldTick()) {
|
||||||
|
Helper.printWarning();
|
||||||
|
}
|
||||||
|
|
||||||
// Case 1: Classic GUI Screen
|
|
||||||
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
|
|
||||||
|
|
||||||
GuiCrafting guiCrafting = (GuiCrafting) Helper.client.currentScreen;
|
|
||||||
Slot currentHoveredSlot = Helper.getSlotAtMousePosition(guiCrafting);
|
|
||||||
int keyDown = Helper.craftingKeyDownToSlotNumber();
|
|
||||||
|
|
||||||
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
|
// Case 1: Classic GUI Screen
|
||||||
|
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
|
||||||
|
|
||||||
// Block Key Interval (avoid multiple Runs)
|
GuiCrafting guiCrafting = (GuiCrafting) Helper.client.currentScreen;
|
||||||
if (!Helper.isSameKey(keyDown)) {
|
Slot currentHoveredSlot = Helper.getSlotAtMousePosition(guiCrafting);
|
||||||
|
int keyDown = Helper.craftingKeyDownToSlotNumber();
|
||||||
|
|
||||||
// Moving item to crafting table
|
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
|
||||||
if (keyDown > 0 && currentHoveredSlot != null) {
|
|
||||||
|
|
||||||
// Shift = Move all
|
// Block Key Interval (avoid multiple Runs)
|
||||||
if (guiCrafting.isShiftKeyDown()) {
|
if (!Helper.isSameKey(keyDown)) {
|
||||||
con.moveAll(currentHoveredSlot.slotNumber, keyDown);
|
|
||||||
} else {
|
|
||||||
con.move(currentHoveredSlot.slotNumber, keyDown, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// Moving item to crafting table
|
||||||
|
if (keyDown > 0 && currentHoveredSlot != null) {
|
||||||
|
|
||||||
if (keyDown == -2) {
|
// Shift = Move all
|
||||||
|
if (guiCrafting.isShiftKeyDown()) {
|
||||||
|
con.moveAll(currentHoveredSlot.slotNumber, keyDown);
|
||||||
|
} else {
|
||||||
|
con.move(currentHoveredSlot.slotNumber, keyDown, 1);
|
||||||
|
}
|
||||||
|
|
||||||
// Space = Move all back
|
}
|
||||||
Helper.debugPrint("onTick(): Move all items back or drop them.");
|
|
||||||
|
|
||||||
for (int i = 1; i < 10; i++) {
|
if (keyDown == -2) {
|
||||||
|
|
||||||
con.putStackToNextEmptySlot(i, true, false);
|
// Space = Move all back
|
||||||
|
Helper.debugPrint("onTick(): Move all items back or drop them.");
|
||||||
|
|
||||||
}
|
for (int i = 1; i < 10; i++) {
|
||||||
}
|
|
||||||
|
|
||||||
// Strg = Take the output
|
con.putStackToNextEmptySlot(i, true, false);
|
||||||
if (guiCrafting.isCtrlKeyDown()) {
|
|
||||||
|
|
||||||
if (guiCrafting.isShiftKeyDown()) {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Strg + Shift = Move all (resp. faster!)
|
// Strg = Take the output
|
||||||
con.clickOnCraftingOutput(true);
|
if (guiCrafting.isCtrlKeyDown()) {
|
||||||
|
|
||||||
} else {
|
if (guiCrafting.isShiftKeyDown()) {
|
||||||
|
|
||||||
// Send mouse click on crafting output (accept also
|
// Strg + Shift = Move all (resp. faster!)
|
||||||
// holding)
|
con.clickOnCraftingOutput(true);
|
||||||
int ticksdown = Helper.getStrgTimesDown(true);
|
|
||||||
if (ticksdown == 2 || ticksdown % 15 == 0 || (ticksdown > 60 && ticksdown % 8 == 0)) {
|
|
||||||
con.clickOnCraftingOutput(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
|
|
||||||
} else {
|
// Send mouse click on crafting output (accept also
|
||||||
|
// holding)
|
||||||
|
int ticksdown = Helper.getStrgTimesDown(true);
|
||||||
|
if (ticksdown == 2 || ticksdown % 15 == 0 || (ticksdown > 60 && ticksdown % 8 == 0)) {
|
||||||
|
con.clickOnCraftingOutput(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Reset Strg
|
}
|
||||||
Helper.getStrgTimesDown(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
// Case 2: Inventory (2x2 Crafting, Quick-Armor)
|
// Reset Strg
|
||||||
|
Helper.getStrgTimesDown(false);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Case 2
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
// Case 2: Inventory (2x2 Crafting, Quick-Armor)
|
||||||
|
|
||||||
|
// TODO: Case 2
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,226 +1,241 @@
|
|||||||
package de.skate702.craftingkeys;
|
package de.skate702.craftingkeys;
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
|
||||||
import org.lwjgl.input.Mouse;
|
|
||||||
|
|
||||||
import net.minecraftforge.fml.client.FMLClientHandler;
|
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
|
import net.minecraft.util.ChatComponentText;
|
||||||
|
import net.minecraft.util.ChatComponentTranslation;
|
||||||
|
import net.minecraftforge.fml.client.FMLClientHandler;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
import org.lwjgl.input.Mouse;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This helper class provides some static helping Methods and Constants.
|
* This helper class provides some static helping Methods and Constants.
|
||||||
*
|
*
|
||||||
* @author sebastian
|
* @author sebastian
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
public class Helper {
|
public class Helper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private Constructor. This is a helping class!
|
* If true, there are Debug-Output-Prints from debugPrint(msg).
|
||||||
*/
|
*/
|
||||||
private Helper() {
|
public static final boolean DEBUG = true;
|
||||||
// Nope.
|
/**
|
||||||
}
|
* Current Instance Client, used for a lot of operations.
|
||||||
|
*/
|
||||||
|
public static Minecraft client = FMLClientHandler.instance().getClient();
|
||||||
|
|
||||||
/**
|
|
||||||
* If true, there are Debug-Output-Prints from debugPrint(msg).
|
|
||||||
*/
|
|
||||||
public static final boolean DEBUG = true;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Current Instance Client, used for a lot of operations.
|
* Saves the last Key that was Pressed
|
||||||
*/
|
*/
|
||||||
public static Minecraft client = FMLClientHandler.instance().getClient();
|
private static int lastKeyDown = -1;
|
||||||
|
/**
|
||||||
|
* Saves the times strg was pressed before reseting
|
||||||
|
*/
|
||||||
|
private static int strgTimesDown = 0;
|
||||||
|
private static boolean firstInWorldTick = true;
|
||||||
|
|
||||||
/**
|
|
||||||
* Standart Output for Debug-Messages - Depends on DEBUG-Constant.
|
|
||||||
*
|
|
||||||
* @param message
|
|
||||||
* The Debug-Message. Syntax: "methodname(): Message"
|
|
||||||
*/
|
|
||||||
public static void debugPrint(String message) {
|
|
||||||
|
|
||||||
if (DEBUG) {
|
/**
|
||||||
System.out.println("CK-DEBUG: " + message);
|
* Private Constructor. This is a helping class!
|
||||||
}
|
*/
|
||||||
|
private Helper() {
|
||||||
|
// Nope.
|
||||||
|
}
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* Returns, if this is the first method call in a fresh opened world.
|
||||||
|
*
|
||||||
|
* @return True, if this is the first tick
|
||||||
|
*/
|
||||||
|
public static boolean isFirstInWorldTick() {
|
||||||
|
if (firstInWorldTick && client.theWorld != null) {
|
||||||
|
firstInWorldTick = false;
|
||||||
|
return true;
|
||||||
|
} else if (client.theWorld == null) {
|
||||||
|
firstInWorldTick = true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
public static void printWarning() {
|
||||||
* Returns true, if the current Screen is a instance of GUI-Screen.
|
client.thePlayer.addChatMessage(new ChatComponentText(
|
||||||
*
|
"Achtung: Crafting-Keys befindet sich in der Alpha!"));
|
||||||
* @param screen
|
client.thePlayer.addChatMessage(new ChatComponentText(
|
||||||
* The input Screen
|
"Es gibt noch viele Fehler, und es fehlen noch einige Funktionen."));
|
||||||
* @return True, if GuiScreen; False if null
|
client.thePlayer.addChatMessage(new ChatComponentText(
|
||||||
*/
|
"Mehr Info's findest du auf: https://github.com/0xSeb/CraftingKeys!"));
|
||||||
public static boolean isCraftingGUI(GuiScreen screen) {
|
client.thePlayer.addChatMessage(new ChatComponentTranslation("key.topleft"));
|
||||||
|
}
|
||||||
|
|
||||||
if (screen != null) {
|
/**
|
||||||
if (screen instanceof GuiCrafting) {
|
* Standart Output for Debug-Messages - Depends on DEBUG-Constant.
|
||||||
return true;
|
*
|
||||||
}
|
* @param message The Debug-Message. Syntax: "methodname(): Message"
|
||||||
}
|
*/
|
||||||
return false;
|
public static void debugPrint(String message) {
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (DEBUG) {
|
||||||
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
|
System.out.println("CK-DEBUG: " + message);
|
||||||
*
|
}
|
||||||
* @param guiContainer
|
|
||||||
* The (Inventory) Container to work with.
|
|
||||||
* @return Returns the slot (or null)
|
|
||||||
*/
|
|
||||||
public static Slot getSlotAtMousePosition(GuiContainer guiContainer) {
|
|
||||||
if (guiContainer != null) {
|
|
||||||
Container container = guiContainer.inventorySlots;
|
|
||||||
|
|
||||||
int x = getMouseX(guiContainer);
|
}
|
||||||
int y = getMouseY(guiContainer);
|
|
||||||
for (int k = 0; k < container.inventorySlots.size(); k++) {
|
|
||||||
Slot slot = (Slot) container.inventorySlots.get(k);
|
|
||||||
if (getIsMouseOverSlot(guiContainer, slot, x, y)) {
|
|
||||||
return slot;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
Helper.debugPrint("getSlotAtMousePosition(): guiContainer == null");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER]
|
* Returns true, if the current Screen is a instance of GUI-Screen.
|
||||||
*
|
*
|
||||||
* @param guiContainer
|
* @param screen The input Screen
|
||||||
* the GuiContainer to work with
|
* @return True, if GuiScreen; False if null
|
||||||
* @param slot
|
*/
|
||||||
* The spcified slot
|
public static boolean isCraftingGUI(GuiScreen screen) {
|
||||||
* @param x
|
|
||||||
* The Mouse x-Position
|
|
||||||
* @param y
|
|
||||||
* The Mouse y-Position
|
|
||||||
* @return True, if the mouse is positioned over this slot. Otherwise false
|
|
||||||
*/
|
|
||||||
private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) {
|
|
||||||
if (guiContainer != null) {
|
|
||||||
|
|
||||||
// Constants from Minecraft Source Code
|
if (screen != null) {
|
||||||
x -= (guiContainer.width - 176) / 2;
|
if (screen instanceof GuiCrafting) {
|
||||||
y -= (guiContainer.height - 166) / 2;
|
return true;
|
||||||
return x >= slot.xDisplayPosition - 1 && x < slot.xDisplayPosition + 16 + 1
|
}
|
||||||
&& y >= slot.yDisplayPosition - 1 && y < slot.yDisplayPosition + 16 + 1;
|
}
|
||||||
} else {
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
|
||||||
*
|
*
|
||||||
* @param guiContainer
|
* @param guiContainer The (Inventory) Container to work with.
|
||||||
* the GuiContainer to work with
|
* @return Returns the slot (or null)
|
||||||
* @return The relative Mouse-Position
|
*/
|
||||||
*/
|
public static Slot getSlotAtMousePosition(GuiContainer guiContainer) {
|
||||||
private static int getMouseX(GuiContainer guiContainer) {
|
if (guiContainer != null) {
|
||||||
return (Mouse.getEventX() * guiContainer.width) / client.displayWidth;
|
Container container = guiContainer.inventorySlots;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
int x = getMouseX(guiContainer);
|
||||||
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
int y = getMouseY(guiContainer);
|
||||||
*
|
for (int k = 0; k < container.inventorySlots.size(); k++) {
|
||||||
* @param guiContainer
|
Slot slot = (Slot) container.inventorySlots.get(k);
|
||||||
* the GuiContainer to work with
|
if (getIsMouseOverSlot(guiContainer, slot, x, y)) {
|
||||||
* @return The relative Mouse-Position
|
return slot;
|
||||||
*/
|
}
|
||||||
private static int getMouseY(GuiContainer guiContainer) {
|
}
|
||||||
return guiContainer.height - (Mouse.getEventY() * guiContainer.height) / client.displayHeight - 1;
|
return null;
|
||||||
}
|
} else {
|
||||||
|
Helper.debugPrint("getSlotAtMousePosition(): guiContainer == null");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the current Keyboard-Input and converts it to a Inventory-Slot.
|
* Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER]
|
||||||
*
|
*
|
||||||
* @return A Inventory-Slot (based on CraftingGUI), -1 for wrong input, -2
|
* @param guiContainer the GuiContainer to work with
|
||||||
* for space
|
* @param slot The spcified slot
|
||||||
*/
|
* @param x The Mouse x-Position
|
||||||
public static int craftingKeyDownToSlotNumber() {
|
* @param y The Mouse y-Position
|
||||||
|
* @return True, if the mouse is positioned over this slot. Otherwise false
|
||||||
|
*/
|
||||||
|
private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) {
|
||||||
|
if (guiContainer != null) {
|
||||||
|
|
||||||
// TODO: Make this dynamic! // Use Settings
|
// Constants from Minecraft Source Code
|
||||||
|
x -= (guiContainer.width - 176) / 2;
|
||||||
|
y -= (guiContainer.height - 166) / 2;
|
||||||
|
return x >= slot.xDisplayPosition - 1 && x < slot.xDisplayPosition + 16 + 1
|
||||||
|
&& y >= slot.yDisplayPosition - 1 && y < slot.yDisplayPosition + 16 + 1;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int returnValue = -1;
|
/**
|
||||||
|
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
||||||
|
*
|
||||||
|
* @param guiContainer the GuiContainer to work with
|
||||||
|
* @return The relative Mouse-Position
|
||||||
|
*/
|
||||||
|
private static int getMouseX(GuiContainer guiContainer) {
|
||||||
|
return (Mouse.getEventX() * guiContainer.width) / client.displayWidth;
|
||||||
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_Q)) {
|
/**
|
||||||
returnValue = 1;
|
* Returns a calculated Mouse Position for getSlotAtMousePosition().
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
|
*
|
||||||
returnValue = 2;
|
* @param guiContainer the GuiContainer to work with
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_E)) {
|
* @return The relative Mouse-Position
|
||||||
returnValue = 3;
|
*/
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
|
private static int getMouseY(GuiContainer guiContainer) {
|
||||||
returnValue = 4;
|
return guiContainer.height - (Mouse.getEventY() * guiContainer.height) / client.displayHeight - 1;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
|
}
|
||||||
returnValue = 5;
|
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
|
|
||||||
returnValue = 6;
|
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_Y)) {
|
|
||||||
returnValue = 7;
|
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_X)) {
|
|
||||||
returnValue = 8;
|
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_C)) {
|
|
||||||
returnValue = 9;
|
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
|
||||||
returnValue = -2;
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnValue;
|
/**
|
||||||
}
|
* Reads the current Keyboard-Input and converts it to a Inventory-Slot.
|
||||||
|
*
|
||||||
|
* @return A Inventory-Slot (based on CraftingGUI), -1 for wrong input, -2
|
||||||
|
* for space
|
||||||
|
*/
|
||||||
|
public static int craftingKeyDownToSlotNumber() {
|
||||||
|
|
||||||
/**
|
// TODO: Make this dynamic! // Use Settings
|
||||||
* Saves the last Key that was Pressed
|
|
||||||
*/
|
|
||||||
private static int lastKeyDown = -1;
|
|
||||||
|
|
||||||
/**
|
int returnValue = -1;
|
||||||
* 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 (Keyboard.isKeyDown(Keyboard.KEY_Q)) {
|
||||||
|
returnValue = 1;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
|
||||||
|
returnValue = 2;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_E)) {
|
||||||
|
returnValue = 3;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
|
||||||
|
returnValue = 4;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
|
||||||
|
returnValue = 5;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
|
||||||
|
returnValue = 6;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_Y)) {
|
||||||
|
returnValue = 7;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_X)) {
|
||||||
|
returnValue = 8;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_C)) {
|
||||||
|
returnValue = 9;
|
||||||
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
|
||||||
|
returnValue = -2;
|
||||||
|
}
|
||||||
|
|
||||||
if (lastKeyDown == currentKey && currentKey != -1) {
|
return returnValue;
|
||||||
returnValue = true;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
lastKeyDown = currentKey;
|
/**
|
||||||
return returnValue;
|
* 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) {
|
||||||
* Saves the times strg was pressed before reseting
|
returnValue = true;
|
||||||
*/
|
}
|
||||||
private static int strgTimesDown = 0;
|
|
||||||
|
|
||||||
/**
|
lastKeyDown = currentKey;
|
||||||
* Return the times Strg was pressed before reseting
|
return returnValue;
|
||||||
*
|
|
||||||
* @param strgDown
|
|
||||||
* false, if reset
|
|
||||||
* @return A number of tick strg was down before
|
|
||||||
*/
|
|
||||||
public static int getStrgTimesDown(boolean strgDown) {
|
|
||||||
|
|
||||||
if (!strgDown)
|
}
|
||||||
strgTimesDown = 0;
|
|
||||||
|
|
||||||
return ++strgTimesDown;
|
/**
|
||||||
|
* Return the times Strg was pressed before reseting
|
||||||
|
*
|
||||||
|
* @param strgDown false, if reset
|
||||||
|
* @return A number of tick strg was down before
|
||||||
|
*/
|
||||||
|
public static int getStrgTimesDown(boolean strgDown) {
|
||||||
|
|
||||||
}
|
if (!strgDown)
|
||||||
|
strgTimesDown = 0;
|
||||||
|
|
||||||
|
return ++strgTimesDown;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package de.skate702.craftingkeys;
|
||||||
|
|
||||||
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.client.settings.KeyBinding;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
import net.minecraftforge.fml.client.registry.ClientRegistry;
|
||||||
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides all Key Bindings and methods to register and check them.
|
||||||
|
*/
|
||||||
|
public class KeyBindings {
|
||||||
|
|
||||||
|
// WARNING: This does NOT work! Has to been removed. Own Option Dialog OR Settings file. Bindings are exclusive. Shit!
|
||||||
|
|
||||||
|
private static final String category = "key.categories.craftingkeys";
|
||||||
|
private static KeyBinding[] bindings = { // Inspired by CSS Position Properties
|
||||||
|
new KeyBinding("key.topleft", Keyboard.KEY_Q, category),
|
||||||
|
new KeyBinding("key.topcenter", Keyboard.KEY_W, category),
|
||||||
|
new KeyBinding("key.topright", Keyboard.KEY_E, category),
|
||||||
|
|
||||||
|
new KeyBinding("key.centerleft", Keyboard.KEY_A, category),
|
||||||
|
new KeyBinding("key.centercenter", Keyboard.KEY_S, category),
|
||||||
|
new KeyBinding("key.centerright", Keyboard.KEY_D, category),
|
||||||
|
|
||||||
|
new KeyBinding("key.lowerleft", Keyboard.KEY_Y, category), // GERMAN Keyboard layout
|
||||||
|
new KeyBinding("key.lowercenter", Keyboard.KEY_X, category),
|
||||||
|
new KeyBinding("key.lowerright", Keyboard.KEY_C, category),
|
||||||
|
|
||||||
|
new KeyBinding("key.stack", Keyboard.KEY_LSHIFT, category),
|
||||||
|
new KeyBinding("key.interact", Keyboard.KEY_LCONTROL, category),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes all key bindings and registers them to the client-side.
|
||||||
|
*/
|
||||||
|
public static void init() {
|
||||||
|
for (KeyBinding binding : bindings) {
|
||||||
|
ClientRegistry.registerKeyBinding(binding);
|
||||||
|
}
|
||||||
|
ClientRegistry.registerKeyBinding(Minecraft.getMinecraft().gameSettings.keyBindRight);
|
||||||
|
//Minecraft.getMinecraft().gameSettings.keybind
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+9
-1
@@ -1,9 +1,14 @@
|
|||||||
package de.skate702.craftingkeys;
|
package de.skate702.craftingkeys.manager;
|
||||||
|
|
||||||
|
import de.skate702.craftingkeys.CraftingKeys;
|
||||||
|
import de.skate702.craftingkeys.Helper;
|
||||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||||
import net.minecraft.inventory.Container;
|
import net.minecraft.inventory.Container;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.util.ChatComponentText;
|
import net.minecraft.util.ChatComponentText;
|
||||||
import net.minecraft.util.IChatComponent;
|
import net.minecraft.util.IChatComponent;
|
||||||
|
|
||||||
@@ -215,6 +220,9 @@ public class ContainerManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GameRegistry.addShapelessRecipe(new ItemStack(Item.getByNameOrId("Diamond")),
|
||||||
|
new ItemStack(Block.getBlockFromName("Dirt")));
|
||||||
|
|
||||||
for (int i = 10; i < container.inventorySlots.size(); i++) {
|
for (int i = 10; i < container.inventorySlots.size(); i++) {
|
||||||
|
|
||||||
if (getItemStack(i) == null) {
|
if (getItemStack(i) == null) {
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
?# Control Names
|
||||||
|
key.topleft=1. Top Left
|
||||||
|
key.topcenter=2. Top Center
|
||||||
|
key.topright=3. Top Right
|
||||||
|
key.centerleft=4. Center Left
|
||||||
|
key.centercenter=5. Center Center
|
||||||
|
key.centerright=6. Center Right
|
||||||
|
key.lowerleft=7. Lower Left
|
||||||
|
key.lowercenter=8. Lower Center
|
||||||
|
key.lowerright=9. Lower Right
|
||||||
|
key.stack=Stack Key
|
||||||
|
key.interact=Interaction Key
|
||||||
|
# Control Category Name
|
||||||
|
key.categories.craftingkeys=Crafting Keys (Mostly red Keys are NO problem!)
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"modid": "CraftingKeysID",
|
"modid": "craftingkeys",
|
||||||
"name": "Crafting Keys",
|
"name": "Crafting Keys",
|
||||||
"description": "TODO",
|
"description": "TODO",
|
||||||
"version": "${version}",
|
"version": "${version}",
|
||||||
|
|||||||
Reference in New Issue
Block a user