From 80c0f52e179c4919ab31c43c9cb96314cba95c5a Mon Sep 17 00:00:00 2001 From: teknomunk Date: Wed, 7 Aug 2024 06:36:50 -0500 Subject: [PATCH] Update API documentation to always use , add compatibility shim to mcl_minecarts.is_rail() and mcl_minecarts.ge_rail_direction() --- mods/ENTITIES/mcl_minecarts/API.md | 4 ++-- mods/ENTITIES/mcl_minecarts/functions.lua | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/API.md b/mods/ENTITIES/mcl_minecarts/API.md index e628e0d59..1f90c32f4 100644 --- a/mods/ENTITIES/mcl_minecarts/API.md +++ b/mods/ENTITIES/mcl_minecarts/API.md @@ -77,7 +77,7 @@ Calculate the rail adjacency information for rail placement. Arguments are: - `ignore_neightbor_connections` - if true, don't check that a cart could leave the neighboring node from this direction. -`mcl_minecarts:is_rail(position, railtype)` +`mcl_minecarts.is_rail(position, railtype)` Determines if the node at `position` is a rail. If `railtype` is provided, determine if the node at `position` is that type of rail. @@ -101,7 +101,7 @@ Converts the rail at `node_position`, if possible, another variant (curve, etc.) and rotates the node as needed so that rails connect together. `options` is passed thru to `mcl_minecarts.get_rail_connections()` -`mcl_minecarts:get_rail_direction(rail_position, cart_direction)` +`mcl_minecarts.get_rail_direction(rail_position, cart_direction)` Returns the next direction a cart traveling in the direction specified in `cart_direction` will travel from the rail located at `rail_position`. diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index d476d606b..88a03a4c8 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -53,7 +53,13 @@ function mcl_minecarts:velocity_to_dir(v) end end -function mcl_minecarts:is_rail(pos, railtype) +function mcl_minecarts.is_rail(self, pos, railtype) + -- Compatibility with mcl_minecarts:is_rail() usage + if self ~= mcl_minecarts then + railtype = pos + pos = self + end + local node_name = force_get_node(pos).name if minetest.get_item_group(node_name, "rail") == 0 then @@ -324,7 +330,13 @@ local function get_rail_direction_inner(pos, dir) return dir end -function mcl_minecarts:get_rail_direction(pos_, dir) +function mcl_minecarts.get_rail_direction(self, pos_, dir) + -- Compatibility with mcl_minecarts:get_rail_direction() usage + if self ~= mcl_minecarts then + dir = pos_ + pos_ = self + end + local pos = vector.round(pos_) -- diagonal direction handling