Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chests = {peripheral.find("minecraft:chest")}
- local mon = peripheral.find("monitor")
- local furnaces = {peripheral.find("minecraft:furnace")}
- local fuel = {"minecraft:coal", "minecraft:coal_block", "minecraft:oak_log", "minecraft:jungle_log", "minecraft:charcoal"}
- local canSmelt = false
- local smelting = false
- local scroll = 0
- local windowHeight = 8
- function draw_text(x, y, text, text_color, bg_color)
- mon.setBackgroundColor(bg_color)
- mon.setTextColor(text_color)
- mon.setCursorPos(x,y)
- mon.write(text)
- end
- function draw_line(x, y, length, color)
- if length < 0 then
- length = 0
- end
- mon.setBackgroundColor(color)
- mon.setCursorPos(x,y)
- mon.write(string.rep(" ", length))
- end
- function progress_bar(x, y, length, minVal, maxVal, bar_color, bg_color)
- draw_line(x, y, length, bg_color) --backgoround bar
- local barSize = math.floor((minVal/maxVal) * length)
- draw_line(x, y, barSize, bar_color) --progress so far
- end
- function clear()
- --term.clear()
- --term.setCursorPos(1,1)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- end
- function getInventories()
- for idx, chest in pairs(chests) do
- items = chest.list()
- for slot = scroll, scroll + windowHeight do
- if(items[slot] ~= nil) then
- draw_text(4, slot - scroll, ("%d x %s"):format(items[slot].count, items[slot].name), colors.cyan, colors.black)
- end
- end
- end
- end
- function button()
- while (true) do
- event, side, xPos, yPos = os.pullEvent("monitor_touch")
- if(yPos == 19 and xPos >=2 and xPos <= 6 and canSmelt and not smelting) then
- smelting = true
- end
- if(xPos >= 1 and xPos <= 2) then
- if(yPos == 1) then
- scroll = scroll - 1
- if(scroll < 0) then
- scroll = 0
- end
- else if(yPos == 7) then
- scroll = scroll + 1
- end
- end
- end
- end
- end
- function moveFuels(init, tar, qty)
- for slot, item in pairs(init.list()) do
- for i = 1, table.getn(fuel) do
- if(item.name == fuel[i]) then
- init.pushItems(peripheral.getName(tar), slot, qty)
- end
- end
- end
- end
- function moveFuels(init, tar, qty, idx)
- for slot, item in pairs(init.list()) do
- for i = 1, table.getn(fuel) do
- if(item.name == fuel[i]) then
- init.pushItems(peripheral.getName(tar), slot, qty, idx)
- end
- end
- end
- end
- function moveItems(init, tar, qty, tarItem, idx)
- for slot, item in pairs(init.list()) do
- if(item.name == tarItem) then
- init.pushItems(peripheral.getName(tar), slot, qty, idx)
- return true
- end
- end
- end
- function emptySlot(init, tar, idx)
- for slot, item in pairs(init.list()) do
- if(slot == idx) then
- init.pushItems(peripheral.getName(tar), slot)
- end
- end
- end
- function refuel()
- fuelChest = chests[1]
- while(true) do
- if(smelting) then
- for idx, chest in pairs(chests) do
- moveFuels(chest, fuelChest, 64)
- end
- for idx, furnace in pairs(furnaces) do
- moveFuels(fuelChest, furnace, 1, 2)
- end
- end
- sleep(0.1)
- end
- end
- function loadTar(tar)
- foundItem = true
- while(foundItem) do
- foundItem = false
- for _, chest in pairs(chests) do
- for _, furnace in pairs(furnaces) do
- foundItem = moveItems(chest, furnace, 1, tar, 1)
- sleep(0.1)
- end
- end
- end
- canSmelt = true
- end
- function smelt()
- while(true) do
- if(canSmelt == false) then
- print("Please give the desired target to smelt: ")
- tar = read()
- loadTar(tar)
- end
- sleep(0.1)
- end
- end
- function isDone()
- fuelChest = chests[1]
- allEmpty = true
- while(true) do
- if(canSmelt) then
- for idx, furnace in pairs(furnaces) do
- for slot, item in pairs(furnace.list()) do
- if(slot == 1 and item.count ~= 0) then
- allEmpty = false
- end
- end
- end
- if(allEmpty) then
- canSmelt = false
- smelting = false
- for _, furnace in pairs(furnaces) do
- emptySlot(furnace, fuelChest, 3)
- emptySlot(furnace, fuelChest, 2)
- end
- end
- end
- allEmpty = true
- sleep(0.1)
- end
- end
- function drawGUI()
- while(true) do
- draw_text(1, 1, "/\\", colors.white, colors.gray)
- draw_text(1, 7, "\\/", colors.white, colors.gray)
- local btnColor = colors.gray
- if(canSmelt) then
- btnColor = colors.green
- end
- if(smelting) then
- btnColor = colors.blue
- end
- draw_text(2, 19, "SMELT", colors.white, btnColor)
- getInventories()
- drawFurnaceStatus()
- sleep(1)
- clear()
- --term.clear()
- --term.setCursorPos(1,1)
- end
- end
- function drawFurnaceStatus()
- local row = 1
- local column = 1
- local maxHeight = 5
- for idx, furnace in pairs(furnaces) do
- local textColor = colors.gray
- local itemCount = 0
- furnaceInv = furnace.list()
- if(furnaceInv[1] ~= nil) then
- if(furnaceInv[2] ~= nil) then
- textColor = colors.green
- else
- textColor = colors.blue
- end
- itemCount = furnaceInv[1].count
- end
- draw_text(column * 2, 7 + row * 2, ("%d"):format(itemCount), colors.white, textColor)
- row = row + 1
- if(row == maxHeight) then
- row = 1
- column = column + 1
- end
- end
- end
- parallel.waitForAny(drawGUI, button, smelt, refuel, isDone)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement