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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Thanks, I've now installed a slightly newer version and the server is at least starting up now.
    • i have the same issue. Found 1 Create mod class dependency(ies) in createdeco-1.3.3-1.19.2.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Found 11 Create mod class dependency(ies) in createaddition-fabric+1.19.2-20230723a.jar, which are missing from the current create-1.19.2-0.5.1.i.jar Detailed walkthrough of mods which rely on missing Create mod classes: Mod: createaddition-fabric+1.19.2-20230723a.jar Missing classes of create: com/simibubi/create/compat/jei/category/sequencedAssembly/JeiSequencedAssemblySubCategory com/simibubi/create/compat/recipeViewerCommon/SequencedAssemblySubCategoryType com/simibubi/create/compat/rei/CreateREI com/simibubi/create/compat/rei/EmptyBackground com/simibubi/create/compat/rei/ItemIcon com/simibubi/create/compat/rei/category/CreateRecipeCategory com/simibubi/create/compat/rei/category/WidgetUtil com/simibubi/create/compat/rei/category/animations/AnimatedBlazeBurner com/simibubi/create/compat/rei/category/animations/AnimatedKinetics com/simibubi/create/compat/rei/category/sequencedAssembly/ReiSequencedAssemblySubCategory com/simibubi/create/compat/rei/display/CreateDisplay Mod: createdeco-1.3.3-1.19.2.jar Missing classes of create: com/simibubi/create/content/kinetics/fan/SplashingRecipe
    • The crash points to moonlight lib - try other builds or make a test without this mod and the mods requiring it
    • Do you have shaders enabled? There is an issue with the mod simpleclouds - remove this mod or disable shaders, if enabled  
    • Maybe you need to create file in assets/<modid>/items/<itemname>.json with content like this:   { "model": { "type": "minecraft:model", "model": "modname:item/itemname" } }  
  • Topics

×
×
  • Create New...

Important Information

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