Optimized Crafting again. Current speed level: Super fast!

This commit is contained in:
0xSeb
2015-11-02 15:17:53 +01:00
parent 2da43ff690
commit 77b8f9c346
2 changed files with 26 additions and 9 deletions
@@ -32,8 +32,7 @@ public abstract class ContainerManager {
protected void handleNumKey() { protected void handleNumKey() {
// see: http://wiki.vg/Inventory // hotbar-slots are always the last 9 slots of the currently opened inventory
// hotbar-slots are always the last 9 slots of the currently opened inventory.
int hotbarStartIndex = Util.client.thePlayer.openContainer.getInventory().size() - 9 - 1; int hotbarStartIndex = Util.client.thePlayer.openContainer.getInventory().size() - 9 - 1;
if (Keyboard.isKeyDown(Keyboard.KEY_1)) { if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
@@ -59,8 +58,8 @@ public abstract class ContainerManager {
} }
moveStackToInventory(-1); moveStackToInventory(-1);
// Minecraft handles the Keyboard-keys as well, that's why we need to clear them first
// see: GuiContainer#keyTyped(char,int); -> checkHotbarKeys // Handle Minecraft handling. Ah...
while (Keyboard.next()) { while (Keyboard.next()) {
} }
} }
@@ -146,13 +145,16 @@ public abstract class ContainerManager {
// Move some // Move some
if (destination == null || source.isItemEqual(destination)) { if (destination == null || source.isItemEqual(destination)) {
if (srcIndex > 0) {
leftClick(srcIndex); leftClick(srcIndex);
}
for (int i = 0; i < movedAmount; i++) { for (int i = 0; i < movedAmount; i++) {
rightClick(destIndex); rightClick(destIndex);
} }
// Move back // Move back
if (movedAmount < sourceSize) { if (movedAmount < sourceSize && srcIndex > 0) {
leftClick(srcIndex); leftClick(srcIndex);
} }
@@ -176,6 +178,8 @@ public abstract class ContainerManager {
Slot slot = (Slot) (container.inventorySlots.get(index)); Slot slot = (Slot) (container.inventorySlots.get(index));
return (slot == null) ? null : slot.getStack(); return (slot == null) ? null : slot.getStack();
} else if (index == -1 && Util.client.thePlayer.inventory.getItemStack() != null) {
return Util.client.thePlayer.inventory.getItemStack();
} else { } else {
Logger.debug("getItemStack(i)", "Invalid index"); Logger.debug("getItemStack(i)", "Invalid index");
@@ -57,6 +57,10 @@ public class CraftingManager extends ContainerManager {
// Get from output // Get from output
} else if (isInteractionKeyDown()) { } else if (isInteractionKeyDown()) {
if (Util.client.thePlayer.inventory.getItemStack() != null) {
moveStackToInventory(-1);
}
if (isStackKeyDown()) { if (isStackKeyDown()) {
int oldStackSize = -1; int oldStackSize = -1;
@@ -73,8 +77,9 @@ public class CraftingManager extends ContainerManager {
clickOnCraftingOutput(); clickOnCraftingOutput();
} }
// Move // Move from hovered slot
} else if (slotIndex > 0 && currentHoveredSlot != null) { } else if (slotIndex > 0 && currentHoveredSlot != null &&
Util.client.thePlayer.inventory.getItemStack() == null) {
if (isStackKeyDown()) { if (isStackKeyDown()) {
moveAll(currentHoveredSlot.slotNumber, slotIndex); moveAll(currentHoveredSlot.slotNumber, slotIndex);
@@ -83,8 +88,16 @@ public class CraftingManager extends ContainerManager {
move(currentHoveredSlot.slotNumber, slotIndex, 1); move(currentHoveredSlot.slotNumber, slotIndex, 1);
} }
// Handle NumKey-moving // Handle NumKey-moving and held-moving
} else if (Util.client.thePlayer.inventory.getItemStack() != null) { } else if (Util.client.thePlayer.inventory.getItemStack() != null) {
if (isStackKeyDown()) {
moveAll(-1, slotIndex);
moveStackToInventory(-1);
} else {
move(-1, slotIndex, 1);
}
handleNumKey(); handleNumKey();
} }
} }