]> git.lizzy.rs Git - xdecor.git/commitdiff
Convert cauldrons ABM to nodetimers
authorJean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
Sun, 28 Feb 2016 20:07:43 +0000 (21:07 +0100)
committerJean-Patrick Guerrero <jeanpatrick.guerrero@gmail.com>
Sun, 28 Feb 2016 20:07:43 +0000 (21:07 +0100)
cooking.lua
handlers/animations.lua

index eee096b38259fc55c1c9c9467170e63bd1dc97a4..d15cdc01876d2cb6606400ea0828d5f88e692646 100644 (file)
@@ -45,7 +45,21 @@ xdecor.register("cauldron_idle", {
        drop = "xdecor:cauldron_empty",
        infotext = "Cauldron (idle)",
        collision_box = xdecor.pixelbox(16, cauldron_cbox),
-       on_rightclick = fill_water_bucket
+       on_rightclick = fill_water_bucket,
+       on_construct = function(pos)
+               local timer = minetest.get_node_timer(pos)
+               timer:start(10.0)
+       end,
+       on_timer = function(pos)
+               local below_node = {x=pos.x, y=pos.y-1, z=pos.z}
+               if not minetest.get_node(below_node).name:find("fire") then
+                       return true
+               end
+
+               local node = minetest.get_node(pos)
+               minetest.set_node(pos, {name="xdecor:cauldron_boiling_water", param2=node.param2})
+               return true
+       end
 })
 
 xdecor.register("cauldron_boiling_water", {
@@ -60,7 +74,49 @@ xdecor.register("cauldron_boiling_water", {
                "xdecor_cauldron_sides.png"
        },
        collision_box = xdecor.pixelbox(16, cauldron_cbox),
-       on_rightclick = fill_water_bucket
+       on_rightclick = fill_water_bucket,
+       on_construct = function(pos)
+               local meta = minetest.get_meta(pos)
+               local timer = minetest.get_node_timer(pos)
+               meta:set_string("infotext", "Cauldron (active) - Drop some foods inside to make a soup")
+               timer:start(5.0)
+       end,
+       on_timer = function(pos)
+               local objs = minetest.get_objects_inside_radius(pos, 0.5)
+               if objs == {} then return true end
+
+               local ingredients = {}
+               for _, obj in pairs(objs) do
+                       if obj and not obj:is_player() and obj:get_luaentity().itemstring then
+                               local itemstring = obj:get_luaentity().itemstring:match(":([%w_]+)")
+                               if ingredients == {} then
+                                       for _, rep in pairs(ingredients) do
+                                               if itemstring == rep then return end
+                                       end
+                               end
+
+                               for _, ing in pairs(ingredients_list) do
+                                       if itemstring and itemstring:find(ing) then
+                                               ingredients[#ingredients+1] = itemstring
+                                       end
+                               end
+                       end
+               end
+
+               local node = minetest.get_node(pos)
+               if #ingredients >= 2 then
+                       for _, obj in pairs(objs) do
+                               obj:remove()
+                       end
+                       minetest.set_node(pos, {name="xdecor:cauldron_soup", param2=node.param2})
+               end
+
+               local node_under = {x=pos.x, y=pos.y-1, z=pos.z}
+               if not minetest.get_node(node_under).name:find("fire") then
+                       minetest.set_node(pos, {name="xdecor:cauldron_idle", param2=node.param2})
+               end
+               return true
+       end     
 })
 
 xdecor.register("cauldron_soup", {
@@ -99,55 +155,3 @@ xdecor.register("cauldron_soup", {
        end
 })
 
-minetest.register_abm({
-       nodenames = {"xdecor:cauldron_idle"},
-       interval = 15, chance = 1,
-       action = function(pos, node)
-               local below_node = {x=pos.x, y=pos.y-1, z=pos.z}
-               if minetest.get_node(below_node).name:find("fire") then
-                       minetest.set_node(pos, {name="xdecor:cauldron_boiling_water", param2=node.param2})
-               end
-       end
-})
-
-minetest.register_abm({
-       nodenames = {"xdecor:cauldron_boiling_water"},
-       interval = 5, chance = 1,
-       action = function(pos, node)
-               local objs = minetest.get_objects_inside_radius(pos, 0.5)
-               if not objs then return end
-
-               local ingredients = {}
-               for _, obj in pairs(objs) do
-                       if obj and obj:get_luaentity().itemstring then
-                               local itemstring = obj:get_luaentity().itemstring:match(":([%w_]+)")
-                               if ingredients == {} then
-                                       for _, rep in pairs(ingredients) do
-                                               if itemstring == rep then return end
-                                       end
-                               end
-
-                               for _, ing in pairs(ingredients_list) do
-                                       if itemstring and itemstring:find(ing) then
-                                               ingredients[#ingredients+1] = itemstring
-                                       end
-                               end
-                       end
-               end
-
-               if #ingredients >= 2 then
-                       for _, obj in pairs(objs) do
-                               if obj and obj:get_luaentity() then
-                                       obj:remove()
-                               end
-                       end
-                       minetest.set_node(pos, {name="xdecor:cauldron_soup", param2=node.param2})
-               end
-
-               local node_under = {x=pos.x, y=pos.y-1, z=pos.z}
-               if not minetest.get_node(node_under).name:find("fire") then
-                       minetest.set_node(pos, {name="xdecor:cauldron_idle", param2=node.param2})
-               end
-       end
-})
-
index 92d65cc2f58ace8960c574f95111198d4f67eed2..7a275032c1866851ada985b7bcef1c74911294a0 100644 (file)
@@ -5,30 +5,32 @@ end
 
 function xdecor.sit(pos, node, clicker, pointed_thing)
        if not top_face(pointed_thing) then return end
-       local player = clicker:get_player_name()
+       local player_name = clicker:get_player_name()
        local objs = minetest.get_objects_inside_radius(pos, 0.1)
        local vel = clicker:get_player_velocity()
        local ctrl = clicker:get_player_control()
 
-       for _, p in pairs(objs) do
-               if p:get_player_name() ~= player then return end
+       for _, obj in pairs(objs) do
+               if obj:is_player() and obj:get_player_name() ~= player_name then
+                       return
+               end
        end
 
-       if default.player_attached[player] then
+       if default.player_attached[player_name] then
                pos.y = pos.y - 0.5
                clicker:setpos(pos)
                clicker:set_eye_offset({x=0, y=0, z=0}, {x=0, y=0, z=0})
                clicker:set_physics_override(1, 1, 1)
-               default.player_attached[player] = false
+               default.player_attached[player_name] = false
                default.player_set_animation(clicker, "stand", 30)
 
-       elseif not default.player_attached[player] and node.param2 <= 3 and not
+       elseif not default.player_attached[player_name] and node.param2 <= 3 and not
                        ctrl.sneak and vel.x == 0 and vel.y == 0 and vel.z == 0 then
 
                clicker:set_eye_offset({x=0, y=-7, z=2}, {x=0, y=0, z=0})
                clicker:set_physics_override(0, 0, 0)
                clicker:setpos(pos)
-               default.player_attached[player] = true
+               default.player_attached[player_name] = true
                default.player_set_animation(clicker, "sit", 30)
 
                if     node.param2 == 0 then clicker:set_look_yaw(3.15)