Update API documentation to always use , add compatibility shim to mcl_minecarts.is_rail() and mcl_minecarts.ge_rail_direction()

This commit is contained in:
teknomunk 2024-08-07 06:36:50 -05:00
parent 3ac29cc455
commit d4c2ecc16f
2 changed files with 16 additions and 4 deletions

View File

@ -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 - `ignore_neightbor_connections` - if true, don't check that a cart could leave
the neighboring node from this direction. 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, Determines if the node at `position` is a rail. If `railtype` is provided,
determine if the node at `position` is that type of rail. 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 and rotates the node as needed so that rails connect together. `options` is
passed thru to `mcl_minecarts.get_rail_connections()` 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` Returns the next direction a cart traveling in the direction specified in `cart_direction`
will travel from the rail located at `rail_position`. will travel from the rail located at `rail_position`.

View File

@ -53,7 +53,13 @@ function mcl_minecarts:velocity_to_dir(v)
end end
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 local node_name = force_get_node(pos).name
if minetest.get_item_group(node_name, "rail") == 0 then if minetest.get_item_group(node_name, "rail") == 0 then
@ -324,7 +330,13 @@ local function get_rail_direction_inner(pos, dir)
return dir return dir
end 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_) local pos = vector.round(pos_)
-- diagonal direction handling -- diagonal direction handling