add building_def.remove_conditions
support
This commit is contained in:
parent
02da70515f
commit
89cb60e394
@ -72,13 +72,20 @@ function building_lib.check_condition_group(mapblock_pos1, mapblock_pos2, condit
|
|||||||
elseif selector == "base" then
|
elseif selector == "base" then
|
||||||
-- match only base positions
|
-- match only base positions
|
||||||
it = mapblock_lib.pos_iterator(mapblock_pos1, {x=mapblock_pos2.x, y=mapblock_pos1.y, z=mapblock_pos2.z})
|
it = mapblock_lib.pos_iterator(mapblock_pos1, {x=mapblock_pos2.x, y=mapblock_pos1.y, z=mapblock_pos2.z})
|
||||||
elseif selector == "underground" then
|
elseif selector == "underground" or selector == "below" then
|
||||||
-- match only underground positions
|
-- match only underground positions
|
||||||
it = mapblock_lib.pos_iterator({
|
it = mapblock_lib.pos_iterator({
|
||||||
x=mapblock_pos1.x, y=mapblock_pos1.y-1, z=mapblock_pos1.z
|
x=mapblock_pos1.x, y=mapblock_pos1.y-1, z=mapblock_pos1.z
|
||||||
},{
|
},{
|
||||||
x=mapblock_pos2.x, y=mapblock_pos1.y-1, z=mapblock_pos2.z
|
x=mapblock_pos2.x, y=mapblock_pos1.y-1, z=mapblock_pos2.z
|
||||||
})
|
})
|
||||||
|
elseif selector == "above" then
|
||||||
|
-- match only above positions
|
||||||
|
it = mapblock_lib.pos_iterator({
|
||||||
|
x=mapblock_pos1.x, y=mapblock_pos1.y+1, z=mapblock_pos1.z
|
||||||
|
},{
|
||||||
|
x=mapblock_pos2.x, y=mapblock_pos1.y+1, z=mapblock_pos2.z
|
||||||
|
})
|
||||||
else
|
else
|
||||||
-- try to parse a manual position
|
-- try to parse a manual position
|
||||||
local rel_pos = minetest.string_to_pos(selector)
|
local rel_pos = minetest.string_to_pos(selector)
|
||||||
|
@ -20,8 +20,13 @@ local success, message = building_lib.remove(mapblock_pos)
|
|||||||
building_lib.register_building("buildings:my_building", {
|
building_lib.register_building("buildings:my_building", {
|
||||||
placement = "mapblock_lib",
|
placement = "mapblock_lib",
|
||||||
conditions = {
|
conditions = {
|
||||||
|
-- can only be placed if the whole area is empty
|
||||||
{["*"] = { empty = true }}
|
{["*"] = { empty = true }}
|
||||||
},
|
},
|
||||||
|
remove_conditions = {
|
||||||
|
-- can only be removed if nothing is built above
|
||||||
|
{["above"] = { empty = true }}
|
||||||
|
},
|
||||||
-- simple catalog
|
-- simple catalog
|
||||||
catalog = "my.zip",
|
catalog = "my.zip",
|
||||||
-- more catalog options
|
-- more catalog options
|
||||||
|
18
remove.lua
18
remove.lua
@ -1,15 +1,27 @@
|
|||||||
|
|
||||||
function building_lib.can_remove(mapblock_pos)
|
function building_lib.can_remove(mapblock_pos)
|
||||||
local mapblock_data = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
local building_info, origin = building_lib.get_placed_building_info(mapblock_pos)
|
||||||
if not mapblock_data or not mapblock_data.building then
|
if not building_info then
|
||||||
return false, "no building found"
|
return false, "no building found"
|
||||||
end
|
end
|
||||||
|
|
||||||
local building_def = building_lib.get_building(mapblock_data.building.name)
|
local building_def = building_lib.get_building(building_info.name)
|
||||||
if not building_def then
|
if not building_def then
|
||||||
return false, "unknown building"
|
return false, "unknown building"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if building_def.remove_conditions then
|
||||||
|
-- check removal conditions
|
||||||
|
local size = building_info.size or {x=1, y=1, z=1}
|
||||||
|
local mapblock_pos2 = vector.add(origin, vector.subtract(size, 1))
|
||||||
|
local success, message = building_lib.check_condition_groups(
|
||||||
|
origin, mapblock_pos2, building_def.remove_conditions
|
||||||
|
)
|
||||||
|
if not success then
|
||||||
|
return false, message
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user