This repository was archived by the owner on May 6, 2025. It is now read-only.
forked from oversword/robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathabilities.lua
More file actions
865 lines (772 loc) · 22.2 KB
/
abilities.lua
File metadata and controls
865 lines (772 loc) · 22.2 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
local api = robot.internal_api
local S = api.translator
api.abilities = {}
api.abilities_item_index = {}
api.abilities_ability_index = {}
minetest.register_craftitem(api.config.god_item, {
description = "God Ability",
inventory_image = 'robot_god_ability_item.png',
groups = {
not_in_creative_inventory = 1
}
})
function robot.add_ability(ability_obj)
local existing_item_ability = api.abilities_item_index[ability_obj.item]
if existing_item_ability and existing_item_ability.ability ~= ability_obj.ability then
error(("An ability already exists for this item: '%s'."):format(ability_obj.item))
return
end
if not ability_obj.ability then
error("You must define an ability name as ability_obj.ability")
return
end
if not ability_obj.description then
error("You must define an ability description as ability_obj.description")
return
end
if type(ability_obj.item) == 'function' then
local item = ability_obj.item()
ability_obj.item = item
end
if not ability_obj.item then
minetest.log("warning", ("[robot] ability %s will not be usable until an item is set for it"):format(ability_obj.ability))
end
local existing_ability_obj = api.abilities_ability_index[ability_obj.ability]
if existing_ability_obj then
minetest.log("warning", ("[robot] overriding %s ability"):format(ability_obj.ability))
local new_abilities = {}
for _,ability in ipairs(api.abilities) do
if ability.ability == ability_obj.ability then
table.insert(new_abilities, ability_obj)
else
table.insert(new_abilities, ability)
end
end
api.abilities = new_abilities
else
table.insert(api.abilities, ability_obj)
end
api.abilities_item_index[ability_obj.item] = ability_obj
api.abilities_ability_index[ability_obj.ability] = ability_obj
end
function robot.set_ability_item(ability, item)
local ability_obj = api.abilities_ability_index[ability]
if not ability_obj then
error("Cannot set the item of an ability that does not exist.")
return
end
local existing_item_ability = api.abilities_item_index[item]
if existing_item_ability then
error(("An ability already exists for this item: '%s'."):format(item))
return
end
api.abilities_item_index[ability_obj.item] = nil
api.abilities_item_index[item] = ability_obj
ability_obj.item = item
end
function api.ability_enabled(ability)
local ability_obj = api.abilities_ability_index[ability]
if not ability_obj then return false end
if ability_obj.disabled then return false end
if not ability_obj.item then return false end
return ability_obj
end
function api.any_has_ability(nodeinfo, ability, ignore_god_item)
local ns = nodeinfo.robot_set()
for _,n in ipairs(ns) do
if api.has_ability(n, ability, ignore_god_item) then return n end
end
end
function api.has_ability(nodeinfo, ability, ignore_god_item)
local ability_obj = api.ability_enabled(ability)
if not ability_obj then return end
local info = nodeinfo.info()
if not info.part then return end
for _,def_ability in ipairs(api.parts[info.part].default_abilities or {}) do
if def_ability == ability then
return true
end
end
if ability_obj.done_by and not ability_obj.done_by[info.part] then return end
local extras_enabled_list = string.split(nodeinfo.meta():get_string('extras'),',')
for _,def in ipairs(extras_enabled_list) do
if def == ability and api.tiers[info.tier].extra_abilities then
for _,ab in ipairs(api.tiers[info.tier].extra_abilities) do
if ab == ability then return true end
end
end
end
local inv = nodeinfo.inv()
if not ignore_god_item and not ability_obj.interface_enabled and inv:contains_item('abilities', api.config.god_item) then
return true
end
if inv:contains_item('abilities', ability_obj.item) then
return true
end
end
function api.can_have_ability_item(nodeinfo, item)
if item == api.config.god_item then return true end
local ability = api.abilities_item_index[item]
if not ability then return end
if ability.interface_enabled then return end
local info = nodeinfo.info()
if not info.part then return end
for _,def_ability in ipairs(api.parts[info.part].default_abilities or {}) do
if def_ability == ability.ability then return end
end
if ability.done_by and not ability.done_by[info.part] then return end
local inv = nodeinfo.inv()
if inv:contains_item('abilities', item) then return end
return true
end
function api.can_have_ability(nodeinfo, ability_name)
local ability = api.abilities_ability_index[ability_name]
if not ability then return end
if ability.interface_enabled then return end
local info = nodeinfo.info()
if not info.part then return end
for _,def_ability in ipairs(api.parts[info.part].default_abilities or {}) do
if def_ability == ability.ability then return end
end
if ability.done_by and not ability.done_by[info.part] then return end
local inv = nodeinfo.inv()
if inv:contains_item('abilities', ability.item) then return end
return true
end
function api.apply_ability(nodeinfo, player_name, ability)
if ability.modifier then
if not ability.un_modifier then
minetest.log("error", "[robot] Ability modifier will not run unless it has an un-modfier method.")
return
end
ability.modifier(nodeinfo, player_name)
end
end
function api.unapply_ability(nodeinfo, player_name, ability)
if ability.un_modifier then
ability.un_modifier(nodeinfo, player_name)
end
end
robot.add_ability({
ability = 'turn',
item = function()
if minetest.get_modpath('rhotator') then
return 'rhotator:screwdriver'
elseif minetest.get_modpath('screwdriver') then
return 'screwdriver:screwdriver'
end
return "default:acacia_bush_leaves"
end,
description = S("Rotate the robot 90 degrees"),
command_example = "robot.turn(<anticlockwise? true|false/nil>)",
done_by = { head = true, legs = true },
act_on = 'all',
depends_on = 'any',
action = function (nodeinfo, anticlockwise)
local ns = nodeinfo.robot_set()
for _, n in ipairs(ns) do
local node = n.node()
n.set_node({
param2 = anticlockwise
and (node.param2-1)%4
or (node.param2+1)%4
})
end
end
})
robot.add_ability({
ability = 'move',
item = function ()
if minetest.get_modpath('carts') then
return "carts:cart"
end
return "default:acacia_bush_sapling"
end,
description = S("Move one block forwards"),
done_by = { head = true, legs = true },
act_on = 'all',
depends_on = 'any',
action = function (nodeinfo)
local ns = nodeinfo.robot_set()
local meta = nodeinfo.meta()
local owner = meta:get_string('player_name')
local above = vector.add(ns[1].pos(), {x=0, y=1, z=0})
if api.any_has_ability(nodeinfo, 'push') then
-- ### Step 1: Push nodes in front ###
local moved = false
for _,n in ipairs(ns) do
local new_pos = n.front()
local success, stack, oldstack = mesecon.mvps_push(new_pos, n.direction(), api.config.max_push, owner)
if not success then
if moved then
minetest.check_for_falling(n.pos())
minetest.check_for_falling(above)
end
if stack == "protected" then
error("protected area in the way", 2)
return
end
error("blocked", 2)
return
end
mesecon.mvps_move_objects(new_pos, n.direction(), oldstack)
api.move_robot(n, new_pos)
moved = true
end
-- ### Step 4: Let things fall ###
if moved then
minetest.check_for_falling(ns[#ns].pos())
minetest.check_for_falling(above)
end
else
local can_move = true
for _,n in ipairs(ns) do
local frontpos = n.front()
if minetest.is_protected(frontpos, owner) then
error("protected area in the way", 2)
return
end
if not api.can_move_to(frontpos) then
can_move = false
break
end
end
if not can_move then
error("blocked", 2)
return
end
-- ### Step 2: Move the movestone ###
for _,n in ipairs(ns) do
local new_pos = n.front()
api.move_robot(n, new_pos)
end
-- ### Step 4: Let things fall ###
minetest.check_for_falling(ns[#ns].pos())
minetest.check_for_falling(above)
end
end
})
robot.add_ability({
ability = 'climb',
item = function ()
if minetest.get_modpath('mesecons_pistons') then
return 'mesecons_pistons:piston_normal_off'
end
return "default:acacia_bush_stem"
end,
description = S("Climb up and forwards one block"),
done_by = { head = true, legs = true },
act_on = 'all',
depends_on = 'any',
action = function (nodeinfo)
local ns = nodeinfo.robot_set()
local lastinfo = ns[#ns]
local meta = nodeinfo.meta()
local owner = meta:get_string('player_name')
for _, n in ipairs(ns) do
local uppos = vector.add(n.front(), {x=0,y=1,z=0})
if minetest.is_protected(uppos, owner) then
error("protected area in the way", 2)
return
elseif not api.can_move_to(uppos) then
error("blocked", 2)
return
end
end
local under_node = minetest.get_node(lastinfo.front())
local under_node_def = minetest.registered_nodes[under_node.name]
if not under_node_def.walkable then
error("no support", 2)
return
end
-- TODO: ray trace to make sure the hitbox isn't blocking?
for _, n in ipairs(ns) do
n.set_pos(vector.add(n.front(), {x=0,y=1,z=0}))
end
end
})
robot.add_ability({
ability = "look",
item = function ()
if minetest.get_modpath('mesecons_detector') then
return 'mesecons_detector:node_detector_off'
elseif minetest.get_modpath('binoculars') then
return "binoculars:binoculars"
end
return "default:acacia_leaves"
end,
description = S("Get the name of the node in front of the robot"),
command_example = "node_name = robot.look()",
done_by = { head = true },
act_on = 'first',
depends_on = 'self',
action = function (nodeinfo)
local actorinfo = api.any_has_ability(nodeinfo, 'look')
if not actorinfo then return end
return minetest.get_node(actorinfo.front()).name
end,
runtime = true
})
robot.add_ability({
ability = "locate",
item = function ()
if minetest.get_modpath('orienteering') then
return 'orienteering:gps'
elseif minetest.get_modpath('map') then
return 'map:mapping_kit'
end
return "default:acacia_sapling"
end,
act_on = 'last',
depends_on = 'any',
description = S("Get the position of the robot"),
command_example = "node_pos = robot.locate()",
done_by = { head = true },
action = function (nodeinfo)
local ns = nodeinfo.robot_set()
local pos = ns[#ns].pos()
return {
x = pos.x,
y = pos.y,
z = pos.z,
}
end,
runtime = true
})
robot.add_ability({
ability = 'place',
disabled = not minetest.get_modpath('dispenser'),
item = 'dispenser:dispenser',
act_on = 'first',
depends_on = 'self',
description = S("Place a block down"),
command_example = "robot.place(<dir 'up'|'front'/nil|'down'>)",
done_by = { head = true, body = true },
action = function (nodeinfo, dir)
local ns = nodeinfo.robot_set()
local actorinfo = api.any_has_ability(nodeinfo, 'place')
if not actorinfo then return end
if not dir then dir = 'front' end
if type(dir) ~= 'string' then
error('placing dir must be a string',2)
return
end
if not (dir == 'up' or dir == 'front' or dir == 'down') then
error(("direction '%s' is invalid"):format(dir), 2)
return
end
local meta = actorinfo.meta()
local direction
local frontpos
if dir == 'front' then
direction = actorinfo.direction()
frontpos = actorinfo.front()
elseif dir == 'up' then
direction = {x=0,y=1,z=0}
frontpos = vector.add(ns[1].pos(), direction)
elseif dir == 'down' then
if not api.any_has_ability(nodeinfo, 'climb') then
error('requires climb ability to place block below', 2)
return
end
direction = {x=0,y=-1,z=0}
frontpos = ns[#ns].pos()
end
local owner = meta:get_string('player_name')
if minetest.is_protected(frontpos, owner) then
error("protected area in the way", 2)
return
end
local inv_info
local next_index
local next_stack
for _,n in ipairs(ns) do
local list = n.inv():get_list('main')
for index, stack in ipairs(list) do
if not stack:is_empty() then
next_index = index
inv_info = n
next_stack = stack
break
end
end
if inv_info then break end
end
if not inv_info then
error("inventory empty", 2)
return
end
local item_name = next_stack:get_name()
local def = minetest.registered_items[item_name]
if not (def and def.on_place) then
error("item not placable", 2)
return
end
local player_opts = {
front = frontpos,
dir = direction,
index = next_index
}
local fuel_used
if dir == 'down' then
for i, n in ipairs(ns) do
local uppos = vector.add(n.pos(), {x=0,y=1,z=0})
if minetest.is_protected(uppos, owner) then
error("protected area in the way", 2)
return
elseif i == 1 and not api.can_move_to(uppos) then
error("blocked", 2)
return
end
end
for _, n in ipairs(ns) do
local uppos = vector.add(n.pos(), {x=0,y=1,z=0})
api.move_robot(n, uppos)
end
fuel_used = 2
end
player_opts.pos = actorinfo.pos()
player_opts.meta = inv_info.meta()
next_stack = inv_info.inv():get_stack('main', next_index)
local player = dispenser.actions.fake_player(next_stack, player_opts)
if not player then
error("player not logged in", 2)
return
end
local result = def.on_place(next_stack, player, {
type="node",
under=frontpos,
above=frontpos
})
minetest.check_for_falling(frontpos)
if result then
inv_info.inv():set_stack('main', next_index, result)
end
return nil, fuel_used
end
})
robot.add_ability({
ability = 'use',
disabled = not minetest.get_modpath('dispenser'),
item = function ()
if minetest.get_modpath('bones') then
return "bones:bones"
end
return "default:acacia_tree"
end,
act_on = 'first',
depends_on = 'self',
description = S("Use an item (not a tool)"),
done_by = { head = true, body = true },
action = function (nodeinfo)
local actorinfo = api.any_has_ability(nodeinfo, 'use')
if not actorinfo then return end
local inv_info
local next_stack
local next_index
local frontpos = actorinfo.front()
for _,n in ipairs(nodeinfo.robot_set()) do
local node_inv = n.inv()
local list = node_inv:get_list('main')
for index,stack in ipairs(list) do
if not stack:is_empty() then
next_stack = stack
next_index = index
inv_info = n
break
end
end
if inv_info then break end
end
if not next_stack then
error("inventory empty", 2)
return
end
local item_name = next_stack:get_name()
local def = minetest.registered_items[item_name]
if not (def and def.on_use) then
error("item not usable", 2)
return
end
local player = dispenser.actions.fake_player(next_stack, {
front = frontpos,
dir = actorinfo.direction(),
pos = actorinfo.pos(),
meta = inv_info.meta(),
index = next_index
})
if not player then
error("player not logged in", 2)
return
end
local result = def.on_use(next_stack, player, {
type="node",
under=frontpos,
above=vector.add(frontpos, {x=0,y=1,z=0})
})
if result then
inv_info.inv():set_stack('main', next_index, result)
end
end
})
robot.add_ability({
ability = 'switch',
disabled = not minetest.get_modpath('tubelib'),
item = function ()
if minetest.get_modpath('tubelib') then
return 'tubelib:button'
end
return "default:acacia_wood"
end,
act_on = 'first',
depends_on = 'self',
description = S("Switch a tubelib machine on and off"),
done_by = { head = true, body = true },
action = function (nodeinfo)
local actorinfo = api.any_has_ability(nodeinfo, 'switch')
if not actorinfo then return end
local frontpos = actorinfo.front()
local tube_meta = minetest.get_meta(frontpos)
local state = tube_meta:get_int("tubelib_state")
local number = tubelib.get_node_number(frontpos)
if not state or not number or number == "" then return end
local meta = actorinfo.meta()
local owner = meta:get_string('player_name')
tubelib.send_message(number, owner, nil, state == tubelib.STOPPED and "on" or "off", nil)
end
})
robot.add_ability({
ability = 'push',
disabled = not minetest.get_modpath('mesecons_mvps'),
item = function ()
if minetest.get_modpath('mesecons_movestones') then
return "mesecons_movestones:movestone"
end
return "default:apple"
end,
act_on = 'all',
depends_on = 'any',
done_by = { legs = true, body = true },
description = S("Push a block when moving forwards")
})
robot.add_ability({
ability = 'carry',
item = function ()
if minetest.get_modpath('unified_inventory') then
return 'unified_inventory:bag_large'
elseif minetest.get_modpath('default') then
return 'default:chest'
end
return "default:aspen_leaves"
end,
act_on = 'self',
depends_on = 'self',
description = S("Expand the item inventory"),
done_by = { legs = true, body = true },
updates_formspec = true,
modifier = function(nodeinfo, player_name)
local info = nodeinfo.info()
local inv = nodeinfo.inv()
local new_size = api.tiers[info.tier].form_size*2
if api.has_ability(nodeinfo, 'fuel_swap') then
new_size = new_size - 4
inv:set_size('fuel', inv:get_size('fuel') + 3)
end
inv:set_size('main', new_size)
end,
un_modifier = function(nodeinfo, player_name)
local info = nodeinfo.info()
local inv = nodeinfo.inv()
local new_size = api.tiers[info.tier].inventory_size
if api.has_ability(nodeinfo, 'fuel_swap') then
new_size = new_size - 1
local new_fuel_size = inv:get_size('fuel') - 3
local fuel_list = inv:get_list('fuel')
for i,stack in ipairs(fuel_list) do
if i > new_fuel_size then
minetest.add_item(vector.add(nodeinfo.pos(), {x=0,y=0.5,z=0}), stack)
end
end
inv:set_size('fuel', new_fuel_size)
end
-- Spit out any extra items
local list = inv:get_list('main')
for i,stack in ipairs(list) do
if i > new_size then
minetest.add_item(vector.add(nodeinfo.pos(), {x=0,y=0.5,z=0}), stack)
end
end
inv:set_size('main', new_size)
end,
})
robot.add_ability({
ability = 'fuel',
item = function ()
if minetest.get_modpath('unified_inventory') then
return 'unified_inventory:bag_small'
elseif minetest.get_modpath('default') then
return 'default:furnace'
end
return "default:aspen_sapling"
end,
act_on = 'self',
depends_on = 'self',
description = S("Expand the fuel inventory"),
done_by = { head = true, legs = true, body = true },
updates_formspec = true,
modifier = function(nodeinfo, player_name)
local inv = nodeinfo.inv()
inv:set_size('fuel', inv:get_size('fuel')+3)
end,
un_modifier = function(nodeinfo, player_name)
local inv = nodeinfo.inv()
-- Spit out any extra items
local list = inv:get_list('fuel')
local new_size = inv:get_size('fuel')-3
for i,stack in ipairs(list) do
if i > new_size then
minetest.add_item(vector.add(nodeinfo.pos(), {x=0,y=0.5,z=0}), stack)
end
end
inv:set_size('fuel', new_size)
end,
})
robot.add_ability({
ability = 'fill',
disabled = not minetest.get_modpath('tubelib'),
item = function ()
if minetest.get_modpath('tubelib') then
return 'tubelib:tubeS'
end
return "default:aspen_tree"
end,
act_on = 'self',
depends_on = 'self',
done_by = { legs = true, body = true },
description = S("Fill and empty the inventory using pushers"),
})
robot.add_ability({
ability = 'speed',
item = function ()
if minetest.get_modpath('terumet') then
return 'terumet:item_upg_speed_up'
elseif minetest.get_modpath('carts') then
return 'carts:powerrail'
end
return "default:aspen_wood"
end,
act_on = 'all',
depends_on = 'any',
description = S("Make the robot run twice as fast"),
done_by = { legs = true },
modifier = function (nodeinfo)
if not nodeinfo.speed_enabled() then
nodeinfo.meta():set_int('robot_speed', 1)
end
end,
un_modifier = function (nodeinfo)
if nodeinfo.speed_enabled() then
nodeinfo.meta():set_int('robot_speed', 0)
end
end
})
robot.add_ability({
ability = 'connectivity',
item = function ()
return "digistuff:insulated_straight"
end,
act_on = 'self',
depends_on = 'self',
description = S("Connect to robot parts above"),
done_by = { legs = true, body = true },
updates_formspec = true,
modifier = function (nodeinfo)
api.correct_connection(nodeinfo)
end,
un_modifier = function (nodeinfo)
api.correct_connection(nodeinfo)
end,
})
robot.add_ability({
interface_enabled = true,
ability = "fuel_swap",
item = function ()
if minetest.get_modpath('replacer') then
return "replacer:replacer"
end
return "default:blueberries"
end,
act_on = 'self',
depends_on = 'self',
description = S("Swap some normal inventory for fuel inventory"),
done_by = { legs = true, body = true, head = true },
updates_formspec = true,
modifier = function(nodeinfo, player_name)
local inv = nodeinfo.inv()
local size_change = 1
if api.has_ability(nodeinfo, 'carry') then
size_change = size_change + 3
end
inv:set_size('fuel', inv:get_size('fuel')+size_change)
-- Spit out any extra items
local list = inv:get_list('main')
local new_size = inv:get_size('main')-size_change
for i,stack in ipairs(list) do
if i > new_size then
minetest.add_item(vector.add(nodeinfo.pos(), {x=0,y=0.5,z=0}), stack)
end
end
inv:set_size('main', new_size)
end,
un_modifier = function(nodeinfo, player_name)
local inv = nodeinfo.inv()
local size_change = 1
if api.has_ability(nodeinfo, 'carry') then
size_change = size_change + 3
end
inv:set_size('main', inv:get_size('main')+size_change)
-- Spit out any extra items
local list = inv:get_list('fuel')
local new_size = inv:get_size('fuel')-size_change
for i,stack in ipairs(list) do
if i > new_size then
minetest.add_item(vector.add(nodeinfo.pos(), {x=0,y=0.5,z=0}), stack)
end
end
inv:set_size('fuel', new_size)
end,
})
robot.add_ability({
interface_enabled = true,
ability = "boost",
item = function ()
if minetest.get_modpath('orienteering') then
return "orienteering:speedometer"
end
return "default:blueberry_bush_leaves"
end,
act_on = 'all',
depends_on = 'any',
description = S("Speed up but use more fuel randomly"),
done_by = { legs = true, body = true, head = true },
modifier = function (nodeinfo)
if not nodeinfo.boost_enabled() then
nodeinfo.meta():set_int('robot_boost', 1)
end
end,
un_modifier = function (nodeinfo)
if nodeinfo.boost_enabled() then
nodeinfo.meta():set_int('robot_boost', 0)
end
end
})
function api.stop_action (nodeinfo)
api.set_status(nodeinfo, 'stopped')
return nil, 0
end
function api.log_action (nodeinfo,...)
local meta = nodeinfo.meta()
local owner = meta:get_string('player_name')
minetest.chat_send_player(owner, "[robot] LOG: "..dump({...}))
return nil, 0
end