@@ -3,18 +3,44 @@ local enable_max_limit = minetest.settings:get_bool("pipeworks_enable_items_per_
3
3
local max_tube_limit = tonumber (minetest .settings :get (" pipeworks_max_items_per_tube" )) or 30
4
4
if enable_max_limit == nil then enable_max_limit = true end
5
5
6
+ if pipeworks .enable_item_tags then
7
+ local max_tag_length = tonumber (minetest .settings :get (" pipeworks_max_item_tag_length" )) or 32
8
+ local max_tags = tonumber (minetest .settings :get (" pipeworks_max_item_tags" )) or 16
9
+
10
+ function pipeworks .sanitize_tags (tags )
11
+ if type (tags ) == " string" then
12
+ tags = tags :split (" ," )
13
+ end
14
+ local sanitized = {}
15
+ for i , tag in ipairs (tags ) do
16
+ if type (tag ) == " string" then
17
+ tag = tag :gsub (" [%s,]" , " " ) -- Remove whitespace and commas
18
+ tag = tag :gsub (" %$%b%{%}" , " " ) -- Remove special ${key} values
19
+ if tag ~= " " then
20
+ table.insert (sanitized , tag :sub (1 , max_tag_length ))
21
+ end
22
+ end
23
+ if # sanitized >= max_tags then
24
+ break
25
+ end
26
+ end
27
+ return sanitized
28
+ end
29
+ end
30
+
6
31
function pipeworks .tube_item (pos , item )
7
32
error (" obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead" )
8
33
end
9
34
10
- function pipeworks .tube_inject_item (pos , start_pos , velocity , item , owner )
35
+ function pipeworks .tube_inject_item (pos , start_pos , velocity , item , owner , tags )
11
36
-- Take item in any format
12
37
local stack = ItemStack (item )
13
38
local obj = luaentity .add_entity (pos , " pipeworks:tubed_item" )
14
39
obj :set_item (stack :to_string ())
15
40
obj .start_pos = vector .new (start_pos )
16
41
obj :set_velocity (velocity )
17
42
obj .owner = owner
43
+ obj .tags = tags
18
44
-- obj:set_color("red") -- todo: this is test-only code
19
45
return obj
20
46
end
79
105
80
106
-- compatibility behaviour for the existing can_go() callbacks,
81
107
-- which can only specify a list of possible positions.
82
- local function go_next_compat (pos , cnode , cmeta , cycledir , vel , stack , owner )
108
+ local function go_next_compat (pos , cnode , cmeta , cycledir , vel , stack , owner , tags )
83
109
local next_positions = {}
84
110
local max_priority = 0
85
111
local can_go
86
112
87
- if minetest .registered_nodes [cnode .name ] and minetest .registered_nodes [cnode .name ].tube and minetest .registered_nodes [cnode .name ].tube .can_go then
88
- can_go = minetest .registered_nodes [cnode .name ].tube .can_go (pos , cnode , vel , stack )
113
+ local def = minetest .registered_nodes [cnode .name ]
114
+ if def and def .tube and def .tube .can_go then
115
+ can_go = def .tube .can_go (pos , cnode , vel , stack , tags )
89
116
else
90
117
local adjlist_string = minetest .get_meta (pos ):get_string (" adjlist" )
91
118
local adjlist = minetest .deserialize (adjlist_string ) or default_adjlist -- backward compat: if not found, use old behavior: all directions
144
171
-- * a "multi-mode" data table (or nil if N/A) where a stack was split apart.
145
172
-- if this is not nil, the luaentity spawns new tubed items for each new fragment stack,
146
173
-- then deletes itself (i.e. the original item stack).
147
- local function go_next (pos , velocity , stack , owner )
174
+ local function go_next (pos , velocity , stack , owner , tags )
148
175
local cnode = minetest .get_node (pos )
149
176
local cmeta = minetest .get_meta (pos )
150
177
local speed = math.abs (velocity .x + velocity .y + velocity .z )
@@ -172,7 +199,7 @@ local function go_next(pos, velocity, stack, owner)
172
199
-- n is the new value of the cycle counter.
173
200
-- XXX: this probably needs cleaning up after being split out,
174
201
-- seven args is a bit too many
175
- local n , found , new_velocity , multimode = go_next_compat (pos , cnode , cmeta , cycledir , vel , stack , owner )
202
+ local n , found , new_velocity , multimode = go_next_compat (pos , cnode , cmeta , cycledir , vel , stack , owner , tags )
176
203
177
204
-- if not using output cycling,
178
205
-- don't update the field so it stays the same for the next item.
@@ -276,6 +303,7 @@ luaentity.register_entity("pipeworks:tubed_item", {
276
303
color_entity = nil ,
277
304
color = nil ,
278
305
start_pos = nil ,
306
+ tags = nil ,
279
307
280
308
set_item = function (self , item )
281
309
local itemstring = ItemStack (item ):to_string () -- Accept any input format
@@ -337,8 +365,9 @@ luaentity.register_entity("pipeworks:tubed_item", {
337
365
local node = minetest .get_node (self .start_pos )
338
366
if minetest .get_item_group (node .name , " tubedevice_receiver" ) == 1 then
339
367
local leftover
340
- if minetest .registered_nodes [node .name ].tube and minetest .registered_nodes [node .name ].tube .insert_object then
341
- leftover = minetest .registered_nodes [node .name ].tube .insert_object (self .start_pos , node , stack , vel , self .owner )
368
+ local def = minetest .registered_nodes [node .name ]
369
+ if def .tube and def .tube .insert_object then
370
+ leftover = def .tube .insert_object (self .start_pos , node , stack , vel , self .owner )
342
371
else
343
372
leftover = stack
344
373
end
@@ -353,7 +382,14 @@ luaentity.register_entity("pipeworks:tubed_item", {
353
382
return
354
383
end
355
384
356
- local found_next , new_velocity , multimode = go_next (self .start_pos , velocity , stack , self .owner ) -- todo: color
385
+ local tags
386
+ if pipeworks .enable_item_tags then
387
+ tags = self .tags or {}
388
+ end
389
+ local found_next , new_velocity , multimode = go_next (self .start_pos , velocity , stack , self .owner , tags ) -- todo: color
390
+ if pipeworks .enable_item_tags then
391
+ self .tags = # tags > 0 and pipeworks .sanitize_tags (tags ) or nil
392
+ end
357
393
local rev_vel = vector .multiply (velocity , - 1 )
358
394
local rev_dir = vector .direction (self .start_pos ,vector .add (self .start_pos ,rev_vel ))
359
395
local rev_node = minetest .get_node (vector .round (vector .add (self .start_pos ,rev_dir )))
0 commit comments