I started out with five items and had them grouped in a custom creative tab, then I converted them to food and now they're missing (I can still get to them with the /give command though). Also, my language files seem like they're set up but nothing changes when I load the game.
public static Item milk_chocolate_bar;
public static Item white_chocolate_bar;
public static Item dark_chocolate_bar;
public static Item chocolate_milk;
public static Item hot_chocolate;
public static void init(){
milk_chocolate_bar = new Item().setUnlocalizedName("milk_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
white_chocolate_bar = new Item().setUnlocalizedName("white_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
dark_chocolate_bar = new Item().setUnlocalizedName("dark_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
chocolate_milk = new Item().setUnlocalizedName("chocolate_milk").setCreativeTab(MicroMod.tabChocoMod);
hot_chocolate = new Item().setUnlocalizedName("hot_chocolate").setCreativeTab(MicroMod.tabChocoMod);
}
public static void register(){
GameRegistry.registerItem(milk_chocolate_bar = new ItemFoodExtend("milk_chocolate_bar", 2, 0.4F, false), milk_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(white_chocolate_bar = new ItemFoodExtend("white_chocolate_bar", 2, 0.4F, false), white_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(dark_chocolate_bar = new ItemFoodExtend("dark_chocolate_bar", 2, 0.4F, false), dark_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(chocolate_milk = new ItemFoodExtend("chocolate_milk", 2, 0.4F, false), chocolate_milk.getUnlocalizedName().substring(5));
GameRegistry.registerItem(hot_chocolate = new ItemFoodExtend("hot_chocolate", 2, 0.4F, false), hot_chocolate.getUnlocalizedName().substring(5));
}
public static void registerRender(Item item){
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
My lang file (a few people seemed to have errors when they wrote the filename in caps so I took care to write it out as "eng_US.lang")
< en_US.lang - English language localization file >
item.milk_chocolate_bar.name=Milk Chocolate Bar
item.white_chocolate_bar.name=White Chocolate Bar
item.dark_chocolate_bar.name=Dark Chocolate Bar
tile.milk_chocolate_block.name=Milk Chocolate Block
tile.white_chocolate_block.name=White Chocolate Block
tile.dark_chocolate_block.name=Dark chocolate Block
tile.milk_chocolate_brick.name=Milk Chocolate Brick
tile.white_chocolate_brick.name=White Chocolate Brick
tile.dark_chocolate_brick.name=Dark chocolate Brick
tile.block_of_lead.name=Block of Lead
tile.block_of_graphite.name=Block of Graphite
tile.block_of_basalt.name=Basalt
tile.block_of_white_marble.name= White Marble
tile.block_of_green_marble.name=Green Marble
itemgroup.tabChocoMod=ChocoBlocks Mod
itemgroup.tabMaterialsMod=Materials Mod
I still have a copy of the items file before I made the conversion too, would it be better to go back to that and try again?
EDIT: Apparently the food items all got moved over to the vanilla food tab, so somehow my custom tab is being overridden. I have a vague idea as to what's going on but it's too soon to say if it's that. Lang files are still giving me trouble.
lang file should be 'en_US.lang' not 'eng_US.lang'
Looking at your code, you initialize all your items in init() but override everything you did in register(). You only set the creative tab in init().
Pick one: do you want to initialize your items in the same spot as you register them, or do you want to do that separately?
Also, you should never have to use substring(5) to register . . . use the registry name as well as unlocalized name, because that's going to be much more important in 1.9.
Use setRegistryName("modid","name") as well as setting the unlocalized name. When you register renders, do new ModelResourceLocation(item.getRegistryName().toString(), "inventory"))
Ah, nice save on the 3rd letter. Thank you! That's been driving me bonkers @___@
Also I took out the ".setCreativeTab(MicroMod.tabChocoMod)" from my init() and when I loaded the game I found that my custom food was hanging out in the vanilla food tab. I had another tutorial open on the side where the person assigned a creative tab right in his custom item class (the first couple of videos I watched didn't cover that) so I tried the same method on my own food class. Now my food items are where I wanted them to be. I was under the impression that items would not be included in any tab unless you manually set one.
So I'd have to take out all instances of substring(5), then append "item.getRegistryName().toString()," where you've specified, correct? Is that something that will work in 1.8.9 or is it just in preparation for 1.9?
So I'd have to take out all instances of substring(5), then append "item.getRegistryName().toString()," where you've specified, correct? Is that something that will work in 1.8.9 or is it just in preparation for 1.9?
Yes, this works in 1.8.x as well as 1.9, and all modders are being encouraged to use the latest (and safest) registration techniques.
It's a tad complicated because you seem to want your lang file entries to not have item. or tile. In order to not have to change your .lang files, I recommend you use helper methods like these that avoid using the unlocalized name for registration:
Helper methods are especially useful in 1.9 -- I can register an ItemBlock with the block there (because that's no longer automatic in 1.9).
Because the registry name should never change but I may want to change the unlocalized name, these methods let me use one name argument or two. Here's an example of how I called these (where I did change the unlocalized name at one point)
I usually initialize my blocks and items separately from registering them, but you can adapt this to whatever you're used to.
Finally, if you find a technique that works for you, go for it. You do not need to use exactly what I use here. Just be aware of good modding practice, such as registering with the registry name instead of modifying the unlocalized name.
Oh, and are you still initializing your items twice? In your previous snippet of code, you set all the properties and objects of your items / blocks in init(), and then completely erase all that work in register() when you re-initialize them. Pick one, so that your code is less confusing when something goes wrong.
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
At the moment I've got it set up something like this,
public static void init(){
milk_chocolate_bar = new ItemChocoFoodExtend("milk_chocolate_bar", 2, 0.4F, false).setUnlocalizedName("milk_chocolate_bar").setRegistryName(Reference.MOD_ID, "Milk Chocolate Bar");
}
public static void register(){
GameRegistry.registerItem(milk_chocolate_bar, milk_chocolate_bar.getUnlocalizedName().substring(5));
}
Trying to do away with substring(5) caused a bit of a mess (to the tune of models and textures not loading, I think I did it wrong). I suppose I'l have to revisit that tomorrow. Thank you again for looking at my code!
setRegistryName is not a substitute for lang files. I don't think you are allowed to have spaces.
Generally, I have no reason to use different keys for the unlocalized name and registry name -- using.setRegistryName(Reference.MOD_ID, "milk_chocolate_bar") should work much better than passing "Milk Chocolate Bar"
Happy modding!
Rollback Post to RevisionRollBack
Click this banner for a list of illegal mod distributors -- only download from legal sites!
I started out with five items and had them grouped in a custom creative tab, then I converted them to food and now they're missing (I can still get to them with the /give command though). Also, my language files seem like they're set up but nothing changes when I load the game.
My items class
package microrave.micromodsuite.init;
import microrave.micromodsuite.MicroMod;
import microrave.micromodsuite.Reference;
import net.minecraft.client.Minecraft;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.item.Item;
import net.minecraftforge.fml.common.registry.GameRegistry;
public class MicroItems {
public static Item milk_chocolate_bar;
public static Item white_chocolate_bar;
public static Item dark_chocolate_bar;
public static Item chocolate_milk;
public static Item hot_chocolate;
public static void init(){
milk_chocolate_bar = new Item().setUnlocalizedName("milk_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
white_chocolate_bar = new Item().setUnlocalizedName("white_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
dark_chocolate_bar = new Item().setUnlocalizedName("dark_chocolate_bar").setCreativeTab(MicroMod.tabChocoMod);
chocolate_milk = new Item().setUnlocalizedName("chocolate_milk").setCreativeTab(MicroMod.tabChocoMod);
hot_chocolate = new Item().setUnlocalizedName("hot_chocolate").setCreativeTab(MicroMod.tabChocoMod);
}
public static void register(){
GameRegistry.registerItem(milk_chocolate_bar = new ItemFoodExtend("milk_chocolate_bar", 2, 0.4F, false), milk_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(white_chocolate_bar = new ItemFoodExtend("white_chocolate_bar", 2, 0.4F, false), white_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(dark_chocolate_bar = new ItemFoodExtend("dark_chocolate_bar", 2, 0.4F, false), dark_chocolate_bar.getUnlocalizedName().substring(5));
GameRegistry.registerItem(chocolate_milk = new ItemFoodExtend("chocolate_milk", 2, 0.4F, false), chocolate_milk.getUnlocalizedName().substring(5));
GameRegistry.registerItem(hot_chocolate = new ItemFoodExtend("hot_chocolate", 2, 0.4F, false), hot_chocolate.getUnlocalizedName().substring(5));
}
public static void registerRenders(){
registerRender(milk_chocolate_bar);
registerRender(white_chocolate_bar);
registerRender(dark_chocolate_bar);
registerRender(chocolate_milk);
registerRender(hot_chocolate);
}
public static void registerRender(Item item){
Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(item, 0, new ModelResourceLocation(Reference.MOD_ID + ":" + item.getUnlocalizedName().substring(5), "inventory"));
}
}
My lang file (a few people seemed to have errors when they wrote the filename in caps so I took care to write it out as "eng_US.lang")
< en_US.lang - English language localization file >
item.milk_chocolate_bar.name=Milk Chocolate Bar
item.white_chocolate_bar.name=White Chocolate Bar
item.dark_chocolate_bar.name=Dark Chocolate Bar
tile.milk_chocolate_block.name=Milk Chocolate Block
tile.white_chocolate_block.name=White Chocolate Block
tile.dark_chocolate_block.name=Dark chocolate Block
tile.milk_chocolate_brick.name=Milk Chocolate Brick
tile.white_chocolate_brick.name=White Chocolate Brick
tile.dark_chocolate_brick.name=Dark chocolate Brick
tile.block_of_lead.name=Block of Lead
tile.block_of_graphite.name=Block of Graphite
tile.block_of_basalt.name=Basalt
tile.block_of_white_marble.name= White Marble
tile.block_of_green_marble.name=Green Marble
itemgroup.tabChocoMod=ChocoBlocks Mod
itemgroup.tabMaterialsMod=Materials Mod
I still have a copy of the items file before I made the conversion too, would it be better to go back to that and try again?
EDIT: Apparently the food items all got moved over to the vanilla food tab, so somehow my custom tab is being overridden. I have a vague idea as to what's going on but it's too soon to say if it's that. Lang files are still giving me trouble.
lang file should be 'en_US.lang' not 'eng_US.lang'
Looking at your code, you initialize all your items in init() but override everything you did in register(). You only set the creative tab in init().
Pick one: do you want to initialize your items in the same spot as you register them, or do you want to do that separately?
Also, you should never have to use substring(5) to register . . . use the registry name as well as unlocalized name, because that's going to be much more important in 1.9.
Use setRegistryName("modid","name") as well as setting the unlocalized name. When you register renders, do new ModelResourceLocation(item.getRegistryName().toString(), "inventory"))
Ah, nice save on the 3rd letter. Thank you! That's been driving me bonkers @___@
Also I took out the ".setCreativeTab(MicroMod.tabChocoMod)" from my init() and when I loaded the game I found that my custom food was hanging out in the vanilla food tab. I had another tutorial open on the side where the person assigned a creative tab right in his custom item class (the first couple of videos I watched didn't cover that) so I tried the same method on my own food class. Now my food items are where I wanted them to be. I was under the impression that items would not be included in any tab unless you manually set one.
So I'd have to take out all instances of substring(5), then append "item.getRegistryName().toString()," where you've specified, correct? Is that something that will work in 1.8.9 or is it just in preparation for 1.9?
Yes, this works in 1.8.x as well as 1.9, and all modders are being encouraged to use the latest (and safest) registration techniques.
It's a tad complicated because you seem to want your lang file entries to not have item. or tile. In order to not have to change your .lang files, I recommend you use helper methods like these that avoid using the unlocalized name for registration:
Helper methods are especially useful in 1.9 -- I can register an ItemBlock with the block there (because that's no longer automatic in 1.9).
Because the registry name should never change but I may want to change the unlocalized name, these methods let me use one name argument or two. Here's an example of how I called these (where I did change the unlocalized name at one point)
I usually initialize my blocks and items separately from registering them, but you can adapt this to whatever you're used to.
Finally, if you find a technique that works for you, go for it. You do not need to use exactly what I use here. Just be aware of good modding practice, such as registering with the registry name instead of modifying the unlocalized name.
Oh, and are you still initializing your items twice? In your previous snippet of code, you set all the properties and objects of your items / blocks in init(), and then completely erase all that work in register() when you re-initialize them. Pick one, so that your code is less confusing when something goes wrong.
At the moment I've got it set up something like this,
Trying to do away with substring(5) caused a bit of a mess (to the tune of models and textures not loading, I think I did it wrong). I suppose I'l have to revisit that tomorrow. Thank you again for looking at my code!
setRegistryName is not a substitute for lang files. I don't think you are allowed to have spaces.
Generally, I have no reason to use different keys for the unlocalized name and registry name -- using.setRegistryName(Reference.MOD_ID, "milk_chocolate_bar") should work much better than passing "Milk Chocolate Bar"
Happy modding!