Added Furnace Manager. Fixed minor bugs. Managing should be refactored soon!
This commit is contained in:
@@ -14,6 +14,7 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import de.skate702.craftingkeys.config.Config;
|
||||
import de.skate702.craftingkeys.manager.ContainerManager;
|
||||
import de.skate702.craftingkeys.manager.CraftingManager;
|
||||
import de.skate702.craftingkeys.manager.FurnaceManager;
|
||||
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
|
||||
import de.skate702.craftingkeys.util.Logger;
|
||||
import de.skate702.craftingkeys.util.Util;
|
||||
@@ -114,19 +115,25 @@ public class CraftingKeys {
|
||||
} else if (currentScreen instanceof GuiInventory) {
|
||||
|
||||
Logger.warn("onTick()", "Inventory not implemented");
|
||||
|
||||
} else if (currentScreen instanceof GuiMerchant) {
|
||||
|
||||
Logger.warn("onTick()", "Villager not implemented");
|
||||
|
||||
} else if (currentScreen instanceof GuiFurnace) {
|
||||
|
||||
Logger.warn("onTick()", "Furnace not implemented");
|
||||
ContainerManager con = FurnaceManager.getInstance(
|
||||
((GuiFurnace) currentScreen).inventorySlots);
|
||||
con.acceptKey();
|
||||
|
||||
} else if (currentScreen instanceof GuiDispenser) {
|
||||
|
||||
Logger.warn("onTick()", "Dispenser not implemented");
|
||||
|
||||
} else if (currentScreen instanceof GuiBrewingStand) {
|
||||
|
||||
Logger.warn("onTick()", "BrewingStand not implemented");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class Config {
|
||||
return keyTopLeft.getInt(retDefKey);
|
||||
}
|
||||
|
||||
public static int getkeyTopCenter() {
|
||||
public static int getKeyTopCenter() {
|
||||
return keyTopCenter.getInt(retDefKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -147,10 +147,16 @@ public abstract class ContainerManager {
|
||||
int sourceSize = source.stackSize;
|
||||
int movedAmount = Math.min(amount, sourceSize);
|
||||
|
||||
// Clear goal slot (May fail on full inventory!); only available if not holdling
|
||||
if (destination != null && !source.isItemEqual(destination) && srcIndex >= 0) {
|
||||
moveStackToInventory(destIndex);
|
||||
destination = getItemStack(destIndex);
|
||||
}
|
||||
|
||||
// Move some
|
||||
if (destination == null || source.isItemEqual(destination)) {
|
||||
|
||||
if (srcIndex > 0) {
|
||||
if (srcIndex >= 0) {
|
||||
leftClick(srcIndex);
|
||||
}
|
||||
|
||||
@@ -166,7 +172,7 @@ public abstract class ContainerManager {
|
||||
Logger.info("move(i,i,i)", "Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!");
|
||||
|
||||
} else {
|
||||
Logger.info("move(i,i,i)", "Not the same block type!");
|
||||
Logger.info("move(i,i,i)", "Unable to move!");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,8 +189,8 @@ public abstract class ContainerManager {
|
||||
Slot slot = (Slot) (container.inventorySlots.get(index));
|
||||
return (slot == null) ? null : slot.getStack();
|
||||
|
||||
} else if (index == -1 && Util.client.thePlayer.inventory.getItemStack() != null) {
|
||||
return Util.client.thePlayer.inventory.getItemStack();
|
||||
} else if (index == -1 && Util.isHoldingStack()) {
|
||||
return Util.getHeldStack();
|
||||
} else {
|
||||
|
||||
Logger.debug("getItemStack(i)", "Invalid index");
|
||||
@@ -206,14 +212,14 @@ public abstract class ContainerManager {
|
||||
|
||||
// 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();
|
||||
if (Util.isHoldingStack()) {
|
||||
stackToMove = Util.getHeldStack();
|
||||
}
|
||||
} else {
|
||||
stackToMove = getItemStack(sourceIndex);
|
||||
|
||||
// Is there a currently held stack?
|
||||
if (Util.client.thePlayer.inventory.getItemStack() != null) {
|
||||
if (Util.isHoldingStack()) {
|
||||
moveStackToInventory(-1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,9 +62,9 @@ public class CraftingManager extends ContainerManager {
|
||||
Logger.info("acceptKey()", "Interaction Key down.");
|
||||
|
||||
// Handles Interaction with items held
|
||||
if (Util.client.thePlayer.inventory.getItemStack() != null && (
|
||||
!Util.client.thePlayer.inventory.getItemStack().isItemEqual(getItemStack(0))
|
||||
|| Util.client.thePlayer.inventory.getItemStack().stackSize + getItemStack(0).stackSize
|
||||
if (Util.isHoldingStack() && (
|
||||
!Util.getHeldStack().isItemEqual(getItemStack(0))
|
||||
|| Util.getHeldStack().stackSize + getItemStack(0).stackSize
|
||||
>= getItemStack(0).getMaxStackSize())) {
|
||||
moveStackToInventory(-1);
|
||||
}
|
||||
@@ -74,10 +74,10 @@ public class CraftingManager extends ContainerManager {
|
||||
int oldStackSize = -1;
|
||||
clickOnCraftingOutput();
|
||||
|
||||
while (Util.client.thePlayer.inventory.getItemStack() != null &&
|
||||
oldStackSize != Util.client.thePlayer.inventory.getItemStack().stackSize) {
|
||||
while (Util.isHoldingStack() &&
|
||||
oldStackSize != Util.getHeldStack().stackSize) {
|
||||
|
||||
oldStackSize = Util.client.thePlayer.inventory.getItemStack().stackSize;
|
||||
oldStackSize = Util.getHeldStack().stackSize;
|
||||
clickOnCraftingOutput();
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ public class CraftingManager extends ContainerManager {
|
||||
|
||||
// Move from hovered slot
|
||||
} else if (slotIndex > 0 && currentHoveredSlot != null &&
|
||||
Util.client.thePlayer.inventory.getItemStack() == null) {
|
||||
Util.getHeldStack() == null) {
|
||||
|
||||
Logger.info("acceptKey()", "Key for index " + slotIndex + " down.");
|
||||
|
||||
@@ -99,7 +99,7 @@ public class CraftingManager extends ContainerManager {
|
||||
}
|
||||
|
||||
// Handle NumKey-moving and held-moving
|
||||
} else if (Util.client.thePlayer.inventory.getItemStack() != null) {
|
||||
} else if (Util.isHoldingStack()) {
|
||||
|
||||
if (isStackKeyDown()) {
|
||||
moveAll(-1, slotIndex);
|
||||
@@ -119,7 +119,7 @@ public class CraftingManager extends ContainerManager {
|
||||
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()) ||
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
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.GuiFurnace;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class FurnaceManager extends ContainerManager {
|
||||
|
||||
private static FurnaceManager instance = null;
|
||||
|
||||
/**
|
||||
* Creates a new Furnace Manager with the given container.
|
||||
*
|
||||
* @param container The container from a crafting GUI
|
||||
*/
|
||||
private FurnaceManager(Container container) {
|
||||
super(container);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Furnace Manager Instance operating on the given container
|
||||
*
|
||||
* @param container A container from a GUI
|
||||
* @return manager-singleton
|
||||
*/
|
||||
public static FurnaceManager getInstance(Container container) {
|
||||
if (instance == null) {
|
||||
instance = new FurnaceManager(container);
|
||||
} else {
|
||||
instance.container = container;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptKey() {
|
||||
|
||||
Slot currentHoveredSlot = InputUtil.getSlotAtMousePosition((GuiFurnace) Util.client.currentScreen);
|
||||
|
||||
int slotIndex = specificKeyDownToSlotIndex();
|
||||
|
||||
if (!InputUtil.isSameKey(slotIndex)) {
|
||||
|
||||
// Drop
|
||||
if (isDropKeyDown()) {
|
||||
|
||||
Logger.info("acceptKey()", "Drop Key down.");
|
||||
|
||||
for (int i = 0; i < 3; 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;
|
||||
clickOnFurnaceOutput();
|
||||
|
||||
while (Util.isHoldingStack() &&
|
||||
oldStackSize != Util.getHeldStack().stackSize) {
|
||||
|
||||
oldStackSize = Util.getHeldStack().stackSize;
|
||||
clickOnFurnaceOutput();
|
||||
}
|
||||
|
||||
} else {
|
||||
clickOnFurnaceOutput();
|
||||
}
|
||||
|
||||
// Move from hovered slot
|
||||
} else if (slotIndex >= 0 && currentHoveredSlot != null &&
|
||||
!Util.isHoldingStack()) {
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void clickOnFurnaceOutput() {
|
||||
|
||||
// Click on furnace output
|
||||
Logger.info("clickOnCraftingOutput()", "Clicked on Crafing Output.");
|
||||
rightClick(2);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int specificKeyDownToSlotIndex() {
|
||||
|
||||
if (Keyboard.isKeyDown(Config.getKeyTopCenter()) ||
|
||||
Config.isNumPadEnabled() && Keyboard.isKeyDown(72)) {
|
||||
return 0;
|
||||
} else if (Keyboard.isKeyDown(Config.getKeyCenterCenter()) ||
|
||||
Config.isNumPadEnabled() && Keyboard.isKeyDown(76)) {
|
||||
return 1;
|
||||
} else if (Keyboard.isKeyDown(Config.getKeyInteract())) {
|
||||
return -101;
|
||||
} else if (Keyboard.isKeyDown(Config.getKeyDrop())) {
|
||||
return -102;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getInventoryStartIndex() {
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class Util {
|
||||
* Returns if the current player is helding a item stack.
|
||||
* @return True, if held stack != null
|
||||
*/
|
||||
public static boolean isHeldingStack() {
|
||||
public static boolean isHoldingStack() {
|
||||
return (getHeldStack() != null);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user