Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local term = require("term")
- local event = require("event")
- local sides = {0,1,2,3,4,5}
- local transposer = component.transposer
- local gpu = component.gpu
- local w, h = gpu.getResolution()
- local dislocatorReceptacleName = "draconicevolution:dislocator_receptacle"
- local dislocatorReceptacleSide = -1
- local portals = {}
- local infoMessage = ""
- function Message(text)
- gpu.fill(5,49,125,1," ")
- local newText = string.sub("[Info]: "..text, 1, 120)
- gpu.set(5,49,newText)
- infoMessage = text
- end
- function FindDislocatorReceptacle()
- for k,v in pairs(sides)do
- if(transposer.getInventoryName(v)==dislocatorReceptacleName)then
- dislocatorReceptacleSide = v
- return true
- end
- end
- return false
- end
- function CheckDislocatorReceptacle()
- local found = false
- if(dislocatorReceptacleSide >= 0)then
- if(transposer.getInventoryName(dislocatorReceptacleSide)==dislocatorReceptacleName)then
- found = true
- end
- end
- if not(found)then
- if(FindDislocatorReceptacle())then
- found = true
- else
- Message("Can't find Dislocator Receptacle!")
- end
- end
- return found
- end
- function ScanInventorysForAvailablePortals()
- portals = {}
- for k,v in pairs(sides)do
- local stacks = transposer.getAllStacks(v)
- if(stacks~=nil)then
- for a,b in pairs(stacks.getAll())do
- if(b.name=="draconicevolution:dislocator")then
- if(transposer.getInventoryName(v)==dislocatorReceptacleName)then
- table.insert(portals, {name=b.label, active=true, slot = a, side=v})
- else
- table.insert(portals, {name=b.label, active=false, slot = a, side=v})
- end
- end
- end
- end
- end
- end
- function GetFreeInventorySlot()
- local side, slot
- for k,v in pairs(sides)do
- local stacks = transposer.getAllStacks(v)
- if(stacks~=nil)then
- for a,b in pairs(stacks.getAll())do
- if(b.name=="minecraft:air")then
- return v, a
- end
- end
- end
- end
- return side, slot
- end
- function GetPortal(side,slot)
- for k,v in pairs(portals)do
- if(v.side==side)and(v.slot==slot)then
- return v
- end
- end
- return nil
- end
- function RemoveActivePortal()
- if(CheckDislocatorReceptacle())then
- local side, slot = GetFreeInventorySlot()
- if(side~=nil)and(slot~=nil)then
- local portal = GetPortal(dislocatorReceptacleSide, 1)
- if(portal~=nil)then
- if(transposer.transferItem(dislocatorReceptacleSide, side, 1, 1, slot))then
- portal.side = side
- portal.slot = slot
- portal.active = false
- return true
- else
- Message("Removing portal didn't work!")
- end
- else
- Message("Can't find portal entry!")
- end
- else
- Message("Inventory is full!")
- end
- end
- return false
- end
- function IsPortalActive()
- if(CheckDislocatorReceptacle())then
- local item = transposer.getStackInSlot(dislocatorReceptacleSide, 1)
- if(item ~= nil)then
- return true
- else
- return false
- end
- end
- return nil
- end
- function ItemStillExist(portal)
- local item = transposer.getStackInSlot(portal.side, portal.slot)
- if(item.label == portal.name)then
- return true
- end
- return false
- end
- function InsertPortal(portal)
- if(CheckDislocatorReceptacle())then
- local item = ItemStillExist(portal)
- if(item)then
- if not(transposer.transferItem(portal.side, dislocatorReceptacleSide, 1, portal.slot, 1))then
- Message("Inserting a portal didn't work!")
- else
- portal.active = true
- portal.side = dislocatorReceptacleSide
- portal.slot = 1
- end
- else
- Message("Can't find item in inventory!")
- end
- end
- end
- function CreateOrUpdateGUI()
- local x = 15
- local y = 5
- local xAddr = (w-40)/4
- gpu.fill(1, 1, w, h, " ")
- gpu.setForeground(0xFFFFFF)
- gpu.setBackground(0x000000)
- if(#portals>0)then
- for k,v in pairs(portals)do
- if(v.active)then
- gpu.setBackground(0x32CD32)
- else
- gpu.setBackground(0xFF0000)
- end
- local portalName = string.sub(v.name, 1, 16)
- gpu.fill(x-1,y-1,string.len(portalName)+2,3," ")
- gpu.set(x,y,portalName)
- gpu.setBackground(0x000000)
- x = x+xAddr
- if(x >= w-40/4)then
- x = 15
- y = y+6
- end
- end
- gpu.setBackground(0x32CD32)
- gpu.fill(w-8,h-2,8,3," ")
- gpu.set(w-7,h-1,"Reload")
- gpu.setBackground(0x000000)
- end
- if(string.len(infoMessage)>0)then
- Message(infoMessage)
- end
- end
- function TouchEvent()
- local x = 15
- local y = 5
- local xAddr = (w-40)/4
- local _, _, xInput, yInput = event.pull("touch")
- if(#portals>0)then
- for k,v in pairs(portals)do
- local portalName = string.sub(v.name, 1, 16)
- if(xInput >= x-1)and(xInput <= x+string.len(portalName)+1)and(yInput >= y-1)and(yInput <= y+1)then
- if not(v.active)then
- if(IsPortalActive())then
- if(RemoveActivePortal())then
- InsertPortal(v)
- end
- else
- InsertPortal(v)
- end
- os.sleep(0.25)
- end
- end
- x = x+xAddr
- if(x >= w-40/4)then
- x = 15
- y = y+6
- end
- end
- if(xInput>= w-8)and(xInput<=w)and(yInput>=h-3)and(yInput<=h)then
- ScanInventorysForAvailablePortals()
- end
- else
- ScanInventorysForAvailablePortals()
- end
- end
- CheckDislocatorReceptacle()
- ScanInventorysForAvailablePortals()
- while true do
- CreateOrUpdateGUI()
- TouchEvent()
- end
Add Comment
Please, Sign In to add comment