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:
parent
c1ea49940b
commit
d08d34d803
16 changed files with 347 additions and 6 deletions
6
games/devtest/mods/testabms/README.md
Normal file
6
games/devtest/mods/testabms/README.md
Normal 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.
|
12
games/devtest/mods/testabms/after_node.lua
Normal file
12
games/devtest/mods/testabms/after_node.lua
Normal 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 },
|
||||
})
|
||||
|
56
games/devtest/mods/testabms/chances.lua
Normal file
56
games/devtest/mods/testabms/chances.lua
Normal 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
|
||||
})
|
||||
|
7
games/devtest/mods/testabms/init.lua
Normal file
7
games/devtest/mods/testabms/init.lua
Normal 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")
|
56
games/devtest/mods/testabms/intervals.lua
Normal file
56
games/devtest/mods/testabms/intervals.lua
Normal 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
|
||||
})
|
||||
|
58
games/devtest/mods/testabms/min_max.lua
Normal file
58
games/devtest/mods/testabms/min_max.lua
Normal 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
|
||||
})
|
||||
|
2
games/devtest/mods/testabms/mod.conf
Normal file
2
games/devtest/mods/testabms/mod.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
name = testabms
|
||||
description = Contains some nodes for test ABMs.
|
99
games/devtest/mods/testabms/neighbors.lua
Normal file
99
games/devtest/mods/testabms/neighbors.lua
Normal 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
|
||||
})
|
||||
|
BIN
games/devtest/mods/testabms/textures/testabms_after_node.png
Normal file
BIN
games/devtest/mods/testabms/textures/testabms_after_node.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 179 B |
BIN
games/devtest/mods/testabms/textures/testabms_wait_node.png
Normal file
BIN
games/devtest/mods/testabms/textures/testabms_wait_node.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 183 B |
Loading…
Add table
Add a link
Reference in a new issue