Posted June 10, 201411 yr I am making multiple blocks and items, so what I wanted was a class for items and for blocks that I could call multiple times for each item and block in code, instead of having a class for every item and block just because it has a different unlocalizedname. Is there a way I can do this? This is my current item class (Just for a pickaxe): package com.mjj.colormod.items; import com.mjj.colormod.ColorMod; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.item.Item; import net.minecraft.item.ItemPickaxe; public class GreenPickaxe extends ItemPickaxe { public GreenPickaxe(ToolMaterial material) { super(material); setUnlocalizedName("greenPickaxe"); setTextureName(ColorMod.modid + ":" + getUnlocalizedName().substring(5)); setCreativeTab(CreativeTabs.tabTools); } }
June 11, 201411 yr What you are asking makes no sense. You can make as many blocks or items from a class as you want. As long as they each get registered with separate names... and should probably have unique textures as well. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
June 11, 201411 yr You could 1) be stupid and put everything in the constructor; 2) be smart and use chaining(i.e., when initializing your Item object, chain on methods to the end public static Item item = new ItemExample(ToolMaterialExample).setUnlocalizedName("name").method(args) ); 3) (this is if you already have 2 done) Cast your Item object to your item class when initializing it so you can chain on methods that you make for setters that you add, that aren't in the vanilla game, or change something for your item.; (and sequituri, I think his question was how to do multiple names and textures and such from one class. ^this answers that.)
June 11, 201411 yr Author Alix, Thanks for your response, but I'm misunderstanding one thing, can you give me an example on what you mean by casting my item object to my item class when initializing? Here is my green pickaxe now (in the mod file): greenPickaxe = new GreenPickaxe(greenMaterial).setUnlocalizedName("greenMaterial").setTextureName("greenMaterial"); The thing is, which I'm assuming gets fixed in step 3, whenever I launch the game it doesn't understand .setUnlocalizedName. It want's it in the constructor for some reason. I assume you already know all of this and I'm stupid for typing it, but I don't understand so If you could give an example of what I need to change. I know that in the actual Item class they call .setUnlocalizedName from out of the constructor on the actual object but I'm not sure how I need to do that myself. I hope you understand what I'm saying here and can answer my question. Thanks
June 11, 201411 yr As long as each method in the chain ends with "return this", you should be able to chain as you were told. The constructor does that automatically, so does setUnlocalizedName and a couple others. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
June 11, 201411 yr Author Turns out, all you have to do is keep setUnlocalizedName in the constructor, but when you chain it onto the end of the item it will override the constructor, so in that way you can use one class for multiple items. Thanks
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.