How to check if a node would be diggable by hand under normal conditions

Post Reply
User avatar
Trogramming
Member
Posts: 19
Joined: Sun Aug 14, 2022 08:04
GitHub: Troy-Osborne
IRC: Pseudomander Dudeonym MiguelSanchez
In-game: Pseudomander
Contact:

How to check if a node would be diggable by hand under normal conditions

by Trogramming » Post

Hey everybody, long time lurker but first time poster (excluding one reply I forgot I made 2 years ago)

I've been playing around with modding minetest on and off for about a year but I'm still learning the ropes and haven't made anything to the standard of publishing, though I'm getting there on my current magic mod (designed as a learning exercise more than a practical mod)

I was hoping to make a predicate which takes a node as an input and returns true if that node could be broken by hand under normal conditions (As in using survival rules even if the player is in creative mode), I've tried a few methods with varying success.

I'm sure the answer would exist on here already and I did try searching myself, but while I found a lot of answers but all seemed to have various issues.

First I tried to work it out manually with

Code: Select all

  
return minetest.get_item_group(nodename, "snappy") >= 1 or minetest.get_item_group(nodename, "crumbly") >= 1 or minetest.get_item_group(nodename, "oddly_breakable_by_hand") >=1

Which still seems to be my best solution so far, but I didn't know if it would be comprehensive enough so I looked around and learned how actually look up the tool capabilities of hand, which brought me to

Code: Select all

local groups = minetest.registered_nodes[nodename].groups
local inv = player:get_inventory()
local stack = inv:get_stack("hand", 1)
local toolcap= stack:get_tool_capabilities(stack)
return minetest.get_dig_params(groups, toolcap).diggable
which is more or less the right answer I was looking for but I didn't account for the effects that creative mode would have on this.

So my solution was to export the tool_capabilities of the hand while in survival mode and then make it a variable, I assume this is the right way to do it but that I've some how done it wrong.

The hand capabilites I exported were

Code: Select all

local hand_capabilities = {full_punch_interval="0.89999997615814",
  max_drop_level=0,
  damage_groups={fleshy=1},
  punch_attack_uses=0,
  groupcaps= {snappy={maxlevel=1,uses=0,times={0.40000000596046}},
              oddly_breakable_by_hand={maxlevel=1,uses=0,times={3.5,2,0.69999998807907}},
              crumbly={maxlevel=1,uses=0,times={3,0.69999998807907}}}} 
but when I run

Code: Select all

local groups = minetest.registered_nodes[nodename].groups
return minetest.get_dig_params(groups, hand_capabilities).diggable

it seems to work for trees but wasn't working on sand for some reason.

I assume I've formatted the table wrong as I'm pretty new to lua and probably exported the table incorrectly, if someone else can point me to the default hand capabilities, or a better method to do this it would be greatly appreciated.

Astrobe
Member
Posts: 638
Joined: Sun Apr 01, 2018 10:46

Re: How to check if a node would be diggable by hand under normal conditions

by Astrobe » Post

For MTG or derivative, the properties of the hand are defined in default/tools.lua. The hand is implemented as a "tool", it should be the first definition in the file, named ":".
My game? It's Minefall.

User avatar
Blockhead
Moderator
Posts: 2183
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: How to check if a node would be diggable by hand under normal conditions

by Blockhead » Post

The creative mode hand lives in a separate mod inside MTG, so to target MTG correctly one would need to put default and creative in the optional dependencies. That way your mod loads after creative, at which point the hand's capabilities are guaranteed to be accurate to what they will be after loading, instead of potentially inaccurate if creative mode is ticked.

VoxeLibre has its own method for updating the hand capabilities, where there are two items: a survival hand and a creative hand, and players can have either one in their hand slot. You thus need to know if creative mode applies when you perform calculation for that game. I think the mod name is mcl_hand.

In general, for each game, you need to know whether it uses the hand Inventory list or not, and what mod(s) override the hand from the basic engine definition or add hand items. Then you should be able to get the tool capabilities out of minetest.registered_items[""] (or some other key for game-specific hand items).
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

User avatar
Desour
Member
Posts: 1524
Joined: Thu Jun 19, 2014 19:49
GitHub: Desour
IRC: Desour
In-game: DS
Location: I'm scared that if this is too exact, I will be unable to use my keyboard.

Re: How to check if a node would be diggable by hand under normal conditions

by Desour » Post

Maybe the sand node you used doesn't use crumbly.
Astrobe wrote:
Sat Oct 05, 2024 10:23
For MTG or derivative, the properties of the hand are defined in default/tools.lua. The hand is implemented as a "tool", it should be the first definition in the file, named ":".
Just FYI, it's just "", not ":". The colon is there because of the naming convention (minetest complains if you try to register e.g. "foo:bla" in a mod "bar", but it allows if you use ":foo:bar").
he/him; Codeberg; GitHub; ContentDB; public personal TODO list; "DS" is preferred (but often too short)

Astrobe
Member
Posts: 638
Joined: Sun Apr 01, 2018 10:46

Re: How to check if a node would be diggable by hand under normal conditions

by Astrobe » Post

Desour wrote:
Sat Oct 05, 2024 13:57
Maybe the sand node you used doesn't use crumbly.
Astrobe wrote:
Sat Oct 05, 2024 10:23
For MTG or derivative, the properties of the hand are defined in default/tools.lua. The hand is implemented as a "tool", it should be the first definition in the file, named ":".
Just FYI, it's just "", not ":". The colon is there because of the naming convention (minetest complains if you try to register e.g. "foo:bla" in a mod "bar", but it allows if you use ":foo:bar").
Ah, yes, thanks. This detail shows up in Blockhead's answer. It did ring a bell because I was confused by this some time ago, but forgot about it.
My game? It's Minefall.

User avatar
Trogramming
Member
Posts: 19
Joined: Sun Aug 14, 2022 08:04
GitHub: Troy-Osborne
IRC: Pseudomander Dudeonym MiguelSanchez
In-game: Pseudomander
Contact:

Re: How to check if a node would be diggable by hand under normal conditions

by Trogramming » Post

Astrobe wrote:
Sat Oct 05, 2024 10:23
For MTG or derivative, the properties of the hand are defined in default/tools.lua. The hand is implemented as a "tool", it should be the first definition in the file, named ":".
Awesome and it's right at the top too!

Here's what I'd done wrong:
instead of

Code: Select all

times={[2]=3.00, [3]=0.70}, uses=0, maxlevel=1},
or

Code: Select all

times={[3]=0.40} 
My output method was omitting the square brackets, as evident in my opening post.
Thanks heaps everyone

I've definitely got a few more unrelated questions for their own threads,
but I'll see where I can get with this knowledge first :)

Post Reply