diff --git a/common.lua b/common.lua index 72e2918..bad843a 100644 --- a/common.lua +++ b/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) diff --git a/conditions.lua b/conditions.lua index 84476cc..59f0149 100644 --- a/conditions.lua +++ b/conditions.lua @@ -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