-
Notifications
You must be signed in to change notification settings - Fork 1
/
dispenseFront.lua
85 lines (66 loc) · 1.83 KB
/
dispenseFront.lua
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
args = {...}
if not args[1] or not args[2] then
error("Set the id of the receiver and the display controller")
end
ReceiverId = tonumber(args[1])
DisplayId = tonumber(args[2])
SLOT_COUNT = 16
rednet.open("right")
Prices = {
["minecraft:iron_ingot"] = 1,
["minecraft:iron_block"] = 10,
["minecraft:diamond"] = 14,
["minecraft:netherite_scrap"] = 144
}
StartTime = os.epoch('utc')
ResetTime = 1000 * 60 * 5
CurrentPaid = 0
PayLimit = 420
function CheckTime()
local time = os.epoch('utc')
if time - StartTime >= ResetTime then
StartTime = os.epoch('utc')
CurrentPaid = 0
end
end
LimitReached = false
while true do
rednet.send(DisplayId, "", "printPrices")
CheckTime()
if CurrentPaid >= PayLimit then
if not LimitReached then
rednet.send(DisplayId, StartTime, "limitReached")
LimitReached = true
end
else
LimitReached = false
turtle.suckUp()
end
local itemsCount = 0
for i = 1, SLOT_COUNT, 1 do
itemsCount = itemsCount + turtle.getItemCount(i)
end
if itemsCount > 0 then
local potatoes = 0
for i = 1, SLOT_COUNT, 1 do
turtle.select(i)
local item = turtle.getItemDetail()
if item then
if Prices[item["name"]] then
rednet.send(DisplayId, "", "processingTransaction")
potatoes = potatoes + Prices[item["name"]] * item["count"]
turtle.dropDown()
else
turtle.dropUp()
end
end
end
turtle.select(1)
if potatoes ~= 0 then
CurrentPaid = potatoes
rednet.send(ReceiverId, potatoes, "givePotatoes")
local id, message = rednet.receive()
end
end
sleep(0.2)
end