]> git.lizzy.rs Git - xdecor.git/blobdiff - cooking.lua
Turn repairable tools to be a function
[xdecor.git] / cooking.lua
index 201ea829e0467a820da00475cbfe8a388e19e4ff..c1213c7d065bd74e9d919cfaebe7a60f56167197 100644 (file)
@@ -1,12 +1,15 @@
+-- Add more ingredients here that make a soup.
+local ingredients_list = {
+       "apple", "mushroom", "honey", "pumpkin", "egg", "bread", "meat",
+       "chicken", "carrot", "potato"
+}
+
 local cauldron_cbox = {
-       type = "fixed",
-       fixed = {
-               {-0.5, -0.5, -0.5, 0.5, 0.5, -0.5},
-               {-0.5, -0.5, 0.5, 0.5, 0.5, 0.5},
-               {-0.5, -0.5, -0.5, -0.5, 0.5, 0.5},
-               {0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
-               {-0.5, -0.5, -0.5, 0.5, 0, 0.5}
-       }
+       {0,  0, 0,  16, 16, 0},
+       {0,  0, 16, 16, 16, 0},
+       {0,  0, 0,  0,  16, 16},
+       {16, 0, 0,  0,  16, 16},
+       {0,  0, 0,  16, 8,  16}
 }
 
 local function fill_water_bucket(pos, node, clicker, itemstack)
@@ -32,7 +35,7 @@ xdecor.register("cauldron_empty", {
                        itemstack:replace("bucket:bucket_empty")
                end
        end,
-       collision_box = cauldron_cbox
+       collision_box = xdecor.pixelbox(16, cauldron_cbox)
 })
 
 xdecor.register("cauldron_idle", {
@@ -41,7 +44,7 @@ xdecor.register("cauldron_idle", {
        tiles = {"xdecor_cauldron_top_idle.png", "xdecor_cauldron_sides.png"},
        drop = "xdecor:cauldron_empty",
        infotext = "Cauldron (idle)",
-       collision_box = cauldron_cbox,
+       collision_box = xdecor.pixelbox(16, cauldron_cbox),
        on_rightclick = fill_water_bucket
 })
 
@@ -56,7 +59,7 @@ xdecor.register("cauldron_boiling_water", {
                        animation = {type="vertical_frames", length=3.0} },
                "xdecor_cauldron_sides.png"
        },
-       collision_box = cauldron_cbox,
+       collision_box = xdecor.pixelbox(16, cauldron_cbox),
        on_rightclick = fill_water_bucket
 })
 
@@ -71,7 +74,7 @@ xdecor.register("cauldron_soup", {
                        animation = {type="vertical_frames", length=3.0} },
                "xdecor_cauldron_sides.png"
        },
-       collision_box = cauldron_cbox,
+       collision_box = xdecor.pixelbox(16, cauldron_cbox),
        on_rightclick = function(pos, node, clicker, itemstack)
                local inv = clicker:get_inventory()
                local wield_item = clicker:get_wielded_item()
@@ -115,14 +118,9 @@ minetest.register_abm({
                if not objs then return end
 
                local ingredients = {}
-               local ingredients_list = {  -- Add more ingredients here that make a soup.
-                       "apple", "mushroom", "honey", "pumpkin", "egg", "bread",
-                       "meat", "chicken"
-               }
-
                for _, obj in pairs(objs) do
                        if obj and obj:get_luaentity() then
-                               local itemstring = obj:get_luaentity().itemstring:match("[^:]+$")
+                               local itemstring = obj:get_luaentity().itemstring:match(":([%w_]+)")
                                if not next(ingredients) then
                                        for _, rep in pairs(ingredients) do
                                                if itemstring == rep then return end
@@ -130,7 +128,7 @@ minetest.register_abm({
                                end
 
                                for _, ing in pairs(ingredients_list) do
-                                       if itemstring and itemstring:match(ing) then
+                                       if itemstring and itemstring:find(ing) then
                                                ingredients[#ingredients+1] = itemstring
                                        end
                                end
@@ -139,15 +137,13 @@ minetest.register_abm({
 
                if #ingredients >= 2 then
                        for _, obj in pairs(objs) do
-                               if obj and obj:get_luaentity() then
-                                       obj:remove()
-                               end
+                               if obj and obj:get_luaentity() then obj:remove() end
                        end
                        minetest.set_node(pos, {name="xdecor:cauldron_soup", param2=node.param2})
                end
 
-               local below_node = {x=pos.x, y=pos.y-1, z=pos.z}
-               if not minetest.get_node(below_node).name:find("fire") then
+               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