Jump to content

Recommended Posts

Posted

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! ;D

Posted

well that and ... you're using the same class for both item WITHOUT meta. you should be either using meta OR 2 different class

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Posted

Sorry, forgot to mention. Both of them have their own respective properties, just that the names are swapped. Is there anyway of doing it without 2 different classes?

Posted

Well, as I stated before, I am quite new to modding, so I'll have to learn how to "meta", but is there an alternate solution where I can declare a new food similar to how I declare regular items?

ModItem 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.util.Icon;

public class ModItem extends Item {

private String iconPath;

@SideOnly(Side.CLIENT)
private Icon icon;

public ModItem(int par1, String par2String){
	super(par1);
	this.iconPath = par2String;
}

@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;
}
}

 

If I want to make a new item with this method:

public static Item example = new ModItem(1337, "texture").setUnlocalizedName("example");

Posted

public String getItemDisplayName(ItemStack par1)

{

    return "YourItemName";

}

 

this function is vannila and make GameRegistry/Modloader addName totally useless!

 

Just put the Function i wrote up ther inside of your Item and you will see how good that works^^

Posted

LanguageRegistry.addName() asks for your item return of method getUnlocalizedName().

In your ModFood, it is null because you are overriding setUnlocalizedName to change your own internal String instead of the one in the Item class.

Either use super.setUnlocalizedName(string) in it, or don't override it (i highly recommend this, since you don't use your unlocalizedname string).

Posted

LanguageRegistry.addName() asks for your item return of method getUnlocalizedName().

In your ModFood, it is null because you are overriding setUnlocalizedName to change your own internal String instead of the one in the Item class.

Either use super.setUnlocalizedName(string) in it, or don't override it (i highly recommend this, since you don't use your unlocalizedname string).

 

I have very limited knowledge, but with a stroke of luck, a little bit of common sense, your method worked for me! I didn't have to change the way I made all my items, or anything. So I thank you for that. As for everyone else who helped, I really appreciate it, for this experience made me learn A LOT. Thanks~ ;D

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • coupon, shopping on the app or website becomes more affordable and rewarding. acp856709 – Enjoy a flat $100 discount on any order. acp856709 – Unlock a $100 coupon pack usable across multiple purchases. acp856709 – Exclusive $100 discount just for new users. acp856709 – Extra $100 promo code for loyal, returning customers. acp856709 – $100 coupon specially tailored for users in the USA and Canada. Temu Coupon Code $100 Off For New Users In 2025 If you’re a new Temu user, you can receive the most benefits by using our verified code. This Temu coupon $100 off combined with the Temu coupon code $100 off ensures a budget-friendly shopping experience. acp856709 – Flat $100 discount on your first-ever order. acp856709 – $100 coupon bundle designed exclusively for new customers. acp856709 – Up to $100 coupon bundle usable across different purchases. acp856709 – Benefit from free shipping to 68 countries globally. acp856709 – An extra 30% discount for first-timLooking for the best deals online? Our Temu coupon code $100 off is exactly what you need to unlock maximum savings. Use the Temu code acp856709 to get exclusive discounts for users across the USA, Canada, and Europe. This is your chance to shop smart and save big. Whether you are searching for a Temu coupon $100 off or a Temu 100 off coupon code, we’ve got you covered with verified offers that work every time. What Is The Coupon Code For Temu $100 Off? Both new and existing Temu customers can enjoy exciting savings when they use our exclusive Temu coupon $100 off. With the $100 off Temue users on any item. How To Redeem The Temu Coupon $100 Off For New Customers? To use the Temu $100 coupon and claim the Temu $100 off coupon code for new users, follow these steps: Download and install the Temu app or visit the website. Sign up as a new user with your email or phone number. Add your favorite products to the cart. Go to checkout and paste the coupon code acp856709 in the promo code box. Your discount will be automatically applied, and you can enjoy your savings. Temu Coupon $100 Off For Existing Customers Even existing customers can reap the rewards with our exclusive code. Use the Temu $100 coupon codes for existing users and benefit from Temu coupon $100 off for existing customers free shipping without missing out. acp856709 – An additional $100 off for loyal Temu users. acp856709 – Receive a $100 coupon bundle for several orders. acp856709 – Free gift and express shipping in the USA and Canada. acp856709 – Enjoy 30% off on top of any running offer. acp856709 – Free global shipping to 68 countries. How To Use The Temu Coupon Code $100 Off For Existing Customers? To make the most of the Temu coupon code $100 off and Temu coupon $100 off code as a returning customer: Open the Temu app or website and log in. Browse through the products and add items to your cart. At checkout, enter acp856709 in the promo section. Review your updated total reflecting the applied discount. Complete your purchase and enjoy amazing savings. Latest Temu Coupon $100 Off First Order Your first order with Temu just got even better! The Temu coupon code $100 off first order, Temu coupon code first order, and Temu coupon code $100 off first time user are here to elevate your shopping experience. acp856709 – Flat $100 off the first purchase. acp856709 – Verified $100 Temu coupon code for initial orders. acp856709 – Use this code to get a $100 coupon for multiple uses. acp856709 – Free shipping included for first orders in 68 countries. acp856709 – Additional 30% off on your first transaction. How To Find The Temu Coupon Code $100 Off? Wondering where to grab the best Temu coupon $100 off or track the Temu coupon $100 off Reddit discussions? Simply sign up for Temu’s newsletter for insider updates. You can also follow Temu on social media for limited-time offers and verified codes. For the latest and working codes, visit trusted coupon websites like ours for real-time updates. Is Temu $100 Off Coupon Legit? Yes, the Temu $100 Off Coupon Legit claim is absolutely true. Our code acp856709 is thoroughly tested and verified. You can safely use it for your first order and even on future ones without any concerns. The Temu 100 off coupon legit status means the code is valid worldwide and doesn’t expire anytime soon. How Does Temu $100 Off Coupon Work? The Temu coupon code $100 off first-time user and Temu coupon codes 100 off allow you to receive up to $100 in discounts when making a purchase on Temu. It works by applying the code acp856709 during checkout, which instantly reduces your payable total. Whether you're a first-time or repeat buyer, this coupon code brings significant value to your orders. How To Earn Temu $100 Coupons As A New Customer? To earn your Temu coupon code $100 off and enjoy the 100 off Temu coupon code benefits, all you need to do is sign up as a new user. Then, enter our verified code acp856709 at checkout to get instant access to your $100 discount, free shipping, and other benefits designed specifically for first-time shoppers. What Are The Advantages Of Using The Temu Coupon $100 Off? Using the Temu coupon code 100 off and Temu coupon code $100 off brings amazing shopping perks: $100 off on your very first Temu order $100 coupon bundle for ongoing purchases Up to 70% discount on selected trending items Extra 30% discount for returning users Up to 90% savings on exclusive deals Free welcome gift for new customers Complimentary global shipping to 68 nations Temu $100 Discount Code And Free Gift For New And Existing Customers There’s more than just savings when using our Temu $100 off coupon code and $100 off Temu coupon code. You’ll also receive valuable gifts and extended discounts. acp856709 – $100 off your very first order on Temu. acp856709 – Extra 30% off on any purchase. acp856709 – Complimentary gift for new shoppers. acp856709 – Access to 70% off selected items on the app. acp856709 – Free gift and free delivery in 68 nations. Pros And Cons Of Using The Temu Coupon Code $100 Off This Month Explore the highlights and considerations when using the Temu coupon $100 off code and Temu 100 off coupon: Pros: Verified and easy to apply   Valid for new and existing customers   Flat $100 discount on all orders   Global shipping with no extra cost   Up to 30% extra off even on discounted items   Cons: Limited to one use per account   May not stack with other special offers   Terms And Conditions Of Using The Temu Coupon $100 Off In 2025 Before using the Temu coupon code $100 off free shipping and latest Temu coupon code $100 off, please review the following terms: The code has no expiration date.   Valid in 68 countries, including the USA, UK, and Canada.   Applicable to both new and existing users.   No minimum purchase amount required.   Can be used through both app and website.   Final Note: Use The Latest Temu Coupon Code $100 Off Using the Temu coupon code $100 off is your gateway to incredible savings and rewards on every order. Shop now to make the most of this limited-time opportunity. Enjoy unbeatable prices, exclusive gifts, and free global shipping with the Temu coupon $100 off by applying our verified code today. FAQs Of Temu $100 Off Coupon Is the Temu $100 off coupon real? Yes, the Temu $100 off coupon is real, verified, and works for both new and returning customers across 68 countries. How do I apply the Temu coupon code on my first order? Add products to your cart, head to checkout, and enter the code acp856709 to instantly get $100 off. Can existing customers use the Temu $100 off coupon? Absolutely. Existing customers can use the code acp856709 to get an extra $100 discount and free gifts. Does the coupon code expire? No, our coupon code acp856709 does not have an expiration date, so you can use it anytime. What do I get apart from the $100 off? Along with the $100 discount, you get up to 30% extra off, free gifts, and free shipping worldwide. !  
    • coupon, shopping on the app or website becomes more affordable and rewarding. acp856709 – Enjoy a flat $100 discount on any order. acp856709 – Unlock a $100 coupon pack usable across multiple purchases. acp856709 – Exclusive $100 discount just for new users. acp856709 – Extra $100 promo code for loyal, returning customers. acp856709 – $100 coupon specially tailored for users in the USA and Canada. Temu Coupon Code $100 Off For New Users In 2025 If you’re a new Temu user, you can receive the most benefits by using our verified code. This Temu coupon $100 off combined with the Temu coupon code $100 off ensures a budget-friendly shopping experience. acp856709 – Flat $100 discount on your first-ever order. acp856709 – $100 coupon bundle designed exclusively for new customers. acp856709 – Up to $100 coupon bundle usable across different purchases. acp856709 – Benefit from free shipping to 68 countries globally. acp856709 – An extra 30% discount for first-timLooking for the best deals online? Our Temu coupon code $100 off is exactly what you need to unlock maximum savings. Use the Temu code acp856709 to get exclusive discounts for users across the USA, Canada, and Europe. This is your chance to shop smart and save big. Whether you are searching for a Temu coupon $100 off or a Temu 100 off coupon code, we’ve got you covered with verified offers that work every time. What Is The Coupon Code For Temu $100 Off? Both new and existing Temu customers can enjoy exciting savings when they use our exclusive Temu coupon $100 off. With the $100 off Temue users on any item. How To Redeem The Temu Coupon $100 Off For New Customers? To use the Temu $100 coupon and claim the Temu $100 off coupon code for new users, follow these steps: Download and install the Temu app or visit the website. Sign up as a new user with your email or phone number. Add your favorite products to the cart. Go to checkout and paste the coupon code acp856709 in the promo code box. Your discount will be automatically applied, and you can enjoy your savings. Temu Coupon $100 Off For Existing Customers Even existing customers can reap the rewards with our exclusive code. Use the Temu $100 coupon codes for existing users and benefit from Temu coupon $100 off for existing customers free shipping without missing out. acp856709 – An additional $100 off for loyal Temu users. acp856709 – Receive a $100 coupon bundle for several orders. acp856709 – Free gift and express shipping in the USA and Canada. acp856709 – Enjoy 30% off on top of any running offer. acp856709 – Free global shipping to 68 countries. How To Use The Temu Coupon Code $100 Off For Existing Customers? To make the most of the Temu coupon code $100 off and Temu coupon $100 off code as a returning customer: Open the Temu app or website and log in. Browse through the products and add items to your cart. At checkout, enter acp856709 in the promo section. Review your updated total reflecting the applied discount. Complete your purchase and enjoy amazing savings. Latest Temu Coupon $100 Off First Order Your first order with Temu just got even better! The Temu coupon code $100 off first order, Temu coupon code first order, and Temu coupon code $100 off first time user are here to elevate your shopping experience. acp856709 – Flat $100 off the first purchase. acp856709 – Verified $100 Temu coupon code for initial orders. acp856709 – Use this code to get a $100 coupon for multiple uses. acp856709 – Free shipping included for first orders in 68 countries. acp856709 – Additional 30% off on your first transaction. How To Find The Temu Coupon Code $100 Off? Wondering where to grab the best Temu coupon $100 off or track the Temu coupon $100 off Reddit discussions? Simply sign up for Temu’s newsletter for insider updates. You can also follow Temu on social media for limited-time offers and verified codes. For the latest and working codes, visit trusted coupon websites like ours for real-time updates. Is Temu $100 Off Coupon Legit? Yes, the Temu $100 Off Coupon Legit claim is absolutely true. Our code acp856709 is thoroughly tested and verified. You can safely use it for your first order and even on future ones without any concerns. The Temu 100 off coupon legit status means the code is valid worldwide and doesn’t expire anytime soon. How Does Temu $100 Off Coupon Work? The Temu coupon code $100 off first-time user and Temu coupon codes 100 off allow you to receive up to $100 in discounts when making a purchase on Temu. It works by applying the code acp856709 during checkout, which instantly reduces your payable total. Whether you're a first-time or repeat buyer, this coupon code brings significant value to your orders. How To Earn Temu $100 Coupons As A New Customer? To earn your Temu coupon code $100 off and enjoy the 100 off Temu coupon code benefits, all you need to do is sign up as a new user. Then, enter our verified code acp856709 at checkout to get instant access to your $100 discount, free shipping, and other benefits designed specifically for first-time shoppers. What Are The Advantages Of Using The Temu Coupon $100 Off? Using the Temu coupon code 100 off and Temu coupon code $100 off brings amazing shopping perks: $100 off on your very first Temu order $100 coupon bundle for ongoing purchases Up to 70% discount on selected trending items Extra 30% discount for returning users Up to 90% savings on exclusive deals Free welcome gift for new customers Complimentary global shipping to 68 nations Temu $100 Discount Code And Free Gift For New And Existing Customers There’s more than just savings when using our Temu $100 off coupon code and $100 off Temu coupon code. You’ll also receive valuable gifts and extended discounts. acp856709 – $100 off your very first order on Temu. acp856709 – Extra 30% off on any purchase. acp856709 – Complimentary gift for new shoppers. acp856709 – Access to 70% off selected items on the app. acp856709 – Free gift and free delivery in 68 nations. Pros And Cons Of Using The Temu Coupon Code $100 Off This Month Explore the highlights and considerations when using the Temu coupon $100 off code and Temu 100 off coupon: Pros: Verified and easy to apply   Valid for new and existing customers   Flat $100 discount on all orders   Global shipping with no extra cost   Up to 30% extra off even on discounted items   Cons: Limited to one use per account   May not stack with other special offers   Terms And Conditions Of Using The Temu Coupon $100 Off In 2025 Before using the Temu coupon code $100 off free shipping and latest Temu coupon code $100 off, please review the following terms: The code has no expiration date.   Valid in 68 countries, including the USA, UK, and Canada.   Applicable to both new and existing users.   No minimum purchase amount required.   Can be used through both app and website.   Final Note: Use The Latest Temu Coupon Code $100 Off Using the Temu coupon code $100 off is your gateway to incredible savings and rewards on every order. Shop now to make the most of this limited-time opportunity. Enjoy unbeatable prices, exclusive gifts, and free global shipping with the Temu coupon $100 off by applying our verified code today. FAQs Of Temu $100 Off Coupon Is the Temu $100 off coupon real? Yes, the Temu $100 off coupon is real, verified, and works for both new and returning customers across 68 countries. How do I apply the Temu coupon code on my first order? Add products to your cart, head to checkout, and enter the code acp856709 to instantly get $100 off. Can existing customers use the Temu $100 off coupon? Absolutely. Existing customers can use the code acp856709 to get an extra $100 discount and free gifts. Does the coupon code expire? No, our coupon code acp856709 does not have an expiration date, so you can use it anytime. What do I get apart from the $100 off? Along with the $100 discount, you get up to 30% extra off, free gifts, and free shipping worldwide. !  
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post logs as described there using a site like https://mclo.gs and post the link to it here. It may have the information required to solve your problem.  
    • the error code comes up when i trry to run it and ive tried to fix it but i cant  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.