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;
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.inventory.Slot;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
@@ -13,162 +14,158 @@ import net.minecraftforge.fml.common.SidedProxy;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
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.gameevent.InputEvent;
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
* base on the open-source Inventory Tweaks. Big Thanks for that!
*
* @author skate702
* based on the open-source Inventory Tweaks. Big Thanks for that!
*
* @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 {
/**
* Current Instance of CraftingKeys.
*/
@Instance(value = "CraftingKeysID")
public static CraftingKeys instance;
/**
* Current Instance of CraftingKeys.
*/
@Instance(value = "CraftingKeys")
public static CraftingKeys instance;
/**
* Current Proxy (Common or Client)
*/
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy", serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
public static CraftingKeysProxy proxy;
/**
* Current Proxy (Common or Client)
*/
@SidedProxy(clientSide = "de.skate702.craftingkeys.proxies.CraftingKeysClientProxy",
serverSide = "de.skate702.craftingkeys.proxies.CraftingKeysProxy")
public static CraftingKeysProxy proxy;
/**
* This method will be executed before Init.
*
* @param event
* Input Event from FML
*/
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
}
/**
* This method will be executed before Init.
*
* @param event Input Event from FML
*/
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
KeyBindings.init();
/**
* This method will be executed while loading.
*
* @param event
* Input Event from FML
*/
@EventHandler
public void load(FMLInitializationEvent event) {
}
// Regeistring
proxy.registerRenderers();
FMLCommonHandler.instance().bus().register(this);
/**
* This method will be executed while loading.
*
* @param event Input Event from FML
*/
@EventHandler
public void load(FMLInitializationEvent event) {
Helper.debugPrint("load(): Loaded CraftingKeys successful");
// Registering
proxy.registerRenderers();
FMLCommonHandler.instance().bus().register(this);
}
/**
* This method will be executed after Init.
*
* @param event
* Input Event from FML
*/
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
Helper.debugPrint("load(): Loaded CraftingKeys successful");
/**
* To show a chat message at first start in minecraft.
*/
boolean firstInWorldTick = true;
}
/**
* This method will be executed every Ingame Tick.
*
* @param tick
*/
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent tick) {
@SubscribeEvent
public void onKeyInput(InputEvent.KeyInputEvent event) {
System.out.println(event.toString());
}
// Message
if (Helper.client.theWorld != null && firstInWorldTick) {
/**
* This method will be executed after Init.
*
* @param event Input Event from FML
*/
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
}
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!"));
/**
* This method will be executed every Ingame Tick.
*
* @param tick
*/
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent tick) {
firstInWorldTick = !firstInWorldTick;
}
// Message
if(Helper.isFirstInWorldTick()) {
Helper.printWarning();
}
// Case 1: Classic GUI Screen
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
GuiCrafting guiCrafting = (GuiCrafting) Helper.client.currentScreen;
Slot currentHoveredSlot = Helper.getSlotAtMousePosition(guiCrafting);
int keyDown = Helper.craftingKeyDownToSlotNumber();
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
// Case 1: Classic GUI Screen
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
// Block Key Interval (avoid multiple Runs)
if (!Helper.isSameKey(keyDown)) {
GuiCrafting guiCrafting = (GuiCrafting) Helper.client.currentScreen;
Slot currentHoveredSlot = Helper.getSlotAtMousePosition(guiCrafting);
int keyDown = Helper.craftingKeyDownToSlotNumber();
// Moving item to crafting table
if (keyDown > 0 && currentHoveredSlot != null) {
ContainerManager con = new ContainerManager(guiCrafting.inventorySlots);
// Shift = Move all
if (guiCrafting.isShiftKeyDown()) {
con.moveAll(currentHoveredSlot.slotNumber, keyDown);
} else {
con.move(currentHoveredSlot.slotNumber, keyDown, 1);
}
// Block Key Interval (avoid multiple Runs)
if (!Helper.isSameKey(keyDown)) {
}
// Moving item to crafting table
if (keyDown > 0 && currentHoveredSlot != null) {
if (keyDown == -2) {
// Shift = Move all
if (guiCrafting.isShiftKeyDown()) {
con.moveAll(currentHoveredSlot.slotNumber, keyDown);
} else {
con.move(currentHoveredSlot.slotNumber, keyDown, 1);
}
// Space = Move all back
Helper.debugPrint("onTick(): Move all items back or drop them.");
}
for (int i = 1; i < 10; i++) {
if (keyDown == -2) {
con.putStackToNextEmptySlot(i, true, false);
// Space = Move all back
Helper.debugPrint("onTick(): Move all items back or drop them.");
}
}
for (int i = 1; i < 10; i++) {
// Strg = Take the output
if (guiCrafting.isCtrlKeyDown()) {
con.putStackToNextEmptySlot(i, true, false);
if (guiCrafting.isShiftKeyDown()) {
}
}
// Strg + Shift = Move all (resp. faster!)
con.clickOnCraftingOutput(true);
// Strg = Take the output
if (guiCrafting.isCtrlKeyDown()) {
} else {
if (guiCrafting.isShiftKeyDown()) {
// Send mouse click on crafting output (accept also
// holding)
int ticksdown = Helper.getStrgTimesDown(true);
if (ticksdown == 2 || ticksdown % 15 == 0 || (ticksdown > 60 && ticksdown % 8 == 0)) {
con.clickOnCraftingOutput(true);
}
// Strg + Shift = Move all (resp. faster!)
con.clickOnCraftingOutput(true);
}
} else {
} else {
// Send mouse click on crafting output (accept also
// holding)
int ticksdown = Helper.getStrgTimesDown(true);
if (ticksdown == 2 || ticksdown % 15 == 0 || (ticksdown > 60 && ticksdown % 8 == 0)) {
con.clickOnCraftingOutput(true);
}
// Reset Strg
Helper.getStrgTimesDown(false);
}
}
}
}
} else {
// Case 2: Inventory (2x2 Crafting, Quick-Armor)
// Reset Strg
Helper.getStrgTimesDown(false);
}
// TODO: Case 2
}
}
}
// Case 2: Inventory (2x2 Crafting, Quick-Armor)
// TODO: Case 2
}
}