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