Jump to content

Recommended Posts

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.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.