API: https://github.com/raymoo/multiblock/bl ... er/API.txt
Depends: Nothing (default is required for the demo)
License: LGPL2 or any later version
Download: https://github.com/raymoo/multiblock/archive/master.zip
Multiblock is a pattern matching library for node structures. Suppose I want to make a node duplication altar. Then I can make a pattern like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local pattern = {
size = {x=5, y=2, z=5},
center = {x=3, y=2, z=3},
pattern = {
"default:cobble", "default:cobble", "default:cobble", "default:cobble", "default:cobble",
"default:cobble", "default:cobble", "default:cobble", "default:cobble", "default:cobble",
"default:cobble", "default:cobble", "default:cobble", "default:cobble", "default:cobble",
"default:cobble", "default:cobble", "default:cobble", "default:cobble", "default:cobble",
"default:cobble", "default:cobble", "default:cobble", "default:cobble", "default:cobble",
"?air", "?air", "?air", "?air", "?air",
"?air", "mat!", "mat!", "mat!", "?air",
"?air", "mat!", "multiblock:test_core", "mat!", "?air",
"?air", "mat!", "mat!", "mat!", "?air",
"?air", "?air", "?air", "?air", "?air",
},
}
This specifies a structure with a 5x5 cobble base, and a layer on top with air on the outside edge, the chosen material surrounding the middle, and a "multiblock:test_core" in the center. The question mark before "air" makes that node pattern a "capture", which means the name and position of the node is saved for later use. The structure of an ordinary capture is "capturename?nodename". "capturename" names the capture (here it is empty, so the capture name is ""), and nodename is either the name of a node or a group specified with "group:groupname". "mat!" is a different kind of capture called a strict capture. Every node matched under a strict capture with the same name must be the same node. The structure of the pattern is the same as for normal captures - here I left nodename blank, so it will match any node. I use the strict capture to enforce that all eight of the nodes are the same node.
Later, I can invoke it like this:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local function fill_out_possibly(pos, clicker)
local captures = multiblock.match(pattern, pos)
if not captures then
minetest.chat_send_player(clicker:get_player_name(), "Match failed.")
return
end
local mat = captures.mat[1]
for i, capture in ipairs(captures[""]) do
minetest.place_node(capture.pos, mat)
end
end
I am able to access the nodes matched by the "mat" capture name in the corresponding field of the capture table. The unnamed air captures end up in the capture list for "" instead, and I use their positions to duplicate the nodes.
Trying the demo:
1. Give yourself a multiblock:test_core with /giveme
2. Place a 5x5 base of cobble
3. Place the test core on top, in the middle
4. Surround the core with 8 identical nodes of your choice
5. Right-click the core
6. Rejoice in your duplication hax
It is possible to use this mod as a standalone library. Copy multiblock.lua and do
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local multiblock = dofile(path_to_multiblock_lua)