[Tutorial] Make block mineable with hand AND tool!

Started by asbjornb04 on Wed, 03/09/2022 - 13:11

Topic category: User side tutorials

Last seen on 15:45, 24. Jul 2022
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
[Tutorial] Make block mineable with hand AND tool!
Sun, 06/26/2022 - 22:58 (edited)

UPDATE:
This is now deprecated since the 1st 2022.2 snapshot, I haven't tested it yet but it says you can now have blocks require correct tool.

 

Have you ever tried making something like custom dirt or logs only to find that you couldn't have them be mineable with both hand and a tool?
Well sadly MCreator still for some reason doesn't support this but I'm making this tutorial to help those, like myself, who really need that feature.

Firstly, finish making your block fully because we're going to be modifying the code.

When you're ready; lock your element's code using the lock icon to the left or rightclicking on your element and choosing "lock/unlock mod element".

Then double click the element and choose the <YOUR_BLOCKS_NAME>Block.java

Then find this piece of code,

public class DirtOreBlock extends Block {
	public DirtOreBlock() {
		super(BlockBehaviour.Properties.of(Material.WOOD).sound(SoundType.GRAVEL).strength(1f, 10f).requiresCorrectToolForDrops());
		setRegistryName("dirt_ore");
	}

Then modify it, removing ".requiresCorrectToolForDrops()",

public class DirtOreBlock extends Block {
	public DirtOreBlock() {
		super(BlockBehaviour.Properties.of(Material.WOOD).sound(SoundType.GRAVEL).strength(1f, 10f));
		setRegistryName("dirt_ore");
	}

Then find this,

@Override
public boolean canHarvestBlock(BlockState state, BlockGetter world, BlockPos pos, Player player) {
	if (player.getInventory().getSelected().getItem()instanceof TieredItem tieredItem)
		return tieredItem.getTier().getLevel() >= 1;
	return false;
}

And simply replace its content with a "return true;"

@Override
public boolean canHarvestBlock(BlockState state, BlockGetter world, BlockPos pos, Player player) {
	return true;
}

 

Now simply press ctrl+s and close the element.

Edited by asbjornb04 on Sun, 06/26/2022 - 22:58
Last seen on 19:08, 26. Jul 2022
Joined Feb 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you so much!!! Been…
Fri, 03/11/2022 - 05:27

Thank you so much!!! Been looking forever for a way to do this. Mcreator devs should consider adding this as a feature

Last seen on 15:45, 24. Jul 2022
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
They really should but this…
Mon, 03/14/2022 - 08:59

They really should but this will work until then.

Last seen on 02:18, 18. Jul 2022
Joined Aug 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
My blocks dont have the…
Sun, 03/27/2022 - 20:32

My blocks dont have the CanHarvestBlock in the code and when i remove the first thing i get errors

Last seen on 15:45, 24. Jul 2022
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
You have to set a tool to…
Wed, 03/30/2022 - 15:22

You have to set a tool to break and harvest level first doesn't matter what.

Last seen on 02:18, 18. Jul 2022
Joined Aug 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Well i found another way to…
Wed, 03/30/2022 - 16:00

Well i found another way to do it i just put my blocks in the tag mineable/axe

Last seen on 13:39, 24. Jul 2022
Joined Jul 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
the devs need to get on this…
Sun, 05/01/2022 - 19:22

the devs need to get on this issue or i cant update my mod at all, ive been stuck trying and trying and nothing worked only to realize that even the developers didnt fix it, how annoying.

Last seen on 13:56, 27. Jul 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
Thank you!!
Tue, 06/14/2022 - 19:35

Thank you!!

Last seen on 01:05, 8. Aug 2022
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
If you use the material…
Sat, 07/02/2022 - 00:01

If you use the material settings on a block correctly you should be able to do this without any need to code anything extra.

Last seen on 15:45, 24. Jul 2022
Joined Dec 2014
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
CharlyMan, nope not until…
Sun, 07/03/2022 - 02:41

CharlyMan, nope not until the 1st 2022.2 snapshot. Trust me I tried EVERYTHING before making this post.