-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchem_lab.lua
More file actions
1198 lines (1117 loc) · 39 KB
/
chem_lab.lua
File metadata and controls
1198 lines (1117 loc) · 39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local S = core.get_translator(core.get_current_modname())
local time_scl = 10
local has_pipeworks = core.get_modpath("pipeworks")
local tube_entry_metal = ""
if has_pipeworks then
tube_entry_metal = "^pipeworks_tube_connection_metallic.png"
end
local connect_default = {"bottom", "back"}
local function isNumber(str)
return tonumber(str) ~= nil
end
local function round(v)
return math.floor(v + 0.5)
end
----------------------------------------------------
local function update_formspec(meta, data)
local machine_desc = data.tier .. " " .. data.machine_desc
local typename = data.typename
local tier = data.tier
local ltier = string.lower(tier)
local formspec = nil
if typename == 'chem_lab' then
local enabled = ctg_machines.machine_enabled(meta)
local btnName = "Status: "
if enabled then
btnName = btnName .. "Enabled"
else
btnName = btnName .. "Disabled"
end
local percent1 = 0
if meta:get_int("output_count") and meta:get_int("output_max") then
percent1 = (meta:get_int("output_count") / meta:get_int("output_max")) * 100
end
local progress_proc = "image[3.25,1.5;1.5,1;gui_furnace_arrow_bg.png^[lowpart:" .. tostring(percent1) ..
":gui_furnace_arrow_fg.png^[transformR270]]";
local percent2 = 0
if meta:get_int("src_time") then
percent2 = (meta:get_int("src_time") / round(time_scl * 10)) * 100
end
local progress_time = "image[3.25,1.0;1.5,0.5;gui_furnace_arrow_bg.png^[lowpart:" .. tostring(percent2) ..
":gui_furnace_arrow_fg.png^[transformR270]]"
local recipe_index = meta:get_int("recipe")
local bg_images = {
"bucket_cave_cavewater.png^[colorize:#75757575",
"technic_sulfur_dust.png^[colorize:#75757575",
"saltd_salt_crystals.png^[colorize:#75757575",
"livingcaves_mushroom_top.png^[colorize:#75757575"
}
if recipe_index == 2 then
bg_images = {
"bucket_water.png^[colorize:#75757575",
"default_leaves.png^[colorize:#75757575",
"x_farming_rice_seed_inv.png^[colorize:#75757575",
"x_farming_rice_seed_inv.png^[colorize:#75757575"
}
end
local images = "image[1,1;1,1;" .. bg_images[1] .. "]" .. "image[2,1;1,1;" .. bg_images[2] .. "]" ..
"image[1,2;1,1;" .. bg_images[3] .. "]" .. "image[2,2;1,1;" .. bg_images[4] .. "]"
local recipe_label = "label[1,3.175;" .. S("Selected Recipe") .. "]"
local recipe_dropdown = "dropdown[1,3.6;2.5;recipe;Coolant,Seed Oil;"..recipe_index..";true]"
formspec = "size[8,9;]" .. images..
"list[current_name;src1;1,1;1,1;]" .. "list[current_name;src2;2,1;1,1;]" ..
"list[current_name;src3;1,2;1,1;]" .. "list[current_name;src4;2,2;1,1;]" ..
"list[current_name;dst;5,1;2,2;]" ..
"list[current_player;main;0,5;8,4;]" .. "label[0,0;" .. machine_desc:format(tier) .. "]" ..
progress_proc .. progress_time .. "listring[current_name;dst]" ..
"listring[current_player;main]" .. "listring[current_name;src1]" .. "listring[current_name;src2]" ..
"listring[current_name;src3]" .. "listring[current_name;src4]" .. "listring[current_player;main]" ..
recipe_label .. recipe_dropdown .. "button[4.5,3.5;2.5,1;toggle;" .. btnName .. "]"
end
if data.upgrade then
formspec = formspec .. "list[current_name;upgrade1;1,3;1,1;]" .. "list[current_name;upgrade2;2,3;1,1;]" ..
"label[1,4;" .. S("Upgrade Slots") .. "]" .. "listring[current_name;upgrade1]" ..
"listring[current_player;main]" .. "listring[current_name;upgrade2]" ..
"listring[current_player;main]"
end
return formspec
end
----------------------------------------------------
local function do_particle_effect(pos, amount)
local grav = 0.25;
if (pos.y > 4000) then
grav = 0.4;
end
local prt = {
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1
},
texture = {
name = "ctg_coolant_bubble_anim.png",
alpha = 1.0,
alpha_tween = {1, 0},
scale_tween = {{
x = 0.1,
y = 0
}, {
x = 3,
y = 3
}}
},
texture_r180 = {
name = "ctg_coolant_bubble_anim.png" .. "^[transformR180",
alpha = 1.0,
alpha_tween = {1, 0},
scale_tween = {{
x = 0.1,
y = 0.0
}, {
x = 3,
y = 3
}}
},
vel = 2.7,
time = 2.5,
size = 0.7,
glow = 6,
cols = false
}
local rx = math.random(-0.064, 0.064) * 0.2
local rz = math.random(-0.064, 0.064) * 0.2
local texture = prt.texture
if (math.random() >= 0.52) then
texture = prt.texture_r180
end
core.add_particlespawner({
amount = amount,
time = prt.time + math.random(-0.3, 1),
minpos = {
x = pos.x - 0.4,
y = pos.y + 0.46,
z = pos.z - 0.4
},
maxpos = {
x = pos.x + 0.4,
y = pos.y + 0.67,
z = pos.z + 0.4
},
minvel = {
x = rx,
y = prt.vel * 0.2 * grav,
z = rz
},
maxvel = {
x = rx,
y = prt.vel * 0.7 * grav,
z = rz
},
minacc = {
x = -0.1,
y = -0.15,
z = -0.1
},
maxacc = {
x = 0.1,
y = 0.23 * grav,
z = 0.1
},
minexptime = prt.time * 0.30,
maxexptime = prt.time * 0.96,
minsize = prt.size * 0.5,
maxsize = prt.size * 1.2,
collisiondetection = prt.cols,
collision_removal = false,
object_collision = false,
vertical = false,
animation = prt.animation,
texture = texture,
glow = prt.glow
})
end
----------------------------------------------------
----------------------------------------------------
local function get_sulfur(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
if stack:get_name() == 'technic:sulfur_dust' and stack:get_count() > 0 then
new_input = ItemStack(stack)
if take then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_bio_water(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
if stack:get_name() == "livingcaves:bucket_cavewater" and stack:get_count() > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_river_water(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
local group = core.get_item_group(stack:get_name(), "water_bucket")
if group > 0 and stack:get_count() > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_water(meta, items, take)
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
return get_bio_water(items, take)
elseif recipe_index == 2 then
return get_river_water(items, take)
end
end
local function get_shrooms(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
local group = core.get_item_group(stack:get_name(), "glow_shroom")
if group > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_salt(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
local group = core.get_item_group(stack:get_name(), "salt")
if group > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_leaves(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
local group = core.get_item_group(stack:get_name(), "leaves")
if group > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function get_seeds(items, take)
if not items then
return nil
end
local new_input = nil
local c = 0;
for i, stack in ipairs(items) do
local is_seed = true
local stack_name = stack:get_name()
if stack_name == "x_farming:seed_icefishing" then
is_seed = false
end
if stack_name == "x_farming:seed_salt" then
is_seed = false
end
if is_seed then
local group = core.get_item_group(stack_name, "seed")
if group > 0 then
new_input = ItemStack(stack)
if (take) then
new_input:take_item(1)
end
c = c + 1
break
end
end
end
if (c > 0) then
return {
new_input = new_input
}
else
return nil
end
end
local function has_items_coolant(meta)
local inv = meta:get_inventory()
local src2 = inv:get_list("src2")
local src3 = inv:get_list("src3")
local src4 = inv:get_list("src4")
local has_sulfur = false
local has_salt = false
local has_shroom = false
if src2[1]:get_name() == 'technic:sulfur_dust' and src2[1]:get_count() > 0 then
has_sulfur = true
end
local group = core.get_item_group(src3[1]:get_name(), "salt")
if group > 0 then
has_salt = true
end
local group = core.get_item_group(src4[1]:get_name(), "glow_shroom")
if group > 0 then
has_shroom = true
end
return has_sulfur and has_shroom and has_salt
end
local function has_water_coolant(meta)
local inv = meta:get_inventory()
local src1 = inv:get_list("src1")
if src1[1]:get_name() == 'livingcaves:bucket_cavewater' and src1[1]:get_count() > 0 then
return true
end
return false
end
local function add_output_coolant(meta, do_run, do_use)
local output = {}
if do_use then
output = {"ctg_machines:bottle_of_coolant"}
end
if do_run then
table.insert(output, "livingcaves:bucket_empty")
end
local inv = meta:get_inventory()
if type(output) ~= "table" then
output = {output}
end
local output_stacks = {}
for _, o in ipairs(output) do
table.insert(output_stacks, ItemStack(o))
end
local room_for_output = true
inv:set_size("dst_tmp", inv:get_size("dst"))
inv:set_list("dst_tmp", inv:get_list("dst"))
for _, o in ipairs(output_stacks) do
if not inv:room_for_item("dst_tmp", o) then
room_for_output = false
break
end
inv:add_item("dst_tmp", o)
end
if not room_for_output then
return false
end
inv:set_list("dst", inv:get_list("dst_tmp"))
return true
end
local function has_items_oil(meta)
local inv = meta:get_inventory()
local src2 = inv:get_list("src2")
local src3 = inv:get_list("src3")
local src4 = inv:get_list("src4")
local has_leaves = false
local has_seed_1 = false
local has_seed_2 = false
local group = core.get_item_group(src2[1]:get_name(), "leaves")
if group > 0 then
has_leaves = true
end
local group = core.get_item_group(src3[1]:get_name(), "seed")
if group > 0 then
has_seed_1 = true
end
local group = core.get_item_group(src4[1]:get_name(), "seed")
if group > 0 then
has_seed_2 = true
end
return has_leaves and has_seed_1 and has_seed_2
end
local function has_water_oil(meta)
local inv = meta:get_inventory()
local src1 = inv:get_list("src1")
local group = core.get_item_group(src1[1]:get_name(), "water_bucket")
if group > 0 and src1[1]:get_count() > 0 then
return true
end
return false
end
local function add_output_oil(meta, do_run, do_use, tier)
local output = {}
if do_use then
local count = 1
if tier == 'mv' then
local r = 0
if math.random(0,5) == 0 then
r = 1
end
count = 1 + r
elseif tier == 'hv' then
count = math.random(1,2)
end
output = {{ name = "basic_materials:oil_extract", count = count}}
end
if do_run then
table.insert(output, {name = "bucket:bucket_empty", count = 1})
end
local inv = meta:get_inventory()
if type(output) ~= "table" then
output = {output}
end
local output_stacks = {}
for _, o in ipairs(output) do
table.insert(output_stacks, ItemStack(o))
end
local room_for_output = true
inv:set_size("dst_tmp", inv:get_size("dst"))
inv:set_list("dst_tmp", inv:get_list("dst"))
for _, o in ipairs(output_stacks) do
if not inv:room_for_item("dst_tmp", o) then
room_for_output = false
break
end
inv:add_item("dst_tmp", o)
end
if not room_for_output then
return false
end
inv:set_list("dst", inv:get_list("dst_tmp"))
return true
end
local function has_items(meta)
if not meta then
return nil
end
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
return has_items_coolant(meta)
elseif recipe_index == 2 then
return has_items_oil(meta)
end
return false
end
local function has_water(meta)
if not meta then
return nil
end
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
return has_water_coolant(meta)
elseif recipe_index == 2 then
return has_water_oil(meta)
end
return false
end
local function add_output(meta, do_run, do_use, tier)
if not meta then
return nil
end
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
return add_output_coolant(meta, do_run, do_use)
elseif recipe_index == 2 then
return add_output_oil(meta, do_run, do_use, tier)
end
return false
end
local function is_seed(stack_name)
local g_seeds = core.get_item_group(stack_name, "seed")
if g_seeds > 0 then
if stack_name == "x_farming:seed_icefishing" then
g_seeds = 0
elseif stack_name == "x_farming:seed_salt" then
g_seeds = 0
end
end
return g_seeds
end
----------------------------------------------------
----------------------------------------------------
----------------------------------------------------
function ctg_machines.register_chem_lab(custom_data)
local data = custom_data or {}
data.tube = 1
data.speed = custom_data.speed or 1
data.demand = custom_data.demand or {200, 180, 150}
data.tier = (custom_data and custom_data.tier) or "LV"
data.typename = (custom_data and custom_data.typename) or "chem_lab"
data.modname = (custom_data and custom_data.modname) or "ctg_machines"
data.machine_name = (custom_data and custom_data.machine_name) or string.lower(data.tier) ..
"_chemical_lab"
data.machine_desc = (custom_data and custom_data.machine_desc) or "Chemical Lab"
local tier = data.tier
local ltier = string.lower(tier)
local modname = data.modname
local machine_name = data.machine_name
local machine_desc = tier .. " " .. data.machine_desc
local lmachine_name = string.lower(machine_name)
local node_name = modname .. ":" .. machine_name
local groups = {
cracky = 2,
technic_machine = 1,
["technic_" .. ltier] = 1,
ctg_machine = 1,
metal = 1,
ctg_machines = 1
}
if data.tube then
groups.tubedevice = 1
groups.tubedevice_receiver = 1
end
local active_groups = {
not_in_creative_inventory = 1
}
for k, v in pairs(groups) do
active_groups[k] = v
end
local tube = {
input_inventory = 'dst',
insert_object = function(pos, node, stack, direction)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local added = nil
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
local g_water = stack:get_name() == "livingcaves:bucket_cavewater"
if g_water then
added = inv:add_item("src1", stack)
end
local g_sulfur = stack:get_name() == "technic:sulfur_dust"
if g_sulfur then
added = inv:add_item("src2", stack)
end
local g_salt = core.get_item_group(stack:get_name(), "salt")
if g_salt > 0 then
added = inv:add_item("src3", stack)
end
local g_shroom = core.get_item_group(stack:get_name(), "glow_shroom")
if g_shroom > 0 then
added = inv:add_item("src4", stack)
end
elseif recipe_index == 2 then
local g_water = core.get_item_group(stack:get_name(), "water_bucket") or 0
if g_water > 0 then
added = inv:add_item("src1", stack)
end
local g_leaves = core.get_item_group(stack:get_name(), "leaves")
if g_leaves then
added = inv:add_item("src2", stack)
end
local g_seeds_1 = is_seed(stack:get_name())
if g_seeds_1 > 0 then
added = inv:add_item("src3", stack)
end
local g_seeds_2 = is_seed(stack:get_name())
if g_seeds_2 > 0 then
added = inv:add_item("src4", stack)
end
end
return added
end,
can_insert = function(pos, node, stack, direction)
local meta = core.get_meta(pos)
local inv = meta:get_inventory()
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
local g_water = stack:get_name() == "livingcaves:bucket_cavewater"
if g_water then
return inv:room_for_item("src1", stack)
end
local g_sulfur = stack:get_name() == "technic:sulfur_dust"
if g_sulfur then
return inv:room_for_item("src2", stack)
end
local g_salt = core.get_item_group(stack:get_name(), "salt")
if g_salt > 0 then
return inv:room_for_item("src3", stack)
end
local g_shroom = core.get_item_group(stack:get_name(), "glow_shroom")
if g_shroom > 0 then
return inv:room_for_item("src4", stack)
end
elseif recipe_index == 2 then
local g_water = core.get_item_group(stack:get_name(), "water_bucket") or 0
if g_water > 0 then
return inv:room_for_item("src1", stack)
end
local g_leaves = core.get_item_group(stack:get_name(), "leaves")
if g_leaves then
return inv:room_for_item("src2", stack)
end
local g_seeds_1 = is_seed(stack:get_name())
if g_seeds_1 > 0 then
return inv:room_for_item("src3", stack)
end
local g_seeds_2 = is_seed(stack:get_name())
if g_seeds_2 > 0 then
return inv:room_for_item("src4", stack)
end
end
return false
end,
connect_sides = {
--left = 1,
right = 1,
back = 1,
top = 1,
bottom = 1,
}
}
if data.can_insert then
tube.can_insert = data.can_insert
end
if data.insert_object then
tube.insert_object = data.insert_object
end
local allow_metadata_inventory_put = function(pos, listname, index, stack, player)
local meta = core.get_meta(pos)
if core.is_protected(pos, player:get_player_name()) then
return 0
end
local recipe_index = meta:get_int("recipe")
local stackname = stack:get_name()
if recipe_index == 1 then
if listname == "src1" then
local is_water = stackname == "livingcaves:bucket_cavewater"
if is_water then
return stack:get_count()
end
elseif listname == "src2" then
local is_sulfur = stackname == "technic:sulfur_dust"
if is_sulfur then
return stack:get_count()
end
elseif listname == "src3" then
local is_salt = core.get_item_group(stackname, "salt") or 0
if is_salt > 0 then
return stack:get_count()
end
elseif listname == "src4" then
local is_shroom = core.get_item_group(stackname, "glow_shroom") or 0
if is_shroom > 0 then
return stack:get_count()
end
end
elseif recipe_index == 2 then
if listname == "src1" then
local is_water = core.get_item_group(stackname, "water_bucket") or 0
if is_water > 0 then
return stack:get_count()
end
elseif listname == "src2" then
local is_leaves = core.get_item_group(stackname, "leaves") or 0
if is_leaves > 0 then
return stack:get_count()
end
elseif listname == "src3" then
local is_seeds = is_seed(stackname)
if is_seeds > 0 then
return stack:get_count()
end
elseif listname == "src4" then
local is_seeds = is_seed(stackname)
if is_seeds > 0 then
return stack:get_count()
end
end
end
return 0
end
-------------------------------------------------------
-------------------------------------------------------
-- technic run
local run = function(pos, node)
local meta = core.get_meta(pos)
local owner = meta:get_string("owner")
local operator = core.get_player_by_name(owner);
local inv = meta:get_inventory()
local eu_input = meta:get_int(tier .. "_EU_input")
local machine_desc_tier = machine_desc:format(tier)
local machine_node = data.modname .. ":" .. machine_name
local machine_demand_active = data.demand
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int(tier .. "_EU_demand", machine_demand_active[1])
meta:set_int(tier .. "_EU_input", 0)
return
end
local powered = eu_input >= machine_demand_active[1]
if powered then
if meta:get_int("src_time") < round(time_scl * 10) then
meta:set_int("src_time", meta:get_int("src_time") + round(data.speed * 10))
end
end
while true do
local enabled = meta:get_int("enabled") == 1
if not enabled then
meta:set_int(tier .. "_EU_demand", 0)
technic.swap_node(pos, machine_node)
return
end
meta:set_int(tier .. "_EU_demand", machine_demand_active[1])
if not powered then
meta:set_string("infotext", machine_desc_tier .. S(" - Not Powered"))
technic.swap_node(pos, machine_node)
return
end
meta:set_string("infotext", machine_desc_tier .. S(" - Online"))
if meta:get_int("output_count") == 0 and not has_water(meta) then
technic.swap_node(pos, machine_node)
meta:set_int("input_valid", 0)
meta:set_int("src_time", 0)
end
if meta:get_int("input_valid") <= 1 and not has_items(meta) then
meta:set_int("src_time", 0)
technic.swap_node(pos, machine_node)
break;
end
if (meta:get_int("src_time") % 2 == 0) then
local formspec = update_formspec(meta, data)
meta:set_string("formspec", formspec)
end
if (meta:get_int("src_time") < round(time_scl * 10)) then
if meta:get_int("input_valid") >= 1 then
technic.swap_node(pos, machine_node .. "_active")
end
if meta:get_int("output_count") > 0 then
break
end
end
local used_bucket = false
if meta:get_int("input_valid") == 0 and has_water(meta) then
local input1 = get_water(meta, inv:get_list("src1"), true)
if input1 ~= nil then
inv:set_list("src1", {input1.new_input})
used_bucket = true
end
if used_bucket then
meta:set_int("input_valid", 1)
meta:set_int("output_count", 0)
end
end
if meta:get_int("input_valid") >= 1 and has_items(meta) then
local recipe_index = meta:get_int("recipe")
if recipe_index == 1 then
local input2 = get_sulfur(inv:get_list("src2"), true)
local input3 = get_salt(inv:get_list("src3"), true)
local input4 = get_shrooms(inv:get_list("src4"), true)
if input2 and input2.new_input then
inv:set_list("src2", {input2.new_input})
end
if input3 and input3.new_input then
inv:set_list("src3", {input3.new_input})
end
if input4 and input4.new_input then
inv:set_list("src4", {input4.new_input})
end
elseif recipe_index == 2 then
local input2 = get_leaves(inv:get_list("src2"), true)
local input3 = get_seeds(inv:get_list("src3"), true)
local input4 = get_seeds(inv:get_list("src4"), true)
if input2 and input2.new_input then
inv:set_list("src2", {input2.new_input})
end
if input3 and input3.new_input then
inv:set_list("src3", {input3.new_input})
end
if input4 and input4.new_input then
inv:set_list("src4", {input4.new_input})
end
end
meta:set_int("input_valid", 2)
technic.swap_node(pos, machine_node .. "_active")
elseif meta:get_int("input_valid") >= 1 then
meta:set_int("input_valid", 1)
technic.swap_node(pos, machine_node)
end
if meta:get_int("input_valid") == 2 then
meta:set_int("input_valid", 1)
local tick_max = meta:get_int("output_max")
local tick = meta:get_int("output_count")
if tick < tick_max then
tick = tick + 1
end
meta:set_int("output_count", tick)
if tick >= tick_max then
meta:set_int("input_valid", 0)
meta:set_int("output_count", 0)
end
add_output(meta, used_bucket, true, ltier)
meta:set_string("infotext", machine_desc_tier .. S(" - Processing"))
do_particle_effect(pos, 16)
end
meta:set_int("src_time", 0)
break
end
end
local on_receive_fields = function(pos, formname, fields, sender)
local meta = core.get_meta(pos)
if fields.quit then
return
end
local enabled = meta:get_int("enabled")
if fields.toggle then
if enabled >= 1 then
meta:set_int("enabled", 0)
else
meta:set_int("enabled", 1)
end
end
if fields.recipe then
local recipe = tonumber(fields.recipe)
if recipe then
meta:set_int("recipe", recipe)
end
end
local formspec = update_formspec(meta, data)
meta:set_string("formspec", formspec)
end
core.register_node(node_name, {
description = machine_desc,
tiles = {"ctg_" .. ltier .. "_chem_lab_top.png^[transformR90" .. tube_entry_metal,
"ctg_" .. ltier .. "_chem_lab_bottom.png^[transformFXR90" .. tube_entry_metal, "ctg_" .. ltier .. "_chem_lab_side_r.png" .. tube_entry_metal,
"ctg_" .. ltier .. "_chem_lab_side_l.png^[transformFX", "ctg_" .. ltier .. "_chem_lab_back.png" .. tube_entry_metal,
"ctg_" .. ltier .. "_chem_lab_front.png"},
param = "light",
paramtype2 = "facedir",
light_source = 1,
drop = node_name,
groups = groups,
tube = data.tube and tube or nil,
connect_sides = data.connect_sides or connect_default,
legacy_facedir_simple = true,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.46875, -0.5, -0.46875, 0.5, 0.46875, 0.5}, -- base
{0.0625, -0.5, -0.5, 0.5, 0.5, -0.4375}, -- front_r
{-0.5, -0.5, -0.5, 0.5, -0.125, -0.4375}, -- front_bottom
{-0.5, -0.5, 0.0625, -0.4375, 0.5, 0.5}, -- left
{-0.5, -0.5, -0.5, -0.4375, -0.125, 0.5}, -- left_bottom
{0.0625, 0.4375, -0.46875, 0.5, 0.5, 0.5}, -- top_0
{-0.4375, 0.4375, 0.0625, 0.0625, 0.5, 0.5}, -- top_1
{-0.1875, 0.4375, -0.1875, 0.0625, 0.5, 0.0625}, -- top_m
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- col_base
}
},
sounds = default.node_sound_metal_defaults(),
after_place_node = function(pos, placer, itemstack, pointed_thing)
if data.tube then
pipeworks.after_place(pos)
end
local meta = core.get_meta(pos)
meta:set_string("infotext", machine_desc)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
if data.tube then
pipeworks.after_dig(pos)
end
return technic.machine_after_dig_node