From fbb5cb5649b782511fd942fe342ab94e5d841858 Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Tue, 8 Nov 2022 13:08:30 +0100 Subject: [PATCH] doc updates / replacements --- mapgen.lua | 11 +++++++++-- placements/default.lua | 6 +++++- readme.md | 29 ++++++++++++++++++++++++++++- 3 files changed, 42 insertions(+), 4 deletions(-) diff --git a/mapgen.lua b/mapgen.lua index c9f2804..68d8456 100644 --- a/mapgen.lua +++ b/mapgen.lua @@ -117,9 +117,9 @@ function building_lib.create_mapgen(opts) end local mapblock_pos = { x=x, y=y, z=z } - local temperature, humidity = get_temperature_humidity(mapblock_pos) local height = get_height(mapblock_pos) + local temperature, humidity = get_temperature_humidity(mapblock_pos) local biome = select_biome(opts.biomes, temperature, humidity) if mapblock_pos.y == opts.water_level and height <= mapblock_pos.y then @@ -183,5 +183,12 @@ function building_lib.create_mapgen(opts) end --z end --y end --x - end + end, { + get_height = get_height, + get_temperature_humidity = get_temperature_humidity, + get_biome = function(mapblock_pos) + local temperature, humidity = get_temperature_humidity(mapblock_pos) + return select_biome(opts.biomes, temperature, humidity) + end + } end \ No newline at end of file diff --git a/placements/default.lua b/placements/default.lua index 722d6e2..3604bf2 100644 --- a/placements/default.lua +++ b/placements/default.lua @@ -46,6 +46,10 @@ building_lib.register_placement("default", { -- translate to world-coords local world_pos = vector.add(mapblock_pos, rotated_rel_catalog_pos) + local replace = building_def.replace + if type(building_def.replace) == "function" then + replace = building_def.replace(mapblock_pos, building_def) + end local place_fn = catalog:prepare(catalog_pos, { transform = { @@ -54,7 +58,7 @@ building_lib.register_placement("default", { angle = rotation, disable_orientation = building_def.disable_orientation }, - replace = building_def.replace + replace = replace } }) diff --git a/readme.md b/readme.md index 7fbe41c..8ad984a 100644 --- a/readme.md +++ b/readme.md @@ -10,6 +10,12 @@ local success, message = building_lib.can_build(mapblock_pos, playername, buildi -- build it there local success, message = building_lib.do_build(mapblock_pos, playername, building_name, rotation, callback) +-- check if it can be removed +local success, message = building_lib.can_remove(mapblock_pos) + +-- remove it +local success, message = building_lib.do_remove(mapblock_pos) + -- registers a placeable building building_lib.register_building("buildings:my_building", { placement = "default", @@ -21,11 +27,32 @@ building_lib.register_building("buildings:my_building", { { on_slope = true, on_biome = "grass" }, { on_flat_surface = true, on_biome = "water" }, }, + -- simple catalog catalog = "my.zip", + -- more catalog options + catalog = { + filename = "my.zip", + -- offset in the catalog + offset = {x=0, y=2, z=0}, + -- size + size = {x=1, y=1, z=1}, + -- enable cache (only for 1x1x1 sized buildings, for mapgens) + cache = true + }, -- optional groups attribute groups = { building = true - } + }, + -- replacements + replace = { + ["old_mod:node"] = "new_mod:node" + }, + -- replacements as a function, can be used for biome-replacements + replace = function(mapblock_pos, building_def) + return { + ["old_mod:node"] = "new_mod:node" + } + end }) -- registers a placement type (connected, simple, etc)