diff --git a/mods/jvmi_biomes/api.lua b/mods/jvmi_biomes/api.lua new file mode 100644 index 0000000..79c0c7f --- /dev/null +++ b/mods/jvmi_biomes/api.lua @@ -0,0 +1,14 @@ +-- Imports ----------------------------------------------------------------------------------------- + +local api = _G["jvmi_biomes"] + + +-- Functions --------------------------------------------------------------------------------------- + +--[[ + Apply biomes to the base terrain provided. + + Args: + region:jvmi_mapgen:Region - the region currently being generated +]]-- +function api.apply_biomes(region) end diff --git a/mods/jvmi_biomes/apply.lua b/mods/jvmi_biomes/apply.lua new file mode 100644 index 0000000..5091356 --- /dev/null +++ b/mods/jvmi_biomes/apply.lua @@ -0,0 +1,82 @@ +-- Imports ----------------------------------------------------------------------------------------- + +-- Since we're in the mapgen environment, we can't count on the mod loading process. Instead, we +-- have to load everything we need from other mods manually. + +local core = _G["core"] +local api = _G["jvmi_biomes"] + +local path = core.get_modpath("jvmi_constants") +dofile(path.."/constants.lua") +local C = _G["jvmi_constants"] + +path = core.get_modpath("jvmi_mapgen") +dofile(path.."/init.lua") +local mapgen = _G["jvmi_mapgen"] +local Region = mapgen.Region + + +-- Private ----------------------------------------------------------------------------------------- + +local private = {} + +--[[ + Assigns a specific biome to each position in the region. + + Args: + region:Region - the region currently being generated +]]-- +function private.assign_biomes(region) + region.iterate_columns(function(x, z) + local terrain_type = region:get_meta(Region.META.TERRAIN_TYPE, x, z) + local terrain = C.TERRAIN_TYPES[terrain_type] + region:set_meta(Region.META.BIOME, x, z, core.get_biome_id(terrain.name)) + end) +end + +--[[ + Replace the upper layers of stone with biome-specific top and filler nodes. + + Args: + region:Region - the region currently being generated +]]-- +function private.fill_surface(region) + region.iterate_columns(function(x, z) + local biome_id = region:get_meta(Region.META.BIOME, x, z) + local biome_name = core.get_biome_name(biome_id) + local biome = core.registered_biomes[biome_name] + + local y = region:get_meta(Region.META.ALTITUDE) + local top_count = biome.depth_top or 0 + local filler_count = biome.depth_filler or 0 + + while y >= region.fill_min.y do + if top_count > 0 then + local content_id = core.get_content_id(biome.node_top) + if content_id then + region:set_content_id(x, y, z, content_id) + end + top_count = top_count - 1 + elseif filler_count > 0 then + local content_id = core.get_content_id(biome.node_filler) + if content_id then + region:set_content_id(x, y, z, content_id) + end + filler_count = filler_count - 1 + else + break + end + + y = y - 1 + end + end) +end + + +-- API Implementations ----------------------------------------------------------------------------- + +function api.apply_biomes(region) + private.assign_biomes(region) + + private.fill_surface(region) +end diff --git a/mods/jvmi_biomes/definitions.lua b/mods/jvmi_biomes/definitions.lua new file mode 100644 index 0000000..74f266d --- /dev/null +++ b/mods/jvmi_biomes/definitions.lua @@ -0,0 +1,52 @@ +-- Imports ----------------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_biome({ + name = "ocean_floor", + node_top = "jvmi_nodes:clay", depth_top = 4, +}) + +core.register_biome({ + name = "ocean_abyss", + node_top = "jvmi_nodes:clay", depth_top = 2, + node_filler = "jvmi_nodes:gravel", depth_filler = 2, +}) + +core.register_biome({ + name = "ocean_shelf", + node_top = "jvmi_nodes:sand", depth_top = 2, + node_filler = "jvmi_nodes:gravel", depth_filler = 2, +}) + +core.register_biome({ + name = "ocean_surface", + node_top = "jvmi_nodes:sand", depth_top = 2, + node_filler = "jvmi_nodes:gravel", depth_filler = 2, +}) + +core.register_biome({ + name = "land_plains", + node_top = "jvmi_nodes:turf", depth_top = 1, + node_filler = "jvmi_nodes:dirt", depth_filler = 3, +}) + +core.register_biome({ + name = "land_hills", + node_top = "jvmi_nodes:turf", depth_top = 1, + node_filler = "jvmi_nodes:dirt", depth_filler = 2, +}) + +core.register_biome({ + name = "land_moors", + node_top = "jvmi_nodes:turf", depth_top = 1, + node_filler = "jvmi_nodes:dirt", depth_filler = 1, +}) + +core.register_biome({ + name = "land_mountains", + node_top = "jvmi_nodes:gravel", depth_top = 1, +}) diff --git a/mods/jvmi_biomes/init.lua b/mods/jvmi_biomes/init.lua new file mode 100644 index 0000000..4da95ff --- /dev/null +++ b/mods/jvmi_biomes/init.lua @@ -0,0 +1,23 @@ +-- Imports ----------------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Public ------------------------------------------------------------------------------------------ + +jvmi_biomes = {} -- luacheck: globals jvmi_biomes + +local path = core.get_modpath("jvmi_biomes") +dofile(path.."/api.lua") +dofile(path.."/apply.lua") + + +-- Registrations ----------------------------------------------------------------------------------- + +core.clear_registered_biomes() +dofile(path.."/definitions.lua") + + +-- Script ------------------------------------------------------------------------------------------ + +core.log("info", "jvmi_biomes loaded") diff --git a/mods/jvmi_biomes/mod.conf b/mods/jvmi_biomes/mod.conf new file mode 100644 index 0000000..b5fe126 --- /dev/null +++ b/mods/jvmi_biomes/mod.conf @@ -0,0 +1,4 @@ +name = jvmi_biomes +title = Jules Verne's Mysterious Island / Biomes +description = define biomes and decoration/generation functions for them +author = tungstonminer diff --git a/mods/jvmi_constants/api.lua b/mods/jvmi_constants/api.lua new file mode 100644 index 0000000..398fa62 --- /dev/null +++ b/mods/jvmi_constants/api.lua @@ -0,0 +1,112 @@ +-- Import ------------------------------------------------------------------------------------------ + +local C = _G["jvmi_constants"] +local core = _G["core"] + + +-- Node Definition Constants ----------------------------------------------------------------------- + +C.ANIMATION_TYPE = { + VERTICAL_FRAMES = "vertical_frames", + SHEET_2D = "sheet_2d", +} + +C.DRAW_TYPE = { + ALL_FACES_OPTIONAL = "allfaces_optional", + FLOWING_LIQUID = "flowingliquid", + LIQUID = "liquid", + MESH = "mesh", + NODE_BOX = "nodebox", + NORMAL = "normal", + PLANT_LIKE = "plantlike", +} + +C.LIQUID_TYPE = { + NONE = "none", + SOURCE = "source", + FLOWING = "flowing", +} + +C.TEXTURE_ALPHA = { + OPAQUE = "opaque", + CLIP = "clip", + BLEND = "blend", +} + +C.VISCOSITY = { + XXX_FAST = 0, + XX_FAST = 1, + X_FAST = 2, + FAST = 3, + SLOW = 4, + X_SLOW = 5, + XX_SLOW = 6, + XXX_SLOW = 7, +} + +C.WAVING = { + NO = 0, + PLANT_LIKE = 1, + LEAF_LIKE = 2, + LIQUID_LIKE = 3, +} + + +-- Mapgen Constants -------------------------------------------------------------------------------- + +--[[ Key altitudes which define the vertical regions of the generated map. ]]-- +C.ALTITUDE = { + SKY = 256, + MOUNTAIN = 128, + MOOR = 64, + HILL = 32, + PLAIN = 16, + SURFACE = 0, + SHALLOW = -16, + DEEP = -32, + ABYSS = -64, + BEDROCK = -128, +} + +local A = C.ALTITUDE + +--[[ The amount of overlap (as a perentage of total weight) between adjacent terrain types. ]]-- +C.TERRAIN_BLEND = 0.15 + +--[[ The distance from the center of the map at which only the lowest terrain types are used. ]]-- +C.TERRAIN_RADIUS = 3096 + +--[[ The noise generator that decides which terrain type is active at a given x,z location. ]]-- +C.TERRAIN_TYPE_NOISE = core.get_value_noise({ + flags = "eased", + lacunarity = 2, + octaves = 1, + offset = 0, + persistence = 0.5, + scale = 1.0, + seed = 8381909047, + spread = { x = 512, y = 512, z = 0 }, +}) + +--[[ + A table defining the terrain types used in generating the base terrain. + + These must be listed in average altitude order from lowest to highest. The weights are merely + relative values, and can be whatever you like. I find it easiest to think of them as + percentages and choose value which tally to 100. + + Bear in mind that noise values are adjusted downward are you approach `TERRAIN_RADIUS` meters + from the center of the map, so these weights are only going to be fully reflected in the terrain + generated at the center of the map, and will progressively favor lower altitudes as you move + toward the edges. +]]-- +C.TERRAIN_TYPES = { + { name = "ocean_floor", lowest = A.BEDROCK + 10, highest = A.BEDROCK + 26, weight = 5 }, + { name = "ocean_abyss", lowest = A.ABYSS, highest = A.DEEP, weight = 15 }, + { name = "ocean_shelf", lowest = A.DEEP, highest = A.SHALLOW, weight = 10 }, + { name = "ocean_surface", lowest = A.SURFACE - 4, highest = A.SURFACE, weight = 5 }, + { name = "land_plains", lowest = A.PLAIN - 8, highest = A.PLAIN, weight = 20 }, + { name = "land_hills", lowest = A.HILL - 32, highest = A.HILL, weight = 25 }, + { name = "land_moors", lowest = A.MOOR - 16, highest = A.MOOR, weight = 15 }, + { name = "land_mountains", lowest = A.MOUNTAIN - 80, highest = A.MOUNTAIN, weight = 5 }, +} diff --git a/mods/jvmi_constants/constants.lua b/mods/jvmi_constants/constants.lua deleted file mode 100644 index 483d0a5..0000000 --- a/mods/jvmi_constants/constants.lua +++ /dev/null @@ -1,55 +0,0 @@ --- Constants --------------------------------------------------------------------------------------- - -jvmi_constants = { -- luacheck: globals jvmi_constants - ALTITUDE = { - SKY = 256, - MOUNTAIN = 128, - MOOR = 64, - HILL = 32, - PLAIN = 16, - SURFACE = 0, - SHALLOW = -16, - DEEP = -32, - ABYSS = -64, - BEDROCK = -128, - }, - ANIMATION_TYPE = { - VERTICAL_FRAMES = "vertical_frames", - SHEET_2D = "sheet_2d", - }, - DRAW_TYPE = { - ALL_FACES_OPTIONAL = "allfaces_optional", - FLOWING_LIQUID = "flowingliquid", - LIQUID = "liquid", - MESH = "mesh", - NODE_BOX = "nodebox", - NORMAL = "normal", - PLANT_LIKE = "plantlike", - }, - LIQUID_TYPE = { - NONE = "none", - SOURCE = "source", - FLOWING = "flowing", - }, - TEXTURE_ALPHA = { - OPAQUE = "opaque", - CLIP = "clip", - BLEND = "blend", - }, - VISCOSITY = { - XXX_FAST = 0, - XX_FAST = 1, - X_FAST = 2, - FAST = 3, - SLOW = 4, - X_SLOW = 5, - XX_SLOW = 6, - XXX_SLOW = 7, - }, - WAVING = { - NO = 0, - PLANT_LIKE = 1, - LEAF_LIKE = 2, - LIQUID_LIKE = 3, - }, -} diff --git a/mods/jvmi_constants/init.lua b/mods/jvmi_constants/init.lua index 98031ec..25755e1 100644 --- a/mods/jvmi_constants/init.lua +++ b/mods/jvmi_constants/init.lua @@ -2,10 +2,11 @@ local core = _G["core"] -local path = core.get_modpath("jvmi_constants") -dofile(path.."/constants.lua") - -- Script ------------------------------------------------------------------------------------------ +jvmi_constants = {} -- luacheck: globals jvmi_constants +local path = core.get_modpath("jvmi_constants") +dofile(path.."/api.lua") + core.log("info", "jvmi_constants loaded") diff --git a/mods/jvmi_first/init.lua b/mods/jvmi_first/init.lua index b927749..9b2b9da 100644 --- a/mods/jvmi_first/init.lua +++ b/mods/jvmi_first/init.lua @@ -3,19 +3,6 @@ local core = _G["core"] --- Private Functions ------------------------------------------------------------------------------- - -local private = {} - -function private.register_mapgen_aliases() - core.register_alias("mapgen_stone", "jvmi_nodes:stone") - core.register_alias("mapgen_water_source", "jvmi_nodes:water_source") - core.register_alias("mapgen_river_water_source", "jvmi_nodes:water_source") -end - - -- Script ------------------------------------------------------------------------------------------ -private.register_mapgen_aliases() - core.log("info", "jvmi_first loaded") diff --git a/mods/jvmi_mapgen/init.lua b/mods/jvmi_mapgen/init.lua index f8aeec8..bf0eb51 100644 --- a/mods/jvmi_mapgen/init.lua +++ b/mods/jvmi_mapgen/init.lua @@ -2,11 +2,10 @@ local core = _G["core"] -local path = core.get_modpath("jvmi_mapgen") - -- Registrations ----------------------------------------------------------------------------------- +local path = core.get_modpath("jvmi_mapgen") core.register_mapgen_script(path.."/mapenv.lua") diff --git a/mods/jvmi_mapgen/mapenv.lua b/mods/jvmi_mapgen/mapenv.lua index 3327bad..3fe743b 100644 --- a/mods/jvmi_mapgen/mapenv.lua +++ b/mods/jvmi_mapgen/mapenv.lua @@ -1,193 +1,169 @@ -- Imports & Exports ------------------------------------------------------------------------------- +local biomes = _G["jvmi_biomes"] local core = _G["core"] local math = _G["math"] -local VoxelArea = _G["VoxelArea"] +local mapgen = _G["mapgen"] +local table = _G["jvmi_table"] +local vector = _G["vector"] --- Since this script runs inside the mapgen environment, the constants won't be in the global table, --- yet, so we need to run the file manually. +-- Since this script runs inside the mapgen environment, we can't count on the jvmi_constants mod +-- to have been loaded. Instead, we just need to load the constants manually. local jvmi_constants_path = core.get_modpath("jvmi_constants") dofile(jvmi_constants_path.."/constants.lua") local C = _G["jvmi_constants"] local A = C.ALTITUDE +local Region = mapgen.Region + -- Constants --------------------------------------------------------------------------------------- ---[[ The amount of overlap (as a perentage of total weight) between adjacent terrain types. ]]-- -local TERRAIN_BLEND = 0.15 +local AIR_ID = core.CONTENT_AIR +local BEDROCK_ID = core.get_content_id("jvmi_nodes:bedrock") +local STONE_ID = core.get_content_id("jvmi_nodes:stone") +local WATER_ID = core.get_content_id("jvmi_nodes:water_source") ---[[ The distance from the center of the map at which only the lowest terrain types are used. ]]-- -local TERRAIN_RADIUS = 3096 - ---[[ The noise generator that decides which terrain type is active at a given x,z location. ]]-- -local TERRAIN_TYPE_NOISE = core.get_value_noise({ - flags = "eased", - lacunarity = 2, - octaves = 1, - offset = 0, - persistence = 0.5, - scale = 1.0, - seed = 8381909047, - spread = { x = 512, y = 512, z = 0 }, -}) - ---[[ - A table defining the terrain types used in generating the base terrain. - - These must be listed in average altitude order from lowest to highest. The weights are merely - relative values, and can be whatever you like. I find it easiest to think of them as - percentages and choose value which tally to 100. - - Bear in mind that noise values are adjusted downward are you approach `TERRAIN_RADIUS` meters - from the center of the map, so these weights are only going to be fully reflected in the terrain - generated at the center of the map, and will progressively favor lower altitudes as you move - toward the edges. -]]-- -local TERRAIN_TYPES = { - { name = "ocean_floor", lowest = A.BEDROCK + 10, highest = A.BEDROCK + 26, weight = 5 }, - { name = "ocean_abyss", lowest = A.ABYSS, highest = A.DEEP, weight = 15 }, - { name = "ocean_shelf", lowest = A.DEEP, highest = A.SHALLOW, weight = 10 }, - { name = "ocean_surface", lowest = A.SURFACE - 4, highest = A.SURFACE, weight = 5 }, - { name = "land_plains", lowest = A.PLAIN - 8, highest = A.PLAIN, weight = 20 }, - { name = "land_hills", lowest = A.HILL - 32, highest = A.HILL, weight = 25 }, - { name = "land_moors", lowest = A.MOOR - 16, highest = A.MOOR, weight = 15 }, - { name = "land_mountains", lowest = A.MOUNTAIN - 80, highest = A.MOUNTAIN, weight = 5 }, -} +--[[ Create a deep clone of the shared terrain types as we need to augment the entries. ]]-- +local TERRAIN_TYPES = nil -- Private ----------------------------------------------------------------------------------------- local private = { - - --[[ A shared buffer used to hold raw voxel data during terrain generation. ]]-- - data = {} + --[[ A share object which assists in generating regions of the map. ]]-- + region = Region:new() } --[[ - Compute the altitude of a certain world location from underlying noise generators. - - This function uses a set of individual terrain types defined by `TERRAIN_TYPES`. An overall - terrain noise generator (see: `TERRAIN_TYPE_NOISE`) is used to determine which terrain type - should appear at a given location. Each terrain type has its own noise generator, which is - then used to determine the altitude at the given location. - - To avoid abrupt lines where we shift from one terrain type to another, the `TERRAIN_BLEND` - factor indicates the percentage overlap between adjacent zones where values from both noise - generators are smoothly blended into a single value. - - Finally, we want the map to make up an island with a smooth transition from higher-altitude - terrain in the center to deep ocean terrain at the edges. So, we modify the values from - `TERRAIN_TYPE_NOISE` to force them lower and lower as you move toward `TERRAIN_RADIUS`. By the - time you reach that distance from the center of the islands, the terrain selection will be - pinned to the lowest possible terrain type. + Fill the `Region.META.ALTITUDE` meta data for the given region. Args: - - pos:vector - the position whose altitude is wanted - - Returns: - - an int indicating the highest ground-level block in the x,z coordinate given + region:Region - a region of the world being generated. The results of the caluations are + written back to the same map. ]]-- -function private.compute_altitude_at(pos) - local radius = TERRAIN_RADIUS - local radius_factor = ((pos.x * pos.x) + (pos.y * pos.y)) / (radius * radius) - radius_factor = math.max(0, math.min(1, 1.0 - radius_factor)) +function private.assign_altitudes(region) + local pos = vector:new() - local raw_index = (TERRAIN_TYPE_NOISE:get_2d(pos) + 2) / 2 - raw_index = math.max(0, math.min(1, raw_index)) - raw_index = raw_index * radius_factor + region.iterate_columns(function(x, z) + local altitude = 0 + pos.x, pos.y = x, z - local band_start = raw_index - TERRAIN_BLEND / 2 - local band_end = raw_index + TERRAIN_BLEND / 2 - - local result = 0 - for _, terrain in ipairs(TERRAIN_TYPES) do - local overlap_start = math.max(band_start, terrain.range_start) - local overlap_end = math.min(band_end, terrain.range_end) - local overlap = overlap_end - overlap_start - - if overlap > 0 then - local factor = overlap / TERRAIN_BLEND - result = result + factor * terrain.noise:get_2d(pos) + for _, blend in ipairs(region:get_meta(Region.META.TERRAIN_BLEND)) do + local terrain = TERRAIN_TYPES[blend.terrain_type] + local contribution = blend.weight * terrain.noise:get_2d(pos) + altitude = altitude + contribution end - end + end) +end - return math.floor(result) +--[[ +]]-- +function private.assign_biomes(region) + +end + +--[[ + Compute the combination of terrain types which contribute to each map location. + + This function uses a set of individual terrain types defined by `C.TERRAIN_TYPES`. An overall + terrain noise generator, `C.TERRAIN_TYPE_NOISE`, is used to determine which terrain type should + appear at a given location. + + To avoid abrupt lines where we shift from one terrain type to another, the `C.TERRAIN_BLEND` + factor indicates the percentage overlap between adjacent zones where both types are smoothly + blended together. + + Finally, we want the map to make up an island with a smooth transition from higher-altitude + terrain in the center to deep ocean terrain at the edges. So, we modify the values from + `C.TERRAIN_TYPE_NOISE` to force them lower and lower as you move toward `C.TERRAIN_RADIUS`. By + the time you reach that distance from the center of the islands, the terrain selection will be + pinned to the lowest possible terrain type. + + The results of these calculations are stored in the `TERRAIN_BLEND` and `TERRAIN_TYPE` meta + data for the given region. + + Args: + region:Region - the region of the world being generated. The results of the caluations are + written back to the same object. +]]-- +function private.assign_terrain_meta(region) + local radius_squared = C.TERRAIN_RADIUS * C.TERRAIN_RADIUS + local pos = { x = 0, y = 0, z = 0 } + + region.iterate_columns(function(x, z) + local radius_weight = ((x * x) + (z * z)) / radius_squared + radius_weight = math.max(0, math.min(1, 1.0 - radius_weight)) + + pos.x, pos.y = x, z + local raw_index = (C.TERRAIN_TYPE_NOISE:get_2d(pos) + 2) / 2 + raw_index = math.max(0, math.min(1, raw_index)) + raw_index = raw_index * radius_weight + + local band_start = raw_index - C.TERRAIN_BLEND / 2 + local band_end = raw_index + C.TERRAIN_BLEND / 2 + + local max_weight = 0 + for terrain_type, terrain in ipairs(TERRAIN_TYPES) do + local overlap_start = math.max(band_start, terrain.range_start) + local overlap_end = math.min(band_end, terrain.range_end) + local overlap = overlap_end - overlap_start + + local blend = {} + if overlap > 0 then + local weight = overlap / C.TERRAIN_BLEND + table.append(blend, { weight = weight, terrain_type = terrain_type }) + + if weight >= max_weight then + max_weight = weight + region:set_meta(Region.META.TERRAIN_TYPE, x, z, terrain_type) + end + end + + region:set_meta(Region.META_TERRAIN_BLEND, x, z, blend) + end + end) end --[[ Fill the lowest layer of the world with bedrock covered by stone. Args: - - area:VoxelArea - an area calibrated to the area to fill - - fill_min:vector - the minimal corner of the area to fill - - fill_max:vector - the maximal corner of the area to fill + region:Region - the portion of the world currently being generated ]]-- -function private.fill_bedrock(area, fill_min, fill_max) - if fill_min.y > A.BEDROCK then return end - - local bedrock_id = core.get_content_id("jvmi_nodes:bedrock") - local stone_id = core.get_content_id("mapgen_stone") - - for x = fill_min.x, fill_max.x do - for z = fill_min.z, fill_max.z do - private.data[area:index(x, A.BEDROCK, z)] = bedrock_id - private.data[area:index(x, A.BEDROCK + 1, z)] = stone_id - end - end +function private.fill_bedrock(region) + region.iterate_plane(A.BEDROCK, function(x, y, z) + region:set_content_id(x, y, z, BEDROCK_ID) + region:set_content_id(x, y + 1, z, STONE_ID) + end) end --[[ Fill in the oceans by replacing air blocks below sea level with water. Args: - - area:VoxelArea - an area calibrated to the area to fill - - fill_min:vector - the minimal corner of the area to fill - - fill_max:vector - the maximal corner of the area to fill + region:Region - the portion of the world currently being generated ]]-- -function private.fill_ocean(area, fill_min, fill_max) - if fill_min.y > A.SURFACE then return end - - local water_id = core.get_content_id("mapgen_water_source") - local y_max = math.min(fill_max.y, A.SURFACE) - local y_min = math.max(fill_min.y, A.BEDROCK) - - for x = fill_min.x, fill_max.x do - for y = y_min, y_max do - for z = fill_min.z, fill_max.z do - local index = area:index(x, y, z) - if private.data[index] == core.CONTENT_AIR then - private.data[index] = water_id - end - end +function private.fill_ocean(region) + region.iterate_below(A.SURFACE, function(x, y, z) + if region:get_content_id(x, y, z) == AIR_ID then + region:set_content_id(x, y, z, WATER_ID) end - end + end) end --[[ - Fill in base stone terrain using altitude noise. + Fill in base stone terrain using the pre-computed altitudes. Args: - - area:VoxelArea - an area calibrated to the area to fill - - fill_min:vector - the minimal corner of the area to fill - - fill_max:vector - the maximal corner of the area to fill + region:Region - the portion of the world currently being generated ]]-- -function private.fill_terrain(area, fill_min, fill_max) - local pos = { x = 0, y = 0, z = 0 } - local stone_id = core.get_content_id("mapgen_stone") - local y_max = math.min(fill_max.y, A.SKY) - local y_min = math.max(fill_min.y, A.BEDROCK) - - for x = fill_min.x, fill_max.x do - for z = fill_min.z, fill_max.z do - pos.x, pos.y = x, z - local y_terrain = private.compute_altitude_at(pos) - - for y = y_min, math.min(y_max, y_terrain) do - private.data[area:index(x, y, z)] = stone_id - end - end - end +function private.fill_terrain(region) + region:iterate_fill(function(x, y, z) + local altitude = region:get_meta(Region.META.ALTITUDE) + if y > altitude then return end + region:set_content_id(x, y, z, STONE_ID) + end) end --[[ @@ -214,7 +190,7 @@ function private.make_noise_in_range(lowest, highest) end --[[ - Add computed values to the `TERRAIN_TYPES` table. + Clone the `C.TERRAIN_TYPES` table and add pre-computed values to it. The table is declared with the fewest values which uniquely define a terrain type, however the terrain calculation requires a few extra fields to aid in its work. This function adds the @@ -223,6 +199,8 @@ end This function *must* be called prior to the start of map generation. ]]-- function private.prepare_terrain_table() + TERRAIN_TYPES = table.clone(C.TERRAIN_TYPES) + local total_weight = 0 for _, terrain in ipairs(TERRAIN_TYPES) do total_weight = total_weight + terrain.weight @@ -235,10 +213,10 @@ function private.prepare_terrain_table() terrain.range_end = start + (terrain.weight / total_weight) if index == 1 then - terrain.range_start = -1 * TERRAIN_BLEND / 2 + terrain.range_start = -1 * C.TERRAIN_BLEND / 2 end if index == #TERRAIN_TYPES then - terrain.range_end = terrain.range_end + TERRAIN_BLEND / 2 + terrain.range_end = terrain.range_end + C.TERRAIN_BLEND / 2 end start = terrain.range_end end @@ -248,17 +226,19 @@ end -- Registrations ----------------------------------------------------------------------------------- core.register_on_generated(function(voxels, fill_min, fill_max) - local emerged_min, emerged_max = voxels:get_emerged_area() - local area = VoxelArea(emerged_min, emerged_max) + local region = private.region + region:read(voxels, fill_min, fill_max) - voxels:get_data(private.data) - private.fill_terrain(area, fill_min, fill_max) - private.fill_bedrock(area, fill_min, fill_max) - private.fill_ocean(area, fill_min, fill_max) - voxels:set_data(private.data) + private.assign_terrain_meta(region) + private.assign_altitudes(region) - voxels:calc_lighting() - voxels:update_liquids() + private.fill_terrain(region) + private.fill_bedrock(region) + private.fill_ocean(region) + + biomes.apply_biomes(region) + + region:save() end) diff --git a/mods/jvmi_mapgen/region.lua b/mods/jvmi_mapgen/region.lua new file mode 100644 index 0000000..eed6fd5 --- /dev/null +++ b/mods/jvmi_mapgen/region.lua @@ -0,0 +1,272 @@ +-- Import ------------------------------------------------------------------------------------------ + +local jvmi_mapgen = _G["jvmi_mapgen"] +local math = _G["math"] +local VoxelArea = _G["VoxelArea"] + + +-- Region Class ------------------------------------------------------------------------------------ + +local Region = { + --[[ Defines the names of the known metadata tables. ]]-- + META = { + --[[ The highest solid block in a certain x,z location. ]]-- + ALTITUDE = "altitude", + + --[[ The id of the biome at each x,z location. ]]-- + BIOME = "biome", + + --[[ A list of {weight:int, terrain_type:int} tuples for each x,z location. ]]-- + TERRAIN_BLEND = "terrain_blend", + + --[[ The heaviest weighted terrain type from the `TERRAIN_BLEND` list. ]]-- + TERRAIN_TYPE = "terrain_type", + } +} +jvmi_mapgen.Region = Region + +--[[ + Create a new Region object to manage the generation of a part of the map. + + Returns: + an empty Region ready to be filled +]]-- +function Region:new() + local result = { + _emerged_area = nil, + _emerged_data = {}, + _fill_min = nil, + _fill_max = nil, + _meta = {}, + _voxels = nil, + } + setmetatable(result, Region) + return result +end + +--[[ + Return the content_id of the node at the indicated coordinate. + + Args: + x:int - the x-axis position + y:int - the y-axis position + z:int - the z-axis position + + Returns: + an int giving the content_id of the node at that location +]]-- +function Region:get_content_id(x, y, z) + return self._emerged_data[self._emerged_area:index(x, y, z)] +end + +--[[ + Alter the content_id of the node at the indicated coordinate. + + Args: + x:int - the x-axis position + y:int - the y-axis position + z:int - the z-axis position + content_id:int - the new content_id for the given location +]]-- +function Region:set_content_id(x, y, z, content_id) + self._emerged_data[self._emerged_area:index(x, y, z)] = content_id +end + +--[[ + Iterate over every voxel within a specified area. + + For each voxel, inside the described cuboid, call the `doOperation` function which should have + the following signature: + + function doOperation(x:int, y:int, z:int) -> None + + The called function can then inspect and manipulate the content ids and meta data in the region + using the various methods on this class. + + Args: + x_min:int - the lowest x coordinate in the desired cuboid + x_max:int - the highest x coordinate in the desired cuboid + y_min:int - the lowest y coordinate in the desired cuboid + y_max:int - the highest y coordinate in the desired cuboid + z_min:int - the lowest z coordinate in the desired cuboid + z_max:int - the highest z coordinate in the desired cuboid + doOperation:function(x:int,y:int,z:int) - the callback to be invoked for each voxel +]]-- +function Region:iterate(x_min, x_max, y_min, y_max, z_min, z_max, doOperation) + x_min = math.max(x_min, self._fill_min.x) + x_max = math.min(x_max, self._fill_max.x) + y_min = math.max(y_min, self._fill_min.y) + y_max = math.min(y_max, self._fill_max.y) + z_min = math.max(z_min, self._fill_min.z) + z_max = math.min(z_max, self._fill_max.z) + + for z = z_min, z_max do + for y = y_min, y_max do + for x = x_min, x_max do + doOperation(self, x, y, z) + end + end + end +end + +--[[ + Iterates over all voxels at or below a certain altitude. + + Works identically to the `Region:iterate` function, except that the x & z ranges are the full + area being filled by this region, and the y range is capped at the given altitude. + + Args: + y_max:int - the maximum y value to include + doOperation:function(x:int,y:int,z:int) - the callback to be invoked for each voxel +]]-- +function Region:iterate_below(y_max, doOperation) + self:iterate( + self._fill_min.x, self._fill_max.x, + self._fill_min.y, y_max, + self._fill_min.z, self._fill_max.z, + doOperation + ) +end + +--[[ + Iterates over all the x,z columns in the fill region. + + Works identically to the `Region:iterate` function, except that the x & z ranges are the full + area being filled by this region, and the y-axis coordinate is omitted. + + Args: + doOperation:function(x:int,z:int) - the callback to be invoked for each voxel +]]-- +function Region:iterate_columns(doOperation) + self:iterate( + self._fill_min.x, self._fill_max.x, + 0, 0, + self._fill_min.z, self._fill_max.z, + function(x, y, z) doOperation(x, z) end + ) +end + +--[[ + Iterates over all voxels being filled in this region. + + Works identically to the `Region:iterate` function, except that the x, y, and z ranges are the + full area being filled by this region. + + Args: + doOperation:function(nt,int,int) - the callback to be invoked for each voxel +]]-- +function Region:iterate_fill(doOperation) + self:iterate( + self._fill_min.x, self._fill_max.x, + self._fill_min.y, self._fill_max.y, + self._fill_min.z, self._fill_max.z, + doOperation + ) +end + +--[[ + Iterates over all voxels at a specific altitude. + + Works identically to the `Region:iterate` function, except that the x & z ranges are the full + area being filled by this region, and y is limited to exactly the given altitude. + + Args: + y:int - the y value to use + doOperation:function(int,int,int) - the callback to be invoked for each voxel +]]-- +function Region:iterate_plane(y, doOperation) + if y < self._fill_min.y then return end + if y > self._fill_max.y then return end + + self:iterate( + self._fill_min.x, self._fill_max.x, + y, y, + self._fill_min.z, self._fill_max.z, + doOperation + ) +end + +--[[ + Get the named metadata at the indicated coordinate. + + The canonical use for this method is to find the previously-calculated altitude of the base + terrain at a certain location (e.g., `get_meta(Region.META.ALTITUDE, 292, 998)`). However, any + meta name can be used, and any data stored. This data is let until overwritten, so each mapgen + cycle should be careful to recompute any metadata it requires before running algorithms which + depend upon it. + + Args: + name:string - the name of the metadata table to access + x:int - the x coordinate of the desired data + z:int - the z coordinate of the desired data + + Returns: + the value previously stored for that location or `nil` if there isn't any +]]-- +function Region:get_meta(name, x, z) + local meta_data = self._meta[name] + if not meta_data then return nil end + return meta_data[self._emerged_area:index(x, 0, z)] +end + +--[[ + Change the metadata at the indicated coordinate. + + This will automatically fill in any necessary pieces to ensure that the operation succeeds + (e.g., creating a missing metadata table), so it is highly advised to use the provided + `Region.META` constants to avoid accidentally creating new tables through misspellings. + + Args: + name:string - the name of the metadata table to access + x:int - the x coordinate of the desired data + z:int - the z coordinate of the desired data + value:any - the value to be stored +]]-- +function Region:set_meta(name, x, z, value) + local meta_data = self._meta[name] + if not meta_data then + meta_data = {} + self._meta[name] = meta_data + end + + meta_data[self._emerged_area:index(x, 0, z)] = value +end + +--[[ + Reads raw voxel data from a voxel manipulator. + + Args: + voxels:VoxelManip - the voxel manipulator containing the data + fill_min:vector - the smaller corner of the cuboid to be filled + fill_max:vector - the larger corner of the cuboid to be filled +]]-- +function Region:read_voxels(voxels, fill_min, fill_max) + self:save_voxels() + + self._voxels = voxels + self._fill_min = fill_min + self._fill_max = fill_max + + local min_emerged, max_emerged = voxels:get_emerged_area() + self._emerged_area = VoxelArea(min_emerged, max_emerged) + self._voxels:get_data(self._emerged_data) +end + +--[[ + Writes raw voxel data back into the source voxel manipulator. + + If no voxel data has been read (or none has been read since the last save), then this function + returns immediately. +]]-- +function Region:save_voxels() + if not self._voxels then return end + + self._voxels:set_data(self._emerged_data) + self._voxels:calc_lighting() + self._voxels:update_liquids() + + self._emerged_area = nil + self._fill_max = nil + self._fill_min = nil + self._voxels = nil +end diff --git a/mods/jvmi_nodes/earthy.lua b/mods/jvmi_nodes/earthy.lua new file mode 100644 index 0000000..40447fa --- /dev/null +++ b/mods/jvmi_nodes/earthy.lua @@ -0,0 +1,43 @@ +-- Imports & Exports ------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Constants --------------------------------------------------------------------------------------- + +local S = core.get_translator("jvmi_nodes") + + +-- Registrations ----------------------------------------------------------------------------------- + +core.register_node("jvmi_nodes:clay", { + description = S("Clay"), + drop = "jvmi_nodes:clay", + is_ground_content = true, + sounds = { footstep = "jvmi_nodes_clay_footstep" }, + tiles = {"jvmi_nodes_clay.png"}, +}) + +core.register_node("jvmi_nodes:dirt", { + description = S("Dirt"), + drop = "jvmi_nodes:dirt", + is_ground_content = true, + sounds = { footstep = "jvmi_nodes_dirt_footstep" }, + tiles = {"jvmi_nodes_dirt.png"}, +}) + +core.register_node("jvmi_nodes:sand", { + description = S("Sand"), + drop = "jvmi_nodes:sand", + is_ground_content = true, + sounds = { footstep = "jvmi_nodes_sand_footstep" }, + tiles = {"jvmi_nodes_sand.png"}, +}) + +core.register_node("jvmi_nodes:turf", { + description = S("Turf"), + drop = "jvmi_nodes:turf", + is_ground_content = true, + sounds = { footstep = "jvmi_nodes_turf_footstep" }, + tiles = {"jvmi_nodes_turf.png"}, +}) diff --git a/mods/jvmi_nodes/init.lua b/mods/jvmi_nodes/init.lua index b06e098..2fd0c64 100644 --- a/mods/jvmi_nodes/init.lua +++ b/mods/jvmi_nodes/init.lua @@ -2,11 +2,12 @@ local core = _G["core"] -local path = core.get_modpath("jvmi_nodes") - -- Script ------------------------------------------------------------------------------------------ -dofile(path.."/earthlike.lua") +local path = core.get_modpath("jvmi_nodes") +dofile(path.."/earthy.lua") dofile(path.."/liquid.lua") +dofile(path.."/stony.lua") + core.log("info", "jvmi_nodes loaded") diff --git a/mods/jvmi_nodes/liquid.lua b/mods/jvmi_nodes/liquid.lua index bd74f2e..4f010ed 100644 --- a/mods/jvmi_nodes/liquid.lua +++ b/mods/jvmi_nodes/liquid.lua @@ -76,3 +76,4 @@ core.register_node("jvmi_nodes:water_source", { post_effect_color = "#033C5CCC", groups = { }, }) +core.register_alias("mapgen_water_source", "jvmi_nodes:water_source") diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.1.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.1.ogg new file mode 100644 index 0000000..e32996f Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.1.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.2.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.2.ogg new file mode 100644 index 0000000..6ad28ef Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.2.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.3.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.3.ogg new file mode 100644 index 0000000..92d6cd3 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.3.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.4.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.4.ogg new file mode 100644 index 0000000..47b9cd6 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_clay_footstep.4.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.1.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.1.ogg new file mode 100644 index 0000000..201aa3b Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.1.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.2.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.2.ogg new file mode 100644 index 0000000..2667dbc Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_dirt_footstep.2.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.1.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.1.ogg new file mode 100644 index 0000000..8d260ce Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.1.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.2.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.2.ogg new file mode 100644 index 0000000..2aba2c6 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.2.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.3.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.3.ogg new file mode 100644 index 0000000..1bcd8a1 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.3.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.4.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.4.ogg new file mode 100644 index 0000000..696c9ff Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_gravel_footstep.4.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.1.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.1.ogg new file mode 100644 index 0000000..b92feab Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.1.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.2.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.2.ogg new file mode 100644 index 0000000..6bc5da3 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.2.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.3.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.3.ogg new file mode 100644 index 0000000..880306f Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_sand_footstep.3.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.1.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.1.ogg new file mode 100644 index 0000000..a04cdb4 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.1.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.2.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.2.ogg new file mode 100644 index 0000000..d193068 Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.2.ogg differ diff --git a/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.3.ogg b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.3.ogg new file mode 100644 index 0000000..e1897ea Binary files /dev/null and b/mods/jvmi_nodes/sounds/jvmi_nodes_turf_footstep.3.ogg differ diff --git a/mods/jvmi_nodes/earthlike.lua b/mods/jvmi_nodes/stoney.lua similarity index 87% rename from mods/jvmi_nodes/earthlike.lua rename to mods/jvmi_nodes/stoney.lua index 71504fe..7573dc3 100644 --- a/mods/jvmi_nodes/earthlike.lua +++ b/mods/jvmi_nodes/stoney.lua @@ -17,6 +17,7 @@ core.register_node("jvmi_nodes:bedrock", { sounds = { footstep = "jvmi_nodes_stone_footstep" }, tiles = {"jvmi_nodes_bedrock.png"}, }) +core.register_alias("mapgen_bedrock", "jvmi_nodes:stone") core.register_node("jvmi_nodes:stone", { description = S("Stone"), @@ -24,3 +25,4 @@ core.register_node("jvmi_nodes:stone", { sounds = { footstep = "jvmi_nodes_stone_footstep" }, tiles = {"jvmi_nodes_stone.png"}, }) +core.register_alias("mapgen_stone", "jvmi_nodes:stone") diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_clay.png b/mods/jvmi_nodes/textures/jvmi_nodes_clay.png new file mode 100644 index 0000000..1e412de Binary files /dev/null and b/mods/jvmi_nodes/textures/jvmi_nodes_clay.png differ diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_dirt.png b/mods/jvmi_nodes/textures/jvmi_nodes_dirt.png new file mode 100644 index 0000000..3c57e2c Binary files /dev/null and b/mods/jvmi_nodes/textures/jvmi_nodes_dirt.png differ diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_gravel.png b/mods/jvmi_nodes/textures/jvmi_nodes_gravel.png new file mode 100644 index 0000000..d193422 Binary files /dev/null and b/mods/jvmi_nodes/textures/jvmi_nodes_gravel.png differ diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_sand.png b/mods/jvmi_nodes/textures/jvmi_nodes_sand.png new file mode 100644 index 0000000..4d6071f Binary files /dev/null and b/mods/jvmi_nodes/textures/jvmi_nodes_sand.png differ diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_turf.png b/mods/jvmi_nodes/textures/jvmi_nodes_turf.png new file mode 100644 index 0000000..a96bb1c Binary files /dev/null and b/mods/jvmi_nodes/textures/jvmi_nodes_turf.png differ diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_water_flowing_animated.png b/mods/jvmi_nodes/textures/jvmi_nodes_water_flowing.png similarity index 100% rename from mods/jvmi_nodes/textures/jvmi_nodes_water_flowing_animated.png rename to mods/jvmi_nodes/textures/jvmi_nodes_water_flowing.png diff --git a/mods/jvmi_nodes/textures/jvmi_nodes_water_source_animated.png b/mods/jvmi_nodes/textures/jvmi_nodes_water_source.png similarity index 100% rename from mods/jvmi_nodes/textures/jvmi_nodes_water_source_animated.png rename to mods/jvmi_nodes/textures/jvmi_nodes_water_source.png diff --git a/mods/jvmi_table/api.lua b/mods/jvmi_table/api.lua new file mode 100644 index 0000000..74a4621 --- /dev/null +++ b/mods/jvmi_table/api.lua @@ -0,0 +1,90 @@ +-- Imports ----------------------------------------------------------------------------------------- + +local api = _G["jvmi_table"] +local table = _G["table"] + + +-- API Functions ----------------------------------------------------------------------------------- + +--[[ + Performs a deep clone of a given table. + + This function only clones regular keys, and makes no effort to preserve the metatables of the + resulting tables. It also does not attempt to handle cycles among the given tables. + + Args: + source:table - the table to be cloned + + Returns: + a new table which the same keys and deeply copied values +]]-- +function api.clone(source) + if type(source) ~= "table" then return source end + + local target = {} + for key, value in pairs(source) do + target[key] = api.clone(value) + end + + return target +end + +--[[ + Performs a shallow clone of a given table. + + This is similar to `clone`, but it does not attempt to deeply copy the values of the given + table, instead creating a new table with the same keys and values as the original. + + Args: + source:table - the table to be copied + + Returns: + a new table with the same keys and values as the original + +]]-- +function api.copy(source) + return api.merge({}, source) +end + +--[[ + Add a value to the end of an array-like table. + + Args: + target:array - a table which is being used like an array (i.e., contiguous integer keys) + value:any - the value to be appeneded to the array + + Returns: + the target table +]]-- +function api.append(target, value) + target[#target] = value + return target +end + +--[[ + Overwrite the contents of a target table with the values in one or more source tables. + + Only those keys defined by one of the source tables will be overridden in the target table. + Each successive source table in the given sequence may override values in the earlier source + tables. This function only performs a shallow copy, so any objects in the source tables are only copied + by reference. To create a brand new table with the merged contents of the following tables, + provide nil as the first argument. + + Args: + target:table - a table whose values are to be overridden + ...:table - a sequence of one or more source tables whose keys are to be copied + + Returns: + the target table +]]-- +function api.merge(target, ...) + target = target or nil + + for _, source in ipairs(arg) do + for key, value in pairs(source) do + target[key] = value + end + end + + return target +end diff --git a/mods/jvmi_table/init.lua b/mods/jvmi_table/init.lua new file mode 100644 index 0000000..5d5a349 --- /dev/null +++ b/mods/jvmi_table/init.lua @@ -0,0 +1,15 @@ +-- Imports ----------------------------------------------------------------------------------------- + +local core = _G["core"] + + +-- Public ------------------------------------------------------------------------------------------ + +jvmi_table = {} -- luacheck: globals jvmi_table +local path = core.get_modpath("jvmi_table") +dofile(path.."/api.lua") + + +-- Script ------------------------------------------------------------------------------------------ + +core.log("info", "jvmi_tables ready") diff --git a/mods/jvmi_table/mod.conf b/mods/jvmi_table/mod.conf new file mode 100644 index 0000000..263d901 --- /dev/null +++ b/mods/jvmi_table/mod.conf @@ -0,0 +1,4 @@ +name = jvmi_table +title = Jules Verne's Mysterious Island / Table +description = helpers for table manipulation +author = tungstonminer