Jump to content

[1.12.2] Making a Tool that Modifies block drops when used (New to Modded)


intipablo

Recommended Posts

I'm pretty new to Minecraft Modding, but I've been doing well so far (I've got blocks, items, creative tabs, foods, recipes, down pat).

I'm at the stage where I want to start doing some more advanced stuff, starting with a custom tool.


My question is: How can I make a tool (called whatever, let's say a sickle), that upon breaking grass, increases the chance of seeds dropping.

Edited by intipablo
Link to comment
Share on other sites

Add this to your class that has @Mod.EventBusSubscriber

@SubscribeEvent
	public static void onHarvest(BlockEvent.HarvestDropsEvent event)
	{
		if (event.getHarvester() != null)
		{
			List<ItemStack> drops = event.getDrops();
			if(drops!=null && drops.size()>0) {
				BlockPos pos = event.getPos();
				IBlockState blockstate = event.getWorld().getBlockState(pos);
				Block block = blockstate.getBlock();
				if(block instanceof BlockGrass) {
					drops.add(new ItemStack(Item.REGISTRY.getObject(new ResourceLocation("minecraft", "wheat_seeds"))));
				}
            }
        }
    }  
  • Confused 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

14 hours ago, diesieben07 said:

Please don't just vomit code into your post saying "just copy this". This helps nobody, especially someone who explicitly said they are new to modding.

Also, your code is terrible.

 

@intipablo Read the documentation on events. Then you can use HarvestDropsEvent to change the drops of a block.

 

Thanks for the help. Much appreciated!

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.

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...

×   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.

Announcements



×
×
  • Create New...

Important Information

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