diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2017-07-04 20:12:57 +0100 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2017-07-04 20:12:57 +0100 |
commit | f78f7c305903f89038ab778c752d6a25dc29660b (patch) | |
tree | 37c5d095bf5e4698d398bedc56e836b4f9e51eed /api.lua | |
parent | bad4dcb36f1e29676a3fc834439e6e4562d1610c (diff) |
add on_replace function (thanks wuzzy)
Diffstat (limited to 'api.lua')
-rw-r--r-- | api.lua | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -944,12 +944,23 @@ local replace = function(self, pos) -- print ("replace node = ".. minetest.get_node(pos).name, pos.y) - minetest.set_node(pos, {name = with}) + local oldnode = {name = what} + local newnode = {name = with} + local on_replace_return - -- when cow/sheep eats grass, replace wool and milk - if self.gotten == true then - self.gotten = false - self.object:set_properties(self) + if self.on_replace then + on_replace_return = self.on_replace(self, pos, oldnode, newnode) + end + + if on_replace_return ~= false then + + minetest.set_node(pos, {name = with}) + + -- when cow/sheep eats grass, replace wool and milk + if self.gotten == true then + self.gotten = false + self.object:set_properties(self) + end end end end @@ -2599,6 +2610,7 @@ minetest.register_entity(name, { replace_what = def.replace_what, replace_with = def.replace_with, replace_offset = def.replace_offset or 0, + on_replace = def.on_replace, timer = 0, env_damage_timer = 0, -- only used when state = "attack" tamed = false, |