Jump to content

Recommended Posts

Posted

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.

Posted

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

Posted

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.

Posted

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

Posted

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.

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



×
×
  • Create New...

Important Information

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