diff --git a/src/main/java/de/skate702/craftingkeys/CraftingKeys.java b/src/main/java/de/skate702/craftingkeys/CraftingKeys.java index ffaaa5a..a945ca0 100644 --- a/src/main/java/de/skate702/craftingkeys/CraftingKeys.java +++ b/src/main/java/de/skate702/craftingkeys/CraftingKeys.java @@ -15,6 +15,7 @@ import de.skate702.craftingkeys.config.Config; import de.skate702.craftingkeys.manager.ContainerManager; import de.skate702.craftingkeys.manager.CraftingManager; import de.skate702.craftingkeys.proxies.CraftingKeysProxy; +import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Util; import net.minecraft.client.gui.inventory.GuiCrafting; @@ -87,7 +88,7 @@ public class CraftingKeys { /** * This method will be executed every Ingame Tick. * - * @param tick + * @param tick This is a tick. What did you think about it? */ @SubscribeEvent public void onTick(TickEvent.ClientTickEvent tick) { @@ -105,11 +106,11 @@ public class CraftingKeys { } else if (Util.isInventoryGUI(Util.client.currentScreen)) { // do do do - System.out.println("Inventory"); + Logger.warn("onTick()", "Inventory"); } else if (Util.isVillagerGUI(Util.client.currentScreen)) { // do do do //((GuiMerchant) Util.client.currentScreen).inventorySlots - System.out.println("Villager"); + Logger.warn("onTick()", "Villager"); } } diff --git a/src/main/java/de/skate702/craftingkeys/config/Config.java b/src/main/java/de/skate702/craftingkeys/config/Config.java index eaa78c8..008d37a 100644 --- a/src/main/java/de/skate702/craftingkeys/config/Config.java +++ b/src/main/java/de/skate702/craftingkeys/config/Config.java @@ -92,7 +92,7 @@ public class Config { return keyDrop.getInt(retDefKey); } - public static boolean getEnableNumPad() { + public static boolean isNumPadEnabled() { return enableNumPad.getBoolean(true); } diff --git a/src/main/java/de/skate702/craftingkeys/manager/ContainerManager.java b/src/main/java/de/skate702/craftingkeys/manager/ContainerManager.java index ac8fc90..021b429 100644 --- a/src/main/java/de/skate702/craftingkeys/manager/ContainerManager.java +++ b/src/main/java/de/skate702/craftingkeys/manager/ContainerManager.java @@ -2,6 +2,7 @@ package de.skate702.craftingkeys.manager; import de.skate702.craftingkeys.CraftingKeys; import de.skate702.craftingkeys.config.Config; +import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Util; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; @@ -75,9 +76,8 @@ public abstract class ContainerManager { ItemStack source = getItemStack(srcIndex); if (source == null) { - System.out.println("moveAll(): source == null"); + Logger.debug("moveAll(i,i)", "Source ItemStack from Index == null"); } else { - System.out.println("moveAll(): Redirected to move()"); move(srcIndex, destIndex, source.stackSize); } @@ -99,10 +99,8 @@ public abstract class ContainerManager { // Same Location? if (source == null) { - System.out.println("Move(): srcIndex == destIndex OR source == null"); return; } else if (srcIndex == destIndex) { - System.out.println("Move(): srcIndex == destIndex OR source == null"); return; } @@ -123,10 +121,10 @@ public abstract class ContainerManager { leftClick(srcIndex); } - System.out.println("move(): Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!"); + Logger.info("move(i,i,i)", "Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!"); } else { - System.out.println("Move(): Not the same block type!"); + Logger.info("move(i,i,i)", "Not the same block type!"); } } @@ -145,7 +143,7 @@ public abstract class ContainerManager { } else { - System.out.println("getItemStack(): Invalid index"); + Logger.debug("getItemStack(i)", "Invalid index"); return null; } @@ -153,42 +151,45 @@ public abstract class ContainerManager { } /** - * Takes all items from a slot and moves them to the next empty slot or - * drops them. + * Moves a stack (held or not) to the next fitting inventory slot. * - * @param sourceIndex The index of the slot to move items from - * @param isCraftingGUI true, if the craftingGUI is opened + * @param sourceIndex A slot index of the source items */ - protected void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) { + protected void moveStackToInventory(int sourceIndex) { - // Check for Item-Type - ItemStack stackToMove; - if (isHeld) { - stackToMove = Util.client.thePlayer.inventory.getItemStack(); + // Moving Stack + ItemStack stackToMove = null; + + // Get the stack, index or held, cleanup held stack + if (sourceIndex == -1) { + if (Util.client.thePlayer.inventory.getItemStack() != null) { + stackToMove = Util.client.thePlayer.inventory.getItemStack(); + } } else { - putItemAway(isCraftingGUI); stackToMove = getItemStack(sourceIndex); + + // Is there a currently held stack? + if (Util.client.thePlayer.inventory.getItemStack() != null) { + moveStackToInventory(-1); + } } - // Test for empty crafting table slot - if (!isHeld && getItemStack(sourceIndex) == null) { - - System.out.println("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + "."); + // Test stack + if (stackToMove == null) { + Logger.debug("moveStackToInvetory(i)", "Stack at sourceIndex not found."); return; } - // Get Destination Index - int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove); + // Get destination index + int destIndex = calcInventoryDestination(stackToMove); // Additional click on source index, if not held - if (!isHeld) { + if (sourceIndex != -1) { leftClick(sourceIndex); } - // TODO: Optional (beta-like): Fill the items up. Let's become INVTW! - - // destIndex = -1 -> drop item - if (destIndex == -1) { + // Move the item + if (destIndex == -1) { // -1 means: Found none, drop item leftClick(-999); // Nice one, InvTweaks! } else { leftClick(destIndex); @@ -196,48 +197,48 @@ public abstract class ContainerManager { } - protected void putItemAway(boolean isCraftingGUI) { - // Put current Item away - if (Util.client.thePlayer.inventory.getItemStack() != null) { - putStackToNextEmptySlot(-1, isCraftingGUI, true); - } - } - /** - * Returns the first free index in a inventory + * Calculates the next fitting or free inventory slot. * - * @param isCraftingGUI true, if the craftingGUI is opened - * @return a slot index + * @param stackToMove The ItemType and sized Stack to move + * @return A super cool inventory slot index! Or -1, if you are to dumb + * to keep your bloody inventory sorted! WHY U NO USE INV TWEAKS?! */ - protected int getFirstPropperSlotIndex(boolean isCraftingGUI, ItemStack movingItem) { + private int calcInventoryDestination(ItemStack stackToMove) { - if (isCraftingGUI) { + // First run: Try to find a nice stack to put items on additionally + for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) { - for (int i = 10; i < container.inventorySlots.size(); i++) { + ItemStack potentialGoalStack = getItemStack(i); - if (getItemStack(i) != null) { - if (getItemStack(i).isItemEqual(movingItem)) { - if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) { - return i; - } + if (potentialGoalStack != null && stackToMove != null) { + if (potentialGoalStack.isItemEqual(stackToMove)) { + if (potentialGoalStack.stackSize + stackToMove.stackSize <= stackToMove.getMaxStackSize()) { + return i; } } } - - for (int i = 10; i < container.inventorySlots.size(); i++) { - - if (getItemStack(i) == null) { - return i; - } - } - System.out.println("getFirstProperSlotIndex(): No Propper / Empty Slot found!"); - return -1; - } else { - // TODO: Same for inventory - return -1; } + + // Second run: Find a free slot + for (int i = getInventoryStartIndex(); i < container.inventorySlots.size(); i++) { + if (getItemStack(i) == null) { + return i; + } + } + + // Third run: No slot found. Drop this shit! + return -1; + } + /** + * Returns the start index of the user inventory in the current Gui. + * + * @return A slot index + */ + protected abstract int getInventoryStartIndex(); + /** * Executes a left mouse click on a slot. [Based on INVTW] * @@ -264,7 +265,7 @@ public abstract class ContainerManager { */ protected void slotClick(int index, boolean rightClick) { - System.out.println("slotClick(): Clicked @ Slot " + index + " with data " + rightClick + "."); + Logger.info("slotClick(i,b)", "Clicked @ Slot " + index + " with data " + rightClick + "."); int rightClickData = (rightClick) ? 1 : 0; diff --git a/src/main/java/de/skate702/craftingkeys/manager/CraftingManager.java b/src/main/java/de/skate702/craftingkeys/manager/CraftingManager.java index 9939c6d..cbd493b 100644 --- a/src/main/java/de/skate702/craftingkeys/manager/CraftingManager.java +++ b/src/main/java/de/skate702/craftingkeys/manager/CraftingManager.java @@ -2,6 +2,7 @@ package de.skate702.craftingkeys.manager; import de.skate702.craftingkeys.config.Config; import de.skate702.craftingkeys.util.InputUtil; +import de.skate702.craftingkeys.util.Logger; import de.skate702.craftingkeys.util.Util; import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.inventory.Container; @@ -32,52 +33,68 @@ public class CraftingManager extends ContainerManager { if (isDropKeyDown()) { for (int i = 1; i < 10; i++) { - putStackToNextEmptySlot(i, true, false); + moveStackToInventory(i); } } else if (isInteractionKeyDown()) { if (isStackKeyDown()) { - // TODO: Get for all - System.out.println("Blabla"); + + int oldStackSize = -1; + clickOnCraftingOutput(); + + while (Util.client.thePlayer.inventory.getItemStack() != null && + oldStackSize != Util.client.thePlayer.inventory.getItemStack().stackSize) { + + oldStackSize = Util.client.thePlayer.inventory.getItemStack().stackSize; + clickOnCraftingOutput(); + } + } else { - clickOnCraftingOutput(); // TODO: Change that shit! + clickOnCraftingOutput(); } } else if (slotIndex > 0 && currentHoveredSlot != null) { if (isStackKeyDown()) { moveAll(currentHoveredSlot.slotNumber, slotIndex); + moveStackToInventory(-1); } else { move(currentHoveredSlot.slotNumber, slotIndex, 1); } - } - } - } @Override protected int specificKeyDownToSlotIndex() { - if (Keyboard.isKeyDown(Config.getKeyTopLeft())) { + if (Keyboard.isKeyDown(Config.getKeyTopLeft()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(71)) { return 1; - } else if (Keyboard.isKeyDown(Config.getkeyTopCenter())) { + } else if (Keyboard.isKeyDown(Config.getkeyTopCenter()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(72)) { return 2; - } else if (Keyboard.isKeyDown(Config.getKeyTopRight())) { + } else if (Keyboard.isKeyDown(Config.getKeyTopRight()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(73)) { return 3; - } else if (Keyboard.isKeyDown(Config.getKeyCenterLeft())) { + } else if (Keyboard.isKeyDown(Config.getKeyCenterLeft()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(75)) { return 4; - } else if (Keyboard.isKeyDown(Config.getKeyCenterCenter())) { + } else if (Keyboard.isKeyDown(Config.getKeyCenterCenter()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(76)) { return 5; - } else if (Keyboard.isKeyDown(Config.getKeyCenterRight())) { + } else if (Keyboard.isKeyDown(Config.getKeyCenterRight()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(77)) { return 6; - } else if (Keyboard.isKeyDown(Config.getKeyLowerLeft())) { + } else if (Keyboard.isKeyDown(Config.getKeyLowerLeft()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(79)) { return 7; - } else if (Keyboard.isKeyDown(Config.getKeyLowerCenter())) { + } else if (Keyboard.isKeyDown(Config.getKeyLowerCenter()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(80)) { return 8; - } else if (Keyboard.isKeyDown(Config.getKeyLowerRight())) { + } else if (Keyboard.isKeyDown(Config.getKeyLowerRight()) || + Config.isNumPadEnabled() && Keyboard.isKeyDown(81)) { return 9; } else if (Keyboard.isKeyDown(Config.getKeyInteract())) { return -101; @@ -89,17 +106,19 @@ public class CraftingManager extends ContainerManager { } + @Override + protected int getInventoryStartIndex() { + return 10; + } + /** * Sends a click on the crafting output (craftingGUI or Inventory) */ - public void clickOnCraftingOutput() { - - //putItemAway(); // TODO! + private void clickOnCraftingOutput() { // Click on crafting output - System.out.println("clickOnCraftingOutput(): Clicked on Crafing Output."); + Logger.info("clickOnCraftingOutput()", "Clicked on Crafing Output."); leftClick(0); - } } diff --git a/src/main/java/de/skate702/craftingkeys/util/InputUtil.java b/src/main/java/de/skate702/craftingkeys/util/InputUtil.java index bac8eac..dd9de4c 100644 --- a/src/main/java/de/skate702/craftingkeys/util/InputUtil.java +++ b/src/main/java/de/skate702/craftingkeys/util/InputUtil.java @@ -41,7 +41,7 @@ public class InputUtil { } return null; } else { - System.out.println("getSlotAtMousePosition(): guiContainer == null"); + Logger.debug("getSlotAtMousePosition(gui)", "guiContainer == null"); return null; } }