Jump to content

HarvestDropsEvent - Removing and Adding Drops


MrArcane111

Recommended Posts

I've made an enchantment that has a chance to smelt blocks when mined, however, I have run into a snag: adding drops is no problem, but removing them is. Here is my code:

 

@ForgeSubscribe
public void onHarvestBlocks(BlockEvent.HarvestDropsEvent event)
{
EntityPlayer player = event.harvester;
ItemStack heldItem = player.inventory.getCurrentItem();
Block block = event.block;

flameTouchAmount = EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.flameTouch.effectId, heldItem);

if(heldItem == null)
{
	return;
} else if(flameTouchAmount > 0)
{
	isFlameTouched = true;
}

if(isFlameTouched = true)
{
	if(player.worldObj.rand.nextInt(2) == 0)
	{
		// So I was going to use FurnaceRecipes, but then I decided against it because this way gives me more flexibility
		if(block == Block.oreIron)
		{
			event.drops.add(new ItemStack(Item.ingotIron, 1));
			event.drops.remove(15);
		}
		if(block == Block.oreGold)
		{
			event.drops.add(new ItemStack(Item.ingotGold, 1));
			event.drops.remove(Block.oreGold);
		}
	}
}
}

 

The "event.drops.remove" has two options: an item index or an Object. I have tried various ways for each but either they do not work, or they crash the game because of an ArrayList error. If anyone point me in the right direction, that would be fantastic. I hope you have a great day, and thank you for taking the time to read this post/help me out. :)

Link to comment
Share on other sites

So would

 

for(int size = 0; size < event.drops.size(); size++)
{
ItemStack stack = event.drops.get(size).getEntityItem();
}

 

be somewhere along those lines? Correct me if I'm wrong, but the int size is grabbing the ItemStack ArrayList size and then getting an EntityItem instance of it. So how would that assist me in removing the drop as an item index? Thanks.

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.



×
×
  • Create New...

Important Information

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