Thanks to CoFH Code (Properly Credited)
This commit is contained in:
parent
2ee4b97679
commit
4e15e4df96
2 changed files with 177 additions and 48 deletions
|
|
@ -9,12 +9,14 @@ import com.oitsjustjose.criss_cross.TileEntity.TileEntityElectroextractor;
|
||||||
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
import com.oitsjustjose.criss_cross.TileEntity.TileEntityWoodchipper;
|
||||||
import com.oitsjustjose.criss_cross.Util.CCLog;
|
import com.oitsjustjose.criss_cross.Util.CCLog;
|
||||||
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
import com.oitsjustjose.criss_cross.Util.ConfigHandler;
|
||||||
|
import com.oitsjustjose.criss_cross.Util.ItemHelper;
|
||||||
|
|
||||||
import cpw.mods.fml.common.registry.GameRegistry;
|
import cpw.mods.fml.common.registry.GameRegistry;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.block.BlockLog;
|
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.init.Items;
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraftforge.oredict.OreDictionary;
|
import net.minecraftforge.oredict.OreDictionary;
|
||||||
|
|
||||||
|
|
@ -53,7 +55,8 @@ public class CCMachineRecipes
|
||||||
if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null)
|
if (GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1) != null)
|
||||||
{
|
{
|
||||||
ItemStack newStack = GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1);
|
ItemStack newStack = GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1);
|
||||||
CropomatorRecipes.getInstance().addRecipe(newStack, new ItemStack(newStack.getItem(), cropomatorQTY, newStack.getItemDamage()));
|
CropomatorRecipes.getInstance().addRecipe(newStack,
|
||||||
|
new ItemStack(newStack.getItem(), cropomatorQTY, newStack.getItemDamage()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -71,7 +74,8 @@ public class CCMachineRecipes
|
||||||
GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1,
|
GameRegistry.findItemStack(unlocStack[0], unlocStack[1], 1).getItem(), 1,
|
||||||
Integer.parseInt(unlocStack[2]));
|
Integer.parseInt(unlocStack[2]));
|
||||||
newStack.stackSize = cropomatorQTY;
|
newStack.stackSize = cropomatorQTY;
|
||||||
CropomatorRecipes.getInstance().addRecipe(newStack, new ItemStack(newStack.getItem(), cropomatorQTY, newStack.getItemDamage()));
|
CropomatorRecipes.getInstance().addRecipe(newStack,
|
||||||
|
new ItemStack(newStack.getItem(), cropomatorQTY, newStack.getItemDamage()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -132,59 +136,58 @@ public class CCMachineRecipes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//All Credit goes to TeamCoFH for the code. After so many algorithms attempted, I gave up and used one that worked:
|
||||||
|
|
||||||
public static void initWoodchipperOreDictionary()
|
public static void initWoodchipperOreDictionary()
|
||||||
{
|
{
|
||||||
ArrayList<ItemStack> logs = OreDictionary.getOres("logWood");
|
Container local1 = new Container()
|
||||||
ArrayList<ItemStack> planks = OreDictionary.getOres("plankWood");
|
|
||||||
|
|
||||||
String logName;
|
|
||||||
String plankName;
|
|
||||||
|
|
||||||
for (int i = 0; i < logs.size(); i++)
|
|
||||||
{
|
{
|
||||||
for (int logMeta = 0; logMeta < 16; logMeta++)
|
public boolean canInteractWith(EntityPlayer paramAnonymousEntityPlayer)
|
||||||
{
|
{
|
||||||
ItemStack log = new ItemStack(logs.get(i).getItem(), 1, logMeta);
|
return false;
|
||||||
logName = log.getDisplayName();
|
}
|
||||||
logName = logName.toLowerCase();
|
};
|
||||||
logName = logName.replace("wood", "");
|
InventoryCrafting localInventoryCrafting = new InventoryCrafting(local1, 3, 3);
|
||||||
logName = logName.trim();
|
for (int i = 0; i < 9; i++)
|
||||||
|
{
|
||||||
for (int j = 0; j < planks.size(); j++)
|
localInventoryCrafting.setInventorySlotContents(i, null);
|
||||||
|
}
|
||||||
|
ArrayList localArrayList = OreDictionary.getOres("logWood");
|
||||||
|
for (int j = 0; j < localArrayList.size(); j++)
|
||||||
|
{
|
||||||
|
ItemStack localItemStack1 = (ItemStack) localArrayList.get(j);
|
||||||
|
ItemStack localItemStack3;
|
||||||
|
ItemStack localItemStack4;
|
||||||
|
if (ItemHelper.getItemDamage(localItemStack1) == 32767)
|
||||||
|
{
|
||||||
|
for (int k = 0; k < 16; k++)
|
||||||
{
|
{
|
||||||
for (int plankMeta = 0; plankMeta < 16; plankMeta++)
|
localItemStack3 = ItemHelper.cloneStack(localItemStack1, 1);
|
||||||
|
localItemStack3.setItemDamage(k);
|
||||||
|
localInventoryCrafting.setInventorySlotContents(0, localItemStack3);
|
||||||
|
localItemStack4 = ItemHelper.findMatchingRecipe(localInventoryCrafting, null);
|
||||||
|
if (localItemStack4 != null)
|
||||||
{
|
{
|
||||||
ItemStack plank = new ItemStack(planks.get(j).getItem(), 1, plankMeta);
|
ItemStack localItemStack5 = localItemStack4.copy();
|
||||||
plankName = plank.getDisplayName();
|
ItemStack tmp129_127 = localItemStack5;
|
||||||
plankName = plankName.toLowerCase();
|
tmp129_127.stackSize = woodchipperQTY;
|
||||||
plankName = plankName.replace("wood", "");
|
WoodchipperRecipes.getInstance().addRecipe(localItemStack3, localItemStack5);
|
||||||
plankName = plankName.replace("planks", "");
|
|
||||||
plankName = plankName.trim();
|
|
||||||
plank.stackSize = woodchipperQTY;
|
|
||||||
if (plankName.contains(logName))
|
|
||||||
{
|
|
||||||
//Prevents Weird Metadata Being Initialized
|
|
||||||
if(log.getItemDamage() >= 4)
|
|
||||||
break;
|
|
||||||
//Prevents Natura Metadata Breakage
|
|
||||||
if(Block.getBlockFromItem(log.getItem()).getClass().toString().contains("mods.natura.blocks.trees.DarkTreeBlock"))
|
|
||||||
if(log.getItemDamage() >= 2)
|
|
||||||
break;
|
|
||||||
//Prevents ExtraUtils from breaking stuff too
|
|
||||||
if(plank.getDisplayName().toLowerCase().contains("colored"))
|
|
||||||
break;
|
|
||||||
//Prevents Weird MINECRAFT metadata (thanks Jeb >_> )
|
|
||||||
if(log.getDisplayName().contains("Acacia"))
|
|
||||||
{
|
|
||||||
if(log.getItemDamage() == 0)
|
|
||||||
WoodchipperRecipes.getInstance().addRecipe(log, plank);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
WoodchipperRecipes.getInstance().addRecipe(log, plank);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ItemStack localItemStack2 = localItemStack1.copy();
|
||||||
|
localInventoryCrafting.setInventorySlotContents(0, localItemStack2);
|
||||||
|
localItemStack3 = ItemHelper.findMatchingRecipe(localInventoryCrafting, null);
|
||||||
|
if (localItemStack3 != null)
|
||||||
|
{
|
||||||
|
localItemStack4 = localItemStack3.copy();
|
||||||
|
ItemStack tmp201_199 = localItemStack4;
|
||||||
|
tmp201_199.stackSize = woodchipperQTY;
|
||||||
|
WoodchipperRecipes.getInstance().addRecipe(localItemStack2, localItemStack4);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
126
src/main/java/com/oitsjustjose/criss_cross/Util/ItemHelper.java
Normal file
126
src/main/java/com/oitsjustjose/criss_cross/Util/ItemHelper.java
Normal file
|
|
@ -0,0 +1,126 @@
|
||||||
|
package com.oitsjustjose.criss_cross.Util;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.init.Items;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
|
import net.minecraft.item.crafting.IRecipe;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author TeamCoFH
|
||||||
|
* All credit goes to TeamCoFH, this was required for proper woodchipper recipes :)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class ItemHelper
|
||||||
|
{
|
||||||
|
public static ItemStack cloneStack(Item item, int stackSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemStack stack = new ItemStack(item, stackSize);
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack cloneStack(Block item, int stackSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (item == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemStack stack = new ItemStack(item, stackSize);
|
||||||
|
|
||||||
|
return stack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack cloneStack(ItemStack stack, int stackSize)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (stack == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemStack retStack = stack.copy();
|
||||||
|
retStack.stackSize = stackSize;
|
||||||
|
|
||||||
|
return retStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack cloneStack(ItemStack stack)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (stack == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ItemStack retStack = stack.copy();
|
||||||
|
|
||||||
|
return retStack;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getItemDamage(ItemStack stack)
|
||||||
|
{
|
||||||
|
|
||||||
|
return Items.diamond.getDamage(stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack findMatchingRecipe(InventoryCrafting inv, World world)
|
||||||
|
{
|
||||||
|
|
||||||
|
ItemStack[] dmgItems = new ItemStack[2];
|
||||||
|
for (int i = 0; i < inv.getSizeInventory(); i++)
|
||||||
|
{
|
||||||
|
if (inv.getStackInSlot(i) != null)
|
||||||
|
{
|
||||||
|
if (dmgItems[0] == null)
|
||||||
|
{
|
||||||
|
dmgItems[0] = inv.getStackInSlot(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dmgItems[1] = inv.getStackInSlot(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dmgItems[0] == null || dmgItems[0].getItem() == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if (dmgItems[1] != null && dmgItems[0].getItem() == dmgItems[1].getItem() && dmgItems[0].stackSize == 1
|
||||||
|
&& dmgItems[1].stackSize == 1 && dmgItems[0].getItem().isRepairable())
|
||||||
|
{
|
||||||
|
Item theItem = dmgItems[0].getItem();
|
||||||
|
int var13 = theItem.getMaxDamage() - dmgItems[0].getItemDamageForDisplay();
|
||||||
|
int var8 = theItem.getMaxDamage() - dmgItems[1].getItemDamageForDisplay();
|
||||||
|
int var9 = var13 + var8 + theItem.getMaxDamage() * 5 / 100;
|
||||||
|
int var10 = Math.max(0, theItem.getMaxDamage() - var9);
|
||||||
|
|
||||||
|
return new ItemStack(dmgItems[0].getItem(), 1, var10);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
IRecipe recipe;
|
||||||
|
for (int i = 0; i < CraftingManager.getInstance().getRecipeList().size(); i++)
|
||||||
|
{
|
||||||
|
recipe = (IRecipe) CraftingManager.getInstance().getRecipeList().get(i);
|
||||||
|
|
||||||
|
if (recipe.matches(inv, world))
|
||||||
|
{
|
||||||
|
return recipe.getCraftingResult(inv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue