Posted March 22, 201510 yr I want a creature to drop an item specified by name in the config. In 1.6.4 I was I was looking up the name in a HashMap I created using Item.itemlist. itemlist is no longer used in 1.7.10 so I'm looking of another way to do this. At it's most basic, this is what I'm trying to do... public CPDropItem(LivingDropsEvent event) { String itemname = "Baked Patato"; Item drop = Item.?; // How do I get the Item from the itemname? event.entity.dropItem(drop, 1); } It's looking like the Registry utilities might be the way to go but I haven't had any luck find examples or tutorials.
March 22, 201510 yr I have two questions: 1) Do you have to use Localized name? 2) Is it always going to be baked potato? If not, use Items class to determine most of items. I would use this code. public CPDropItem(LivingDropsEvent event) { //I'm not using itemname //String itemname = "Baked Patato"; Item drop = (Item) Item.itemRegistry.getObject("baked_potato") event.entity.dropItem(drop, 1); }
March 22, 201510 yr Author 1) I would like to use the localized name to keep the config user friendly. 2) No it wouldn't always be "Baked Patato". It was just a simple example of what I would put into the variable itemname.
March 22, 201510 yr You could make the config require baked_potato and the add minecraft: prefix. Then combine diesieben's and Anon's suggestions.
March 22, 201510 yr Author First, thank you all for all your help. Hmmm.. I guess I just see the localized name as being "more friendly". Users would only need to put the name they see in game in the config to get it working, without having to dig around for what it's named in code. But you do bring up a good point about it making the mod breakable. I went ahead and set it up to use GameRegistry.findItem but findItem requires the modid. I added modid to the table in the config but now my nice clean config is looking less and less user friendly. But it works. I there no way to build a HashMap of all the available items in game? I was using Item.itemlist in 1.6.4 but I need to find an alternative for 1.7.10
March 22, 201510 yr I there no way to build a HashMap of all the available items in game? I was using Item.itemlist in 1.6.4 but I need to find an alternative for 1.7.10 There is the Item.itemRegistry. You can construct a list of all items in the game like so: ArrayList<Item> itemList = Lists.newArrayList(); Iterable<Item> items = Item.itemRegistry; for (Item item : items) itemList.add(item); Maker of the Craft++ mod.
March 23, 201510 yr Item.itemRegistry was exactly what I was looking for. Thank you. No problem. Maker of the Craft++ mod.
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.