Convert cauldrons & itemframe ABMs to node timers
This commit is contained in:
parent
6fe2681d09
commit
7c647948c0
116
cooking.lua
116
cooking.lua
@ -43,16 +43,30 @@ xdecor.register("cauldron_idle", {
|
|||||||
on_rotate = screwdriver.rotate_simple,
|
on_rotate = screwdriver.rotate_simple,
|
||||||
tiles = {"xdecor_cauldron_top_idle.png", "xdecor_cauldron_sides.png"},
|
tiles = {"xdecor_cauldron_top_idle.png", "xdecor_cauldron_sides.png"},
|
||||||
drop = "xdecor:cauldron_empty",
|
drop = "xdecor:cauldron_empty",
|
||||||
infotext = "Cauldron (idle)",
|
|
||||||
collision_box = xdecor.pixelbox(16, cauldron_cbox),
|
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 (idle)")
|
||||||
|
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
|
||||||
|
timer:stop() return
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.set_node(pos, {name="xdecor:cauldron_boiling_water"})
|
||||||
|
return true
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
xdecor.register("cauldron_boiling_water", {
|
xdecor.register("cauldron_boiling_water", {
|
||||||
groups = {cracky=2, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
groups = {cracky=2, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
||||||
on_rotate = screwdriver.rotate_simple,
|
on_rotate = screwdriver.rotate_simple,
|
||||||
drop = "xdecor:cauldron_empty",
|
drop = "xdecor:cauldron_empty",
|
||||||
infotext = "Cauldron (active) - Drop foods inside to make a soup",
|
|
||||||
damage_per_second = 2,
|
damage_per_second = 2,
|
||||||
tiles = {
|
tiles = {
|
||||||
{ name = "xdecor_cauldron_top_anim_boiling_water.png",
|
{ name = "xdecor_cauldron_top_anim_boiling_water.png",
|
||||||
@ -60,7 +74,51 @@ xdecor.register("cauldron_boiling_water", {
|
|||||||
"xdecor_cauldron_sides.png"
|
"xdecor_cauldron_sides.png"
|
||||||
},
|
},
|
||||||
collision_box = xdecor.pixelbox(16, cauldron_cbox),
|
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(3.0)
|
||||||
|
end,
|
||||||
|
on_timer = function(pos)
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
|
if not objs then timer:stop() return end
|
||||||
|
|
||||||
|
local ingredients = {}
|
||||||
|
for _, obj in pairs(objs) do
|
||||||
|
if obj and obj:get_luaentity() then
|
||||||
|
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
|
||||||
|
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"})
|
||||||
|
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"})
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
xdecor.register("cauldron_soup", {
|
xdecor.register("cauldron_soup", {
|
||||||
@ -99,53 +157,3 @@ xdecor.register("cauldron_soup", {
|
|||||||
end
|
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() then
|
|
||||||
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
|
|
||||||
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
|
|
||||||
})
|
|
||||||
|
|
||||||
|
@ -90,9 +90,19 @@ xdecor.register("frame", {
|
|||||||
"xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
|
"xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
|
||||||
"xdecor_wood.png", "xdecor_wood.png", "xdecor_frame.png"
|
"xdecor_wood.png", "xdecor_wood.png", "xdecor_frame.png"
|
||||||
},
|
},
|
||||||
|
on_timer = function(pos)
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
||||||
|
if num > 0 then timer:stop() return end
|
||||||
|
|
||||||
|
update_item(pos, node)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
after_place_node = function(pos, placer, itemstack)
|
after_place_node = function(pos, placer, itemstack)
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local name = placer:get_player_name()
|
local name = placer:get_player_name()
|
||||||
|
local timer = minetest.get_node_timer(pos)
|
||||||
|
timer:start(15.0)
|
||||||
|
|
||||||
meta:set_string("owner", name)
|
meta:set_string("owner", name)
|
||||||
meta:set_string("infotext", "Item Frame (owned by "..name..")")
|
meta:set_string("infotext", "Item Frame (owned by "..name..")")
|
||||||
@ -132,12 +142,3 @@ xdecor.register("frame", {
|
|||||||
after_destruct = remove_item
|
after_destruct = remove_item
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({
|
|
||||||
nodenames = {"xdecor:frame"},
|
|
||||||
interval = 15, chance = 1,
|
|
||||||
action = function(pos, node)
|
|
||||||
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
|
||||||
if num > 0 then return end
|
|
||||||
update_item(pos, node)
|
|
||||||
end
|
|
||||||
})
|
|
||||||
|
Loading…
Reference in New Issue
Block a user