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;
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.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;
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
@@ -93,12 +89,11 @@ public class CraftingKeys {
public void onTick(TickEvent.ClientTickEvent tick) {
// Message
if(Helper.isFirstInWorldTick()) {
if (Helper.isFirstInWorldTick()) {
Helper.printWarning();
}
// Case 1: Classic GUI Screen
if (Helper.isCraftingGUI(Helper.client.currentScreen)) {
@@ -1,5 +1,6 @@
package de.skate702.craftingkeys;
import cpw.mods.fml.client.FMLClientHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -8,7 +9,6 @@ import net.minecraft.inventory.Container;
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;
@@ -1,9 +1,8 @@
package de.skate702.craftingkeys;
import cpw.mods.fml.client.registry.ClientRegistry;
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;
/**
@@ -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.Helper;
import net.minecraft.client.gui.inventory.GuiCrafting;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
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.
*
* @author skate702
*
*/
public class ContainerManager {
/**
* The Container to work with.
*/
private Container container;
/**
* The Container to work with.
*/
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.
*
* @param srcIndex
* The Source Slot Index of the Container
* @param destIndex
* The Destination Slot Index of the Container
*/
public void moveAll(int srcIndex, int destIndex) {
/**
* Moves a full Stack from a slot to another.
*
* @param srcIndex The Source Slot Index of the Container
* @param destIndex The Destination Slot Index of the Container
*/
public void moveAll(int srcIndex, int destIndex) {
ItemStack source = getItemStack(srcIndex);
ItemStack source = getItemStack(srcIndex);
if (source == null) {
Helper.debugPrint("moveAll(): source == null");
} else {
Helper.debugPrint("moveAll(): Redirected to move()");
move(srcIndex, destIndex, source.stackSize);
}
if (source == null) {
Helper.debugPrint("moveAll(): source == null");
} else {
Helper.debugPrint("moveAll(): Redirected to move()");
move(srcIndex, destIndex, source.stackSize);
}
}
}
/**
* Moves a specified amount of Items from a slot to another. [Based on
* INVTW]
*
* @param srcIndex
* The Source Slot Index of the Container
* @param destIndex
* The Destination Slot Index of the Container
* @param amount
* The amount of items to move (can be bigger then Stack Size)
*/
public void move(int srcIndex, int destIndex, int amount) {
/**
* Moves a specified amount of Items from a slot to another. [Based on
* INVTW]
*
* @param srcIndex The Source Slot Index of the Container
* @param destIndex The Destination Slot Index of the Container
* @param amount The amount of items to move (can be bigger then Stack Size)
*/
public void move(int srcIndex, int destIndex, int amount) {
// Stacks
ItemStack source = getItemStack(srcIndex);
ItemStack destination = getItemStack(destIndex);
// Stacks
ItemStack source = getItemStack(srcIndex);
ItemStack destination = getItemStack(destIndex);
// Same Location?
if (source == null || srcIndex == destIndex) {
Helper.debugPrint("Move(): srcIndex == destIndex OR source == null");
return;
}
// Same Location?
if (source == null || srcIndex == destIndex) {
Helper.debugPrint("Move(): srcIndex == destIndex OR source == null");
return;
}
// Test for max. moving Amount
int sourceSize = source.stackSize;
int movedAmount = Math.min(amount, sourceSize);
// Test for max. moving Amount
int sourceSize = source.stackSize;
int movedAmount = Math.min(amount, sourceSize);
// Move some
if (destination == null || source.isItemEqual(destination)) {
// Move some
if (destination == null || source.isItemEqual(destination)) {
leftClick(srcIndex);
for (int i = 0; i < movedAmount; i++) {
rightClick(destIndex);
}
leftClick(srcIndex);
for (int i = 0; i < movedAmount; i++) {
rightClick(destIndex);
}
// Move back
if (movedAmount < sourceSize) {
leftClick(srcIndex);
}
// Move back
if (movedAmount < sourceSize) {
leftClick(srcIndex);
}
Helper.debugPrint("move(): Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!");
Helper.debugPrint("move(): Moved " + movedAmount + " from " + srcIndex + " to " + destIndex + "!");
} else {
Helper.debugPrint("Move(): Not the same block type!");
}
} else {
Helper.debugPrint("Move(): Not the same block type!");
}
}
}
/**
* Returns the ItemStack in a slot [Based on INVTW]
*
* @param index
* The index of the slot in the container
* @return Returns the ItemStack
*/
private ItemStack getItemStack(int index) {
/**
* Returns the ItemStack in a slot [Based on INVTW]
*
* @param index The index of the slot in the container
* @return Returns the ItemStack
*/
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));
return (slot == null) ? null : slot.getStack();
Slot slot = (Slot) (container.inventorySlots.get(index));
return (slot == null) ? null : slot.getStack();
} else {
} else {
Helper.debugPrint("getItemStack(): Invalid index");
return null;
Helper.debugPrint("getItemStack(): Invalid index");
return null;
}
}
}
}
/**
* Sends a click on the crafting output (craftingGUI or Inventory)
*
* @param isCraftingGUI
* true, if the craftingGUI is opened
*/
public void clickOnCraftingOutput(boolean isCraftingGUI) {
/**
* Sends a click on the crafting output (craftingGUI or Inventory)
*
* @param isCraftingGUI true, if the craftingGUI is opened
*/
public void clickOnCraftingOutput(boolean isCraftingGUI) {
putItemAway(isCraftingGUI);
putItemAway(isCraftingGUI);
if (isCraftingGUI) {
if (isCraftingGUI) {
// Click on crafting output
Helper.debugPrint("clickOnCraftingOutput(): Clicked on Crafing Output.");
leftClick(0);
// Click on crafting output
Helper.debugPrint("clickOnCraftingOutput(): Clicked on Crafing Output.");
leftClick(0);
} else {
// TODO: Same for inventory
}
} else {
// TODO: Same for inventory
}
}
}
/**
* Takes all items from a slot and moves them to the next empty slot or
* drops them.
*
* @param sourceIndex
* The index of the slot to move items from
* @param isCraftingGUI
* true, if the craftingGUI is opened
*/
public void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) {
/**
* Takes all items from a slot and moves them to the next empty slot or
* drops them.
*
* @param sourceIndex The index of the slot to move items from
* @param isCraftingGUI true, if the craftingGUI is opened
*/
public void putStackToNextEmptySlot(int sourceIndex, boolean isCraftingGUI, boolean isHeld) {
// Check for Item-Type
ItemStack stackToMove;
if (isHeld) {
stackToMove = Helper.client.thePlayer.inventory.getItemStack();
} else {
putItemAway(isCraftingGUI);
stackToMove = getItemStack(sourceIndex);
}
// 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) {
// Test for empty crafting table slot
if (!isHeld && getItemStack(sourceIndex) == null) {
Helper.debugPrint("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + ".");
return;
}
Helper.debugPrint("putStackToNextEmptySlot(): No Item Stack @ " + sourceIndex + ".");
return;
}
// Get Destination Index
int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove);
// Get Destination Index
int destIndex = getFirstPropperSlotIndex(isCraftingGUI, stackToMove);
// Additional click on source index, if not held
if (!isHeld) {
leftClick(sourceIndex);
}
// Additional click on source index, if not held
if (!isHeld) {
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
if (destIndex == -1) {
leftClick(-999); // Nice one, InvTweaks!
} else {
leftClick(destIndex);
}
// 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);
}
}
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) {
/**
* 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) {
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).isItemEqual(movingItem)) {
if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) {
return i;
}
}
}
}
if (getItemStack(i) != null) {
if (getItemStack(i).isItemEqual(movingItem)) {
if (getItemStack(i).stackSize + movingItem.stackSize <= movingItem.getMaxStackSize()) {
return i;
}
}
}
}
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) {
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;
}
}
Helper.debugPrint("getFirstProperSlotIndex(): No Propper / Empty Slot found!");
return -1;
} else {
// TODO: Same for inventory
return -1;
}
}
/**
* Executes a left mouse click on a slot. [Based on INVTW]
*
* @param index The index of the slot in the container
*/
private void leftClick(int index) {
slotClick(index, false);
}
/**
* Executes a left mouse click on a slot. [Based on INVTW]
*
* @param index
* The index of the slot in the container
*/
private void leftClick(int index) {
slotClick(index, false);
}
/**
* Executes a right mouse click on a slot. [Based on INVTW]
*
* @param index The index of the slot in the container
*/
private void rightClick(int index) {
slotClick(index, true);
}
/**
* Executes a right mouse click on a slot. [Based on INVTW]
*
* @param index
* The index of the slot in the container
*/
private void rightClick(int index) {
slotClick(index, true);
}
/**
* 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) {
/**
* 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 + ".");
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);
}
}
}
@@ -5,26 +5,25 @@ import net.minecraft.entity.player.EntityPlayer;
/**
* Client Proxy, extending Common Proxy.
*
* @author skate702
*
* @author skate702
*/
public class CraftingKeysClientProxy extends CraftingKeysProxy {
@Override
public void registerRenderers() {
}
@Override
public void registerRenderers() {
@Override
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
EntityPlayer player) {
}
// TODO: Make this *** multiplayer friendly
@Override
public void sendSlotClick(PlayerControllerMP controller, int windowId, int slot, int rightClick, int action,
EntityPlayer player) {
controller.windowClick(windowId, slot, rightClick, action, player);
// player.openContainer.slotClick(slot, rightClick, action, player);
// TODO: Make this *** multiplayer friendly
}
controller.windowClick(windowId, slot, rightClick, action, player);
// player.openContainer.slotClick(slot, rightClick, action, player);
}
}
@@ -1,45 +1,38 @@
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.entity.player.EntityPlayer;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
/**
* The common proxy.
*
* @author skate702
*
* @author skate702
*/
public class CraftingKeysProxy {
/**
* Register Renderers (not needed here).
*/
public void registerRenderers() {
/**
* Register Renderers (not needed here).
*/
public void registerRenderers() {
}
/**
* The Minecraft call to send a mouse click to a GUI. [Based on INVTW]
*
* @param controller
* The playerController (from Client)
* @param windowId
* The current Windows ID (from GUI)
* @param slot
* The slot to click on (slot index)
* @param rightClick
* 1, if right click. Otherwise 0
* @param action
* 0
* @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) {
}
}
/**
* The Minecraft call to send a mouse click to a GUI. [Based on INVTW]
*
* @param controller The playerController (from Client)
* @param windowId The current Windows ID (from GUI)
* @param slot The slot to click on (slot index)
* @param rightClick 1, if right click. Otherwise 0
* @param action 0
* @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) {
}
}