Started refactoring. Added KeyBindings.

This commit is contained in:
0xSeb
2015-10-20 01:06:12 +02:00
parent 5243dab2a2
commit dd2021bbed
6 changed files with 377 additions and 298 deletions
@@ -1,10 +1,11 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import org.lwjgl.input.Keyboard; import de.skate702.craftingkeys.manager.ContainerManager;
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler; import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.Mod.EventHandler;
@@ -13,74 +14,76 @@ import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent; import net.minecraftforge.fml.common.gameevent.TickEvent;
import de.skate702.craftingkeys.proxies.CraftingKeysProxy;
/** /**
* The Main Class of the Mod with the important onTick-Method. Some Methods are * The Main Class of the Mod with the important onTick-Method. Some Methods are
* base on the open-source Inventory Tweaks. Big Thanks for that! * based on the open-source Inventory Tweaks. Big Thanks for that!
* *
* @author skate702 * @author skate702
*
*/ */
@Mod(modid = "CraftingKeysID", name = "Crafting Keys", version = "1.0.0") @Mod(modid = "craftingkeys", name = "Crafting Keys", version = "1.0.0")
public class CraftingKeys { public class CraftingKeys {
/** /**
* Current Instance of CraftingKeys. * Current Instance of CraftingKeys.
*/ */
@Instance(value = "CraftingKeysID") @Instance(value = "CraftingKeys")
public static CraftingKeys instance; public static CraftingKeys instance;
/** /**
* Current Proxy (Common or Client) * Current Proxy (Common or Client)
*/ */
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy", serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy") @SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy",
serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
public static CraftingKeysProxy proxy; public static CraftingKeysProxy proxy;
/** /**
* This method will be executed before Init. * This method will be executed before Init.
* *
* @param event * @param event Input Event from FML
* Input Event from FML
*/ */
@EventHandler @EventHandler
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
KeyBindings.init();
} }
/** /**
* This method will be executed while loading. * This method will be executed while loading.
* *
* @param event * @param event Input Event from FML
* Input Event from FML
*/ */
@EventHandler @EventHandler
public void load(FMLInitializationEvent event) { public void load(FMLInitializationEvent event) {
// Regeistring // Registering
proxy.registerRenderers(); proxy.registerRenderers();
FMLCommonHandler.instance().bus().register(this); FMLCommonHandler.instance().bus().register(this);
Helper.debugPrint("load(): Loaded CraftingKeys successful"); Helper.debugPrint("load(): Loaded CraftingKeys successful");
} }
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
System.out.println(event.toString());
}
/** /**
* This method will be executed after Init. * This method will be executed after Init.
* *
* @param event * @param event Input Event from FML
* Input Event from FML
*/ */
@EventHandler @EventHandler
public void postInit(FMLPostInitializationEvent event) { 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. * This method will be executed every Ingame Tick.
* *
@@ -90,18 +93,12 @@ public class CraftingKeys {
public void onTick(TickEvent.ClientTickEvent tick) { public void onTick(TickEvent.ClientTickEvent tick) {
// Message // Message
if (Helper.client.theWorld != null && firstInWorldTick) { if(Helper.isFirstInWorldTick()) {
Helper.printWarning();
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 // Case 1: Classic GUI Screen
if (Helper.isCraftingGUI(Helper.client.currentScreen)) { if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
@@ -1,24 +1,45 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.fml.client.FMLClientHandler;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
/** /**
* This helper class provides some static helping Methods and Constants. * This helper class provides some static helping Methods and Constants.
* *
* @author sebastian * @author sebastian
*
*/ */
public class Helper { public class Helper {
/**
* If true, there are Debug-Output-Prints from debugPrint(msg).
*/
public static final boolean DEBUG = true;
/**
* Current Instance Client, used for a lot of operations.
*/
public static Minecraft client = FMLClientHandler.instance().getClient();
/**
* Saves the last Key that was Pressed
*/
private static int lastKeyDown = -1;
/**
* Saves the times strg was pressed before reseting
*/
private static int strgTimesDown = 0;
private static boolean firstInWorldTick = true;
/** /**
* Private Constructor. This is a helping class! * Private Constructor. This is a helping class!
*/ */
@@ -27,20 +48,34 @@ public class Helper {
} }
/** /**
* If true, there are Debug-Output-Prints from debugPrint(msg). * Returns, if this is the first method call in a fresh opened world.
*
* @return True, if this is the first tick
*/ */
public static final boolean DEBUG = true; public static boolean isFirstInWorldTick() {
if (firstInWorldTick && client.theWorld != null) {
firstInWorldTick = false;
return true;
} else if (client.theWorld == null) {
firstInWorldTick = true;
}
return false;
}
/** public static void printWarning() {
* Current Instance Client, used for a lot of operations. client.thePlayer.addChatMessage(new ChatComponentText(
*/ "Achtung: Crafting-Keys befindet sich in der Alpha!"));
public static Minecraft client = FMLClientHandler.instance().getClient(); client.thePlayer.addChatMessage(new ChatComponentText(
"Es gibt noch viele Fehler, und es fehlen noch einige Funktionen."));
client.thePlayer.addChatMessage(new ChatComponentText(
"Mehr Info's findest du auf: https://github.com/0xSeb/CraftingKeys!"));
client.thePlayer.addChatMessage(new ChatComponentTranslation("key.topleft"));
}
/** /**
* Standart Output for Debug-Messages - Depends on DEBUG-Constant. * Standart Output for Debug-Messages - Depends on DEBUG-Constant.
* *
* @param message * @param message The Debug-Message. Syntax: "methodname(): Message"
* The Debug-Message. Syntax: "methodname(): Message"
*/ */
public static void debugPrint(String message) { public static void debugPrint(String message) {
@@ -53,8 +88,7 @@ public class Helper {
/** /**
* Returns true, if the current Screen is a instance of GUI-Screen. * Returns true, if the current Screen is a instance of GUI-Screen.
* *
* @param screen * @param screen The input Screen
* The input Screen
* @return True, if GuiScreen; False if null * @return True, if GuiScreen; False if null
*/ */
public static boolean isCraftingGUI(GuiScreen screen) { public static boolean isCraftingGUI(GuiScreen screen) {
@@ -70,8 +104,7 @@ public class Helper {
/** /**
* Returns the Slot at the current Mouse Position. [FROM GUICONTAINER] * Returns the Slot at the current Mouse Position. [FROM GUICONTAINER]
* *
* @param guiContainer * @param guiContainer The (Inventory) Container to work with.
* The (Inventory) Container to work with.
* @return Returns the slot (or null) * @return Returns the slot (or null)
*/ */
public static Slot getSlotAtMousePosition(GuiContainer guiContainer) { public static Slot getSlotAtMousePosition(GuiContainer guiContainer) {
@@ -96,14 +129,10 @@ public class Helper {
/** /**
* Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER] * Returns, if the mouse cursor is over a specified slot [FROM GUICONTAINER]
* *
* @param guiContainer * @param guiContainer the GuiContainer to work with
* the GuiContainer to work with * @param slot The spcified slot
* @param slot * @param x The Mouse x-Position
* The spcified slot * @param y The Mouse y-Position
* @param x
* The Mouse x-Position
* @param y
* The Mouse y-Position
* @return True, if the mouse is positioned over this slot. Otherwise false * @return True, if the mouse is positioned over this slot. Otherwise false
*/ */
private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) { private static boolean getIsMouseOverSlot(GuiContainer guiContainer, Slot slot, int x, int y) {
@@ -122,8 +151,7 @@ public class Helper {
/** /**
* Returns a calculated Mouse Position for getSlotAtMousePosition(). * Returns a calculated Mouse Position for getSlotAtMousePosition().
* *
* @param guiContainer * @param guiContainer the GuiContainer to work with
* the GuiContainer to work with
* @return The relative Mouse-Position * @return The relative Mouse-Position
*/ */
private static int getMouseX(GuiContainer guiContainer) { private static int getMouseX(GuiContainer guiContainer) {
@@ -133,8 +161,7 @@ public class Helper {
/** /**
* Returns a calculated Mouse Position for getSlotAtMousePosition(). * Returns a calculated Mouse Position for getSlotAtMousePosition().
* *
* @param guiContainer * @param guiContainer the GuiContainer to work with
* the GuiContainer to work with
* @return The relative Mouse-Position * @return The relative Mouse-Position
*/ */
private static int getMouseY(GuiContainer guiContainer) { private static int getMouseY(GuiContainer guiContainer) {
@@ -178,16 +205,10 @@ public class Helper {
return returnValue; return returnValue;
} }
/**
* Saves the last Key that was Pressed
*/
private static int lastKeyDown = -1;
/** /**
* Returns, if the current KeyValue is the same * Returns, if the current KeyValue is the same
* *
* @param currentKey * @param currentKey the new input value, saved in the method
* the new input value, saved in the method
* @return True, if these are the same keys * @return True, if these are the same keys
*/ */
public static boolean isSameKey(int currentKey) { public static boolean isSameKey(int currentKey) {
@@ -203,16 +224,10 @@ public class Helper {
} }
/**
* Saves the times strg was pressed before reseting
*/
private static int strgTimesDown = 0;
/** /**
* Return the times Strg was pressed before reseting * Return the times Strg was pressed before reseting
* *
* @param strgDown * @param strgDown false, if reset
* false, if reset
* @return A number of tick strg was down before * @return A number of tick strg was down before
*/ */
public static int getStrgTimesDown(boolean strgDown) { public static int getStrgTimesDown(boolean strgDown) {
@@ -0,0 +1,45 @@
package de.skate702.craftingkeys;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import org.lwjgl.input.Keyboard;
/**
* Provides all Key Bindings and methods to register and check them.
*/
public class KeyBindings {
// WARNING: This does NOT work! Has to been removed. Own Option Dialog OR Settings file. Bindings are exclusive. Shit!
private static final String category = "key.categories.craftingkeys";
private static KeyBinding[] bindings = { // Inspired by CSS Position Properties
new KeyBinding("key.topleft", Keyboard.KEY_Q, category),
new KeyBinding("key.topcenter", Keyboard.KEY_W, category),
new KeyBinding("key.topright", Keyboard.KEY_E, category),
new KeyBinding("key.centerleft", Keyboard.KEY_A, category),
new KeyBinding("key.centercenter", Keyboard.KEY_S, category),
new KeyBinding("key.centerright", Keyboard.KEY_D, category),
new KeyBinding("key.lowerleft", Keyboard.KEY_Y, category), // GERMAN Keyboard layout
new KeyBinding("key.lowercenter", Keyboard.KEY_X, category),
new KeyBinding("key.lowerright", Keyboard.KEY_C, category),
new KeyBinding("key.stack", Keyboard.KEY_LSHIFT, category),
new KeyBinding("key.interact", Keyboard.KEY_LCONTROL, category),
};
/**
* Initializes all key bindings and registers them to the client-side.
*/
public static void init() {
for (KeyBinding binding : bindings) {
ClientRegistry.registerKeyBinding(binding);
}
ClientRegistry.registerKeyBinding(Minecraft.getMinecraft().gameSettings.keyBindRight);
//Minecraft.getMinecraft().gameSettings.keybind
}
}
@@ -1,9 +1,14 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.CraftingKeys;
import de.skate702.craftingkeys.Helper;
import net.minecraft.client.gui.inventory.GuiCrafting; import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraft.item.Item;
import net.minecraft.block.Block;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent; import net.minecraft.util.IChatComponent;
@@ -215,6 +220,9 @@ public class ContainerManager {
} }
} }
GameRegistry.addShapelessRecipe(new ItemStack(Item.getByNameOrId("Diamond")),
new ItemStack(Block.getBlockFromName("Dirt")));
for (int i = 10; i < container.inventorySlots.size(); i++) { for (int i = 10; i < container.inventorySlots.size(); i++) {
if (getItemStack(i) == null) { if (getItemStack(i) == null) {
@@ -0,0 +1,14 @@
?# Control Names
key.topleft=1. Top Left
key.topcenter=2. Top Center
key.topright=3. Top Right
key.centerleft=4. Center Left
key.centercenter=5. Center Center
key.centerright=6. Center Right
key.lowerleft=7. Lower Left
key.lowercenter=8. Lower Center
key.lowerright=9. Lower Right
key.stack=Stack Key
key.interact=Interaction Key
# Control Category Name
key.categories.craftingkeys=Crafting Keys (Mostly red Keys are NO problem!)
+1 -1
View File
@@ -1,6 +1,6 @@
[ [
{ {
"modid": "CraftingKeysID", "modid": "craftingkeys",
"name": "Crafting Keys", "name": "Crafting Keys",
"description": "TODO", "description": "TODO",
"version": "${version}", "version": "${version}",