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'm making some tools and I'm using a Set of type Block to specify on what blocks the tools would work. This is all in my ItemInit class which I use to register items. See below.

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(Blocks.ANDESITE);

This works fine with minecraft blocks. Problems occur when I want to use mod blocks like this:

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(BlockInit.AMBER_BLOCK.get());

 

I get an error while loading the game, which is a NullPointerException. 

Exception message: java.lang.NullPointerException: Registry Object not present: extinctioncraft:amber_block

 

It seems my block can't be found by this set despite the block working fine in the game itself. 

 

I already tried the following without success:

- Checked if the BlockInit is registered in the main class. ( BlockInit.BLOCKS.register(bus); )

- Checked if the block is registered in the BlockInit class. 

where do you use the Set?
you need to use a Supplier when using RegistryObjects before they are initialized (or RegistryObjects)
create a Set of RegistryObjects and use RegistryObject#get when you want to use the Set

  • Author
29 minutes ago, Luis_ST said:

where do you use the Set?
you need to use a Supplier when using RegistryObjects before they are initialized (or RegistryObjects)
create a Set of RegistryObjects and use RegistryObject#get when you want to use the Set

It is used when creating a ToolItem in the third argument. 

public static final RegistryObject<Item> IRON_GEO_HAMMER = ITEMS.register("iron_geo_hammer", 
			() -> new ToolItem(1, 1, ItemTier.IRON, EFFECTIVE_ON, new Item.Properties()));

Do I need to change anything here?

Edited by Myxtro

  • Author
2 minutes ago, Luis_ST said:

replace "EFFECTIVE_ON" with the Set

EFFECTIVE_ON is the name of the set. Here's the set for refference. 

private static Set<Block> EFFECTIVE_ON = Sets.newHashSet(BlockInit.AMBER_BLOCK.get());

I could ofcourse replace EFFECTIVE_ON with the set but I would then have to repeat this for each item it is applicable to.

50 minutes ago, diesieben07 said:

You can't use the RegistryObjects from some random static initializer.

 

  • Author

Is there a workaround for this? All I need is a list of mod blocks that certain mod tools can break. 

58 minutes ago, Luis_ST said:

you need to use a Supplier when using RegistryObjects before they are initialized (or RegistryObjects)
create a Set of RegistryObjects and use RegistryObject#get when you want to use the Set

try this

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.