Jump to content

[1.8] PlayerEvent.HarvestCheck not fired when mining with tools


Failender

Recommended Posts

So I wanted to implement more tools, and making the way to iron a bit harder. Unfortunately Blocks.iron_ore.setHarvestLevel("pickaxe", 3) seemed to do nothing.

So I tried using PlayerEvent.HarvestCheck to check if the block is iron and if it is check the harvestLevel. Problem is that HarvestCheck seems to not get fired when the player is harvesting with tools.. So I am out of ideas how to realize that iron is harder to mine.

Any experiences?

Greetz Failender

Link to comment
Share on other sites

For everyone interested, here's my solution

@SubscribeEvent
public void canHarvest(HarvestDropsEvent event)
{
	if(event.state.getBlock().getUnlocalizedName().equals("tile.oreIron"))
	{
		ItemStack holding = event.harvester.inventory.getStackInSlot(event.harvester.inventory.currentItem);
		if(holding!=null && holding.getItem() instanceof ItemPickaxe)
		{
			if(holding.getItem().getHarvestLevel(holding, "pickaxe") <3)
			{
				event.drops.clear();
			}
		}
		else
		{
			event.drops.clear();
		}
	}
}

@SubscribeEvent
public void breakSpeed(BreakSpeed speed)
{
	if(speed.state.getBlock().getUnlocalizedName().equals("tile.oreIron"))
	{

		ItemStack holding = speed.entityPlayer.inventory.getStackInSlot(speed.entityPlayer.inventory.currentItem);
		if(holding!=null && holding.getItem() instanceof ItemPickaxe)
		{
			if(holding.getItem().getHarvestLevel(holding, "pickaxe") <3)
			{
				speed.newSpeed = speed.originalSpeed/5;
			}
		}
		else
		{
			speed.newSpeed = speed.originalSpeed/5;
		}
	}
}

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.