Created
January 17, 2014 12:41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package makmods.levelstorage.item; | |
import ic2.api.item.ElectricItem; | |
import ic2.api.item.IElectricItem; | |
import java.util.Arrays; | |
import java.util.List; | |
import java.util.Map; | |
import makmods.levelstorage.LSCreativeTab; | |
import makmods.levelstorage.init.IHasRecipe; | |
import makmods.levelstorage.iv.parsers.recipe.RecipeHelper; | |
import makmods.levelstorage.proxy.ClientProxy; | |
import net.minecraft.block.Block; | |
import net.minecraft.creativetab.CreativeTabs; | |
import net.minecraft.entity.player.EntityPlayer; | |
import net.minecraft.inventory.InventoryCrafting; | |
import net.minecraft.item.EnumRarity; | |
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; | |
import net.minecraftforge.oredict.OreDictionary; | |
import com.google.common.collect.Lists; | |
import com.google.common.collect.Maps; | |
import cpw.mods.fml.common.FMLCommonHandler; | |
import cpw.mods.fml.relauncher.Side; | |
import cpw.mods.fml.relauncher.SideOnly; | |
public class ItemNanoHammer extends Item implements IElectricItem, IHasRecipe { | |
public static Map<List<Integer>, List<Integer>> bonusRecipes = Maps | |
.newHashMap(); | |
public static class NanoHammerRecipe implements IRecipe { | |
public static ItemStack getResult(InventoryCrafting grid) { | |
boolean foundHammer = false; | |
boolean foundMaterial = false; | |
List<ItemStack> items = Lists.newArrayList(); | |
ItemStack hammer = null; | |
ItemStack output = null; | |
for (int i = 0; i < grid.getSizeInventory(); i++) { | |
ItemStack stack = grid.getStackInSlot(i); | |
if (stack != null) | |
items.add(stack.copy()); | |
} | |
for (ItemStack stack : items) { | |
if (stack.getItem() instanceof ItemNanoHammer) { | |
if (foundHammer) | |
return null; | |
foundHammer = true; | |
hammer = stack; | |
} else { | |
// specials | |
List<Integer> inputs = Lists.newArrayList(); | |
inputs.add(stack.itemID); | |
inputs.add(stack.getItemDamage()); | |
if (bonusRecipes.containsKey(inputs)) { | |
foundMaterial = true; | |
List<Integer> res = bonusRecipes.get(inputs); | |
output = new ItemStack(res.get(0), 1, res.get(1)); | |
} | |
// regular | |
if (!foundMaterial) { | |
String oreDict = RecipeHelper.resolveOreDict(stack); | |
if (oreDict != null) { | |
// INGOT -> PLATE | |
if (oreDict.startsWith("ingot")) { | |
String nameC = "plate" | |
+ oreDict.replace("ingot", ""); | |
List<ItemStack> outs = OreDictionary | |
.getOres(nameC); | |
if (outs.size() > 0) { | |
foundMaterial = true; | |
output = outs.get(0).copy(); | |
} | |
} | |
// PLATE -> ITEMCASING | |
} | |
} | |
} | |
} | |
return items.size() == 2 && foundHammer && foundMaterial | |
&& ElectricItem.manager.canUse(hammer, ENERGY_PER_USE) ? output | |
: null; | |
} | |
@Override | |
public boolean matches(InventoryCrafting inventorycrafting, World world) { | |
return getResult(inventorycrafting) != null; | |
} | |
@Override | |
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) { | |
return getResult(inventorycrafting); | |
} | |
@Override | |
public int getRecipeSize() { | |
return 10; | |
} | |
@Override | |
public ItemStack getRecipeOutput() { | |
return null; | |
} | |
} | |
public ItemNanoHammer(int par1) { | |
super(par1); | |
this.setMaxDamage(27); | |
this.setNoRepair(); | |
if (FMLCommonHandler.instance().getSide().isClient()) { | |
this.setCreativeTab(LSCreativeTab.instance); | |
this.setTextureName(ClientProxy.getTexturePathFor("nanohammer")); | |
} | |
this.setMaxStackSize(1); | |
CraftingManager.getInstance().getRecipeList() | |
.add(new NanoHammerRecipe()); | |
if (RecipeHelper.resolveOreDict(new ItemStack(Item.ingotIron)) == null) | |
OreDictionary.registerOre("ingotIron", | |
new ItemStack(Item.ingotIron)); | |
if (RecipeHelper.resolveOreDict(new ItemStack(Item.ingotGold)) == null) | |
OreDictionary.registerOre("ingotGold", | |
new ItemStack(Item.ingotGold)); | |
addSpecialRecipe(new ItemStack(Block.stone), new ItemStack( | |
Block.cobblestone)); | |
addSpecialRecipe(new ItemStack(Block.cobblestone), new ItemStack( | |
Block.sand)); | |
} | |
public static final int STORAGE = 1000000; | |
public static final int TRANSFER_LIMIT = 10000; | |
public static final int TIER = 3; | |
public static final int ENERGY_PER_USE = 5000; | |
public static void addSpecialRecipe(ItemStack input, ItemStack output) { | |
bonusRecipes.put(Arrays.asList(input.itemID, input.getItemDamage()), | |
Arrays.asList(output.itemID, output.getItemDamage())); | |
} | |
@Override | |
public void addCraftingRecipe() { | |
// TODO Auto-generated method stub | |
} | |
public void addInformation(ItemStack par1ItemStack, | |
EntityPlayer par2EntityPlayer, List par3List, boolean par4) { | |
int charge = ElectricItem.manager.getCharge(par1ItemStack); | |
par3List.add("" + (charge / ENERGY_PER_USE) + " / " | |
+ (STORAGE / ENERGY_PER_USE) + " uses"); | |
} | |
@Override | |
public boolean canProvideEnergy(ItemStack itemStack) { | |
return false; | |
} | |
@Override | |
public int getChargedItemId(ItemStack itemStack) { | |
return itemID; | |
} | |
@Override | |
public int getEmptyItemId(ItemStack itemStack) { | |
return itemID; | |
} | |
@Override | |
public int getMaxCharge(ItemStack itemStack) { | |
return STORAGE; | |
} | |
@Override | |
public int getTier(ItemStack itemStack) { | |
return TIER; | |
} | |
@Override | |
public int getTransferLimit(ItemStack itemStack) { | |
return TRANSFER_LIMIT; | |
} | |
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, | |
List par3List) { | |
ItemStack charged = new ItemStack(this, 1); | |
ElectricItem.manager.charge(charged, Integer.MAX_VALUE, | |
Integer.MAX_VALUE, true, false); | |
par3List.add(charged); | |
ItemStack discharged = new ItemStack(this, 1, this.getMaxDamage()); | |
par3List.add(discharged); | |
} | |
@Override | |
public boolean doesContainerItemLeaveCraftingGrid(ItemStack itemStack) { | |
return false; | |
} | |
@Override | |
public ItemStack getContainerItemStack(ItemStack itemStack) { | |
ItemStack copiedStack = itemStack.copy(); | |
// copiedStack.setItemDamage(copiedStack.getItemDamage() + 1); | |
ElectricItem.manager.discharge(copiedStack, ENERGY_PER_USE, | |
Integer.MAX_VALUE, true, false); | |
copiedStack.stackSize = 1; | |
return copiedStack; | |
} | |
@Override | |
public boolean hasContainerItem() { | |
return true; | |
} | |
@Override | |
@SideOnly(Side.CLIENT) | |
public EnumRarity getRarity(ItemStack par1ItemStack) { | |
return EnumRarity.uncommon; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment