1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

ABM without_neighbors (#14116)

This commit is contained in:
sfence 2024-09-26 17:32:55 +02:00 committed by GitHub
parent c1ea49940b
commit d08d34d803
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 347 additions and 6 deletions

View file

@ -0,0 +1,6 @@
# Test ABMs
This mod contains a nodes and related ABM actions.
By placing these nodes, you can test basic ABM behaviours.
There are separate tests for ABM `chance`, `interval`, `min_y`, `max_y`, `neighbor` and `without_neighbor` fields.

View file

@ -0,0 +1,12 @@
local S = minetest.get_translator("testnodes")
-- After ABM node
minetest.register_node("testabms:after_abm", {
description = S("After ABM processed node."),
drawtype = "normal",
tiles = { "testabms_after_node.png" },
groups = { dig_immediate = 3 },
})

View file

@ -0,0 +1,56 @@
-- test ABMs with different chances
local S = minetest.get_translator("testnodes")
-- ABM chance 5 node
minetest.register_node("testabms:chance_5", {
description = S("Node for test ABM chance_5"),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:chance_5")
end,
})
minetest.register_abm({
label = "testabms:chance_5",
nodenames = "testabms:chance_5",
interval = 10,
chance = 5,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:chance_5 changed this node.")
end
})
-- ABM chance 20 node
minetest.register_node("testabms:chance_20", {
description = S("Node for test ABM chance_20"),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:chance_20")
end,
})
minetest.register_abm({
label = "testabms:chance_20",
nodenames = "testabms:chance_20",
interval = 10,
chance = 20,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:chance_20 changed this node.")
end
})

View file

@ -0,0 +1,7 @@
local path = minetest.get_modpath(minetest.get_current_modname())
dofile(path.."/after_node.lua")
dofile(path.."/chances.lua")
dofile(path.."/intervals.lua")
dofile(path.."/min_max.lua")
dofile(path.."/neighbors.lua")

View file

@ -0,0 +1,56 @@
-- test ABMs with different interval
local S = minetest.get_translator("testnodes")
-- ABM inteval 1 node
minetest.register_node("testabms:interval_1", {
description = S("Node for test ABM interval_1"),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:interval_1")
end,
})
minetest.register_abm({
label = "testabms:interval_1",
nodenames = "testabms:interval_1",
interval = 1,
chance = 1,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:interval_1 changed this node.")
end
})
-- ABM interval 60 node
minetest.register_node("testabms:interval_60", {
description = S("Node for test ABM interval_60"),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:interval_60")
end,
})
minetest.register_abm({
label = "testabms:interval_60",
nodenames = "testabms:interval_60",
interval = 60,
chance = 1,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:interval_60 changed this node.")
end
})

View file

@ -0,0 +1,58 @@
-- test ABMs with min_y and max_y
local S = minetest.get_translator("testnodes")
-- ABM min_y node
minetest.register_node("testabms:min_y", {
description = S("Node for test ABM min_y."),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:min_y at y "..pos.y.." with min_y = 0")
end,
})
minetest.register_abm({
label = "testabms:min_y",
nodenames = "testabms:min_y",
interval = 10,
chance = 1,
min_y = 0,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:min_y changed this node.")
end
})
-- ABM max_y node
minetest.register_node("testabms:max_y", {
description = S("Node for test ABM max_y."),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Waiting for ABM testabms:max_y at y "..pos.y.." with max_y = 0")
end,
})
minetest.register_abm({
label = "testabms:max_y",
nodenames = "testabms:max_y",
interval = 10,
chance = 1,
max_y = 0,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "ABM testabsm:max_y changed this node.")
end
})

View file

@ -0,0 +1,2 @@
name = testabms
description = Contains some nodes for test ABMs.

View file

@ -0,0 +1,99 @@
-- test ABMs with neighbor and without_neighbor
local S = minetest.get_translator("testnodes")
-- ABM required neighbor
minetest.register_node("testabms:required_neighbor", {
description = S("Node for test ABM required_neighbor.") .. "\n"
.. S("Sensitive neighbor node is testnodes:normal."),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"Waiting for ABM testabms:required_neighbor "
.. "(normal drawtype testnode sensitive)")
end,
})
minetest.register_abm({
label = "testabms:required_neighbor",
nodenames = "testabms:required_neighbor",
neighbors = {"testnodes:normal"},
interval = 1,
chance = 1,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"ABM testabsm:required_neighbor changed this node.")
end
})
-- ABM missing neighbor node
minetest.register_node("testabms:missing_neighbor", {
description = S("Node for test ABM missing_neighbor.") .. "\n"
.. S("Sensitive neighbor node is testnodes:normal."),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"Waiting for ABM testabms:missing_neighbor"
.. " (normal drawtype testnode sensitive)")
end,
})
minetest.register_abm({
label = "testabms:missing_neighbor",
nodenames = "testabms:missing_neighbor",
without_neighbors = {"testnodes:normal"},
interval = 1,
chance = 1,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"ABM testabsm:missing_neighbor changed this node.")
end
})
-- ABM required and missing neighbor node
minetest.register_node("testabms:required_missing_neighbor", {
description = S("Node for test ABM required_missing_neighbor.") .. "\n"
.. S("Sensitive neighbor nodes are testnodes:normal and testnodes:glasslike."),
drawtype = "normal",
tiles = { "testabms_wait_node.png" },
groups = { dig_immediate = 3 },
on_construct = function (pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"Waiting for ABM testabms:required_missing_neighbor"
.. " (wint normal drawtype testnode and no glasslike"
.. " drawtype testnode sensitive)")
end,
})
minetest.register_abm({
label = "testabms:required_missing_neighbor",
nodenames = "testabms:required_missing_neighbor",
neighbors = {"testnodes:normal"},
without_neighbors = {"testnodes:glasslike"},
interval = 1,
chance = 1,
action = function (pos)
minetest.swap_node(pos, {name="testabms:after_abm"})
local meta = minetest.get_meta(pos)
meta:set_string("infotext",
"ABM testabsm:required_missing_neighbor changed this node.")
end
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 179 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 183 B