backguard copatibility for vector helpers - vector.offset

master
mckaygerhard 2024-04-10 02:13:10 +00:00
parent 9799e13d2b
commit 514dd3cd3a
1 changed files with 29 additions and 0 deletions

View File

@ -1,4 +1,33 @@
### vector helpers
#### vector.offset
https://codeberg.org/minenux/minetest-mod-mobs_redo/issues/108
In particular, offsets are usually required for defining an area to pass to minetest.find_nodes_in_area() as well as the VoxelArea constructor. Likewise, an offset of y + 1 is frequently needed with functions like minetest.get_node() and minetest.get_node_light().
Here's are some concrete examples from minetest-mods where these functions would prove useful:
https://github.com/minetest-mods/loot/blob/e7398c3ce1953c443406392efd4fc1bd4d22e771/loot_vault.lua#L20
https://github.com/minetest-mods/mesecons/blob/7013f2e5d47ff2d21fb66fe82966a34ece947eec/mesecons_random/init.lua#L14
https://github.com/minetest-mods/painting/blob/8961849797fa21f168191b10b3693dd5eeab08ea/init.lua#L206
https://github.com/minetest-mods/schemlib_builder_npcf/blob/85cfb2d773a8d18ebd921f18f6bb7565664314e1/init.lua#L239
https://github.com/minetest-mods/mob-engine/blob/c2bedc3816a0c6a3a96b5803bd910b32c09c4f2c/creatures/functions.lua#L34
https://github.com/minetest-mods/mapgen_helper/blob/9c7347691d451f6eee329cd8f7e23ccbd27bd298/place_schematic.lua#L136
Note that vector.offset_y() isn't the direct analog of vector.offset(), because it defaults to 1. Checking the position directly above another position is a very common use-case In fact, nine out of ten situations where I need an offset position, it is y + 1.
vector.offset_y(pos)
vector.offset(pos, 0, 1, 0)
Keep in mind, the goal of these functions isn't to save keystrokes, it's to make code clearer to understand and easier maintain. By using vector.offset_y(), it is apparent at first glance what the intention is, thereby mitigating the likelihood of introducing bugs later, as could happen when using just vector.offset() where it is not as immediately obvious that x and z should never change.
Likewise, one could manually clamp a number by pairing math.min() with math.max(), but that is a far cry from the simplicity and clarity of math.clamp().
### reason or PlayerHPChangeReason