From bd98580eb7f89a5fdc89ef2f1dda6c2979a2b962 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Sun, 19 Mar 2023 22:15:53 +0100 Subject: [PATCH] new event format --- build.lua | 39 +++++++++++++++++++++++++++++-------- mtt.lua | 2 +- placements/mapblock_lib.lua | 10 ++-------- remove.lua | 6 +++++- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/build.lua b/build.lua index e70562d..2436d84 100644 --- a/build.lua +++ b/build.lua @@ -78,18 +78,37 @@ function building_lib.build(mapblock_pos, playername, building_name, rotation, c end end) - placement.place(placement, mapblock_pos, building_def, rotation, function() + -- get or calculate replacements + local replacements = building_def.replace + if type(building_def.replace) == "function" then + replacements = building_def.replace(mapblock_pos, building_def) + end + + placement.place(placement, mapblock_pos, building_def, replacements, rotation, function() callback() if old_building_info then -- replacement local old_building_def = building_lib.get_building(old_building_info.name) - building_lib.fire_event("replaced", mapblock_pos, playername, - old_building_def, old_building_info.rotation, old_building_info.size, - building_def, rotation, size - ) + building_lib.fire_event("replaced", { + playername = playername, + mapblock_pos = mapblock_pos, + old_building_def = old_building_def, + old_building_info = old_building_info, + building_def = building_def, + replacements = replacements, + rotation = rotation, + size = size + }) else -- new build - building_lib.fire_event("placed", mapblock_pos, playername, building_def, rotation, size) + building_lib.fire_event("placed", { + playername = playername, + mapblock_pos = mapblock_pos, + building_def = building_def, + replacements = replacements, + rotation = rotation, + size = size + }) end end) return true @@ -108,6 +127,10 @@ function building_lib.build_mapgen(mapblock_pos, building_name, rotation) } }) - placement.place(placement, mapblock_pos, building_def, rotation) - building_lib.fire_event("placed_mapgen", mapblock_pos, building_def, rotation) + placement.place(placement, mapblock_pos, building_def, {}, rotation) + building_lib.fire_event("placed_mapgen", { + mapblock_pos = mapblock_pos, + building_def = building_def, + rotation = rotation + }) end \ No newline at end of file diff --git a/mtt.lua b/mtt.lua index 5020cc0..41ba619 100644 --- a/mtt.lua +++ b/mtt.lua @@ -4,5 +4,5 @@ building_lib.register_placement("dummy", { local size = building_def.size or {x=1,y=1,z=1} return mapblock_lib.rotate_size(size, rotation) end, - place = function(_, _, _, _, callback) callback() end + place = function(_, _, _, _, _, callback) callback() end }) \ No newline at end of file diff --git a/placements/mapblock_lib.lua b/placements/mapblock_lib.lua index 82ac2ed..d7deb35 100644 --- a/placements/mapblock_lib.lua +++ b/placements/mapblock_lib.lua @@ -1,7 +1,7 @@ -- mapblock_lib schematic catalog building_lib.register_placement("mapblock_lib", { - place = function(self, mapblock_pos, building_def, rotation, callback) + place = function(self, mapblock_pos, building_def, replacements, rotation, callback) callback = callback or function() end local catalog @@ -33,12 +33,6 @@ building_lib.register_placement("mapblock_lib", { local iterator = mapblock_lib.pos_iterator(catalog_pos1, catalog_pos2) - -- get or calculate replacements - local replace = building_def.replace - if type(building_def.replace) == "function" then - replace = building_def.replace(mapblock_pos, building_def) - end - local function worker() local catalog_pos = iterator() if not catalog_pos then @@ -61,7 +55,7 @@ building_lib.register_placement("mapblock_lib", { angle = rotation, disable_orientation = building_def.disable_orientation }, - replace = replace + replace = replacements } }) diff --git a/remove.lua b/remove.lua index 40277bf..ce5f85a 100644 --- a/remove.lua +++ b/remove.lua @@ -46,6 +46,10 @@ function building_lib.remove(mapblock_pos, playername) end end - building_lib.fire_event("removed", origin, playername, building_info) + building_lib.fire_event("removed", { + mapblock_pos = origin, + playername = playername, + building_info = building_info + }) return true end \ No newline at end of file