-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcomputer.lua
More file actions
1215 lines (953 loc) · 29.6 KB
/
computer.lua
File metadata and controls
1215 lines (953 loc) · 29.6 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 lwcomp = ...
local S = lwcomp.S
local function on_construct (pos)
local meta = minetest.get_meta (pos)
meta:set_int ("robot", 0)
end
local function on_construct_robot (pos)
local meta = minetest.get_meta (pos)
meta:set_int ("robot", 1)
end
local function on_destruct (pos)
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local persists = false
if id > 0 then
persists = meta:get_int ("persists") == 1
local data = lwcomp.get_computer_data (id, pos)
if data then
data.mesecons_set (false)
end
lwcomp.remove_computer_data (id)
end
if persists then
minetest.forceload_free_block (pos, false)
end
end
end
local function on_receive_fields (pos, formname, fields, sender)
if not lwcomp.can_interact_with_node (pos, sender) then
return
end
if fields.reboot then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.reboot ()
end
end
elseif fields.power then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
if data.running then
data.shutdown ()
else
data.startup ()
end
end
end
elseif fields.persists then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.toggle_persists ()
data.update_formspec ()
end
end
elseif fields.storage then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.suspend_redraw = true
local spec =
"formspec_version[3]"..
"size[11.75,12.25,false]"..
"no_prepend[]"..
"bgcolor[#E7DAA8]"..
"list[context;storage;1.0,1.0;8,4;]"..
"list[current_player;main;1.0,6.5;8,4;]"..
"listring[]"..
"listcolors[#545454;#6E6E6E;#DBCF9F]"
meta:set_string ("formspec", spec)
end
end
elseif fields.quit then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.suspend_redraw = false
data.update_formspec ()
end
end
else
for k, v in pairs (fields) do
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.id = id
if fields.key_enter_field == "kbinput" then
fields.key_enter_field = ""
for i = 1, #fields.kbinput do
local c = fields.kbinput:sub(i,i)
local n = string.byte(c)
data.queue_event ("char", string.char(n), n)
end
data.queue_event ("char", string.char (13), 13)
end
local key = lwcomp.keys[k]
if key then
if k == "KEY_SHIFT" then
if data.shift and
not data.shift_locked and
(os.clock () - data.shift_when) <= lwcomp.settings.double_click_time then
data.shift_locked = true
else
data.shift = not data.shift
data.update_formspec ()
data.queue_event ("key", key, data.ctrl, data.alt, data.shift)
data.shift_locked = false
if data.shift then
data.shift_when = os.clock ()
end
end
elseif k == "KEY_CAPS" then
data.caps = not data.caps
data.update_formspec ()
data.queue_event ("key", key, data.ctrl, data.alt, data.shift)
elseif k == "KEY_CTRL" then
data.ctrl = not data.ctrl
data.update_formspec ()
data.queue_event ("key", key, data.ctrl, data.alt, data.shift)
elseif k == "KEY_ALT" then
data.alt = not data.alt
data.update_formspec ()
data.queue_event ("key", key, data.ctrl, data.alt, data.shift)
else
if k == "KEY_V" and data.ctrl and data.alt then
local contents = data.get_clipboard_contends ()
if contents then
data.queue_event ("clipboard", contents)
return
end
end
data.queue_event ("key", key, data.ctrl, data.alt, data.shift)
if not data.ctrl and not data.alt then
local char = key
if char < lwcomp.keys.KEY_DELETE then
if char >= lwcomp.keys.KEY_A and char <= lwcomp.keys.KEY_Z then
if (data.caps and data.shift) or (not data.caps and not data.shift) then
-- to lower
char = char + 32
end
else
char = (data.shift and lwcomp.shift_keys[k]) or key
end
data.queue_event ("char", string.char (char), char)
if data.shift and not data.shift_locked then
data.shift = false
data.update_formspec ()
end
end
end
end
else
local click = lwcomp.click_buttons[k]
if click then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
local count = 1
if (os.clock () - data.clicked_when) <= lwcomp.settings.double_click_time then
if data.clicked.x == click.x and data.clicked.y == click.y then
count = data.click_count + 1
end
end
data.clicked_when = os.clock ()
data.clicked = { x = click.x, y = click.y }
data.click_count = count
data.queue_event ("click", click.x, click.y, count)
end
end
end
end
end
end
end
end
local function preserve_metadata (pos, oldnode, oldmeta, drops)
if #drops > 0 then
if drops[1]:get_name ():sub (1, 20) == "lwcomputers:computer" then
local meta = minetest.get_meta (pos)
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local imeta = drops[1]:get_meta ()
local description = meta:get_string ("label")
if description:len () < 1 then
description = S("Computer ")..tostring (id)
end
imeta:set_int ("lwcomputer_id", id)
imeta:set_string ("name", meta:get_string ("name"))
imeta:set_string ("label", meta:get_string ("label"))
imeta:set_string ("infotext", meta:get_string ("infotext"))
imeta:set_string ("inventory", meta:get_string ("inventory"))
imeta:set_string ("digilines_channel", meta:get_string ("digilines_channel"))
imeta:set_string ("description", description)
imeta:set_string ("owner", meta:get_string ("owner"))
imeta:set_string ("access_by", meta:get_string ("access_by"))
imeta:set_int ("persists", meta:get_int ("persists"))
end
end
end
end
local function after_place_node (pos, placer, itemstack, pointed_thing)
local meta = minetest.get_meta (pos)
local is_robot = meta:get_int ("robot") == 1
local imeta = itemstack:get_meta ()
local id = imeta:get_int ("lwcomputer_id")
local name = ""
local label = ""
local infotext = ""
local digilines_channel = ""
local inventory
local owner = ""
local access_by = ""
local persists = 0
if is_robot then
inventory = "{ "..
"main = { [1] = '', [2] = '', [3] = '' }, "..
"storage = { [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] = '' } }"
else
inventory = "{ main = { [1] = '', [2] = '', [3] = '' } }"
end
local unique = false
if id > 0 then
name = imeta:get_string ("name")
label = imeta:get_string ("label")
infotext = imeta:get_string ("infotext")
inventory = imeta:get_string ("inventory")
digilines_channel = imeta:get_string ("digilines_channel")
owner = imeta:get_string ("owner")
access_by = imeta:get_string ("access_by")
persists = imeta:get_int ("persists")
unique = true
else
id = math.random (1000000)
end
meta:set_int ("lwcomputer_id", id)
meta:set_string ("name", name)
meta:set_string ("label", label)
meta:set_int ("running", 0)
meta:set_string ("infotext", infotext)
meta:set_string ("inventory", inventory)
meta:set_string ("digilines_channel", digilines_channel)
meta:set_string ("owner", owner)
meta:set_string ("access_by", access_by)
meta:set_string ("mesecon_front", lwcomp.mesecon_state_off)
meta:set_string ("mesecon_back", lwcomp.mesecon_state_off)
meta:set_string ("mesecon_left", lwcomp.mesecon_state_off)
meta:set_string ("mesecon_right", lwcomp.mesecon_state_off)
meta:set_string ("mesecon_up", lwcomp.mesecon_state_off)
if not is_robot then
persists = 0
end
meta:set_int ("persists", persists)
local inv = meta:get_inventory ()
inv:set_size ("main", 3)
inv:set_width ("main", 3)
if is_robot then
inv:set_size ("storage", 32)
inv:set_width ("storage", 8)
end
local data = lwcomp.reset_computer_data (id, pos)
if data then
meta:set_string ("formspec", lwcomp.term_formspec (data))
end
-- orientate
if placer and placer:is_player () then
local angle = placer:get_look_horizontal ()
local node = minetest.get_node (pos)
local param2
if angle >= (math.pi * 0.25) and angle < (math.pi * 0.75) then
-- x-
param2 = 3
elseif angle >= (math.pi * 0.75) and angle < (math.pi * 1.25) then
-- z-
param2 = 1
elseif angle >= (math.pi * 1.25) and angle < (math.pi * 1.75) then
-- x+
param2 = 4
else
-- z+
param2 = 2
end
meta:set_int ("param2", param2)
if node.name ~= "ignore" then
node.param2 = param2
end
end
if persists == 1 then
minetest.forceload_block (pos, false)
end
if unique and placer and placer:is_player () and
minetest.is_creative_enabled (placer:get_player_name ()) then
-- no duplicates in creative mode
itemstack:clear ()
return true
elseif not unique and placer and placer:is_player () then
local spec =
"formspec_version[3]"..
"size[8.0,3.0,false]"..
"no_prepend[]"..
"bgcolor[#E7DAA8]"..
"style[public;bgcolor=green;textcolor=white]"..
"style[private_"..tostring (id)..";bgcolor=red;textcolor=white]"..
"button_exit[1.0,1.0;2.5,1.0;public;Public]"..
"button_exit[4.5,1.0;2.5,1.0;private_"..tostring (id)..";Private]"
minetest.show_formspec (placer:get_player_name (),
"lwcomputers:computer_set_owner",
spec)
end
-- If return true no item is taken from itemstack
return false
end
local function on_timer (pos, elapsed)
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
if data.awaken then
data.awaken:cancel ()
data.awaken = nil
end
data.tick ()
end
end
-- return true to run the timer for another cycle with the same timeout
return true
end
local function can_dig (pos, player)
if not lwcomp.can_interact_with_node (pos, player) then
return false
end
local meta = minetest.get_meta (pos)
if meta then
local inv = meta:get_inventory ()
if inv then
if not inv:is_empty ("main") then
return false
end
end
if meta:get_int ("robot") == 1 then
if not inv:is_empty ("storage") then
return false
end
end
end
return true
end
local function allow_metadata_inventory_move (pos, from_list, from_index, to_list, to_index, count, player)
if not lwcomp.can_interact_with_node (pos, player) then
return 0
end
return lwcomp.settings.default_stack_max
end
local function allow_metadata_inventory_put (pos, listname, index, stack, player)
if not lwcomp.can_interact_with_node (pos, player) then
return 0
end
if listname == "main" then
if stack and not stack:is_empty () then
local itemname = stack:get_name ()
if lwcomp.is_floppy_disk (itemname) or
lwcomp.is_clipboard (itemname) then
return 1
end
end
elseif listname == "storage" then
return lwcomp.settings.default_stack_max
end
return 0
end
local function allow_metadata_inventory_take (pos, listname, index, stack, player)
if not lwcomp.can_interact_with_node (pos, player) then
return 0
end
return lwcomp.settings.default_stack_max
end
local function on_metadata_inventory_put (pos, listname, index, stack, player)
if listname == "main" then
if stack and not stack:is_empty () then
local itemname = stack:get_name ()
local floppy = lwcomp.is_floppy_disk (itemname)
if floppy then
local imeta = stack:get_meta ()
if imeta then
local id = imeta:get_int ("lwcomputer_id")
if id < 1 then
id = math.random (1000000)
imeta:set_int ("lwcomputer_id", id)
imeta:set_string ("label", floppy.label)
if floppy.label:len () > 0 then
imeta:set_string ("description", floppy.label)
else
imeta:set_string ("description", S("floppy ")..tostring (id))
end
if not lwcomp.filesys:prep_floppy_disk (id, imeta, floppy.files) then
minetest.log ("error", "lwcomputers - could not prep "..itemname)
end
local inv = minetest.get_meta (pos):get_inventory ()
inv:set_stack (listname, index, stack)
end
-- create floppy if not yet
lwcomp.filesys:create_floppy (id)
end
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.queue_event ("disk", true)
end
end
end
end
end
end
local function on_metadata_inventory_take (pos, listname, index, stack, player)
if listname == "main" then
if stack and not stack:is_empty () then
local itemname = stack:get_name ()
if lwcomp.is_floppy_disk (itemname) then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
local data = lwcomp.get_computer_data (id, pos)
if data then
data.queue_event ("disk", false)
end
end
end
end
end
end
local function on_punch_robot (pos, node, puncher, pointed_thing)
if not lwcomp.can_interact_with_node (pos, puncher) then
return
end
if puncher and puncher:is_player () and
puncher:get_player_control ().sneak then
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data and data.running then
local spec =
"formspec_version[3]"..
"size[4.5,3.0,false]"..
"no_prepend[]"..
"bgcolor[#E7DAA8]"..
"style_type[button_exit;bgcolor=red;textcolor=white]"..
"button_exit[1.0,1.0;2.5,1.0;stop_"..tostring (id)..";Stop]"
minetest.show_formspec (puncher:get_player_name (),
"lwcomputers:computer_robot_stop",
spec)
end
end
end
end
end
local function on_destroy (itemstack)
local meta = itemstack:get_meta ()
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
lwcomp.filesys:delete_hdd (id)
end
end
end
local function on_rightclick (pos, node, clicker, itemstack, pointed_thing)
if not lwcomp.can_interact_with_node (pos, clicker) then
if clicker and clicker:is_player () then
local owner = "<unknown>"
local meta = minetest.get_meta (pos)
if meta then
owner = meta:get_string ("owner")
end
local spec =
"formspec_version[3]"..
"size[8.0,4.0,false]"..
"label[1.0,1.0;Owned by "..minetest.formspec_escape (owner).."]"..
"button_exit[3.0,2.0;2.0,1.0;close;Close]"
minetest.show_formspec (clicker:get_player_name (),
"lwcomputers:computer_privately_owned",
spec)
end
end
return itemstack
end
local function on_blast (pos, intensity)
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local is_robot = meta:get_int ("robot") == 1
if intensity >= 1.0 then
local inv = meta:get_inventory ()
if inv then
local slots = inv:get_size ("main")
for slot = 1, slots do
local stack = inv:get_stack ("main", slot)
if stack and not stack:is_empty () then
if math.floor (math.random (0, 5)) == 3 then
lwcomp.item_drop (stack, nil, pos)
else
lwcomp.on_destroy (stack)
end
end
end
if is_robot then
local rslots = inv:get_size ("storage")
for slot = 1, rslots do
local stack = inv:get_stack ("storage", slot)
if stack and not stack:is_empty () then
if math.floor (math.random (0, 5)) == 3 then
lwcomp.item_drop (stack, nil, pos)
else
lwcomp.on_destroy (stack)
end
end
end
end
end
lwcomp.filesys:delete_hdd (id)
on_destruct (pos)
minetest.remove_node (pos)
else -- intensity < 1.0
local inv = meta:get_inventory ()
if inv then
local slots = inv:get_size ("main")
for slot = 1, slots do
local stack = inv:get_stack ("main", slot)
if stack and not stack:is_empty () then
lwcomp.item_drop (stack, nil, pos)
end
end
if is_robot then
local rslots = inv:get_size ("storage")
for slot = 1, rslots do
local stack = inv:get_stack ("storage", slot)
if stack and not stack:is_empty () then
lwcomp.item_drop (stack, nil, pos)
end
end
end
end
local node = minetest.get_node_or_nil (pos)
if node then
local items = minetest.get_node_drops (node, nil)
if items and #items > 0 then
local stack = ItemStack (items[1])
if stack then
preserve_metadata (pos, node, meta, { stack })
lwcomp.item_drop (stack, nil, pos)
on_destruct (pos)
minetest.remove_node (pos)
end
end
end
end
end
end
end
local function digilines_support ()
if lwcomp.digilines_supported then
return
{
wire =
{
rules = digiline.rules.default,
},
effector =
{
action = function (pos, node, channel, msg)
local meta = minetest.get_meta(pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data then
local mychannel = meta:get_string ("digilines_channel")
data.queue_event ("digilines", msg, channel, mychannel)
end
end
end
end,
}
}
end
return nil
end
local function get_mesecon_side_for_rule (pos, param2, rule)
if type (rule) == "table" and param2 >= 1 and param2 <= 4 then
if rule.x == -1 then
return ({ "left", "right", "back", "front" })[param2]
elseif rule.x == 1 then
return ({ "right", "left", "front", "back" })[param2]
elseif rule.z == -1 then
return ({ "back", "front", "right", "left" })[param2]
elseif rule.z == 1 then
return ({ "front", "back", "left", "right" })[param2]
end
end
return nil
end
local function mesecon_support ()
if lwcomp.mesecon_supported then
return
{
receptor =
{
state = mesecon.state.off, -- /on,
rules =
{
{ x = 1, y = 0, z = 0 },
{ x = -1, y = 0, z = 0 },
{ x = 0, y = 0, z = 1 },
{ x = 0, y = 0, z = -1 },
{ x = 0, y = 1, z = 0 },
--{ x = 0, y = -1, z = 0 }, down doesn't work
}
},
effector =
{
rules = mesecon.rules.flat,
action_change = function (pos, node, rule, new_state)
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data then
data.queue_event ("mesecons", new_state,
get_mesecon_side_for_rule (pos, meta:get_int ("param2"), rule))
end
end
end
end
}
}
end
return nil
end
local function wires_support ()
if lwcomp.wires_supported then
return
{
bundle_on = function (pos, wires, bundle_pos)
-- called to notify when any wires are turned on
-- no return used
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data then
data.wires_queue_bundle_on (bundle_pos, wires)
end
end
end
end,
bundle_off = function (pos, wires, bundle_pos)
-- called to notify when any wires are turned off
-- no return used
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data then
data.wires_queue_bundle_off (bundle_pos, wires)
end
end
end
end,
current_state = function (pos, bundle_pos)
-- return table where key is color string and
-- value is true/false for on/off, for every wire
local wires = { }
local meta = minetest.get_meta (pos)
if meta then
local id = meta:get_int ("lwcomputer_id")
if id > 0 then
local data = lwcomp.get_computer_data (id, pos)
if data then
wires = data.wires_current_state_by_pos (bundle_pos)
end
end
end
return wires
end
}
end
return nil
end
minetest.register_node("lwcomputers:computer", {
description = S("Computer"),
tiles = { "lwcomputers_computer.png", "lwcomputers_computer.png", "lwcomputers_computer.png",
"lwcomputers_computer.png", "lwcomputers_computer.png", "lwcomputers_computer_face.png" },
sunlight_propagates = false,
drawtype = "normal",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}
},
groups = { cracky = 2, oddly_breakable_by_hand = 2, bundles_connect = 1 },
sounds = default.node_sound_wood_defaults (),
paramtype = "light",
param1 = 0,
paramtype2 = "facedir",
param2 = 1,
drop = "lwcomputers:computer",
floodable = false,
mesecons = mesecon_support (),
digiline = digilines_support (),
_wires = wires_support (),
on_construct = on_construct,
on_destruct = on_destruct,
on_receive_fields = on_receive_fields,
preserve_metadata = preserve_metadata,
after_place_node = after_place_node,
on_timer = on_timer,
can_dig = can_dig,
allow_metadata_inventory_move = allow_metadata_inventory_move,
allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take,
on_metadata_inventory_put = on_metadata_inventory_put,
on_metadata_inventory_take = on_metadata_inventory_take,
on_rightclick = on_rightclick,
on_destroy = on_destroy,
on_blast = on_blast
})
minetest.register_node("lwcomputers:computer_on", {
description = S("Computer"),
tiles = { "lwcomputers_computer.png", "lwcomputers_computer.png", "lwcomputers_computer.png",
"lwcomputers_computer.png", "lwcomputers_computer.png", "lwcomputers_computer_face_on.png" },
sunlight_propagates = false,
drawtype = "normal",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}
},
groups = { cracky = 2, oddly_breakable_by_hand = 2, not_in_creative_inventory = 1, bundles_connect = 1 },