1 function mcl_minecarts
:get_sign(z
)
9 function mcl_minecarts
:velocity_to_dir(v
)
10 if math
.abs(v
.x
) > math
.abs(v
.z
) then
11 return {x
=mcl_minecarts
:get_sign(v
.x
), y
=mcl_minecarts
:get_sign(v
.y
), z
=0}
13 return {x
=0, y
=mcl_minecarts
:get_sign(v
.y
), z
=mcl_minecarts
:get_sign(v
.z
)}
17 function mcl_minecarts
:is_rail(pos
, railtype
)
18 local node
= minetest
.get_node(pos
).name
19 if node
== "ignore" then
20 local vm
= minetest
.get_voxel_manip()
21 local emin
, emax
= vm
:read_from_map(pos
, pos
)
22 local area
= VoxelArea
:new
{
26 local data
= vm
:get_data()
27 local vi
= area
:indexp(pos
)
28 node
= minetest
.get_name_from_content_id(data
[vi
])
30 if minetest
.get_item_group(node
, "rail") == 0 then
36 return minetest
.get_item_group(node
, "connect_to_raillike") == railtype
39 function mcl_minecarts
:check_front_up_down(pos
, dir_
, check_down
, railtype
)
40 local dir
= vector
.new(dir_
)
45 cur
= vector
.add(pos
, dir
)
46 if mcl_minecarts
:is_rail(cur
, railtype
) then
52 cur
= vector
.add(pos
, dir
)
53 if mcl_minecarts
:is_rail(cur
, railtype
) then
59 cur
= vector
.add(pos
, dir
)
60 if mcl_minecarts
:is_rail(cur
, railtype
) then
66 function mcl_minecarts
:get_rail_direction(pos_
, dir
, ctrl
, old_switch
, railtype
)
67 local pos
= vector
.round(pos_
)
69 local left_check
, right_check
= true, true
71 -- Check left and right
72 local left
= {x
=0, y
=0, z
=0}
73 local right
= {x
=0, y
=0, z
=0}
74 if dir
.z
~= 0 and dir
.x
== 0 then
77 elseif dir
.x
~= 0 and dir
.z
== 0 then
83 if old_switch
== 1 then
85 elseif old_switch
== 2 then
88 if ctrl
.left
and left_check
then
89 cur
= mcl_minecarts
:check_front_up_down(pos
, left
, false, railtype
)
95 if ctrl
.right
and right_check
then
96 cur
= mcl_minecarts
:check_front_up_down(pos
, right
, false, railtype
)
105 cur
= mcl_minecarts
:check_front_up_down(pos
, dir
, true, railtype
)
110 -- Left, if not already checked
112 cur
= mcl_minecarts
:check_front_up_down(pos
, left
, false, railtype
)
118 -- Right, if not already checked
120 cur
= mcl_minecarts
:check_front_up_down(pos
, right
, false, railtype
)
127 if not old_switch
then
128 cur
= mcl_minecarts
:check_front_up_down(pos
, {
138 return {x
=0, y
=0, z
=0}