Refactored all the gui inventory managing. Was a lot. Now adding new GUIs should be fun!

This commit is contained in:
0xSeb
2015-11-02 22:17:51 +01:00
parent a428346b69
commit 01f992e58a
5 changed files with 245 additions and 275 deletions
@@ -1,15 +1,11 @@
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;
import net.minecraft.inventory.Slot;
import org.lwjgl.input.Keyboard;
/**
* Manages a Crafting GUI Inventory.
*/
public class CraftingManager extends ContainerManager {
private static CraftingManager instance = null;
@@ -39,117 +35,9 @@ public class CraftingManager extends ContainerManager {
}
@Override
public void acceptKey() {
protected int specificKeyToSlotIndex() {
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition((GuiCrafting) Util.client.currentScreen);
int slotIndex = specificKeyDownToSlotIndex();
if (!InputUtil.isSameKey(slotIndex)) {
// Drop
if (isDropKeyDown()) {
Logger.info("acceptKey()", "Drop Key down.");
for (int i = 1; i < 10; i++) {
moveStackToInventory(i);
}
// Get from output
} else if (isInteractionKeyDown()) {
Logger.info("acceptKey()", "Interaction Key down.");
// Handles Interaction with items held
if (Util.isHoldingStack() && (
!Util.getHeldStack().isItemEqual(getItemStack(0))
|| Util.getHeldStack().stackSize + getItemStack(0).stackSize
>= getItemStack(0).getMaxStackSize())) {
moveStackToInventory(-1);
}
if (isStackKeyDown()) {
int oldStackSize = -1;
clickOnCraftingOutput();
while (Util.isHoldingStack() &&
oldStackSize != Util.getHeldStack().stackSize) {
oldStackSize = Util.getHeldStack().stackSize;
clickOnCraftingOutput();
}
} else {
clickOnCraftingOutput();
}
// Move from hovered slot
} else if (slotIndex > 0 && currentHoveredSlot != null &&
Util.getHeldStack() == null) {
Logger.info("acceptKey()", "Key for index " + slotIndex + " down.");
if (isStackKeyDown()) {
moveAll(currentHoveredSlot.slotNumber, slotIndex);
moveStackToInventory(-1);
} else {
move(currentHoveredSlot.slotNumber, slotIndex, 1);
}
// Handle NumKey-moving and held-moving
} else if (Util.isHoldingStack()) {
if (isStackKeyDown()) {
moveAll(-1, slotIndex);
moveStackToInventory(-1);
} else {
move(-1, slotIndex, 1);
}
handleNumKey();
}
}
}
@Override
protected int specificKeyDownToSlotIndex() {
if (Keyboard.isKeyDown(Config.getKeyTopLeft()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(71)) {
return 1;
} else if (Keyboard.isKeyDown(Config.getKeyTopCenter()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(72)) {
return 2;
} else if (Keyboard.isKeyDown(Config.getKeyTopRight()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(73)) {
return 3;
} else if (Keyboard.isKeyDown(Config.getKeyCenterLeft()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(75)) {
return 4;
} else if (Keyboard.isKeyDown(Config.getKeyCenterCenter()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(76)) {
return 5;
} else if (Keyboard.isKeyDown(Config.getKeyCenterRight()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(77)) {
return 6;
} else if (Keyboard.isKeyDown(Config.getKeyLowerLeft()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(79)) {
return 7;
} else if (Keyboard.isKeyDown(Config.getKeyLowerCenter()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(80)) {
return 8;
} else if (Keyboard.isKeyDown(Config.getKeyLowerRight()) ||
Config.isNumPadEnabled() && Keyboard.isKeyDown(81)) {
return 9;
} else if (Keyboard.isKeyDown(Config.getKeyInteract())) {
return -101;
} else if (Keyboard.isKeyDown(Config.getKeyDrop())) {
return -102;
} else {
return -1;
}
return mapKeyToSlot(1, 2, 3, 4, 5, 6, 7, 8, 9);
}
@@ -158,12 +46,26 @@ public class CraftingManager extends ContainerManager {
return 10;
}
@Override
protected int getInteractionSlotIndex() {
return 0;
}
@Override
protected int[] getDropSlots() {
return new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9};
}
@Override
protected void interact() {
clickOnCraftingOutput();
}
/**
* Sends a click on the crafting output (craftingGUI or Inventory)
* Sends a click on the crafting output
*/
private void clickOnCraftingOutput() {
// Click on crafting output
Logger.info("clickOnCraftingOutput()", "Clicked on Crafing Output.");
leftClick(0);