Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local version = "Dev" --(26/06 2020)
- os.loadAPI("/spawner/f") -- a monitor API made by myself, it makes my life easier
- os.loadAPI("/spawner/lib/API") -- search_bar
- os.loadAPI("/spawner/lib/APIjson")
- local list_items,items = {},{}
- local a,b,c,chestSize = 1,1,1,100
- local Pcheck = false
- function getPeriphs()
- p = peripheral.find("diamond") -- can change for "chest" instead of "draconic_chest"
- if p == nil then isChest = false else isChest = true end
- m = peripheral.find("monitor") -- running on a monitor
- if m == nil then m = term.current() isMonitor = false else m.setTextScale(0.5) isMonitor = true end
- fxd = peripheral.find("thermaldynamics_fluxduct")
- w,h = m.getSize()
- end
- function addWin(m,x1,y1,x2,y2,name)
- local b = window.create(m,x1,y1,x2,y2)
- b.pos = {b.getPosition()}
- b.size = {b.getSize()}
- b.name = name
- function b:getName() return b.name end
- function b:isClicked(x,y) return f.itrv(x,b.pos[1],b.pos[1]+b.size[1]) and f.itrv(y,b.pos[2],b.pos[2]+b.size[2]-1) end
- return b
- end
- function setWindows()
- bg = addWin(m,1,1,w,h) bg.reset = {bg_color="black"}
- list = addWin(m,1,2,w*3/5-1,chestSize) list.reset = {bg_color="black"}
- up_bar = addWin(m,1,1,w,1) up_bar.reset = {bg_color="lightGray"}
- down_bar = addWin(m,1,h,w,h) down_bar.reset = {bg_color="lightGray",printText = function()
- f.centerTextRight(down_bar,1,"v"..version,"black","lightGray") end}
- scroll_bar = addWin(m,w*(3/5),2,1,h-1) scroll_bar.reset = {bg_color="lightGray",printText = function()
- f.cprint(scroll_bar,1,1,"^","black","gray")
- f.cprint(scroll_bar,1,h-2,"v","black","gray") end}
- bg2 = addWin(m,w*0.6+1,2,w*0.4+1,h-1) bg2.reset = {bg_color="gray",printText = function()
- f.cprint(bg2,2,1,"Mob: ","white","gray")
- f.cprint(bg2,8,10,"Status: ","white","gray") end}
- b1 = addWin(m,2,13,bg2.size[1]-2,3,"button1") b1.reset = {bg_color="red",printText = function()
- f.centerText(b1,2,"i/o","black","red") end}
- b2 = addWin(m,2,9,5,3,"button2") b2.reset = {bg_color="red",printText = function()
- f.centerText(b2,"Rafraichir","black","purple") end}
- b = {}
- b[1] = addWin(m,2,3,5,3) b[2] = addWin(m,10,3,5,3) b[3] = addWin(m,18,3,5,3)
- for i=1,3 do
- b[i]["notSelected"]={bg_color="black",printText=function() f.cprint(b[i],3,2,i,"lightGray","black") end}
- b[i]["selected"] = {bg_color="magenta",printText=function() f.cprint(b[i],3,2,i,"black","magenta") end}
- end
- end
- function apply(obj,name)
- if f.vn(obj[name]) then
- local metatable = {__Index = obj[name]}
- setmetatable(index, metatable)
- obj.setBackgroundColor(index.bg_color)
- obj.clear()
- else error("object not found") end
- end
- local default = {
- spawner1={side="east",curr_item=""},
- spawner2={side="north",curr_item=""},
- spawner3={side="west",curr_item=""},
- rside="right",
- enable = true,
- player_name="MarkFergus",
- server="infinity.mineaurion.com",
- selected = 0, rubrique = 1
- }
- if fs.exists("/spawner/config") == false then f1 = fs.open("/spawner/config","w") f1.write(textutils.serialise(default)) f1.close() end
- f1 = fs.open("/spawner/config","r") index = textutils.unserialize(f1.readAll()) f1.close()
- if fs.exists("/spawner/nbt") == false then error("missing 'nbt file'") end
- f2 = fs.open("/spawner/nbt","r") nbt_index = textutils.unserialize(f2.readAll()) f2.close()
- rubrique = index.rubrique selected = index.selected
- function reset()
- apply(bg,"reset") apply(bg2,"reset") apply(list,"reset")
- apply(up_bar,"reset") apply(down_bar,"reset") apply(scroll_bar,"reset")
- apply(b1,"reset") apply(b2,"reset")
- --for i=1,3 do
- -- if rubrique == i then b[i].apply("selected") f.cprint(bb[i],3,2,i,"black","magenta")
- -- else b[i].apply("notSelected") end
- --end
- if f.vn(fxd) then f.cprint(down_bar,1,1,fxd.getMaxEnergyStored()-fxd.getEnergyStored().." RF","red","lightGray") end
- f.cprint(bg2,7,1,index["spawner"..rubrique].curr_item,"purple","gray")
- if index.enable then f.cprint(bg2,16,10,"actif ","lime","gray") else
- f.cprint(bg2,16,10,"inactif","purple","gray") end
- f.cprint(up_bar,1,1,coordinates,"lime","lightGray")
- end
- function getItems(check1)
- if check1 == true then
- b = 1
- items = {}
- if chestSize ~= nil then
- for a=1,chestSize do
- item = p.getStackInSlot(a)
- if item ~= nil and item.name == "mobSoul" then
- items[b] = {}
- items[b][1] = a
- for ab=1,#nbt_index do
- if item.nbt_hash == nbt_index[ab].nbt_hash then items[b][2] = nbt_index[ab].name end
- end
- items[b]["qty"] = item.qty
- b = b + 1
- end
- end
- end
- if display == nil then display = items end
- end
- end
- function list_display(check1)
- if check1 == true then
- for c=1,#display do
- if c == selected then
- f.drawLine(list,1,c,w,"lightBlue")
- f.centerTextRight(list,c,tostring(items[c].qty),"black")
- else
- list.setBackgroundColor(colors.black)
- end
- if display[c][3] == nil then
- f.centerText(list,c,display[c][2],"purple")
- end
- end
- else f.centerText(list,1,"No chest found","red","black") end
- end
- function scroll(direction)
- local x,y = list.getPosition()
- if direction == "up" and y <=1 then
- list.reposition(1,y+2)
- elseif direction == "down" and y+#items > h-1 then
- list.reposition(1,y-2)
- end
- end
- function checkPlist()
- str = APIjson.decode(http.get("http://api.mineaurion.com/v1/serveurs/"..index.server).readAll())
- local Pcheck = false
- for i,v in pairs(str.joueurs) do
- if v == index.player_name then Pcheck = true end
- end
- if (Pcheck==true and index.enable==true) then rs.setAnalogOutput(index.rside,15) else rs.setAnalogOutput(index.rside,0) end
- end
- function updateIndex()
- shell.run("rm","/spawner/config")
- index.rubrique = rubrique index.selected = selected
- f3 = fs.open("/spawner/config","w") f3.write(textutils.serialise(index)) f3.close()
- end
- getPeriphs() setWindows()
- while true do
- reset() getItems(isChest) list_display(isChest)
- down_bar.redraw() up_bar.redraw()
- checkPlist() updateIndex()
- refresh = os.startTimer(20)
- event = {os.pullEvent()}
- if event[1] == "peripheral_detach" or event[1] == "peripheral" then getPeriphs() setWindows() end
- if event[1] == "monitor_touch" or event[1] == "mouse_click" then
- x = event[3] y = event[4]
- coordinates = tostring(x..";"..y..","..selected..","..j)
- if y-list.pos[1]+1 == selected and display[selected] ~= nil and x < scroll_bar.pos[1]-1 then
- up_bar.clear()
- f.centerText(up_bar,1,"reconfiguration...","black")
- sleep(0.5)
- p.pushItem(index["spawner"..rubrique].side,display[selected][1],1)
- index["spawner"..rubrique].curr_item = display[selected][2]
- getItems(isChest)
- elseif y > 1 and x < scroll_bar.pos[1]-1 then
- selected = y-yl+1
- elseif y == 2 and x == scroll_bar.pos[1] then
- scroll("up")
- elseif list.pos[2] == h-1 and event[3] == scroll_bar.pos[1] then
- scroll("down")
- elseif bg2.isClicked(x,y) then
- xc = x-pbg2[1]+1 yc = y-pbg2[2]+1
- for i=1,3 do if b[i].isClicked(xc,yc) then rubrique = i end end
- if b1.isClicked(xc,yc) then
- if index.enable == true then index.enable = not index.enable end
- end
- if b2.isClicked(xc,yc) then
- display = nil
- sleep(0.4)
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment