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)
|
||||
local _, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
||||
return origin
|
||||
end
|
||||
|
||||
-- returns the building_info on the position
|
||||
function building_lib.get_placed_building_info(mapblock_pos)
|
||||
local mapblock_data, origin = mapblock_lib.resolve_data_link(building_lib.store, mapblock_pos)
|
||||
if mapblock_data and mapblock_data.building then
|
||||
@ -11,6 +13,21 @@ function building_lib.get_placed_building_info(mapblock_pos)
|
||||
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)
|
||||
local placement = building_lib.get_placement(building_def.placement)
|
||||
return placement.get_size(placement, nil, building_def, rotation)
|
||||
|
@ -115,12 +115,9 @@ end
|
||||
-- checks if a building with specified group is placed there already
|
||||
building_lib.register_condition("group", {
|
||||
can_build = function(mapblock_pos, value)
|
||||
local building_info = building_lib.get_placed_building_info(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
|
||||
return true
|
||||
end
|
||||
local building_def = building_lib.get_building_def_at(mapblock_pos)
|
||||
if building_def and building_def.groups and building_def.groups[value] then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user