Topic category: User side tutorials
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.
Thank you so much!!! Been looking forever for a way to do this. Mcreator devs should consider adding this as a feature
They really should but this will work until then.
My blocks dont have the CanHarvestBlock in the code and when i remove the first thing i get errors
You have to set a tool to break and harvest level first doesn't matter what.
Well i found another way to do it i just put my blocks in the tag mineable/axe
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.
Thank you!!
If you use the material settings on a block correctly you should be able to do this without any need to code anything extra.
CharlyMan, nope not until the 1st 2022.2 snapshot. Trust me I tried EVERYTHING before making this post.