Reformat code, updated imports. We are back in 1.7.10 now!

This commit is contained in:
0xSeb
2015-10-21 19:41:44 +02:00
parent 96ef7ed7a6
commit c059b4c03e
10 changed files with 238 additions and 280 deletions
@@ -1,24 +1,20 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import de.skate702.craftingkeys.manager.ContainerManager; import de.skate702.craftingkeys.manager.ContainerManager;
import de.skate702.craftingkeys.proxies.CraftingKeysProxy; 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.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.Mod.Instance;
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;
/** /**
* 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
@@ -93,12 +89,11 @@ public class CraftingKeys {
public void onTick(TickEvent.ClientTickEvent tick) { public void onTick(TickEvent.ClientTickEvent tick) {
// Message // Message
if(Helper.isFirstInWorldTick()) { if (Helper.isFirstInWorldTick()) {
Helper.printWarning(); Helper.printWarning();
} }
// Case 1: Classic GUI Screen // Case 1: Classic GUI Screen
if (Helper.isCraftingGUI(Helper.client.currentScreen)) { if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
@@ -1,5 +1,6 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import cpw.mods.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;
@@ -8,7 +9,6 @@ import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.ChatComponentTranslation;
import net.minecraftforge.fml.client.FMLClientHandler;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
@@ -1,9 +1,8 @@
package de.skate702.craftingkeys; package de.skate702.craftingkeys;
import cpw.mods.fml.client.registry.ClientRegistry;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding; import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
/** /**
@@ -1,5 +0,0 @@
package de.skate702.craftingkeys;
public class Settings {
}
@@ -2,278 +2,254 @@ package de.skate702.craftingkeys.manager;
import de.skate702.craftingkeys.CraftingKeys; import de.skate702.craftingkeys.CraftingKeys;
import de.skate702.craftingkeys.Helper; import de.skate702.craftingkeys.Helper;
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.IChatComponent;
/** /**
* Managing Class to move Items in Inventory Containers. * Managing Class to move Items in Inventory Containers.
* *
* @author skate702 * @author skate702
*
*/ */
public class ContainerManager { public class ContainerManager {
/** /**
* The Container to work with. * The Container to work with.
*/ */
private Container container; private Container container;
public ContainerManager(Container container) { public ContainerManager(Container container) {
this.container = container; this.container = container;
} }
/** /**
* Moves a full Stack from a slot to another. * Moves a full Stack from a slot to another.
* *
* @param srcIndex * @param srcIndex The Source Slot Index of the Container
* The Source Slot Index of the Container * @param destIndex The Destination Slot Index of the Container
* @param destIndex */
* The Destination Slot Index of the Container public void moveAll(int srcIndex, int destIndex) {
*/
public void moveAll(int srcIndex, int destIndex) {
ItemStack source = getItemStack(srcIndex); ItemStack source = getItemStack(srcIndex);
if (source == null) { if (source == null) {
Helper.debugPrint("moveAll(): source == null"); Helper.debugPrint("moveAll(): source == null");
} else { } else {
Helper.debugPrint("moveAll(): Redirected to move()"); Helper.debugPrint("moveAll(): Redirected to move()");
move(srcIndex, destIndex, source.stackSize); move(srcIndex, destIndex, source.stackSize);
} }
} }
/** /**
* Moves a specified amount of Items from a slot to another. [Based on * Moves a specified amount of Items from a slot to another. [Based on
* INVTW] * INVTW]
* *
* @param srcIndex * @param srcIndex The Source Slot Index of the Container
* The Source Slot Index of the Container * @param destIndex The Destination Slot Index of the Container
* @param destIndex * @param amount The amount of items to move (can be bigger then Stack Size)
* The Destination Slot Index of the Container */
* @param amount public void move(int srcIndex, int destIndex, int amount) {
* The amount of items to move (can be bigger then Stack Size)
*/
public void move(int srcIndex, int destIndex, int amount) {
// Stacks // Stacks
ItemStack source = getItemStack(srcIndex); ItemStack source = getItemStack(srcIndex);
ItemStack destination = getItemStack(destIndex); ItemStack destination = getItemStack(destIndex);
// Same Location? // Same Location?
if (source == null || srcIndex == destIndex) { if (source == null || srcIndex == destIndex) {
Helper.debugPrint("Move(): srcIndex == destIndex OR source == null"); Helper.debugPrint("Move(): srcIndex == destIndex OR source == null");
return; return;
} }
// Test for max. moving Amount // Test for max. moving Amount
int sourceSize = source.stackSize; int sourceSize = source.stackSize;
int movedAmount = Math.min(amount, sourceSize); int movedAmount = Math.min(amount, sourceSize);
// Move some // Move some
if (destination == null || source.isItemEqual(destination)) { if (destination == null || source.isItemEqual(destination)) {
leftClick(srcIndex); leftClick(srcIndex);
for (int i = 0; i < movedAmount; i++) { for (int i = 0; i < movedAmount; i++) {
rightClick(destIndex); rightClick(destIndex);
} }
// Move back // Move back
if (movedAmount < sourceSize) { if (movedAmount < sourceSize) {
leftClick(srcIndex); leftClick(srcIndex);
} }
Helper.debugPrint("move(): Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!"); Helper.debugPrint("move(): Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!");
} else { } else {
Helper.debugPrint("Move(): Not the same block type!"); Helper.debugPrint("Move(): Not the same block type!");
} }
} }
/** /**
* Returns the ItemStack in a slot [Based on INVTW] * Returns the ItemStack in a slot [Based on INVTW]
* *
* @param index * @param index The index of the slot in the container
* The index of the slot in the container * @return Returns the ItemStack
* @return Returns the ItemStack */
*/ private ItemStack getItemStack(int index) {
private ItemStack getItemStack(int index) {
if (index >= 0 && index < container.inventorySlots.size()) { if (index >= 0 && index < container.inventorySlots.size()) {
Slot slot = (Slot) (container.inventorySlots.get(index)); Slot slot = (Slot) (container.inventorySlots.get(index));
return (slot == null) ? null : slot.getStack(); return (slot == null) ? null : slot.getStack();
} else { } else {
Helper.debugPrint("getItemStack(): Invalid index"); Helper.debugPrint("getItemStack(): Invalid index");
return null; return null;
} }
} }
/** /**
* Sends a click on the crafting output (craftingGUI or Inventory) * Sends a click on the crafting output (craftingGUI or Inventory)
* *
* @param isCraftingGUI * @param isCraftingGUI true, if the craftingGUI is opened
* true, if the craftingGUI is opened */
*/ public void clickOnCraftingOutput(boolean isCraftingGUI) {
public void clickOnCraftingOutput(boolean isCraftingGUI) {
putItemAway(isCraftingGUI); putItemAway(isCraftingGUI);
if (isCraftingGUI) { if (isCraftingGUI) {
// Click on crafting output // Click on crafting output
Helper.debugPrint("clickOnCraftingOutput(): Clicked on Crafing Output."); Helper.debugPrint("clickOnCraftingOutput(): Clicked on Crafing Output.");
leftClick(0); leftClick(0);
} else { } else {
// TODO: Same for inventory // TODO: Same for inventory
} }
} }
/** /**
* Takes all items from a slot and moves them to the next empty slot or * Takes all items from a slot and moves them to the next empty slot or
* drops them. * drops them.
* *
* @param sourceIndex * @param sourceIndex The index of the slot to move items from
* The index of the slot to move items from * @param isCraftingGUI true, if the craftingGUI is opened
* @param isCraftingGUI */
* true, if the craftingGUI is opened public void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) {
*/
public void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) {
// Check for Item-Type // Check for Item-Type
ItemStack stackToMove; ItemStack stackToMove;
if (isHeld) { if (isHeld) {
stackToMove = Helper.client.thePlayer.inventory.getItemStack(); stackToMove = Helper.client.thePlayer.inventory.getItemStack();
} else { } else {
putItemAway(isCraftingGUI); putItemAway(isCraftingGUI);
stackToMove = getItemStack(sourceIndex); stackToMove = getItemStack(sourceIndex);
} }
// Test for empty crafting table slot // Test for empty crafting table slot
if (!isHeld && getItemStack(sourceIndex) == null) { if (!isHeld && getItemStack(sourceIndex) == null) {
Helper.debugPrint("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + "."); Helper.debugPrint("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + ".");
return; return;
} }
// Get Destination Index // Get Destination Index
int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove); int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove);
// Additional click on source index, if not held // Additional click on source index, if not held
if (!isHeld) { if (!isHeld) {
leftClick(sourceIndex); leftClick(sourceIndex);
} }
// TODO: Optional (beta-like): Fill the items up. Let's become INVTW! // TODO: Optional (beta-like): Fill the items up. Let's become INVTW!
// destIndex = -1 -> drop item // destIndex = -1 -> drop item
if (destIndex == -1) { if (destIndex == -1) {
leftClick(-999); // Nice one, InvTweaks! leftClick(-999); // Nice one, InvTweaks!
} else { } else {
leftClick(destIndex); leftClick(destIndex);
} }
} }
private void putItemAway(boolean isCraftingGUI) { private void putItemAway(boolean isCraftingGUI) {
// Put current Item away // Put current Item away
if (Helper.client.thePlayer.inventory.getItemStack() != null) { if (Helper.client.thePlayer.inventory.getItemStack() != null) {
putStackToNextEmptySlot(-1, isCraftingGUI, true); putStackToNextEmptySlot(-1, isCraftingGUI, true);
} }
} }
/** /**
* Returns the first free index in a inventory * Returns the first free index in a inventory
* *
* @param isCraftingGUI * @param isCraftingGUI true, if the craftingGUI is opened
* true, if the craftingGUI is opened * @return a slot index
* @return a slot index */
*/ private int getFirstPropperSlotIndex(boolean isCraftingGUI, ItemStack movingItem) {
private int getFirstPropperSlotIndex(boolean isCraftingGUI, ItemStack movingItem) {
if (isCraftingGUI) { if (isCraftingGUI) {
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) {
if (getItemStack(i).isItemEqual(movingItem)) { if (getItemStack(i).isItemEqual(movingItem)) {
if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) { if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) {
return i; return i;
} }
} }
} }
} }
GameRegistry.addShapelessRecipe(new ItemStack(Item.getByNameOrId("Diamond")), for (int i = 10; i < container.inventorySlots.size(); i++) {
new ItemStack(Block.getBlockFromName("Dirt")));
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;
}
}
if (getItemStack(i) == null) { /**
return i; * Executes a left mouse click on a slot. [Based on INVTW]
} *
} * @param index The index of the slot in the container
Helper.debugPrint("getFirstProperSlotIndex(): No Propper / Empty Slot found!"); */
return -1; private void leftClick(int index) {
} else { slotClick(index, false);
// TODO: Same for inventory }
return -1;
}
}
/** /**
* Executes a left mouse click on a slot. [Based on INVTW] * Executes a right mouse click on a slot. [Based on INVTW]
* *
* @param index * @param index The index of the slot in the container
* The index of the slot in the container */
*/ private void rightClick(int index) {
private void leftClick(int index) { slotClick(index, true);
slotClick(index, false); }
}
/** /**
* Executes a right mouse click on a slot. [Based on INVTW] * Executes a mouse click on a slot. [Based on INVTW]
* *
* @param index * @param index The index of the slot in the container
* The index of the slot in the container * @param rightClick True, if the click is with the right mouse button
*/ */
private void rightClick(int index) { private void slotClick(int index, boolean rightClick) {
slotClick(index, true);
}
/** Helper.debugPrint("slotClick(): Clicked @ Slot " + index + " with data " + rightClick + ".");
* Executes a mouse click on a slot. [Based on INVTW]
*
* @param index
* The index of the slot in the container
* @param rightClick
* True, if the click is with the right mouse button
*/
private void slotClick(int index, boolean rightClick) {
Helper.debugPrint("slotClick(): Clicked @ Slot " + index + " with data " + rightClick + "."); int rightClickData = (rightClick) ? 1 : 0;
int rightClickData = (rightClick) ? 1 : 0; CraftingKeys.instance.proxy.sendSlotClick(Helper.client.playerController, container.windowId, index,
rightClickData, 0, Helper.client.thePlayer);
CraftingKeys.instance.proxy.sendSlotClick(Helper.client.playerController, container.windowId, index, }
rightClickData, 0, Helper.client.thePlayer);
}
} }
@@ -7,24 +7,23 @@ import net.minecraft.entity.player.EntityPlayer;
* Client Proxy, extending Common Proxy. * Client Proxy, extending Common Proxy.
* *
* @author skate702 * @author skate702
*
*/ */
public class CraftingKeysClientProxy extends CraftingKeysProxy { public class CraftingKeysClientProxy extends CraftingKeysProxy {
@Override @Override
public void registerRenderers() { public void registerRenderers() {
} }
@Override @Override
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action, public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
EntityPlayer player) { EntityPlayer player) {
// TODO: Make this *** multiplayer friendly // TODO: Make this *** multiplayer friendly
controller.windowClick(windowId, slot, rightClick, action, player); controller.windowClick(windowId, slot, rightClick, action, player);
// player.openContainer.slotClick(slot, rightClick, action, player); // player.openContainer.slotClick(slot, rightClick, action, player);
} }
} }
@@ -1,45 +1,38 @@
package de.skate702.craftingkeys.proxies; package de.skate702.craftingkeys.proxies;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.multiplayer.PlayerControllerMP; import net.minecraft.client.multiplayer.PlayerControllerMP;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/** /**
* The common proxy. * The common proxy.
* *
* @author skate702 * @author skate702
*
*/ */
public class CraftingKeysProxy { public class CraftingKeysProxy {
/** /**
* Register Renderers (not needed here). * Register Renderers (not needed here).
*/ */
public void registerRenderers() { public void registerRenderers() {
} }
/** /**
* The Minecraft call to send a mouse click to a GUI. [Based on INVTW] * The Minecraft call to send a mouse click to a GUI. [Based on INVTW]
* *
* @param controller * @param controller The playerController (from Client)
* The playerController (from Client) * @param windowId The current Windows ID (from GUI)
* @param windowId * @param slot The slot to click on (slot index)
* The current Windows ID (from GUI) * @param rightClick 1, if right click. Otherwise 0
* @param slot * @param action 0
* The slot to click on (slot index) * @param player The current player (from Client)
* @param rightClick */
* 1, if right click. Otherwise 0 @SideOnly(Side.CLIENT)
* @param action public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
* 0 EntityPlayer player) {
* @param player
* The current player (from Client)
*/
@SideOnly(Side.CLIENT)
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
EntityPlayer player) {
} }
} }
@@ -0,0 +1 @@
# dummy
@@ -1,4 +1,4 @@
?# Control Names # Control Names
key.topleft=1. Top Left key.topleft=1. Top Left
key.topcenter=2. Top Center key.topcenter=2. Top Center
key.topright=3. Top Right key.topright=3. Top Right
@@ -11,4 +11,4 @@ key.lowerright=9. Lower Right
key.stack=Stack Key key.stack=Stack Key
key.interact=Interaction Key key.interact=Interaction Key
# Control Category Name # Control Category Name
key.categories.craftingkeys=Crafting Keys (Mostly red Keys are NO problem!) key.categories.craftingkeys=Crafting Keys
+1 -1
View File
@@ -7,7 +7,7 @@
"mcversion": "${mcversion}", "mcversion": "${mcversion}",
"url": "http://skate702.de", "url": "http://skate702.de",
"updateUrl": "http://skate702.de", "updateUrl": "http://skate702.de",
"authorList": ["skate702"], "authorList": ["skate702, 0xSeb"],
"credits": "Thanks to Inventory-Tweaks!", "credits": "Thanks to Inventory-Tweaks!",
"logoFile": "", "logoFile": "",
"screenshots": [], "screenshots": [],