Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- multishell.setTitle(multishell.getCurrent(), 'Smeltry')
- turtle.status = 'Smelting'
- require = requireInjector(getfenv(1))
- local Event = require('event')
- local UI = require('ui')
- local inventory = { }
- local selectedTank = nil
- rs.setOutput('bottom', false)
- rs.setOutput('top', false)
- rs.setOutput('right', false)
- turtle.dig()
- for _, slot in pairs(turtle.getFilledSlots()) do
- turtle.select(slot.index)
- if turtle.place() then
- os.pullEvent('device_attach')
- local contents = device.thermalexpansion_tank.getTankInfo()[1].contents
- if not contents then
- contents = {
- name = 'empty',
- rawName = 'empty',
- amount = 0,
- }
- end
- contents.index = slot.index
- table.insert(inventory, contents)
- turtle.dig()
- end
- end
- local function selectFluid(fluidName)
- local tank = Util.find(inventory, 'name', fluidName)
- if not tank then
- return false
- end
- turtle.select(tank.index)
- selectedTank = tank
- return true
- end
- local function waitTilTankEmpty()
- rs.setOutput('top', true)
- repeat
- local tank = device.thermalexpansion_tank.getTankInfo()[1].contents
- os.sleep(1)
- until not tank
- rs.setOutput('top', false)
- end
- local function emptySmeltry()
- rs.setOutput('bottom', true)
- os.sleep(1)
- repeat
- local f = device.blockconduitbundletileentity.getTankInfo()[1].contents
- if f then
- if not selectFluid(f.name) then
- if not selectFluid('empty') then
- error('Need more tanks')
- end
- end
- turtle.place()
- repeat
- os.sleep(1)
- local c = device.blockconduitbundletileentity.getTankInfo()[1].contents
- until not c or c.name ~= f.name
- os.sleep(1)
- local tank = device.thermalexpansion_tank.getTankInfo()[1].contents
- selectedTank.name = tank.name
- selectedTank.rawName = tank.rawName
- selectedTank.amount = tank.amount
- turtle.dig()
- end
- until not f
- rs.setOutput('bottom', false)
- end
- local function insertFluid(tank)
- if not selectFluid(tank.name) then
- error('select failed')
- end
- turtle.place()
- os.pullEvent('device_attach')
- waitTilTankEmpty()
- turtle.dig()
- tank.name = 'empty'
- tank.rawName = 'empty'
- tank.amount = 0
- end
- local page = UI.Page({
- menuBar = UI.MenuBar({
- buttons = {
- { text = 'Empty', event = 'empty' },
- { text = 'Ingots', event = 'ingots' },
- },
- }),
- grid = UI.ScrollingGrid({
- y = 2,
- height = UI.term.height-2,
- values = inventory,
- columns = {
- { heading = 'Name', key = 'rawName' },
- { heading = 'Ingots', key = 'ingots' },
- },
- sortColumn = 'rawName',
- autospace = true,
- }),
- statusBar = UI.StatusBar(),
- accelerators = {
- q = 'quit',
- },
- })
- function page.grid:draw()
- for _,tank in pairs(inventory) do
- tank.ingots = math.floor(tank.amount / 144 * 100) / 100
- end
- return UI.Grid.draw(self)
- end
- function page:eventHandler(event)
- if event.type == 'empty' then
- emptySmeltry()
- self.grid:draw()
- elseif event.type == 'ingots' then
- rs.setOutput('right', true)
- while true do
- rs.setOutput('right', true)
- os.sleep(.25)
- rs.setOutput('right', false)
- os.sleep(2)
- local sc = device.tconstruct_smelterydrain.getTankInfo()[1].contents
- if not sc or sc.amount < 144 then
- break
- end
- end
- elseif event.type == 'grid_select' then
- insertFluid(event.selected)
- self.grid:draw()
- elseif event.type == 'quit' then
- Event.exitPullEvents()
- end
- UI.Page.eventHandler(self, event)
- end
- UI:setPage(page)
- Event.pullEvents()
- UI.term:reset()
- turtle.status = 'idle'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement