From a932670ce5e72ec8dcb688b09ce81c1a891c99a8 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Mon, 7 Nov 2022 11:54:42 +0100 Subject: [PATCH] add `rotation_offset` support --- build.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/build.lua b/build.lua index 92f7016..a24b304 100644 --- a/build.lua +++ b/build.lua @@ -69,6 +69,17 @@ local function check_free(mapblock_pos) end end +local function apply_rotation_offset(building_def, rotation) + if building_def.rotation_offset then + rotation = rotation + building_def.rotation_offset + while rotation >= 360 do + rotation = rotation - 360 + end + end + + return rotation +end + function building_lib.can_build(mapblock_pos, building_name, rotation) local building_def = building_lib.get_building(building_name) if not building_def then @@ -78,6 +89,8 @@ function building_lib.can_build(mapblock_pos, building_name, rotation) -- check placement definition local placement = building_lib.get_placement(building_def.placement) + rotation = apply_rotation_offset(building_def, rotation) + -- check the conditions on every mapblock the building would occupy local size, message = placement.get_size(placement, mapblock_pos, building_def, rotation) if not size then @@ -126,6 +139,8 @@ function building_lib.do_build(mapblock_pos, building_name, rotation, callback) local building_def = building_lib.get_building(building_name) assert(building_def) + rotation = apply_rotation_offset(building_def, rotation) + -- place into world local placement = building_lib.get_placement(building_def.placement) local size = placement.get_size(placement, mapblock_pos, building_def, rotation)