I am fairly new to this whole modding thing, so I have started to experiment by implementing random stuffs into the game.
I just started to work with food items, so I made a new ModFood class file.
Here is the source code:
package net.gwee.mod;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.item.Item;
import net.minecraft.item.ItemFood;
import net.minecraft.util.Icon;
public class ModFood extends ItemFood {
private String iconPath;
private String unlocalizedName;
@SideOnly(Side.CLIENT)
private Icon icon;
public ModFood( int par1, String par5String, int par2, float par3, boolean par4 ){
super(par1, par2, par3, par4);
this.iconPath = par5String;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister par1IconRegister){
this.icon = par1IconRegister.registerIcon("mod/" + this.iconPath);
}
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int par1){
return this.icon;
}
public ModFood setUnlocalizedName(String par1Str)
{
this.unlocalizedName = par1Str;
return this;
}
}
http://paste.minecraftforge.net/view/dbe7ac49
Just in case, here is the source code of ItemFood:
package net.minecraft.item;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.potion.PotionEffect;
import net.minecraft.world.World;
public class ItemFood extends Item
{
public final int itemUseDuration;
private final int healAmount;
private final float saturationModifier;
private final boolean isWolfsFavoriteMeat;
private boolean alwaysEdible;
private int potionId;
private int potionDuration;
private int potionAmplifier;
private float potionEffectProbability;
public ItemFood(int par1, int par2, float par3, boolean par4)
{
super(par1);
this.itemUseDuration = 32;
this.healAmount = par2;
this.isWolfsFavoriteMeat = par4;
this.saturationModifier = par3;
this.setCreativeTab(CreativeTabs.tabFood);
}
public ItemFood(int par1, int par2, boolean par3)
{
this(par1, par2, 0.6F, par3);
}
public ItemStack onEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
--par1ItemStack.stackSize;
par3EntityPlayer.getFoodStats().addStats(this);
par2World.playSoundAtEntity(par3EntityPlayer, "random.burp", 0.5F, par2World.rand.nextFloat() * 0.1F + 0.9F);
this.onFoodEaten(par1ItemStack, par2World, par3EntityPlayer);
return par1ItemStack;
}
protected void onFoodEaten(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (!par2World.isRemote && this.potionId > 0 && par2World.rand.nextFloat() < this.potionEffectProbability)
{
par3EntityPlayer.addPotionEffect(new PotionEffect(this.potionId, this.potionDuration * 20, this.potionAmplifier));
}
}
public int getMaxItemUseDuration(ItemStack par1ItemStack)
{
return 32;
}
public EnumAction getItemUseAction(ItemStack par1ItemStack)
{
return EnumAction.eat;
}
public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
{
if (par3EntityPlayer.canEat(this.alwaysEdible))
{
par3EntityPlayer.setItemInUse(par1ItemStack, this.getMaxItemUseDuration(par1ItemStack));
}
return par1ItemStack;
}
public int getHealAmount()
{
return this.healAmount;
}
public float getSaturationModifier()
{
return this.saturationModifier;
}
public boolean isWolfsFavoriteMeat()
{
return this.isWolfsFavoriteMeat;
}
public ItemFood setPotionEffect(int par1, int par2, int par3, float par4)
{
this.potionId = par1;
this.potionDuration = par2;
this.potionAmplifier = par3;
this.potionEffectProbability = par4;
return this;
}
public ItemFood setAlwaysEdible()
{
this.alwaysEdible = true;
return this;
}
}
http://paste.minecraftforge.net/view/0ccae1ba
Anyways, so I created new 2 new food items, toast and butter. I created everything needed to implement it into the game, but for some odd reason, both of them appear as "Butter". I suspect it must be UnlocalizedName in some way, but I haven't really found out how to fix it.
Here is the code of interest in the main class file:
public static ModFood toast = new ModFood(8150, "toast", 6, 6.5F, false).setUnlocalizedName("toast");
public static ModFood butter = new ModFood(8151, "butter", 1, 1F, false).setUnlocalizedName("butter");
public static CreativeTabs tabBillMod = new CreativeTabBillMod(CreativeTabs.getNextID(), derpEssenceR.itemID, "tabBillMod", "Bill's Mod");
@Override
public void load() {
//Register CreativeTabs
toast.setCreativeTab(tabBillMod);
butter.setCreativeTab(tabBillMod);
//Register Item
GameRegistry.registerItem(toast, "toast");
GameRegistry.registerItem(butter, "butter");
//Register Names
LanguageRegistry.addName(toast, "Toast");
LanguageRegistry.addName(butter, "Butter");
}
http://paste.minecraftforge.net/view/dee39682
Any help or feedback would be extremely appreciated!