It's solved!!!!!!!!!
Hi there,
I tried to solve this problem myself but I didnt get it right, so I'm asking here:
What do I wrong. I try to add electricFood, but I only have one Item(not two) without damage bar(charge), etc.
Would be cool if you could help me
Here is my code:
Java
package de.DrBlock42.extraStuff;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import ic2.api.item.ElectricItem;
import ic2.api.item.IElectricItem;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
public class ElectricItemBase extends Item implements IElectricItem{
public int maxCharge;
public int transferLimit;
public int tier;
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister par1IconRegister)
{
//this.itemIcon = par1IconRegister.registerIcon(IHLModInfo.MODID + ":itemElectricHandpump");
this.setMaxDamage(27);
}
public ElectricItemBase()
{
//this.setMaxDamage(27);
this.setMaxStackSize(1);
}
@Override
public boolean canProvideEnergy(ItemStack itemStack) {
return false;
}
@Override
public Item getChargedItem(ItemStack itemStack) {
return this;
}
@Override
public Item getEmptyItem(ItemStack itemStack) {
return this;
}
@Override
public int getMaxCharge(ItemStack itemStack) {
return this.maxCharge;
}
@Override
public int getTier(ItemStack itemStack) {
return this.tier;
}
@Override
public int getTransferLimit(ItemStack itemStack) {
return this.transferLimit;
}
//@SideOnly(Side.CLIENT)
public void getSubItems(int par, CreativeTabs creativeTabs, List itemList)
{
ItemStack itemStack = new ItemStack(this, 1);
if(getChargedItem(itemStack) == this)
{
ItemStack charged = new ItemStack(this, 1);
ElectricItem.manager.charge(charged, Integer.MAX_VALUE, Integer.MAX_VALUE, true, false);
itemList.add(charged);
}
if(getEmptyItem(itemStack) == this)
{
itemList.add(new ItemStack(this, 1, getMaxDamage()));
}
}
}
Display More
Code
package de.DrBlock42.extraStuff;
import ic2.api.item.ElectricItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentStyle;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IChatComponent;
import net.minecraft.world.World;
public class ElectricFood extends ElectricItemBase{
public ElectricFood()
{
this.setCreativeTab(de.DrBlock42.extraStuff.MainClass.tab);
this.setUnlocalizedName("electricFood");
this.maxCharge = 2000;
this.transferLimit = 100;
this.tier = 1;
}
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
{
if(ElectricItem.manager.use(itemStack, 500, player))
{
ChatComponentText message = new ChatComponentText("How did that taste?");
if(!world.isRemote)
{
player.addChatMessage(message);
}
player.getFoodStats().addStats(2, 2.4F);
return itemStack;
}
return itemStack;
}
}
Display More
Code
package de.DrBlock42.extraStuff;
import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.registry.GameRegistry;
@Mod(modid = MainClass.modid, version = MainClass.version)
public class MainClass {
public static final String modid = "ExtraStuff";
public static final String version = "0.0.1alpha";
public static CreativeTabs tab = new CreativeTabs("ExtraStuffMainTab"){
@Override
public Item getTabIconItem() {
return Items.written_book;
}
};
public static Item electricFood;
@EventHandler
public void init(FMLInitializationEvent e)
{
System.out.println("Extra Stuff loading...");
}
@EventHandler
public void preInit(FMLPreInitializationEvent e)
{
electricFood = new de.DrBlock42.extraStuff.ElectricFood();
GameRegistry.registerItem(electricFood, "electricFood");
}
}
Display More