tnt-deployer.lua

101 lines · 2.1 KB

Open raw

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/perlytiara/BigBaemingGamers/tnt/tnt-deployer.lua
1local SLOT_COUNT = 16
2local FUEL_CHEST = 15
3local TNT_CHEST = 16
4
5local FILL_SLOT_COUNT = 4
6
7
8local modem = peripheral.wrap("left")
9modem.open(100)
10
11function countItems(itemToCount)
12 local itemCount = 0
13 for slot = 1, SLOT_COUNT, 1 do
14 item = turtle.getItemDetail(slot)
15 if(item ~= nil) then
16 if(item.name == itemToCount) then
17 itemCount = itemCount + turtle.getItemCount(slot)
18 end
19 end
20 end
21
22 return itemCount
23end
24
25
26function checkFuel()
27 if(turtle.getFuelLevel() < 100) then
28 turtle.select(FUEL_CHEST)
29 turtle.digUp()
30 turtle.placeUp()
31 --Chest is deployed
32
33 turtle.suckUp()
34
35 while(true) do
36 bucketIndex = getItemIndex("minecraft:lava_bucket")
37 if(bucketIndex == nil) then
38 turtle.suckUp()
39 turtle.dropUp()
40 else
41 turtle.select(bucketIndex)
42 turtle.refuel()
43 turtle.dropUp()
44 turtle.digUp()
45 return true
46 end
47 end
48 end
49 return true
50end
51
52
53
54function checkTNT()
55 if (countItems("minecraft:tnt") < 64) then
56 turtle.select(TNT_CHEST)
57 turtle.digUp()
58 turtle.placeUp()
59
60 for slot = 1, FILL_SLOT_COUNT, 1 do
61 turtle.select(slot)
62 turtle.suckUp()
63 end
64
65 turtle.select(TNT_CHEST)
66 turtle.digUp()
67 end
68end
69
70function getItemIndex(itemName)
71 for slot = 1, SLOT_COUNT, 1 do
72 local item = turtle.getItemDetail(slot)
73 if(item ~= nil) then
74 if(item["name"] == itemName) then
75 return slot
76 end
77 end
78 end
79end
80
81
82print("Waiting for signal")
83event, side, senderChannel, replyChannel, msg, distance = os.pullEvent("modem_message")
84redstone.setOutput("bottom", true)
85
86while(true) do
87 checkFuel()
88 checkTNT()
89
90
91 turtle.forward()
92
93
94
95 turtle.select(getItemIndex("minecraft:tnt"))
96 turtle.placeDown()
97 turtle.placeDown()
98 turtle.placeDown()
99 turtle.placeDown()
100 turtle.placeDown()
101end