Jump to content

Giving a player a diamond if they eat a food?


Recommended Posts

I have added some poop to my mod and I want it to give the player a diamond if they eat it, what code do I need to add to that food class? After I want it to say a custom message in chat which is    "[user] successfully completed the poop eating challenge"      How do I do that as well

Link to comment
Share on other sites

Have poop extend ItemFood. Override OnFoodEaten and put these two lines somewhere in that method. Remember that both should only be called serverside.


//Drops a diamond at player's position
player.dropItem(Items.diamond, 1);


//Broadcasts the message
MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(player.getDisplayName() + " successfully completed the poop eating challenge"));

Link to comment
Share on other sites

protected void onFoodEaten(ItemStack item, World world, EntityPlayer player)
	super.onFoodEaten(item, world, player);
		player.dropItem(Items.diamond, 1);
		MinecraftServer.getServer().getConfigurationManager().sendChatMsg(new ChatComponentText(player.getDisplayName() + "Successfully did the thing!"));

Link to comment
Share on other sites

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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

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