13
13
14
14
local has_boxes_prop = {collision_box = " walkable" , selection_box = " pointable" }
15
15
16
+ -- Required for raycast box IDs to be accurate
17
+ local connect_sides_order = {" top" , " bottom" , " front" , " left" , " back" , " right" }
18
+
19
+ local connect_sides_directions = {
20
+ top = vector .new (0 , 1 , 0 ),
21
+ bottom = vector .new (0 , - 1 , 0 ),
22
+ front = vector .new (0 , 0 , - 1 ),
23
+ left = vector .new (- 1 , 0 , 0 ),
24
+ back = vector .new (0 , 0 , 1 ),
25
+ right = vector .new (1 , 0 , 0 ),
26
+ }
27
+
16
28
-- > list of collisionboxes in Minetest format
17
29
local function get_node_boxes (pos , type )
18
30
local node = minetest .get_node (pos )
@@ -63,19 +75,11 @@ local function get_node_boxes(pos, type)
63
75
end
64
76
if box_type == " connected" then
65
77
boxes = table .copy (boxes )
66
- local connect_sides = {
67
- top = {x = 0 , y = 1 , z = 0 },
68
- bottom = {x = 0 , y = - 1 , z = 0 },
69
- front = {x = 0 , y = 0 , z = - 1 },
70
- left = {x = - 1 , y = 0 , z = 0 },
71
- back = {x = 0 , y = 0 , z = 1 },
72
- right = {x = 1 , y = 0 , z = 0 }
73
- }
74
- if node_def .connect_sides then
75
- for side in pairs (connect_sides ) do
76
- if not node_def .connect_sides [side ] then
77
- connect_sides [side ] = nil
78
- end
78
+ local connect_sides = connect_sides_directions -- (ab)use directions as a "set" of sides
79
+ if node_def .connect_sides then -- build set of sides from given list
80
+ connect_sides = {}
81
+ for _ , side in ipairs (node_def .connect_sides ) do
82
+ connect_sides [side ] = true
79
83
end
80
84
end
81
85
local function add_collisionbox (key )
@@ -84,8 +88,8 @@ local function get_node_boxes(pos, type)
84
88
end
85
89
end
86
90
local matchers = {}
87
- for _ , nodename_or_group in pairs (node_def .connects_to or {}) do
88
- table.insert ( matchers , nodename_matcher (nodename_or_group ) )
91
+ for i , nodename_or_group in ipairs (node_def .connects_to or {}) do
92
+ matchers [ i ] = nodename_matcher (nodename_or_group )
89
93
end
90
94
local function connects_to (nodename )
91
95
for _ , matcher in pairs (matchers ) do
@@ -95,12 +99,15 @@ local function get_node_boxes(pos, type)
95
99
end
96
100
end
97
101
local connected , connected_sides
98
- for side , direction in pairs (connect_sides ) do
99
- local neighbor = minetest .get_node (vector .add (pos , direction ))
100
- local connects = connects_to (neighbor .name )
101
- connected = connected or connects
102
- connected_sides = connected_sides or (side ~= " top" and side ~= " bottom" )
103
- add_collisionbox ((connects and " connect_" or " disconnected_" ) .. side )
102
+ for _ , side in ipairs (connect_sides_order ) do
103
+ if connect_sides [side ] then
104
+ local direction = connect_sides_directions [side ]
105
+ local neighbor = minetest .get_node (vector .add (pos , direction ))
106
+ local connects = connects_to (neighbor .name )
107
+ connected = connected or connects
108
+ connected_sides = connected_sides or (side ~= " top" and side ~= " bottom" )
109
+ add_collisionbox ((connects and " connect_" or " disconnected_" ) .. side )
110
+ end
104
111
end
105
112
if not connected then
106
113
add_collisionbox (" disconnected" )
0 commit comments