So I'm trying to make a custom block in my mod. I tried to register it, but found out that the API has changed and I had no idea how to register my block. After some research, I found out that you need to register the Block AND the ItemBlock. So I tried making an ItemBlock out of my Block using this code:
public ItemBlock itemBlock = new ItemBlock(this);
This code is inside my Block class. Then I tried registering the block:
event.getRegistry().register(new myBlockInMyMod());
event.getRegistry().register(new myBlockInMyMod().itemBlock);
I get this error code on IntelliJ:
register (net.minecraft.block.Block) in IForgeRegistry cannot be applied to net.minecraft.item.ItemBlock
Am I doing anything wrong here? Because the register method doesn't seem to accept ItemBlocks :/
Ok, you have two problems:
Registry.Register<Item>
event, not theRegister<Block>
event, as they are different registries.The first problem is easy to fix:
However, you don't currently have a reference to your block. You instantiate it and shove it directly into the registry, never holding onto a reference to refer to later. Most people create static fields in their main mod class.
You can, if you want, store a reference to the ItemBlock as you are, but when you create a new instance of your block, that ItemBlock has no bearing on the block you registered. They're different objects. You must store a reference to your block somewhere.
The second problem requires you write a second event handler method, only you change
<Block>
to<Item>
: TheBlocks.REGISTERY
cannot acceptItems
, you need to wait for theItems.REGISTRY
to fire its registration event.