diff options
author | Zefram <zefram@fysh.org> | 2014-04-30 10:45:45 +0100 |
---|---|---|
committer | Zefram <zefram@fysh.org> | 2014-04-30 10:45:45 +0100 |
commit | b3d83bc953905190e60eaf60c1dba3cec3def1a7 (patch) | |
tree | 5743566bfe88500b2aa938f3eb8212cb538cc15c /callbacks.lua | |
parent | d1e554b73d4ce4d80474f019b5af102f340bcafa (diff) |
Support item-dependent refill behaviour
The refill slot was only putting as many items as possible in a
stack, which does nothing for tools. Tools could benefit from repair,
recharging, or other behaviour depending on the type of tool. Change the
default refill behaviour to repair mechanical wear as well as fully
stacking. Because other kinds of refill will require knowledge of the
metadata format, they can't be directly handled here. So add an on_refill
hook, that tool definitions can supply to plug in appropriate behaviour.
Diffstat (limited to 'callbacks.lua')
-rw-r--r-- | callbacks.lua | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/callbacks.lua b/callbacks.lua index ce6bcf0..a1e2396 100644 --- a/callbacks.lua +++ b/callbacks.lua @@ -1,3 +1,11 @@ +local function default_refill(stack) + stack:set_count(stack:get_stack_max()) + local itemdef = minetest.registered_items[stack:get_name()] + if itemdef and (itemdef.wear_represents or "mechanical_wear") == "mechanical_wear" and stack:get_wear() ~= 0 then + stack:set_wear(0) + end + return stack +end minetest.register_on_joinplayer(function(player) local player_name = player:get_player_name() @@ -40,7 +48,8 @@ minetest.register_on_joinplayer(function(player) end, on_put = function(inv, listname, index, stack, player) local player_name = player:get_player_name() - stack:set_count(stack:get_stack_max()) + local handle_refill = (minetest.registered_items[stack:get_name()] or {}).on_refill or default_refill + stack = handle_refill(stack) inv:set_stack(listname, index, stack) minetest.sound_play("electricity", {to_player=player_name, gain = 1.0}) |