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

Hello!

 

I am currently porting a mod from 1.16 to 1.18, and have run into an issue.

Originally in 1.16, Minecraft registry items could be referenced and found from within the registry using their Registry name, per the method 

Registry.ITEM.getOrDefault(new ResourceLocation(registryNameString));

After 1.17 however, these registries were wrapped into ResourceKeys and the original Registries were deprecated.

With this port, I am looking to compare an item from the Items class (i.e. Items.AIR) with a RegistryName stored in a config, essentially trying to verify if the RegistryName pulled from the config is AIR or not.

The following code was what was previously used:

for (String s : ClientConfig.items.get()) {

	Item item = Registry.ITEM_REGISTRY.getOrDefault(new ResourceLocation(s));
	if (item == Items.AIR) {

		System.out.println(s + " not found");

	} else {

		cache.add(item);

	}

}

The cache object being a set of Items (Set<Item>)  and every String s being a different RegistryName pulled (as a String) from the config.

 

If there is a new/better way to run this comparison, please let me know. Otherwise, I would appreciate some help understanding the new way to reference Minecraft registry items from the ResourceKey<Registry<Item>> object.

 

Thanks in advance!

 

- Rey

  • Author

The purpose of the config is to allow users to change which items they want this mod to apply to... is there a good way to apply a tag to only the items listed in the config?

 

  • Author

I appreciate your pointers but in this case I want the config to be where the options can be adjusted, not through data packs, plus it is a client side only mod. I appreciate your help regardless, especially by pointing me to the forge registries. Thank you!

Edited by Reyzerbit

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.