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 adding a feature in my mod that will let the player craft grass blocks. Basically the player will right click on a grass block with a shovel and the grass block will be turned into dirt, then the player will receive a grass seed. The grass seed can then be used in a recipe with dirt to craft a grass block. However, I am having an issue when checking if the player has a shovel in their hand, because I am using an itemstack of the item in the players hand, if the player right clicks with an empty hand it crashes. So I tried writing a statement that would check if a player has nothing in their hand and if they do kick them out of the if statement series, however it's not working. So my question is how do I properly perform this check? Below is my code. TIA

 

	@ForgeSubscribe
public void onPlayerInteract(PlayerInteractEvent event) {

	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.inventory.currentItem == 0)) {

			if(itemstack.itemID == 269 || itemstack.itemID == 273 || itemstack.itemID == 256 || itemstack.itemID == 284 || itemstack.itemID == 277) {

				//Change Grass to dirt
				if(event.entityPlayer.worldObj.getBlockId(event.x, event.y, event.z) == 2) {
					event.entityPlayer.worldObj.setBlock(event.x, event.y, event.z, 3);

					//Drop "Grass Seeds" in front of player
					event.entityPlayer.dropPlayerItem(new ItemStack(myMod.grassSeed, 1, 0));
				}
			}
		}
	}		
}

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!

Guest
This topic is now closed to further replies.

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.