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 am working on updating my Minecraft mod, the Recipe Expansion Pack, to 1.7 and I can't figure out how to register events.

 

I have a ModEvents class with the following code

package net.richardsprojects.recipexpack.main;

//Cut out the imports here for this post to save space so none of the issues come from the imports

public class ModEvents
{

@SubscribeEvent
public void shovelHandler(PlayerInteractEvent event) {

	System.out.println("Testttttttttttttttttttttttttt!!!!!!!!!!!!!!!!!!!!!!!!!!");

	ItemStack itemstack = event.entityPlayer.inventory.getCurrentItem();

	//Check to see if the player right clicked
	if(event.action.equals(event.action.RIGHT_CLICK_BLOCK)) {

		//Check if player has nothing in their hand
		//if(event.entityPlayer.getCurrentArmor(0) != null) {

			if(itemstack.getDisplayName() == "Wooden Shovel" || itemstack.getDisplayName() == "Stone Shovel" || itemstack.getDisplayName() == "Iron Shovel" || itemstack.getDisplayName() == "Gold Shovel" || itemstack.getDisplayName() == "Diamond Shovel") {

				//Change Grass to dirt
				if(event.entityPlayer.worldObj.getBlock(event.x, event.y, event.z) == Block.getBlockFromName("Grass")) {
					event.entityPlayer.worldObj.setBlock(event.x, event.y, event.z, Blocks.dirt, 3, 0);

					//Drop "Grass Seeds" in front of player
					event.entityPlayer.dropItem(ItemGrassSeeds.grassSeeds, 1);

					//Reduce the durability
					itemstack.damageItem(1, event.entityPlayer);
				}
			//}
		}
	}
}
}

 

I used the SubscribeEvent annotation because I read that that was the new one. Below my PreInit event in my main class:

    @EventHandler 
    public void preInit(FMLPreInitializationEvent event) {

    	ItemGrassSeeds.mainRegistry();
    	FMLCommonHandler.instance().bus().register(new ModEvents());
    }

 

I do not get any errors just nothing happens when I right click with my shovel and no "Test" line appears in my console. This is making me believe that I am not registering the event right. Any help would be greatly appreciated! :)

Creator of the Recipe Expansion Pack mod.

http://www.minecraftforum.net/topic/1983421-172-forge-recipe-expansion-pack-version-012/

Updated to 1.7.2!

PlayerInteractEvent is posted on the MinecraftForge bus not the FML bus.

 

FML Bus = FMLCommonHandler.instance().bus()

MinecraftForge Bus = MinecraftForge.EVENT_BUS

 

In other words, use the MinecraftForge EventBus.

  • Author

PlayerInteractEvent is posted on the MinecraftForge bus not the FML bus.

 

FML Bus = FMLCommonHandler.instance().bus()

MinecraftForge Bus = MinecraftForge.EVENT_BUS

 

In other words, use the MinecraftForge EventBus.

 

Okay, that seemed to solve it, the event is now registered and seems prints out the "test" text to the log when I interact. However, the event code still doesn't work. In my event I am trying to detect if the player has a shovel (of any type in their hand). Under the old system I simply check using the item id but since that doesn't seem to work in 1.7 I am checking using the item name (downside won't work if the item is renamed on an anvil). The problem is it is not working at all it doesn't detect I have a shovel in my hand and print out test 2. Is there a better way to check the type of item a player has in their hand? Below is my code:

	@SubscribeEvent
public void shovelHandler(PlayerInteractEvent event) {

	System.out.println("Testttttttttttttttttttttttttt!!!!!!!!!!!!!!!!!!!!!!!!!!");

	ItemStack itemstack = event.entityPlayer.inventory.getCurrentItem();

	//Check to see if the player right clicked
	if(event.action.equals(event.action.RIGHT_CLICK_BLOCK)) {

		//Check if player has nothing in their hand
		//if(event.entityPlayer.getCurrentArmor(0) != null) {

			if(itemstack.getDisplayName() == "Wooden Shovel" || itemstack.getDisplayName() == "Stone Shovel" || itemstack.getDisplayName() == "Iron Shovel" || itemstack.getDisplayName() == "Gold Shovel" || itemstack.getDisplayName() == "Diamond Shovel") {

				System.out.println("Test2");

				//Change Grass to dirt
				if(event.entityPlayer.worldObj.getBlock(event.x, event.y, event.z) == Block.getBlockFromName("Grass")) {
					event.entityPlayer.worldObj.setBlock(event.x, event.y, event.z, Blocks.dirt, 3, 0);

					//Drop "Grass Seeds" in front of player
					event.entityPlayer.dropItem(ItemGrassSeeds.grassSeeds, 1);

					//Reduce the durability
					itemstack.damageItem(1, event.entityPlayer);
				}
			//}
		}
	}
}

Creator of the Recipe Expansion Pack mod.

http://www.minecraftforum.net/topic/1983421-172-forge-recipe-expansion-pack-version-012/

Updated to 1.7.2!

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.