Posted September 22, 20213 yr 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.
September 22, 20213 yr 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
September 22, 20213 yr 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 September 22, 20213 yr by Myxtro
September 22, 20213 yr 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.
September 22, 20213 yr 50 minutes ago, diesieben07 said: You can't use the RegistryObjects from some random static initializer.
September 22, 20213 yr Author Is there a workaround for this? All I need is a list of mod blocks that certain mod tools can break.
September 22, 20213 yr 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.