Assembling a longcat works
Disassembling one partially works. - Cats removed from snake return to original name - Remaining cats in snake do NOT reconform
This commit is contained in:
parent
0389d9d09f
commit
4a055e1c01
60
node.lua
60
node.lua
@ -22,7 +22,55 @@ local function checkfacedir(pos)
|
||||
end
|
||||
if #t < 1 then return end
|
||||
node.param2 = t[math_random(1, #t)]
|
||||
return minetest.swap_node(pos, node)
|
||||
minetest.swap_node(pos, node)
|
||||
return node
|
||||
end
|
||||
|
||||
local function getcatid(node)
|
||||
local catid = minetest.get_item_group(node.name, modname .. '_cat')
|
||||
return catid > 0 and catid
|
||||
end
|
||||
local function longcatmatch(nodea, nodeb)
|
||||
local catid = getcatid(nodea)
|
||||
return catid
|
||||
and catid == getcatid(nodeb)
|
||||
and vector.equals(
|
||||
nodecore.facedirs[nodea.param2].f,
|
||||
nodecore.facedirs[nodeb.param2].f)
|
||||
end
|
||||
local function findtail(pos, node, ishead)
|
||||
local fd = nodecore.facedirs[node.param2]
|
||||
local back = vector.add(pos, fd.k)
|
||||
local bnode = minetest.get_node(back)
|
||||
local istail = not longcatmatch(node, bnode)
|
||||
|
||||
local catname = not istail and findtail(back, bnode, false)
|
||||
|
||||
local part = ishead and istail and ":cat_"
|
||||
or ishead and ":longcat_front_"
|
||||
or istail and ":longcat_back_"
|
||||
or ":longcat_mid_"
|
||||
node.name = modname .. part .. getcatid(node)
|
||||
if not istail then node.param2 = bnode.param2 end
|
||||
|
||||
local saved = minetest.get_meta(pos):to_table()
|
||||
saved.fields.realname = saved.fields.realname or saved.fields.description
|
||||
saved.fields.description = istail and saved.fields.realname or catname
|
||||
nodecore.set_node_check(pos, node)
|
||||
minetest.get_meta(pos):from_table(saved)
|
||||
return saved.fields.description
|
||||
end
|
||||
local function findhead(pos, node)
|
||||
local fd = nodecore.facedirs[node.param2]
|
||||
local fore = vector.add(pos, fd.f)
|
||||
local fnode = minetest.get_node(fore)
|
||||
if longcatmatch(node, fnode) then
|
||||
return findhead(fore, fnode)
|
||||
end
|
||||
findtail(pos, node, true)
|
||||
end
|
||||
local function checksnake(pos, node)
|
||||
return findhead(pos, node or minetest.get_node(pos))
|
||||
end
|
||||
|
||||
local function reg(id, base, spot)
|
||||
@ -44,7 +92,7 @@ local function reg(id, base, spot)
|
||||
groups = {
|
||||
snappy = 1,
|
||||
falling_node = 1,
|
||||
[modname .. "_cat"] = 1
|
||||
[modname .. "_cat"] = id
|
||||
},
|
||||
stack_max = 1,
|
||||
paramtype2 = "facedir",
|
||||
@ -54,14 +102,20 @@ local function reg(id, base, spot)
|
||||
return minetest.rotate_and_place(stack, placer, pointed, inf, orient, ...)
|
||||
end,
|
||||
sounds = nodecore.sounds(modname .. "_mew"),
|
||||
drop = modname .. ":cat_" .. id,
|
||||
preserve_metadata = function(_, _, oldmeta, drops)
|
||||
if oldmeta.realname then
|
||||
oldmeta.description = oldmeta.realname
|
||||
oldmeta.realname = nil
|
||||
end
|
||||
drops[1]:get_meta():from_table({fields = oldmeta})
|
||||
end,
|
||||
after_place_node = function(pos, _, itemstack)
|
||||
checkfacedir(pos)
|
||||
local node = checkfacedir(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:from_table(itemstack:get_meta():to_table())
|
||||
myapi.setname(meta)
|
||||
checksnake(pos, node)
|
||||
end
|
||||
}
|
||||
minetest.register_node(modname .. ":cat_" .. id, nodecore.underride({}, basedef))
|
||||
|
Loading…
x
Reference in New Issue
Block a user