]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - doc/lua_api.txt
Schematics: Add indent-with-space option for schematic Lua table serialization
[dragonfireclient.git] / doc / lua_api.txt
index e2589d226f5c5f8187aca7ea3c93d9ada8dbb565..cb8b8848fd95fd3b6f614950b4cf1d8e62f1fbd1 100644 (file)
@@ -419,6 +419,11 @@ the global `minetest.registered_*` tables.
 * `minetest.register_craftitem(name, item definition)`
     * added to `minetest.registered_items[name]`
 
+* `minetest.register_biome(biome definition)`
+    * returns an integer uniquely identifying the registered biome
+    * added to `minetest.registered_biome` with the key of `biome.name`
+    * if `biome.name` is nil, the key is the returned ID
+
 * `minetest.register_ore(ore definition)`
     * returns an integer uniquely identifying the registered ore
     * added to `minetest.registered_ores` with the key of `ore.name`
@@ -429,11 +434,25 @@ the global `minetest.registered_*` tables.
     * added to `minetest.registered_decorations` with the key of `decoration.name`
     * if `decoration.name` is nil, the key is the returned ID
 
+* `minetest.register_schematic(schematic definition)`
+    * returns an integer uniquely identifying the registered schematic
+    * added to `minetest.registered_schematic` with the key of `schematic.name`
+    * if `schematic.name` is nil, the key is the returned ID
+    * if the schematic is loaded from a file, schematic.name is set to the filename
+    * if the function is called when loading the mod, and schematic.name is a relative path,
+    * then the current mod path will be prepended to the schematic filename
+
+* `minetest.clear_registered_biomes()`
+    * clears all biomes currently registered
+
 * `minetest.clear_registered_ores()`
-   * clears all ores currently registered
+    * clears all ores currently registered
 
 * `minetest.clear_registered_decorations()`
-   * clears all decorations currently registered
+    * clears all decorations currently registered
+
+* `minetest.clear_registered_schematics()`
+    * clears all schematics currently registered
 
 Note that in some cases you will stumble upon things that are not contained
 in these tables (e.g. when a mod has been removed). Always check for
@@ -792,11 +811,13 @@ Schematic attributes
 --------------------
 See section "Flag Specifier Format".
 
-Currently supported flags: `place_center_x`, `place_center_y`, `place_center_z`.
+Currently supported flags: `place_center_x`, `place_center_y`,
+                          `place_center_z`, `force_placement`.
 
 * `place_center_x`: Placement of this decoration is centered along the X axis.
 * `place_center_y`: Placement of this decoration is centered along the Y axis.
 * `place_center_z`: Placement of this decoration is centered along the Z axis.
+* `force_placement`: Schematic nodes other than "ignore" will replace existing nodes.
 
 
 HUD element types
@@ -1647,7 +1668,7 @@ Helper functions
 
 ### Utilities
 
-* `minetest.get_current_modname()`: returns a string
+* `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
 * `minetest.get_modpath(modname)`: returns e.g. `"/home/user/.minetest/usermods/modname"`
     * Useful for loading additional `.lua` modules or static data from mod
 * `minetest.get_modnames()`: returns a list of installed mods
@@ -1850,6 +1871,8 @@ and `minetest.auth_reload` call the authetification handler.
 * `minetest.punch_node(pos)`
     * Punch node with the same effects that a player would cause
 
+* `minetest.find_nodes_with_meta(pos1, pos2)`
+    * Get a table of positions of nodes that have metadata within a region {pos1, pos2}
 * `minetest.get_meta(pos)`
     * Get a `NodeMetaRef` at that position
 * `minetest.get_node_timer(pos)`
@@ -1901,10 +1924,12 @@ and `minetest.auth_reload` call the authetification handler.
     * Sets the noiseparams setting of `name` to the noiseparams table specified in `noiseparams`.
     * `set_default` is an optional boolean (default: `true`) that specifies whether the setting
       should be applied to the default config or current active config
-* `minetest.generate_ores(vm)`
-   * Generate all registered ores within the VoxelManip specified by `vm`.
-* `minetest.generate_decorations(vm)`
-   * Generate all registered decorations within the VoxelManip specified by `vm`.
+* `minetest.generate_ores(vm, pos1, pos2)`
+    * Generate all registered ores within the VoxelManip `vm` and in the area from `pos1` to `pos2`.
+    * `pos1` and `pos2` are optional and default to mapchunk minp and maxp.
+* `minetest.generate_decorations(vm, pos1, pos2)`
+    * Generate all registered decorations within the VoxelManip `vm` and in the area from `pos1` to `pos2`.
+    * `pos1` and `pos2` are optional and default to mapchunk minp and maxp.
 * `minetest.clear_objects()`
     * clear all objects in the environments
 * `minetest.delete_area(pos1, pos2)`
@@ -2147,6 +2172,17 @@ These functions return the leftover itemstack.
     * `force_placement` is a boolean indicating whether nodes other than `air` and
       `ignore` are replaced by the schematic
 
+* `minetest.serialize_schematic(schematic, format, options)`
+    * Return the serialized schematic specified by schematic (see: Schematic specifier)
+    * in the `format` of either "mts" or "lua".
+    * "mts" - a string containing the binary MTS data used in the MTS file format
+    * "lua" - a string containing Lua code representing the schematic in table format
+    * `options` is a table containing the following optional parameters:
+    * If `lua_use_comments` is true and `format` is "lua", the Lua code generated will have (X, Z)
+    * position comments for every X row generated in the schematic data for easier reading.
+    * If `lua_num_indent_spaces` is a nonzero number and `format` is "lua", the Lua code generated
+    * will use that number of spaces as indentation instead of a tab character.
+
 ### Misc.
 * `minetest.get_connected_players()`: returns list of `ObjectRefs`
 * `minetest.hash_node_position({x=,y=,z=})`: returns an 48-bit integer
@@ -2248,6 +2284,9 @@ These functions return the leftover itemstack.
 
 Please note that forceloaded areas are saved when the server restarts.
 
+minetest.global_exists(name)
+^ Checks if a global variable has been set, without triggering a warning.
+
 ### Global objects
 * `minetest.env`: `EnvRef` of the server environment and world.
     * Any function in the minetest namespace can be called using the syntax
@@ -2438,7 +2477,7 @@ This is basically a reference to a C++ `ServerActiveObject`
             {x=189, y=198}, -- <  dig animation key frames
             {x=200, y=219}, -- <  walk+dig animation key frames
             frame_speed=30): -- <  animation frame speed
-            
+
 * `set_eye_offset({x=0,y=0,z=0},{x=0,y=0,z=0})`: defines offset value for camera per player
     * in first person view
     * in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
@@ -2512,7 +2551,8 @@ an itemstring, a table or `nil`.
   Returns taken `ItemStack`.
 
 ### `PseudoRandom`
-A pseudorandom number generator.
+A 16-bit pseudorandom number generator.
+Uses a well-known LCG algorithm introduced by K&R.
 
 It can be created via `PseudoRandom(seed)`.
 
@@ -2522,6 +2562,19 @@ It can be created via `PseudoRandom(seed)`.
     * `((max - min) == 32767) or ((max-min) <= 6553))` must be true
       due to the simple implementation making bad distribution otherwise.
 
+### `PcgRandom`
+A 32-bit pseudorandom number generator.
+Uses PCG32, an algorithm of the permuted congruential generator family, offering very strong randomness.
+
+It can be created via `PcgRandom(seed)` or `PcgRandom(seed, sequence)`.
+
+#### Methods
+* `next()`: return next integer random number [`-2147483648`...`2147483647`]
+* `next(min, max)`: return next integer random number [`min`...`max`]
+* `rand_normal_dist(min, max, num_trials=6)`: return normally distributed random number [`min`...`max`]
+    * This is only a rough approximation of a normal distribution with mean=(max-min)/2 and variance=1
+    * Increasing num_trials improves accuracy of the approximation
+
 ### `PerlinNoise`
 A perlin noise generator.
 It can be created via `PerlinNoise(seed, octaves, persistence, scale)`
@@ -3005,7 +3058,7 @@ Definition tables
         ^ Called after destructing node when node was dug using
           minetest.node_dig / minetest.dig_node
         ^ default: nil ]]
-        can_dig = function(pos,player) --[[
+        can_dig = function(pos, [player]) --[[
         ^ returns true if node can be dug, or false if not
         ^ default: nil ]]
 
@@ -3140,6 +3193,10 @@ Definition tables
     --  ^ Multiplier of the randomness contribution to the noise value at any
     --   given point to decide if ore should be placed.  Set to 0 for solid veins.
     --  ^ This parameter is only valid for ore_type == "vein".
+        biomes = {"desert", "rainforest"}
+    --  ^ List of biomes in which this decoration occurs.  Occurs in all biomes if this is omitted,
+    --  ^ and ignored if the Mapgen being used does not support biomes.
+    --  ^ Can be a list of (or a single) biome names, IDs, or definitions.
     }
 
 ### Decoration definition (`register_decoration`)
@@ -3160,6 +3217,7 @@ Definition tables
         biomes = {"Oceanside", "Hills", "Plains"},
     --  ^ List of biomes in which this decoration occurs.  Occurs in all biomes if this is omitted,
     --  ^ and ignored if the Mapgen being used does not support biomes.
+    --  ^ Can be a list of (or a single) biome names, IDs, or definitions.
         y_min = -31000
         y_max = 31000
     -- ^ Minimum and maximum `y` positions these decorations can be generated at.
@@ -3186,13 +3244,16 @@ Definition tables
         schematic = "foobar.mts",
     --  ^ If schematic is a string, it is the filepath relative to the current working directory of the
     --  ^ specified Minetest schematic file.
+    --  ^  - OR -, could be the ID of a previously registered schematic
     --  ^  - OR -, could instead be a table containing two mandatory fields, size and data,
     --  ^ and an optional table yslice_prob:
         schematic = {
             size = {x=4, y=6, z=4},
             data = {
-                {name="cobble", param1=255, param2=0},
-                {name="dirt_with_grass", param1=255, param2=0},
+                {name="default:cobble", param1=255, param2=0},
+                {name="default:dirt_with_grass", param1=255, param2=0},
+                {name="ignore", param1=255, param2=0},
+                {name="air", param1=255, param2=0},
                  ...
             },
             yslice_prob = {
@@ -3203,7 +3264,7 @@ Definition tables
         },
     --  ^ See 'Schematic specifier' for details.
         replacements = {["oldname"] = "convert_to", ...},
-        flags = "place_center_x, place_center_z",
+        flags = "place_center_x, place_center_y, place_center_z, force_placement",
     --  ^ Flags for schematic decorations.  See 'Schematic attributes'.
         rotation = "90" -- rotate schematic 90 degrees on placement
     --  ^ Rotation can be "0", "90", "180", "270", or "random".