handle removal and more tests
This commit is contained in:
parent
6a7431215b
commit
74ec1c2ade
@ -1,4 +1,5 @@
|
||||
|
||||
-- returns the outer corners for the handle nodes
|
||||
local function get_outer_corners(pos1, pos2)
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
pos1 = vector.subtract(pos1, 1)
|
||||
@ -16,6 +17,53 @@ local function get_outer_corners(pos1, pos2)
|
||||
}
|
||||
end
|
||||
|
||||
-- true if already in removal function (disables recursion through on_destruct)
|
||||
local in_removal = false
|
||||
|
||||
-- removes all other handle nodes
|
||||
function pick_and_place.remove_handles(handle_pos)
|
||||
if in_removal then
|
||||
return
|
||||
end
|
||||
|
||||
local node = minetest.get_node(handle_pos)
|
||||
if node.name ~= "pick_and_place:handle" then
|
||||
return false, "not a valid handle node @ " .. minetest.pos_to_string(handle_pos)
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(handle_pos)
|
||||
local pos1 = minetest.string_to_pos(meta:get_string("pos1"))
|
||||
local pos2 = minetest.string_to_pos(meta:get_string("pos2"))
|
||||
|
||||
local name = meta:get_string("name")
|
||||
if not name or not pos1 or not pos2 then
|
||||
return false, "unexpected metadata"
|
||||
end
|
||||
|
||||
-- resolve to absolute coords
|
||||
pos1 = vector.add(pos1, handle_pos)
|
||||
pos2 = vector.add(pos2, handle_pos)
|
||||
|
||||
in_removal = true
|
||||
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
for _, hpos in ipairs(get_outer_corners(pos1, pos2)) do
|
||||
local hnode = minetest.get_node(hpos)
|
||||
if hnode.name == "pick_and_place:handle" then
|
||||
local hmeta = minetest.get_meta(hpos)
|
||||
if hmeta:get_string("name") == name then
|
||||
-- name and node matches, remove
|
||||
minetest.set_node(hpos, { name = "air" })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
in_removal = false
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-- sets handle nodes where possible
|
||||
function pick_and_place.configure(pos1, pos2, name)
|
||||
pos1, pos2 = pick_and_place.sort_pos(pos1, pos2)
|
||||
|
||||
|
23
configure.spec.lua
Normal file
23
configure.spec.lua
Normal file
@ -0,0 +1,23 @@
|
||||
|
||||
-- make sure we don't have any other nodes around
|
||||
local pos1 = {x=20, y=20, z=20}
|
||||
local pos2 = {x=25, y=25, z=25}
|
||||
|
||||
mtt.emerge_area(pos1, pos2)
|
||||
|
||||
mtt.register("configure handles and remove", function(callback)
|
||||
minetest.set_node(pos1, { name = "default:mese" })
|
||||
|
||||
pick_and_place.configure(pos1, pos2, "my build")
|
||||
assert(minetest.get_node(vector.subtract(pos1, 1)).name == "pick_and_place:handle")
|
||||
assert(minetest.get_node(vector.add(pos2, 1)).name == "pick_and_place:handle")
|
||||
|
||||
local success, err = pick_and_place.remove_handles(vector.add(pos2, 1))
|
||||
assert(success)
|
||||
assert(not err)
|
||||
|
||||
assert(minetest.get_node(vector.subtract(pos1, 1)).name == "air")
|
||||
assert(minetest.get_node(vector.add(pos2, 1)).name == "air")
|
||||
|
||||
callback()
|
||||
end)
|
@ -32,6 +32,7 @@ minetest.register_node("pick_and_place:handle", {
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
on_rightclick = on_rightclick,
|
||||
on_destruct = pick_and_place.remove_handles,
|
||||
drop = "",
|
||||
groups = {
|
||||
oddly_breakable_by_hand = 3,
|
||||
|
1
init.lua
1
init.lua
@ -25,6 +25,7 @@ dofile(MP .. "/preview.lua")
|
||||
dofile(MP .. "/craft.lua")
|
||||
|
||||
if minetest.get_modpath("mtt") and mtt.enabled then
|
||||
dofile(MP .. "/configure.spec.lua")
|
||||
dofile(MP .. "/create_tool.spec.lua")
|
||||
dofile(MP .. "/encode.spec.lua")
|
||||
dofile(MP .. "/schematic_rotate.spec.lua")
|
||||
|
@ -1,5 +1,5 @@
|
||||
default_game = minetest_game
|
||||
mg_name = v7
|
||||
mg_name = singlenode
|
||||
mtt_enable = true
|
||||
mtt_filter = pick_and_place
|
||||
secure.trusted_mods = mtt
|
||||
|
Loading…
x
Reference in New Issue
Block a user