add building_lib.get_building_def_at
This commit is contained in:
parent
41491f119b
commit
86f48a85cb
17
common.lua
17
common.lua
@ -1,9 +1,11 @@
|
|||||||
|
|
||||||
|
-- returns the origin of the placed building
|
||||||
function building_lib.get_origin(mapblock_pos)
|
function building_lib.get_origin(mapblock_pos)
|
||||||
local _, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
local _, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
||||||
return origin
|
return origin
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns the building_info on the position
|
||||||
function building_lib.get_placed_building_info(mapblock_pos)
|
function building_lib.get_placed_building_info(mapblock_pos)
|
||||||
local mapblock_data, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
local mapblock_data, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
||||||
if mapblock_data and mapblock_data.building then
|
if mapblock_data and mapblock_data.building then
|
||||||
@ -11,6 +13,21 @@ function building_lib.get_placed_building_info(mapblock_pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- returns the building_def on the position
|
||||||
|
function building_lib.get_building_def_at(mapblock_pos)
|
||||||
|
local info, origin = building_lib.get_placed_building_info(mapblock_pos)
|
||||||
|
if not info then
|
||||||
|
return false, "no building found"
|
||||||
|
end
|
||||||
|
|
||||||
|
local building_def = building_lib.get_building(info.name)
|
||||||
|
if not building_def then
|
||||||
|
return false, "building_def not found for '" .. info.name .. "'"
|
||||||
|
end
|
||||||
|
|
||||||
|
return building_def, origin, info.rotation
|
||||||
|
end
|
||||||
|
|
||||||
function building_lib.get_building_size(building_def, rotation)
|
function building_lib.get_building_size(building_def, rotation)
|
||||||
local placement = building_lib.get_placement(building_def.placement)
|
local placement = building_lib.get_placement(building_def.placement)
|
||||||
return placement.get_size(placement, nil, building_def, rotation)
|
return placement.get_size(placement, nil, building_def, rotation)
|
||||||
|
@ -115,13 +115,10 @@ end
|
|||||||
-- checks if a building with specified group is placed there already
|
-- checks if a building with specified group is placed there already
|
||||||
building_lib.register_condition("group", {
|
building_lib.register_condition("group", {
|
||||||
can_build = function(mapblock_pos, value)
|
can_build = function(mapblock_pos, value)
|
||||||
local building_info = building_lib.get_placed_building_info(mapblock_pos)
|
local building_def = building_lib.get_building_def_at(mapblock_pos)
|
||||||
if building_info then
|
|
||||||
local building_def = building_lib.get_building(building_info.name)
|
|
||||||
if building_def and building_def.groups and building_def.groups[value] then
|
if building_def and building_def.groups and building_def.groups[value] then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user