Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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

  • 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.

  • 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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.