Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

  • Author

Yeah I realized that.. Any other way to realize what I am triing to do? Making iron ore only harvestable with a tool that has miningLevel 3?

  • Author

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;
		}
	}
}

Instead of using event.state.getBlock().getUnlocalizedName().equals("tile.oreIron"), why don't you just do, event.state.getBlock() == Blocks.iron_ore

  • Author

obviously bc i am dumb.

I was just so deep in the code that I was like okay. minecraft is using one class for all the ores. so i should check for the unlocalized name. dumb me ill better go to bed now.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.