View difference between Paste ID: MmnChN6X and 34ZE8aNa
SHOW: | | - or go back to the newest paste.
1
function compareItemName(itemName, slotID)
2
    if turtle.getItemDetail(slotID) ~= nil and
3
       turtle.getItemDetail(slotID).name == itemName then
4
        return true
5
    else
6
        return false
7
    end
8
end
9
10
function isBlazeRod(slotID)
11
    return compareItemName("minecraft:blaze_rod", slotID)
12
end
13
14
function isBlazePowder(slotID)
15
    return compareItemName("minecraft:blaze_powder", slotID)
16
end
17
18
function isDiamond(slotID)
19
    return compareItemName("minecraft:diamond", slotID)
20
end
21
22
function isIron(slotID)
23
    return compareItemName("minecraft:iron_ingot", slotID)
24
end
25
26
function isGold(slotID)
27
    return compareItemName("minecraft:gold_ingot", slotID)
28
end
29
30
function isEmerald(slotID)
31
    return compareItemName("minecraft:emerald", slotID)
32
end
33
34
function isNetherStar(slotID)
35
    return compareItemName("minecraft:nether_star", slotID)
36
end
37
38
function isRedstoneBlock(slotID)
39
    return compareItemName("minecraft:redstone_block", slotID)
40
end
41
42
function isBlazingCrystalBlock(slotID)
43
    return compareItemName("powah:blazing_crystal_block", slotID)
44
end
45
46
function isUranium(slotID)
47
    return compareItemName("emendatusenigmatica:uranium_ingots", slotID)
48
end
49
---@diagnostic disable: redefined-local
50
function craftBlazeRod(blazeRodSlotID)
51
    writeMessage("Found Blaze Rod at "..blazeRodSlotID.."\n"..
52
                 "Crafting with Blaze Rod")
53
    turtle.select(blazeRodSlotID)
54
    turtle.drop(1)
55
end
56
57
function craftBlazePowder()
58
    writeMessage("Found Blaze Powder"..
59
                 "Crafting with Blaze Powder")
60
61
    local needed = 4
62
    for slotNum = 1, 16, 1 do
63
        if isBlazePowder(slotNum) then
64
            local count = turtle.getItemCount(slotNum)
65
            if (count >= needed) then
66
                turtle.select(slotNum)
67
                turtle.drop(needed)
68
                needed = 0
69
            else
70
                turtle.select(slotNum)
71
                turtle.drop(count)
72
                needed = needed - count
73
            end
74
        end
75
        if (needed == 0) then
76
            return
77
        end
78
    end
79
end
80
81
function craftDiamond(diamondSlotID)
82
    writeMessage("Found Diamond at "..diamondSlotID.."\n"..
83
                 "Crafting with Diamond")
84
    turtle.select(diamondSlotID)
85
    turtle.drop(1)
86
end
87
88
function craftIronGold(ironSlotID, goldSlotID)
89
    writeMessage("Found Iron at "..ironSlotID.."\n"..
90
                 " and Gold at "..goldSlotID.."\n"..
91
                 "Crafting with Iron and Gold")
92
    turtle.select(ironSlotID)
93
    turtle.drop(1)
94
    turtle.select(goldSlotID)
95
    turtle.drop(1)
96
end
97
98
function craftEmerald(emeraldSlotID)
99
    writeMessage("Found Emerald at "..emeraldSlotID.."\n"..
100
                 "Crafting with Emerald")
101
    turtle.select(emeraldSlotID)
102
    turtle.drop(1)
103
end
104
105
function craftUranium(uraniumSlotID)
106
    writeMessage("Found Uranium at "..uraniumSlotID.."\n"..
107
                 "Crafting with Uranium")
108
    turtle.select(uraniumSlotID)
109
    turtle.drop(1)
110
end
111
112
function craftNitro(starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID)
113
    writeMessage("Found Nether Star at "..starSlotID.."\n"..
114
                 " and Redstone Block at "..redstoneBlockSlotID.."\n"..
115
                 " and Blazing Crystal Block at "..blazingCrystalBlockSlotID.."\n"..
116
                 "Crafting Nitro")
117
    turtle.select(starSlotID)
118
    turtle.drop(1)
119
    turtle.select(redstoneBlockSlotID)
120
    turtle.drop(2)
121
    turtle.select(blazingCrystalBlockSlotID)
122
    turtle.drop(1)
123
end
124
125
function doCrafting()
126
    local canCraft, blazeRodSlotID = shouldCraftBlaze()
127
    if canCraft then
128
        craftBlazeRod(blazeRodSlotID)
129
        return
130
    end
131
    
132
    local canCraft = shouldCraftBlazePowder()
133
    if canCraft then
134
        craftBlazePowder()
135
        return
136
    end
137
138
    local canCraft, diamondSlotID = shouldCraftDiamond()
139
    if canCraft then
140
        craftDiamond(diamondSlotID)
141
        return
142
    end
143
144
    local canCraft, emeraldSlotID = shouldCraftEmerald()
145
    if canCraft then
146
        craftEmerald(emeraldSlotID)
147
        return
148
    end
149
150
    local canCraft, starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID = shouldCraftNitro()
151
    if canCraft then
152
        craftNitro(starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID)
153
        return
154
    end
155
156
    local canCraft, ironSlotID, goldSlotID = shouldCraftIronGold()
157
    if canCraft then
158
        craftIronGold(ironSlotID, goldSlotID)
159
        return
160
    end
161
162
    local canCraft, slotID = shouldCraftUranium()
163
    if canCraft then
164
        craftUranium(slotID)
165
        return
166
    end
167
end
168
function shouldCraftBlaze()
169
    for slotNum = 1, 16, 1 do
170
        if isBlazeRod(slotNum) then
171
            return true, slotNum
172
        end
173
    end
174
    return false, -1
175
end
176
177
function shouldCraftDiamond()
178
    for slotNum = 1, 16, 1 do
179
        if isDiamond(slotNum) then
180
            return true, slotNum
181
        end
182
    end
183
    return false, -1
184
end
185
186
function shouldCraftEmerald()
187
    for slotNum = 1, 16, 1 do
188
        if isEmerald(slotNum) then
189
            return true, slotNum
190
        end
191
    end
192
    return false, -1
193
end
194
195
function shouldCraftUranium()
196
    for slotNum = 1, 16, 1 do
197
        if isUranium(slotNum) then
198-
    sleep(0.2)
198+
199
        end
200
    end
201-
        sleep(0.2)
201+
202
end
203
204
function shouldCraftIronGold()
205
    local ironSlotID = -1
206
    local goldSlotID = -1
207
    for slotNum = 1, 16, 1 do
208
        if isIron(slotNum) then
209
            ironSlotID = slotNum
210
        elseif isGold(slotNum) then
211
            goldSlotID = slotNum
212
        end
213
    end
214
    
215
    local canCraft = ironSlotID > 0 and goldSlotID > 0
216
    return canCraft, ironSlotID, goldSlotID
217
end
218
219
function shouldCraftBlazePowder()
220
    local count = 0
221
    for slotNum = 1, 16, 1 do
222
        if isBlazePowder(slotNum) then
223
            count = count + turtle.getItemCount(slotNum)
224
        end
225
    end
226
    
227
    return count >= 4
228
end
229
230
function shouldCraftNitro()
231
    local starSlotID = -1
232
    local redstoneBlockSlotID = -1
233
    local blazingCrystalBlockSlotID = -1
234
235
    for slotNum = 1, 16, 1 do
236
        if isNetherStar(slotNum) then
237
            starSlotID = slotNum
238
        elseif isBlazingCrystalBlock(slotNum) then
239
            blazingCrystalBlockSlotID = slotNum
240
        elseif isRedstoneBlock(slotNum) and
241
               turtle.getItemDetail(slotNum).count >= 2 then
242
            redstoneBlockSlotID = slotNum
243
        end
244
    end
245
246
    local canCraft = starSlotID > 0 and blazingCrystalBlockSlotID > 0 and redstoneBlockSlotID > 0
247
    return canCraft, starSlotID, redstoneBlockSlotID, blazingCrystalBlockSlotID
248
end
249
-- Uncomment those lines if you want to keep
250
-- the program as seperate files.
251
--dofile("slotChecking.lua")
252
--dofile("crafting.lua")
253
--dofile("nextCrafting.lua")
254
255
function writeMessage(message)
256
    term.clear()
257
    term.setCursorPos(1, 1)
258
    print("+-----------------------------+")
259
    print("|Welcome to Powah Autocrafting|")
260
    print("+-----------------------------+")
261
    print()
262
    print(message)
263
end
264
265
writeMessage("Startup finished")
266
while true do
267
    doCrafting()
268
    -- Wait two Redstone ticks for the Redstone Signal to update
269
    sleep(0.4)
270
    -- Spin in a loop till crafting is done
271
    while redstone.getInput("back") do
272
        sleep(0.4)
273
    end
274
end
275
276