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 new to Minecraft modding, though I have been programming with Java for about a year now. I fired up forge and created a new GUI bar which works fine, I used a bunch of @SubscribeEvent annotations: from destroying blocks to player eating an item and they worked fine.

 

I am using Forge 1.12

 

Today I wanted to add a new block and checked out the Forge docs, it is said:

Quote

The recommended way to register things is through the RegistryEvents. These events are fired right after preinitialization

However, it seems the RegistryEvent.Register event won't fire for me. I tried this both for the Block, Item class. I looked at this thread but didn't figure out what's wrong.

 

Here's a code snippet of my block - related classes:

 

Blocks.java

public final class Blocks {
	public static Block rock;

	public static void init() { //this method is called at FMLPreInitializationEvent
		rock = new RockBlock("rock_block"); 
	}
	
	@SubscribeEvent
	public void registerBlocks(RegistryEvent.Register<Block> event) {
		System.out.println("registry event test"); // put a break point here but debugging mode won't stop it when starting minecraft or entering a world
	    event.getRegistry().registerAll(Blocks.rock);
	}

//	public static void registerRenders() {
//		registerRender(rock);
//	}

//	private static void registerRender(Block block) {
//		System.out.println(block.getRegistryName());
//		Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(Item.getItemFromBlock(block), 0,
//				new ModelResourceLocation(block.getRegistryName(), "inventory"));
//	}

}

 

RockBlock.java

public class RockBlock extends Block {
	public RockBlock(String unlocalizedName, Material material, float hardness, float resistance){
		super(material);
		this.setRegistryName("rock_block");
		this.setUnlocalizedName(unlocalizedName);
		this.setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
		this.setHardness(hardness);
		this.setResistance(resistance);
	}
	
	public RockBlock(String unlocalizedName, float hardness, float resistance){
		this(unlocalizedName, Material.ROCK, hardness, resistance);
	}
	
	public RockBlock(String unlocalizedName){
		this(unlocalizedName, 2.0f, 10.0f);
	}
}

 

Does anyone have any ideas how I could fix this issue?

 

Thanks in advance for answers.

  • Author

Hmm, no, I think I haven't done that. Is that what's the "@Mod.EventBusSubscriber" annotation is for?

 

Edit: Hah, I figured it out now that you pointed it out. I have forgotten that I registered my handler class for the GUI bar that I had made, what a fool... Thanks anyways

Edited by Dwar

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.