1
- local S = minetest .get_translator (" pipeworks" )
1
+ local S = core .get_translator (" pipeworks" )
2
2
-- cache some recipe data to avoid calling the slow function
3
- -- minetest .get_craft_result() every second
3
+ -- core .get_craft_result() every second
4
4
local autocrafterCache = {}
5
5
6
6
local craft_time = 1
20
20
21
21
local function get_item_info (stack )
22
22
local name = stack :get_name ()
23
- local def = minetest .registered_items [name ]
23
+ local def = core .registered_items [name ]
24
24
local description = def and def .description or S (" Unknown item" )
25
25
return description , name
26
26
end
27
27
28
28
-- Get best matching recipe for what user has put in crafting grid.
29
29
-- This function does not consider crafting method (mix vs craft)
30
30
local function get_matching_craft (output_name , example_recipe )
31
- local recipes = minetest .get_all_craft_recipes (output_name )
31
+ local recipes = core .get_all_craft_recipes (output_name )
32
32
if not recipes then
33
33
return example_recipe
34
34
end
@@ -49,7 +49,7 @@ local function get_matching_craft(output_name, example_recipe)
49
49
elseif recipe_item_name :sub (1 , 6 ) == " group:" then
50
50
group = recipe_item_name :sub (7 )
51
51
for example_item_name , _ in pairs (index_example ) do
52
- if minetest .get_item_group (
52
+ if core .get_item_group (
53
53
example_item_name , group ) ~= 0
54
54
then
55
55
score = score + 1
@@ -68,12 +68,12 @@ local function get_matching_craft(output_name, example_recipe)
68
68
end
69
69
70
70
local function get_craft (pos , inventory , hash )
71
- local hash = hash or minetest .hash_node_position (pos )
71
+ local hash = hash or core .hash_node_position (pos )
72
72
local craft = autocrafterCache [hash ]
73
73
if craft then return craft end
74
74
75
75
local example_recipe = inventory :get_list (" recipe" )
76
- local output , decremented_input = minetest .get_craft_result ({
76
+ local output , decremented_input = core .get_craft_result ({
77
77
method = " normal" , width = 3 , items = example_recipe
78
78
})
79
79
@@ -132,7 +132,7 @@ local function calculate_consumption(inv_index, consumption_with_groups)
132
132
local found = 0
133
133
local count_ingredient_groups = # ingredient_groups
134
134
for i = 1 , count_ingredient_groups do
135
- if minetest .get_item_group (name ,
135
+ if core .get_item_group (name ,
136
136
ingredient_groups [i ]) ~= 0
137
137
then
138
138
found = found + 1
@@ -241,7 +241,7 @@ local function autocraft(inventory, craft)
241
241
for i = 1 , 9 do
242
242
leftover = inventory :add_item (" dst" , craft .decremented_input [i ])
243
243
if leftover and not leftover :is_empty () then
244
- minetest .log (" warning" , " [pipeworks] autocrafter didn't " ..
244
+ core .log (" warning" , " [pipeworks] autocrafter didn't " ..
245
245
" calculate output space correctly." )
246
246
end
247
247
end
252
252
-- is started only from start_autocrafter(pos) after sanity checks and
253
253
-- recipe is cached
254
254
local function run_autocrafter (pos , elapsed )
255
- local meta = minetest .get_meta (pos )
255
+ local meta = core .get_meta (pos )
256
256
local inventory = meta :get_inventory ()
257
257
local craft = get_craft (pos , inventory )
258
258
local output_item = craft .output .item
@@ -270,9 +270,9 @@ local function run_autocrafter(pos, elapsed)
270
270
end
271
271
272
272
local function start_crafter (pos )
273
- local meta = minetest .get_meta (pos )
273
+ local meta = core .get_meta (pos )
274
274
if meta :get_int (" enabled" ) == 1 then
275
- local timer = minetest .get_node_timer (pos )
275
+ local timer = core .get_node_timer (pos )
276
276
if not timer :is_started () then
277
277
timer :start (craft_time )
278
278
end
@@ -286,12 +286,12 @@ end
286
286
-- note, that this function assumes allready being updated to virtual items
287
287
-- and doesn't handle recipes with stacksizes > 1
288
288
local function after_recipe_change (pos , inventory )
289
- local hash = minetest .hash_node_position (pos )
290
- local meta = minetest .get_meta (pos )
289
+ local hash = core .hash_node_position (pos )
290
+ local meta = core .get_meta (pos )
291
291
autocrafterCache [hash ] = nil
292
292
-- if we emptied the grid, there's no point in keeping it running or cached
293
293
if inventory :is_empty (" recipe" ) then
294
- minetest .get_node_timer (pos ):stop ()
294
+ core .get_node_timer (pos ):stop ()
295
295
meta :set_string (" infotext" , S (" unconfigured Autocrafter" ))
296
296
inventory :set_stack (" output" , 1 , " " )
297
297
return
@@ -307,12 +307,12 @@ end
307
307
308
308
-- clean out unknown items and groups, which would be handled like unknown
309
309
-- items in the crafting grid
310
- -- if minetest supports query by group one day, this might replace them
310
+ -- if Luanti supports query by group one day, this might replace them
311
311
-- with a canonical version instead
312
312
local function normalize (item_list )
313
313
for i = 1 , # item_list do
314
314
local name = item_list [i ]
315
- if not minetest .registered_items [name ] then
315
+ if not core .registered_items [name ] then
316
316
item_list [i ] = " "
317
317
end
318
318
end
@@ -324,7 +324,7 @@ local function on_output_change(pos, inventory, stack)
324
324
inventory :set_list (" output" , {})
325
325
inventory :set_list (" recipe" , {})
326
326
else
327
- local input = minetest .get_craft_recipe (stack :get_name ())
327
+ local input = core .get_craft_recipe (stack :get_name ())
328
328
if not input .items or input .type ~= " normal" then return end
329
329
local items , width = normalize (input .items ), input .width
330
330
local item_idx , width_idx = 1 , 1
@@ -349,7 +349,7 @@ local function update_meta(meta, enabled)
349
349
local state = enabled and " on" or " off"
350
350
meta :set_int (" enabled" , enabled and 1 or 0 )
351
351
local list_backgrounds = " "
352
- if minetest .get_modpath (" i3" ) or minetest .get_modpath (" mcl_formspec" ) then
352
+ if core .get_modpath (" i3" ) or core .get_modpath (" mcl_formspec" ) then
353
353
list_backgrounds = " style_type[box;colors=#666]"
354
354
for i = 0 , 2 do
355
355
for j = 0 , 2 do
@@ -389,7 +389,7 @@ local function update_meta(meta, enabled)
389
389
" listring[current_player;main]" ..
390
390
" listring[context;dst]" ..
391
391
" listring[current_player;main]"
392
- if minetest .get_modpath (" digilines" ) then
392
+ if core .get_modpath (" digilines" ) then
393
393
fs = fs .. " field[0.22,4.1;4.5,0.75;channel;" .. S (" Channel" ) ..
394
394
" ;${channel}]" ..
395
395
" button[5,4.1;1.5,0.75;set_channel;" .. S (" Set" ) .. " ]" ..
422
422
-- so we work out way backwards on this history and update each single case
423
423
-- to the newest version
424
424
local function upgrade_autocrafter (pos , meta )
425
- local meta = meta or minetest .get_meta (pos )
425
+ local meta = meta or core .get_meta (pos )
426
426
local inv = meta :get_inventory ()
427
427
428
428
if inv :get_size (" output" ) == 0 then -- we are version 2 or 1
@@ -439,7 +439,7 @@ local function upgrade_autocrafter(pos, meta)
439
439
if not recipe then return end
440
440
for idx , stack in ipairs (recipe ) do
441
441
if not stack :is_empty () then
442
- minetest .add_item (pos , stack )
442
+ core .add_item (pos , stack )
443
443
stack :set_count (1 )
444
444
stack :set_wear (0 )
445
445
inv :set_stack (" recipe" , idx , stack )
@@ -448,27 +448,27 @@ local function upgrade_autocrafter(pos, meta)
448
448
end
449
449
450
450
-- update the recipe, cache, and start the crafter
451
- autocrafterCache [minetest .hash_node_position (pos )] = nil
451
+ autocrafterCache [core .hash_node_position (pos )] = nil
452
452
after_recipe_change (pos , inv )
453
453
end
454
454
end
455
455
456
- minetest .register_node (" pipeworks:autocrafter" , {
456
+ core .register_node (" pipeworks:autocrafter" , {
457
457
description = S (" Autocrafter" ),
458
458
drawtype = " normal" ,
459
459
tiles = {" pipeworks_autocrafter.png" },
460
460
groups = {snappy = 3 , tubedevice = 1 , tubedevice_receiver = 1 , dig_generic = 1 , axey = 1 , handy = 1 , pickaxey = 1 },
461
461
is_ground_content = false ,
462
462
_mcl_hardness = 0.8 ,
463
463
tube = {insert_object = function (pos , node , stack , direction )
464
- local meta = minetest .get_meta (pos )
464
+ local meta = core .get_meta (pos )
465
465
local inv = meta :get_inventory ()
466
466
local added = inv :add_item (" src" , stack )
467
467
after_inventory_change (pos )
468
468
return added
469
469
end ,
470
470
can_insert = function (pos , node , stack , direction )
471
- local meta = minetest .get_meta (pos )
471
+ local meta = core .get_meta (pos )
472
472
local inv = meta :get_inventory ()
473
473
return inv :room_for_item (" src" , stack )
474
474
end ,
@@ -478,7 +478,7 @@ minetest.register_node("pipeworks:autocrafter", {
478
478
}
479
479
},
480
480
on_construct = function (pos )
481
- local meta = minetest .get_meta (pos )
481
+ local meta = core .get_meta (pos )
482
482
local inv = meta :get_inventory ()
483
483
inv :set_size (" src" , 3 * 8 )
484
484
inv :set_size (" recipe" , 3 * 3 )
@@ -492,10 +492,10 @@ minetest.register_node("pipeworks:autocrafter", {
492
492
then
493
493
return
494
494
end
495
- local meta = minetest .get_meta (pos )
495
+ local meta = core .get_meta (pos )
496
496
if fields .on then
497
497
update_meta (meta , false )
498
- minetest .get_node_timer (pos ):stop ()
498
+ core .get_node_timer (pos ):stop ()
499
499
elseif fields .off then
500
500
if update_meta (meta , true ) then
501
501
start_crafter (pos )
@@ -507,7 +507,7 @@ minetest.register_node("pipeworks:autocrafter", {
507
507
end ,
508
508
can_dig = function (pos , player )
509
509
upgrade_autocrafter (pos )
510
- local meta = minetest .get_meta (pos )
510
+ local meta = core .get_meta (pos )
511
511
local inv = meta :get_inventory ()
512
512
return (inv :is_empty (" src" ) and inv :is_empty (" dst" ))
513
513
end ,
@@ -516,12 +516,12 @@ minetest.register_node("pipeworks:autocrafter", {
516
516
pipeworks .scan_for_tube_objects (pos )
517
517
end ,
518
518
on_destruct = function (pos )
519
- autocrafterCache [minetest .hash_node_position (pos )] = nil
519
+ autocrafterCache [core .hash_node_position (pos )] = nil
520
520
end ,
521
521
allow_metadata_inventory_put = function (pos , listname , index , stack , player )
522
522
if not pipeworks .may_configure (pos , player ) then return 0 end
523
523
upgrade_autocrafter (pos )
524
- local inv = minetest .get_meta (pos ):get_inventory ()
524
+ local inv = core .get_meta (pos ):get_inventory ()
525
525
if listname == " recipe" then
526
526
stack :set_count (1 )
527
527
inv :set_stack (listname , index , stack )
@@ -536,13 +536,13 @@ minetest.register_node("pipeworks:autocrafter", {
536
536
end ,
537
537
allow_metadata_inventory_take = function (pos , listname , index , stack , player )
538
538
if not pipeworks .may_configure (pos , player ) then
539
- minetest .log (" action" , string.format (" %s attempted to take from " ..
539
+ core .log (" action" , string.format (" %s attempted to take from " ..
540
540
" autocrafter at %s" ,
541
- player :get_player_name (), minetest .pos_to_string (pos )))
541
+ player :get_player_name (), core .pos_to_string (pos )))
542
542
return 0
543
543
end
544
544
upgrade_autocrafter (pos )
545
- local inv = minetest .get_meta (pos ):get_inventory ()
545
+ local inv = core .get_meta (pos ):get_inventory ()
546
546
if listname == " recipe" then
547
547
inv :set_stack (listname , index , ItemStack (" " ))
548
548
after_recipe_change (pos , inv )
@@ -559,7 +559,7 @@ minetest.register_node("pipeworks:autocrafter", {
559
559
560
560
if not pipeworks .may_configure (pos , player ) then return 0 end
561
561
upgrade_autocrafter (pos )
562
- local inv = minetest .get_meta (pos ):get_inventory ()
562
+ local inv = core .get_meta (pos ):get_inventory ()
563
563
local stack = inv :get_stack (from_list , from_index )
564
564
565
565
if to_list == " output" then
@@ -592,7 +592,7 @@ minetest.register_node("pipeworks:autocrafter", {
592
592
receptor = {},
593
593
effector = {
594
594
action = function (pos ,node ,channel ,msg )
595
- local meta = minetest .get_meta (pos )
595
+ local meta = core .get_meta (pos )
596
596
if channel ~= meta :get_string (" channel" ) then return end
597
597
if type (msg ) == " table" then
598
598
if # msg < 3 then return end
@@ -601,7 +601,7 @@ minetest.register_node("pipeworks:autocrafter", {
601
601
local row = msg [y + 1 ]
602
602
for x = 1 , 3 , 1 do
603
603
local slot = y * 3 + x
604
- if type (row ) == " table" and minetest .registered_items [row [x ]] then
604
+ if type (row ) == " table" and core .registered_items [row [x ]] then
605
605
inv :set_stack (" recipe" , slot , ItemStack (
606
606
row [x ]))
607
607
else
@@ -611,7 +611,7 @@ minetest.register_node("pipeworks:autocrafter", {
611
611
end
612
612
after_recipe_change (pos ,inv )
613
613
elseif msg == " get_recipe" then
614
- local meta = minetest .get_meta (pos )
614
+ local meta = core .get_meta (pos )
615
615
local inv = meta :get_inventory ()
616
616
local recipe = {}
617
617
for y = 0 , 2 , 1 do
@@ -634,7 +634,7 @@ minetest.register_node("pipeworks:autocrafter", {
634
634
})
635
635
elseif msg == " off" then
636
636
update_meta (meta , false )
637
- minetest .get_node_timer (pos ):stop ()
637
+ core .get_node_timer (pos ):stop ()
638
638
elseif msg == " on" then
639
639
if update_meta (meta , true ) then
640
640
start_crafter (pos )
0 commit comments