Fixed crafting bug. Added Logger output.
This commit is contained in:
@@ -6,7 +6,7 @@ Crafting Keys is a modification which adds a lot of new key bindings to minecraf
|
|||||||
##Development Progress
|
##Development Progress
|
||||||
|
|
||||||
The whole project had been refactored and is now almost ready to be release. But there are missing a few things:
|
The whole project had been refactored and is now almost ready to be release. But there are missing a few things:
|
||||||
- Better Log Output
|
- Refactor managers
|
||||||
- Implementing all vanilla guis
|
- Implementing all vanilla guis
|
||||||
- Better, all new GUI
|
- Better, all new GUI
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ public class CraftingKeys {
|
|||||||
*/
|
*/
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
|
Logger.info("preInit(e)", "Loading Config now.");
|
||||||
Config.loadConfig(event);
|
Config.loadConfig(event);
|
||||||
|
Logger.info("preInit(e)", "Finished loading Config.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,6 +71,7 @@ public class CraftingKeys {
|
|||||||
// Registering
|
// Registering
|
||||||
proxy.registerRenderers();
|
proxy.registerRenderers();
|
||||||
FMLCommonHandler.instance().bus().register(this);
|
FMLCommonHandler.instance().bus().register(this);
|
||||||
|
Logger.info("load(e)", "Registered Mod.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +86,10 @@ public class CraftingKeys {
|
|||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
|
public void onConfigChanged(ConfigChangedEvent.OnConfigChangedEvent eventArgs) {
|
||||||
if (eventArgs.modID.equals(MODID))
|
if (eventArgs.modID.equals(MODID)) {
|
||||||
Config.syncConfig();
|
Config.syncConfig();
|
||||||
|
Logger.info("onConfigChanged(e)", "Changed config.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,11 +100,6 @@ public class CraftingKeys {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onTick(TickEvent.ClientTickEvent tick) {
|
public void onTick(TickEvent.ClientTickEvent tick) {
|
||||||
|
|
||||||
// Message
|
|
||||||
if (Util.isFirstInWorldTick()) {
|
|
||||||
Util.printWarning();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get current Screen, then test
|
// Get current Screen, then test
|
||||||
GuiScreen currentScreen = Util.client.currentScreen;
|
GuiScreen currentScreen = Util.client.currentScreen;
|
||||||
|
|
||||||
@@ -129,8 +129,6 @@ public class CraftingKeys {
|
|||||||
Logger.warn("onTick()", "BrewingStand not implemented");
|
Logger.warn("onTick()", "BrewingStand not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: What else should we support?
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.skate702.craftingkeys.config;
|
|||||||
|
|
||||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||||
import de.skate702.craftingkeys.CraftingKeys;
|
import de.skate702.craftingkeys.CraftingKeys;
|
||||||
|
import de.skate702.craftingkeys.util.Logger;
|
||||||
import net.minecraftforge.common.config.Configuration;
|
import net.minecraftforge.common.config.Configuration;
|
||||||
import net.minecraftforge.common.config.Property;
|
import net.minecraftforge.common.config.Property;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
@@ -120,11 +121,11 @@ public class Config {
|
|||||||
public static void syncConfig() {
|
public static void syncConfig() {
|
||||||
|
|
||||||
if (configFile == null) {
|
if (configFile == null) {
|
||||||
// TODO: Throw Error!
|
Logger.error("syncConfig()", "Unable to read config file!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
syncProperties(); // TODO: Why here?
|
syncProperties();
|
||||||
|
|
||||||
if (configFile.hasChanged())
|
if (configFile.hasChanged())
|
||||||
configFile.save();
|
configFile.save();
|
||||||
|
|||||||
@@ -34,33 +34,38 @@ public abstract class ContainerManager {
|
|||||||
|
|
||||||
// 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;
|
||||||
|
int inputdelta;
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
|
||||||
leftClick(hotbarStartIndex + 1);
|
inputdelta = 1;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
|
||||||
leftClick(hotbarStartIndex + 2);
|
inputdelta = 2;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
|
||||||
leftClick(hotbarStartIndex + 3);
|
inputdelta = 3;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
|
||||||
leftClick(hotbarStartIndex + 4);
|
inputdelta = 4;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_5)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_5)) {
|
||||||
leftClick(hotbarStartIndex + 5);
|
inputdelta = 5;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_6)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_6)) {
|
||||||
leftClick(hotbarStartIndex + 6);
|
inputdelta = 6;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_7)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_7)) {
|
||||||
leftClick(hotbarStartIndex + 7);
|
inputdelta = 7;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_8)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_8)) {
|
||||||
leftClick(hotbarStartIndex + 8);
|
inputdelta = 8;
|
||||||
} else if (Keyboard.isKeyDown(Keyboard.KEY_9)) {
|
} else if (Keyboard.isKeyDown(Keyboard.KEY_9)) {
|
||||||
leftClick(hotbarStartIndex + 9);
|
inputdelta = 9;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
leftClick(hotbarStartIndex + inputdelta);
|
||||||
|
Logger.info("handleNumKey()", "Moved to hotbar slot " + inputdelta + ".");
|
||||||
|
|
||||||
moveStackToInventory(-1);
|
moveStackToInventory(-1);
|
||||||
|
|
||||||
// Handle Minecraft handling. Ah...
|
// Handle Minecraft handling. Ah...
|
||||||
while (Keyboard.next()) {
|
while (Keyboard.next()) {
|
||||||
|
Logger.info("handleNumKey()", "The cake is a lie!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -171,7 +176,7 @@ public abstract class ContainerManager {
|
|||||||
* @param index The index of the slot in the container
|
* @param index The index of the slot in the container
|
||||||
* @return Returns the ItemStack
|
* @return Returns the ItemStack
|
||||||
*/
|
*/
|
||||||
private ItemStack getItemStack(int index) {
|
protected ItemStack getItemStack(int index) {
|
||||||
|
|
||||||
if (index >= 0 && index < container.inventorySlots.size()) {
|
if (index >= 0 && index < container.inventorySlots.size()) {
|
||||||
|
|
||||||
@@ -229,9 +234,11 @@ public abstract class ContainerManager {
|
|||||||
|
|
||||||
// Move the item
|
// Move the item
|
||||||
if (destIndex == -1) { // -1 means: Found none, drop item
|
if (destIndex == -1) { // -1 means: Found none, drop item
|
||||||
leftClick(-999); // Nice one, InvTweaks!
|
leftClick(-999);
|
||||||
|
Logger.info("moveStackToInventory(i)", "Dropped item from index " + sourceIndex + ".");
|
||||||
} else {
|
} else {
|
||||||
leftClick(destIndex);
|
leftClick(destIndex);
|
||||||
|
Logger.info("moveStackToInventory(i)", "Moved item from index " + sourceIndex + " to " + destIndex + ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ public class CraftingManager extends ContainerManager {
|
|||||||
// Drop
|
// Drop
|
||||||
if (isDropKeyDown()) {
|
if (isDropKeyDown()) {
|
||||||
|
|
||||||
|
Logger.info("acceptKey()", "Drop Key down.");
|
||||||
|
|
||||||
for (int i = 1; i < 10; i++) {
|
for (int i = 1; i < 10; i++) {
|
||||||
moveStackToInventory(i);
|
moveStackToInventory(i);
|
||||||
}
|
}
|
||||||
@@ -57,7 +59,13 @@ public class CraftingManager extends ContainerManager {
|
|||||||
// Get from output
|
// Get from output
|
||||||
} else if (isInteractionKeyDown()) {
|
} else if (isInteractionKeyDown()) {
|
||||||
|
|
||||||
if (Util.client.thePlayer.inventory.getItemStack() != null) {
|
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
|
||||||
|
>= getItemStack(0).getMaxStackSize())) {
|
||||||
moveStackToInventory(-1);
|
moveStackToInventory(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +89,8 @@ public class CraftingManager extends ContainerManager {
|
|||||||
} else if (slotIndex > 0 && currentHoveredSlot != null &&
|
} else if (slotIndex > 0 && currentHoveredSlot != null &&
|
||||||
Util.client.thePlayer.inventory.getItemStack() == null) {
|
Util.client.thePlayer.inventory.getItemStack() == null) {
|
||||||
|
|
||||||
|
Logger.info("acceptKey()", "Key for index " + slotIndex + " down.");
|
||||||
|
|
||||||
if (isStackKeyDown()) {
|
if (isStackKeyDown()) {
|
||||||
moveAll(currentHoveredSlot.slotNumber, slotIndex);
|
moveAll(currentHoveredSlot.slotNumber, slotIndex);
|
||||||
moveStackToInventory(-1);
|
moveStackToInventory(-1);
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class Logger {
|
|||||||
|
|
||||||
private static void print(String method, String message, LevelOfDetail in) {
|
private static void print(String method, String message, LevelOfDetail in) {
|
||||||
System.out.println(StdOutput + in.toString() + "] " + method + ": " + message);
|
System.out.println(StdOutput + in.toString() + "] " + method + ": " + message);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prints a INFO-Message if allowed.
|
* Prints a INFO-Message if allowed.
|
||||||
@@ -28,8 +28,6 @@ public class Logger {
|
|||||||
* @param method The calling method / method info
|
* @param method The calling method / method info
|
||||||
* @param message The message to print
|
* @param message The message to print
|
||||||
*/
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
public static void info(String method, String message) {
|
public static void info(String method, String message) {
|
||||||
if (MODE.getLevel() <= 0) {
|
if (MODE.getLevel() <= 0) {
|
||||||
print(method, message, LevelOfDetail.INFO);
|
print(method, message, LevelOfDetail.INFO);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.skate702.craftingkeys.util;
|
|||||||
|
|
||||||
import cpw.mods.fml.client.FMLClientHandler;
|
import cpw.mods.fml.client.FMLClientHandler;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ChatComponentTranslation;
|
import net.minecraft.util.ChatComponentTranslation;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,6 +25,22 @@ public class Util {
|
|||||||
private Util() {
|
private Util() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current held item stack.
|
||||||
|
* @return A item stack
|
||||||
|
*/
|
||||||
|
public static ItemStack getHeldStack() {
|
||||||
|
return client.thePlayer.inventory.getItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if the current player is helding a item stack.
|
||||||
|
* @return True, if held stack != null
|
||||||
|
*/
|
||||||
|
public static boolean isHeldingStack() {
|
||||||
|
return (getHeldStack() != null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns, if this is the first method call in a fresh opened world.
|
* Returns, if this is the first method call in a fresh opened world.
|
||||||
*
|
*
|
||||||
@@ -48,13 +65,4 @@ public class Util {
|
|||||||
client.thePlayer.addChatMessage(new ChatComponentTranslation(lang_key));
|
client.thePlayer.addChatMessage(new ChatComponentTranslation(lang_key));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Prints a warning, that this mod is still in alpha-state.
|
|
||||||
*/
|
|
||||||
public static void printWarning() {
|
|
||||||
printMessage("de.skate702.craftingkeys.warn.line1");
|
|
||||||
printMessage("de.skate702.craftingkeys.warn.line2");
|
|
||||||
printMessage("de.skate702.craftingkeys.warn.line3");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user