Posted July 9, 201411 yr I pulled up the ItemFood Class in Forge and it has a lot of fields with p_i#####_#_ with no explanation of what those numbers represent or if they are fields I have to create. So, I fiddled and came up with this. ------------------------------------------------------------------------- import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemFood; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.potion.PotionEffect; import net.minecraft.world.World; public class ItemFoodporriage 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; public ItemFoodporriage(int 1, float 2, boolean 3) { this.itemUseDuration=32; this.healAmount=4; this.isWolfsFavoriteMeat=false; this.saturationModifier=15; this.setCreativeTab(CreativeTabs.tabFood); setUnlocalizedName(Recipes.MODID + "_" + "porriage"); setTextureName(Recipes.MODID + ":" + "porriage"); setCreativeTab(CreativeTabs.tabFood); } public ItemFoodporriage setAlwaysEdible() { this.alwaysEdible=false; return this; } } ------------------------------------------------------------------------ I am receiving 2 Syntax errors. The first is "Syntax error on token "1", invalid VariableDeclaratorId" but near the (int 1, Float 2) line. And the second error is "Syntax error, insert "}" to complete BlockStatements" is appearing after the setCreativeTab line towards the bottom. I know I am missing lines of code, I'm not finished yet, but I was hoping to get some feedback or tips for the code thus far. Also, if someone could explain what the p_i#####_#_ thing is I would appreciate it. I believe it is a place holder, but I am not certain with what values I am supposed to replace them. Thank you
July 9, 201411 yr Basic Java. Numbers are not valid names. There is no point in keeping unused parameters. You are also using setCreativeTab(...) twice. I recommend you extend ItemFood, and find the vanilla foods for practical example.
July 10, 201411 yr Author Thanks. So change "public class ItemFoodporriage extends Item" to "public class ItemFoodporriage extends ItemFood" Some of the numbers were place holders until I could figure out what needed to go there. As far as the Vanilla foods, when I try to open the file I get this error: "The Class File Viewer cannot handle the given input". Any ideas?
July 12, 201411 yr Author Found some of the food files and I have a question. Which of the following strings is the correct way to code a new food item? porriage = (ItemModSoup) new ItemModSoup(3, 1.0F, false).setUnlocalizedName(Recipes.MODID + "_" + "porriage").setTextureName(Recipes.MODID + ":" + "porriage"); OR porriage = new ItemModSoup(3, 1.0F, false).setUnlocalizedName(Recipes.MODID + "_" + "porriage").setTextureName(Recipes.MODID + ":" + "porriage") Also, does this code need to be on the main mod page or the class page under which the new item falls?
July 12, 201411 yr Casting new ItemModSoup() to ItemModSoup is moot, as an ItemModSoup is already returned. The second would be the way to go. Also, don't you mean to write porridge?
July 12, 201411 yr Author So much for spell check. Thanks, Elyon. As far as the code, when I use the second method I get the following error: "Type mismatch: cannot convert from Item to ItemModSoup" I am assuming that means I need a line that says "public static ItemFood extends Item" somewhere on the page or a new class that states it, but you know what they say about people who assume. I remember Java coding being so much easier. Either I really lost it or it has changed that much. Regardless, the old adage of "if you don't use it, you lose it" is statement(true) in this case.
July 12, 201411 yr Java hasn't changed that much - not the Java you need here, anyway; I fear for your sanity public static ItemFood extends Item doesn't make any sense, either; you have a class that extends another class, or you have a field of a specific class. Not both, the inheritance is inferred from the class definition (or declaration, but they're one and the same in Java). What you probably want is public static ItemModSoup porridge; , and then assign this field using the line you pasted earlier. Finally, we don't usually call classes or files "pages" - that terminology is usually reserved for pages in memory.
July 12, 201411 yr Found some of the food files and I have a question. Which of the following strings is the correct way to code a new food item? porriage = (ItemModSoup) new ItemModSoup(3, 1.0F, false).setUnlocalizedName(Recipes.MODID + "_" + "porriage").setTextureName(Recipes.MODID + ":" + "porriage"); OR porriage = new ItemModSoup(3, 1.0F, false).setUnlocalizedName(Recipes.MODID + "_" + "porriage").setTextureName(Recipes.MODID + ":" + "porriage") Also, does this code need to be on the main mod page or the class page under which the new item falls? The recommended way is to not type cast when it is not needed. Type casting means you made some methods in ItemModSoup that you plan to use later on this instance. Otherwise, you can let Item#setUnlocalizedName(String) type-shadow your instance. FML also prefers you initialize and register items and blocks into FMLPreInitializationEvent, as a safe mod-cycle. You can cache the instances wherever you want at the same time.
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.