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