-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcountGolems.lua
More file actions
110 lines (87 loc) · 2.26 KB
/
countGolems.lua
File metadata and controls
110 lines (87 loc) · 2.26 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
wait = 1
p = peripheral.wrap("top")
p.setTextScale(1)
side = "right"
frontLeft = colors.yellow
frontRight = colors.white
backLeft = colors.brown
backRight = colors.black
frontLeftCount = 0
frontRightCount = 0
backLeftCount = 0
backRightCount = 0
count = 0
blocks = 0
countFile = "my/golemCount.txt"
countFileBackup = "my/golemCountBackup.txt"
file = io.open(countFile, "r")
count = tonumber(file:read())
file:close()
frontLeftStatus = rs.testBundledInput(side, frontLeft)
frontRightStatus = rs.testBundledInput(side, frontRight)
backLeftStatus = rs.testBundledInput(side, backLeft)
backRightStatus = rs.testBundledInput(side, backRight)
function newLine()
local _,cY = p.getCursorPos()
p.setCursorPos(1,cY+1)
end
function clear()
p.clear()
p.setCursorPos(1, 1)
end
function display()
clear()
p.write("Golems served:")
newLine()
p.write(tostring(count))
newLine()
newLine()
blocks = math.floor((count * 4 / 9) + 0.5)
p.write("Iron blocks:")
newLine()
p.write("~" .. blocks)
end
display()
while true do
frontLeftCount = 0
frontRightCount = 0
backLeftCount = 0
backRightCount = 0
if(rs.testBundledInput(side, frontLeft) ~= frontLeftStatus) then
frontLeftStatus = rs.testBundledInput(side, frontLeft)
frontLeftCount = frontLeftCount + 1
end
if(rs.testBundledInput(side, frontRight) ~= frontRightStatus) then
frontRightStatus = rs.testBundledInput(side, frontRight)
frontRightCount = frontRightCount + 1
end
if(rs.testBundledInput(side, backLeft) ~= backLeftStatus) then
backLeftStatus = rs.testBundledInput(side, backLeft)
backLeftCount = backLeftCount + 1
end
if(rs.testBundledInput(side, backRight) ~= backRightStatus) then
backRightStatus = rs.testBundledInput(side, backRight)
backRightCount = backRightCount + 1
end
newCount = count + frontLeftCount + frontRightCount + backLeftCount + backRightCount
if(newCount ~= count) then
file = io.open(countFileBackup, "w")
file:write(tostring(count))
file:close()
file = io.open(countFile, "w")
file:write(tostring(count))
file:close()
clear()
p.write("Golems served:")
newLine()
p.write(tostring(count))
newLine()
newLine()
blocks = math.floor((count * 4 / 9) + 0.5)
p.write("Iron blocks:")
newLine()
p.write("~" .. blocks)
end
display()
sleep(1)
end