Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local smeltery = peripheral.find("minecraft:tconstruct_smeltery_controller")
- local monitor = peripheral.find("monitor")
- local ingot_chest = peripheral.wrap("computer_0")
- local modem = peripheral.wrap("right")
- local SERVER_CHANNEL = 1
- local CLIENT_CHANNEL = 2
- -- Smeltery methods:
- --
- -- suck([slot:int[, limit:int]]):int
- -- Suck an item from the ground
- --
- -- pullItems(fromName:string, fromSlot:int[, limit:int[, toSlot:int]]):int
- -- Pull items to this inventory from another inventory. Returns the amount transferred.
- --
- -- drop(slot:int[, limit:int[, direction:string]]):int
- -- Drop an item on the ground. Returns the number of items dropped.
- --
- -- pushItems(toName:string, fromSlot:int[, limit:int[, toSlot:int]]):int
- -- Push items from this inventory to another inventory. Returns the amound transferred.
- --
- -- list():table
- -- List all items in this inventory.
- --
- -- size():int
- -- The size of the inventory.
- --
- -- getItemMeta(slot:int):table|nil
- -- The metadata of the item in the specified slot. The slot number starts from 1.
- --
- -- getItem(slot:int):table|nil
- -- The item in the specified slot. The slot number starts from 1.
- --
- -- getTemperature():number
- -- Get the internal temoerature of this structure.
- --
- -- getFuels():table
- -- Get a list of all fuels currenty used by the seared-bricks multiblock.
- --
- -- getMolten():table
- -- Get a list of all molten fluids within the smeltery.
- --
- -- selectMolten(fluid: number|string)
- -- Select which fluid will be extracted by drains in the smeltery. One can specify a fluid name or an index in list of molten fluids.
- --
- -- getMetadata():table
- -- Get metadata about this object
- --
- -- getTransferLocations([location:string]):table
- -- Get a list of all available objects which can be transferred to or from.
- --
- -- getDocs([name: string]):string|table
- -- Get the documentation for all functions or the function specified. Errors if the function cannot be found.
- -- Smeltery Drain Methods
- --
- -- getMetadata():table
- -- Get metadata about this object
- --
- -- getTransferLocations([location:string]):table
- -- Get a list of all available objects which can be transferred to or from
- --
- -- pullFluid(fromName:string[, limit:int[, fluid:string]]):int
- -- Pull fluid to this tank from another tank. Returns the amount transferred.
- --
- -- getDocs([name: string]):string|table
- -- Get the documentation for all functions or the function specified. Errors if the function cannot be found.
- --
- -- getTanks([side:string]):table
- -- Get a list of all tanks on this side.
- --
- -- pushFluid(toName:string[, limit:int], fluid:string):int
- -- Push fluid from this tank to another tank. Returns the amount transferred.
- --
- -- getController():table|nil
- -- Get the controller for this smeltery component.
- local function mb_to_block_ingot_rest(millibuckets, displayName)
- local block_mb = 1000
- local ingot_mb = 144
- local nugget_mb = 16
- if displayName == "Seared Stone" then
- ingot_mb = 72
- block_mb = 4 * ingot_mb
- elseif displayName == "Liquid Glass" then
- block_mb = 1000
- return millibuckets / block_mb, nil, nil
- else
- nugget_mb = 16
- ingot_mb = 144
- block_mb = 9 * ingot_mb
- end
- local num_blocks = math.floor(millibuckets / block_mb)
- local num_ingots = math.floor((millibuckets - num_blocks * block_mb) / ingot_mb)
- local num_nuggets = math.floor((millibuckets - num_blocks * block_mb - num_ingots * ingot_mb) / nugget_mb)
- local rest = millibuckets - num_blocks * block_mb - num_ingots * ingot_mb - num_nuggets * nugget_mb
- return num_blocks, num_ingots, num_nuggets, rest
- end
- local function notifySmelteryFuel()
- local fuel = smeltery.getFuels()
- for index, value in ipairs(fuel) do
- if value.amount < 250 then
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Please refuel! Only "..value.amount.." mb of fuel left.")
- end
- end
- end
- local function maxStringLength(table, field)
- local max = 0
- for k, v in ipairs(table) do
- local string_len = string.len(v[field])
- if string_len > max then
- max = string_len
- end
- end
- return max
- end
- local function header(window, max_material_length, max_count_length, column_spacing, kind)
- window.setCursorPos(1, 1)
- window.write("Material")
- window.setCursorPos(max_material_length + column_spacing - 1, 1)
- window.write("|")
- if kind == "smeltery" then
- window.setCursorPos(max_material_length + column_spacing + 1, 1)
- window.write("Blocks")
- window.setCursorPos(max_material_length + max_count_length + 2 * column_spacing - 1, 1)
- window.write("|")
- window.setCursorPos(max_material_length + max_count_length + 2 * column_spacing + 1, 1)
- window.write("Ingots")
- window.setCursorPos(max_material_length + 2 * max_count_length + 3 * column_spacing - 1, 1)
- window.write("|")
- window.setCursorPos(max_material_length + 2 * max_count_length + 3 * column_spacing + 1, 1)
- window.write("Nuggets")
- window.setCursorPos(max_material_length + 3 * max_count_length + 4 * column_spacing - 1, 1)
- window.write("|")
- window.setCursorPos(max_material_length + 3 * max_count_length + 4 * column_spacing + 1, 1)
- window.write("Rest")
- else
- window.setCursorPos(max_material_length + column_spacing + 1, 1)
- window.write("Ingots")
- end
- end
- local function sepRow(window, max_name_length, max_count_length, column_spacing, kind)
- window.setCursorPos(1, 2)
- if kind == "smeltery" then
- window.write(string.rep("-", max_name_length)..string.rep("-+"..string.rep("-", max_count_length + column_spacing - 2), 4))
- else
- window.write(string.rep("-", max_name_length)..string.rep("-+"..string.rep("-", max_count_length + column_spacing - 2), 1))
- end
- end
- local function tableContents(window, items, max_name_length, max_count_length, column_spacing, kind)
- if kind == "smeltery" then
- for k, v in ipairs(items) do
- local num_blocks, num_ingots, num_nuggets, rest = mb_to_block_ingot_rest(v.amount, v.displayName)
- local display_height = k + 2
- window.setCursorPos(1, display_height)
- window.write(v.displayName)
- window.setCursorPos(max_name_length + column_spacing - 1, display_height)
- window.write("|")
- window.setCursorPos(max_name_length + column_spacing + 1, display_height)
- if num_blocks ~= nil and num_blocks ~= 0 then
- window.write(num_blocks)
- end
- window.setCursorPos(max_name_length + max_count_length + 2 * column_spacing - 1, display_height)
- window.write("|")
- window.setCursorPos(max_name_length + max_count_length + 2 * column_spacing + 1, display_height)
- if num_ingots ~= nil and num_ingots ~= 0 then
- window.write(num_ingots)
- end
- window.setCursorPos(max_name_length + 2 * max_count_length + 3 * column_spacing - 1, display_height)
- window.write("|")
- window.setCursorPos(max_name_length + 2 * max_count_length + 3 * column_spacing + 1, display_height)
- if num_nuggets ~= nil and num_nuggets ~= 0 then
- window.write(num_nuggets)
- end
- window.setCursorPos(max_name_length + 3 * max_count_length + 4 * column_spacing - 1, display_height)
- window.write("|")
- window.setCursorPos(max_name_length + 3 * max_count_length + 4 * column_spacing + 1, display_height)
- if rest ~= nil and rest ~= 0 then
- window.write(rest)
- end
- end
- else
- for k, v in ipairs(items) do
- local display_height = k + 2
- window.setCursorPos(1, display_height)
- window.write(v.name)
- window.setCursorPos(max_name_length + column_spacing - 1, display_height)
- window.write("|")
- window.setCursorPos(max_name_length + column_spacing + 1, display_height)
- window.write(v.count)
- end
- end
- end
- local function displayTable(window, items, column_spacing, sort_ascending, max_name_length, max_count_length, kind)
- table.sort(items, function(a, b) if sort_ascending then return a.amount < b.amount else return a.amount > b.amount end end)
- window.clear()
- header(window, max_name_length, max_count_length, column_spacing, kind)
- sepRow(window, max_name_length, max_count_length, column_spacing, kind)
- tableContents(window, items, max_name_length, max_count_length, column_spacing, kind)
- end
- local function updateDisplay(window, table, column_spacing, sort_ascending, max_material_length, max_count_length, kind)
- displayTable(window, table, column_spacing, sort_ascending, max_material_length, max_count_length, kind)
- end
- local function requestTable(kind)
- modem.open(CLIENT_CHANNEL)
- if kind == "ingots" then
- modem.transmit(SERVER_CHANNEL, CLIENT_CHANNEL, "req items")
- while true do
- local event, peripheral_name, channel, reply_channel, message, distance = os.pullEvent("modem_message")
- return message
- end
- end
- modem.close("ingots")
- end
- local function main()
- local column_spacing = 3
- local sort_ascending = false
- local molten = smeltery.getMolten()
- --local ingots = requestTable("ingots")
- local smeltery_max_material_length = maxStringLength(molten, "displayName")
- local smeltery_max_count_length = math.max(maxStringLength(molten, "amount"), string.len("Blocks"), string.len("Ingots"), string.len("Nuggets"), string.len("Rest"))
- --local ingots_max_material_length = maxStringLength(ingots, "name")
- --local ingots_max_count_length = math.max(maxStringLength(ingots, "count"), string.len("Ingots"))
- local smeltery_table_width = smeltery_max_material_length + 4 * column_spacing + 1 + 3 * smeltery_max_count_length
- --local ingots_table_width = ingots_max_material_length + column_spacing + 1 + ingots_max_count_length
- monitor.setTextScale(0.5)
- local mon_width, mon_height = monitor.getSize()
- local smeltery_window = window.create(monitor, 1, 1, smeltery_table_width, mon_height)
- --local ingots_window = window.create(monitor, smeltery_table_width + 1, 1, ingots_table_width, mon_height)
- while true do
- notifySmelteryFuel()
- updateDisplay(smeltery_window, molten, column_spacing, sort_ascending, smeltery_max_material_length, smeltery_max_count_length, "smeltery")
- --updateDisplay(ingots_window, ingots, column_spacing, sort_ascending, ingots_max_material_length, ingots_max_count_length, "ingots")
- sleep(5)
- molten = smeltery.getMolten()
- --ingots = requestTable("ingots")
- smeltery_max_material_length = maxStringLength(molten, "displayName")
- smeltery_max_count_length = math.max(maxStringLength(molten, "amount"), string.len("Blocks"), string.len("Ingots"), string.len("Nuggets"), string.len("Rest"))
- --ingots_max_material_length = maxStringLength(ingots, "name")
- --ingots_max_count_length = math.max(maxStringLength(ingots, "count"), string.len("Ingots"))
- smeltery_table_width = smeltery_max_material_length + 4 * column_spacing + 1 + 3 * smeltery_max_count_length
- --ingots_table_width = ingots_max_material_length + column_spacing + 1 + ingots_max_count_length
- smeltery_window.reposition(1, 1, smeltery_table_width, mon_height)
- --ingots_window.reposition(smeltery_table_width + 1, 1, ingots_table_width, mon_height)
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement