Jump to content

[1.8.9] [SOLVED] HarvestDropsEvent with Metadata


nxwhitney

Recommended Posts

I am trying to set spruce logs to drop a custom item when I harvest them with a modded tool, but since spruce logs come from metadata in the BlockOldLog class, I cannot figure out how to adjust them.  I have looked at the

 

event.state.getBlock().getSubBlocks(itemIn, tab, list)

 

section, but I'm stumped.

 

Here is the code that I used for mining gravel with a modded tool.

 

@SubscribeEvent
public void addBlockDrop(HarvestDropsEvent event) {
	if(event.state.getBlock() == Blocks.gravel) {

		Random rand = new Random();

		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if(holding!=null && holding.getItem() instanceof NGShaleMattock) {

			event.drops.clear();
			event.drops.add(new ItemStack(NGItems.viscinousGel, rand.nextInt(4)));
		}
	}
}

 

Any suggestions?

Link to comment
Share on other sites

You need to check that the state's

Block

(

IBlockState#getBlock

) is

Blocks.log

, then use

IBlockState#getValue

to get the value of the

BlockOldLog.VARIANT

property. If it's

BlockPlanks.EnumType.SPRUCE

, the log is a Spruce log.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

That did it!  I got all mixed up on which side to put it!

 

Here's my code for anymore interested:

 

	if(event.state.getBlock() == Blocks.log) {
		if (event.state.getValue(BlockOldLog.VARIANT) == BlockPlanks.EnumType.SPRUCE) {

			Random rand = new Random();

			ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
			if(holding!=null && holding.getItem() instanceof NGPitchHarvester) {

				event.drops.clear(); //only if you don't want spruce to drop as well as tree pitch
				event.drops.add(new ItemStack(NGItems.treePitch, rand.nextInt(4)));
			}
		}
	}

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.