Added moving back from crafting table feature, some fixes, chat message,
dropping. Nice things!
This commit is contained in:
@@ -4,6 +4,8 @@ import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
|
||||
/**
|
||||
* Managing Class to move Items in Inventory Containers.
|
||||
@@ -58,9 +60,6 @@ public class ContainerManager {
|
||||
*/
|
||||
public void move(int srcIndex, int destIndex, int amount) {
|
||||
|
||||
// TODO: What if not same type? Fallback Solution (Stack out of the way)
|
||||
// or swap // if (Helper.client.thePlayer.inventory.getItemStack() !=
|
||||
|
||||
// Stacks
|
||||
ItemStack source = getItemStack(srcIndex);
|
||||
ItemStack destination = getItemStack(destIndex);
|
||||
@@ -127,7 +126,7 @@ public class ContainerManager {
|
||||
*/
|
||||
public void clickOnCraftingOutput(boolean isCraftingGUI) {
|
||||
|
||||
// TODO: Put current Item away
|
||||
putItemAway(isCraftingGUI);
|
||||
|
||||
if (isCraftingGUI) {
|
||||
|
||||
@@ -135,6 +134,8 @@ public class ContainerManager {
|
||||
Helper.debugPrint("clickOnCraftingOutput(): Clicked on Crafing Output.");
|
||||
leftClick(0);
|
||||
|
||||
} else {
|
||||
// TODO: Same for inventory
|
||||
}
|
||||
|
||||
}
|
||||
@@ -143,13 +144,89 @@ public class ContainerManager {
|
||||
* Takes all items from a slot and moves them to the next empty slot or
|
||||
* drops them.
|
||||
*
|
||||
* @param index
|
||||
* @param sourceIndex
|
||||
* The index of the slot to move items from
|
||||
* @param isCraftingGUI
|
||||
* true, if the craftingGUI is opened
|
||||
*/
|
||||
private void putStackToNextEmptySlot(int index) {
|
||||
public void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) {
|
||||
|
||||
// TODO: Method (maybe from INVTW...?)
|
||||
// Check for Item-Type
|
||||
ItemStack stackToMove;
|
||||
if (isHeld) {
|
||||
stackToMove = Helper.client.thePlayer.inventory.getItemStack();
|
||||
} else {
|
||||
putItemAway(isCraftingGUI);
|
||||
stackToMove = getItemStack(sourceIndex);
|
||||
}
|
||||
|
||||
// Test for empty crafting table slot
|
||||
if (!isHeld && getItemStack(sourceIndex) == null) {
|
||||
|
||||
Helper.debugPrint("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + ".");
|
||||
return;
|
||||
}
|
||||
|
||||
// Get Destination Index
|
||||
int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove);
|
||||
|
||||
// Additional click on source index, if not held
|
||||
if (!isHeld) {
|
||||
leftClick(sourceIndex);
|
||||
}
|
||||
|
||||
// TODO: Optional (beta-like): Fill the items up. Let's become INVTW!
|
||||
|
||||
// destIndex = -1 -> drop item
|
||||
if (destIndex == -1) {
|
||||
leftClick(-999); // Nice one, InvTweaks!
|
||||
} else {
|
||||
leftClick(destIndex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void putItemAway(boolean isCraftingGUI) {
|
||||
// Put current Item away
|
||||
if (Helper.client.thePlayer.inventory.getItemStack() != null) {
|
||||
putStackToNextEmptySlot(-1, isCraftingGUI, true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the first free index in a inventory
|
||||
*
|
||||
* @param isCraftingGUI
|
||||
* true, if the craftingGUI is opened
|
||||
* @return a slot index
|
||||
*/
|
||||
private int getFirstPropperSlotIndex(boolean isCraftingGUI, ItemStack movingItem) {
|
||||
|
||||
if (isCraftingGUI) {
|
||||
|
||||
for (int i = 10; i < container.inventorySlots.size(); i++) {
|
||||
|
||||
if (getItemStack(i) != null) {
|
||||
if (getItemStack(i).isItemEqual(movingItem)) {
|
||||
if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 10; i < container.inventorySlots.size(); i++) {
|
||||
|
||||
if (getItemStack(i) == null) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
Helper.debugPrint("getFirstProperSlotIndex(): No Propper / Empty Slot found!");
|
||||
return -1;
|
||||
} else {
|
||||
// TODO: Same for inventory
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,6 +4,7 @@ import org.lwjgl.input.Keyboard;
|
||||
|
||||
import net.minecraft.client.gui.inventory.GuiCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.util.ChatComponentText;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
@@ -75,6 +76,11 @@ public class CraftingKeys {
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
}
|
||||
|
||||
/**
|
||||
* To show a chat message at first start in minecraft.
|
||||
*/
|
||||
boolean firstInWorldTick = true;
|
||||
|
||||
/**
|
||||
* This method will be executed every Ingame Tick.
|
||||
*
|
||||
@@ -83,6 +89,19 @@ public class CraftingKeys {
|
||||
@SubscribeEvent
|
||||
public void onTick(TickEvent.ClientTickEvent tick) {
|
||||
|
||||
// Message
|
||||
if (Helper.client.theWorld != null && firstInWorldTick) {
|
||||
|
||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
||||
"Achtung: Crafting-Keys befindet sich in der Pre-Alpha!"));
|
||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
||||
"Es gibt noch viele Fehler, und es fehlen noch einige Funktionen."));
|
||||
Helper.client.thePlayer.addChatMessage(new ChatComponentText(
|
||||
"Mehr Info's findest du auf: http://craftingkeys.codeplex.com!"));
|
||||
|
||||
firstInWorldTick = !firstInWorldTick;
|
||||
}
|
||||
|
||||
// Case 1: Classic GUI Screen
|
||||
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
|
||||
|
||||
@@ -90,11 +109,11 @@ public class CraftingKeys {
|
||||
Slot currentHoveredSlot = Helper.getSlotAtMousePosition(guiCrafting);
|
||||
int keyDown = Helper.craftingKeyDownToSlotNumber();
|
||||
|
||||
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
|
||||
|
||||
// Block Key Interval (avoid multiple Runs)
|
||||
if (!Helper.isSameKey(keyDown)) {
|
||||
|
||||
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
|
||||
|
||||
// Moving item to crafting table
|
||||
if (keyDown > 0 && currentHoveredSlot != null) {
|
||||
|
||||
@@ -109,9 +128,14 @@ public class CraftingKeys {
|
||||
|
||||
if (keyDown == -2) {
|
||||
|
||||
// TODO: Space = Move all back
|
||||
Helper.debugPrint("onTick(): [TODO] Move all items back or drop them.");
|
||||
// Space = Move all back
|
||||
Helper.debugPrint("onTick(): Move all items back or drop them.");
|
||||
|
||||
for (int i = 1; i < 10; i++) {
|
||||
|
||||
con.putStackToNextEmptySlot(i, true, false);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Strg = Take the output
|
||||
@@ -119,7 +143,7 @@ public class CraftingKeys {
|
||||
|
||||
if (guiCrafting.isShiftKeyDown()) {
|
||||
|
||||
//Strg + Shift = Move all (resp. faster!)
|
||||
// Strg + Shift = Move all (resp. faster!)
|
||||
con.clickOnCraftingOutput(true);
|
||||
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user