View difference between Paste ID: pnPg4h7J and QLmU7Lre
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("button")
2
local m = peripheral.wrap("right")
3
local rsOut = {}
4
local c = peripheral.wrap("container_chest_0")
5
local a = peripheral.wrap("tt_magnet_0")
6
local s = peripheral.wrap("auto_spawner_0")
7
m.clear()
8
local mobArray = {}
9
local buttonColors = {}
10
local attractorStatus = ""
11
local page = 1
12
local pages = 0
13
local currMob = ""
14
   
15
function fillMainTable()
16
   getCurrMob()
17
   checkExact()
18
   getAttractorStatus()
19
   m.clear()
20
   button.clearTable()
21
   button.setTable("Lights", lights, "", 4, 17, 2, 4)
22
   button.setTable("Door", door, "", 20, 33, 2, 4)
23
   button.setTable("Grinders", grinders, "", 4, 17, 6, 8)
24
   button.setTable("DrawBridge", drawBridge, "", 20, 33, 6, 8)
25
   button.setTable("Attractor", attractorToggle, "", 4, 17, 10, 12)
26
   button.setTable(attractorStatus, togglePush, "", 20, 33, 10, 12)
27
   button.setTable("Mob Selector", mobSelect, "", 20, 33, 14, 16)
28
   button.setTable("Spawner", spawner, "", 4, 17, 14, 16)
29
   --button.setTable("Refresh", refresh, "", 15, 35, 19, 19)
30
   print("Filled")
31
   button.screen()
32
   for i,j in pairs(buttonColors) do
33
      if not rsOut[j] then button.toggleButton(i) end
34
   end
35
   button.toggleButton("Attractor")
36
   button.label(1, 19, "Current Mob: "..currMob)
37
   button.label(30, 19, "Exact: "..currExact)
38
end
39
40
function getAttractorStatus()
41
   if a.isPulling() then
42
      attractorStatus = "Pulling"
43
   else
44
      attractorStatus = "Pushing"
45
   end
46
end
47
48
function togglePush()
49
   button.flash(attractorStatus)
50
   a.setPulling(not a.isPulling())
51
   fillMainTable()
52
end
53
54
function fillTable()
55
   checkMobs()
56
   checkExact()
57
   getCurrMob()
58
   m.clear()
59
   button.clearTable()
60
   local totalrows = 0
61
   local npp = 12 --names per page
62
   local numNames = 0
63
   local col = 2
64
   local row = 12
65
   local countRow = 1
66
   local currName = 0
67
   for i,j in pairs(mobArray) do
68
      totalrows = totalrows+1
69
   end
70
   pages = math.ceil(totalrows/npp)
71
   print(totalrows)
72
   for name,slot in pairs(mobArray) do
73
       currName = currName + 1
74
       if currName > npp*(page-1) and currName < npp*page+1 then
75
         row = 4+(countRow)
76
         button.setTable(string.sub(name, 0, 17), insertMob, slot, col, col+17 , row, row)
77
         if col == 21 then 
78
           col = 2 
79
           countRow = countRow + 2
80
         else 
81
           col = col+19 
82
         end
83
       end
84
   end
85
   button.setTable("Next Page", nextPage, "", 27, 38, 1, 1)
86
   button.setTable("Prev Page", prevPage, "", 2, 13, 1, 1)
87
   button.setTable("Main Menu", goMainMenu, "", 15, 25, 1, 1)
88
   button.setTable("Exact: "..currExact, switchExact, "", 21, 38, 18, 19)
89
   button.setTable("Remove Mob", removeMob, "", 2, 19, 18, 19)
90
   button.screen()
91
   button.label(15,3, "Page: "..tostring(page).." of "..tostring(pages))
92
   button.label(12, 16, "Current Mob: "..currMob)
93
end      
94
95
function getCurrMob()
96
   data = s.getStackInSlot(1)
97
   currMob = data.captured
98
end
99
100
function goMainMenu()
101
   fillMainTable()
102
--   refresh()
103
end
104
105
function checkExact()
106
   if s.getSpawnExact() then
107
      currExact = "Yes"
108
   else
109
      currExact = "No"
110
   end
111
end
112
113
function switchExact()
114
   s.setSpawnExact(not s.getSpawnExact())
115
   fillTable()
116
end
117
118
function nextPage()
119
   if page+1 <= pages then 
120
      page = page+1 
121
   end
122
   fillTable()
123
   sleep(0.25)
124
end
125
126
function prevPage()
127
   if page-1 >= 1 then page = page-1 end
128
   fillTable()
129
   sleep(0.25)
130
end   
131
                           
132
function getMobs()
133
   mobArray = {}
134
   for i = 1,27  do
135
      if c.getStackInSlot(i) then
136
         data = c.getStackInSlot(i)
137
         --print(i..":"..data.captured)
138
         mobArray[data.captured] = i
139
      end
140
   end
141
end
142
143
function findEmptySlot()
144
   for i = 1,27 do
145
      if not c.getStackInSlot(i) then
146
         return(i)
147
      end
148
   end
149
end
150
151
function removeMob()
152
   local slot = findEmptySlot()
153
   c.pullItem("down", 1, 1, slot)
154
end
155
156
function insertMob(info)
157
   removeMob()
158
   c.pushItem("down", info, 1, 1)
159
   fillTable()
160
end
161
162
function checkMobs()
163
   getMobs()
164
   --fillTable()
165
end
166
167
function initRS()
168
   rsOut[colors.white] = false
169
   rsOut[colors.orange] = true
170
   rsOut[colors.magenta] = false
171
   rsOut[colors.lightBlue] = true
172
   rsOut[colors.yellow] = false
173
   rsOut[colors.lime] = true
174
   buttonColors["Lights"] = colors.white
175
   buttonColors["Spawner"] = colors.orange
176
   buttonColors["Grinders"] = colors.magenta
177
   buttonColors["DrawBridge"] = colors.lightBlue
178
   buttonColors["Attractor"] = colors.yellow
179
   buttonColors["Door"] = colors.lime
180
end
181
182
function setRS()
183
   local colorOutput = 0
184
   for i,j in pairs(rsOut) do
185
      if j then colorOutput = colorOutput + i end
186
	end
187
	rs.setBundledOutput("left", colorOutput)
188
end
189
190
function lights()
191
   button.toggleButton("Lights")
192
   rsOut[colors.white] = not rsOut[colors.white]
193
   setRS()
194
end
195
196
function door()
197
   button.toggleButton("Door")
198
   rsOut[colors.lime] = not rsOut[colors.lime]
199
   setRS()
200
end
201
 
202
function spawner()
203
   button.toggleButton("Spawner")
204
   rsOut[colors.orange] = not rsOut[colors.orange]
205
   setRS()
206
end
207
208
function grinders()
209
   button.toggleButton("Grinders")
210
   rsOut[colors.magenta] = not rsOut[colors.magenta]
211
   setRS()
212
end
213
214
function drawBridge()
215
   button.toggleButton("DrawBridge")
216
   rsOut[colors.lightBlue] = not rsOut[colors.lightBlue]
217
   setRS()
218
end
219
220
function attractorToggle()
221
   button.toggleButton("Attractor")
222
   rsOut[colors.yellow] = not rsOut[colors.yellow]
223
   setRS()
224
end
225
226
function mobSelect()
227
   fillTable()
228
--   refresh()
229
--   getClick()
230
end
231
232
function getClick()
233
   local event,side,x,y = os.pullEvent()
234
   if event=="monitor_touch" then
235
     button.checkxy(x,y) 
236
   end
237
end
238
239
function refresh()
240
   m.clear()
241
   print("Refreshed")
242
   button.screen()
243
end
244
245
initRS()
246
setRS()
247
fillMainTable()
248
--refresh()
249
while true do getClick() end