Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sleep(2)
- rednet.open("back");
- print("Starting Up...");
- local furnacesConnected = 0;
- local furnaces = {};
- local currentlySmelting = {};
- print("Attempting Connection With Clients")
- for i=1, 32, 1 do
- furnaces[i] = {};
- local furnace = rednet.lookup("furnace", "Furnace" .. i);
- if furnace ~= nil then
- print("Found Server");
- rednet.send(furnace, "iam Server");
- furnacesConnected = furnacesConnected + 1;
- furnaces[i]["connectionStatus"] = "connected";
- else
- furnaces[i]["connectedStatus"] = "disconnected";
- end
- end
- term.clear();
- local isBurning = "Idle"
- local totalFuel = 0;
- local fuel = {};
- local totalItems = 0;
- local items = {};
- function updateScreen()
- term.setCursorPos(1,2);
- term.write("Furnaces Connected: ");
- term.setCursorPos(1,3);
- term.write("Furnace Status: ");
- term.setCursorPos(1,4);
- term.write("Total Fuel Amount In System: ");
- term.setCursorPos(1,5);
- term.write("Fuel In System: ");
- term.setCursorPos(1,9);
- term.write("Total Items in system: ");
- term.setCursorPos(1, 10);
- term.write("Items In System: ");
- term.setCursorPos(1, 14);
- term.setCursorPos(string.len("Furnaces Connected: ") + 1,2)
- term.setTextColor(colors.green);
- term.write(furnacesConnected);
- term.setTextColor(colors.white);
- term.setCursorPos(string.len("Furnace Status: ") + 1, 3)
- if isBurning == "Idle" then term.setTextColor(colors.orange);
- elseif isBurning == "Burning" then term.setTextColor(colors.green);
- elseif isBurning == "Needs Fuel" then term.setTextColor(colors.red);
- end
- term.write(isBurning);
- term.setTextColor(colors.white);
- for i=1, 32, 1 do
- local tempColor;
- if furnaces[i]["status"] == "idle" then tempColor = colors.lightGray;
- elseif furnaces[i]["status"] == "burning" then tempColor = colors.green;
- elseif furnaces[i]["status"] == "needs fuel" then tempColor = colors.red;
- end
- paintutils.drawPixel(1+i, 15, tempColor)
- term.setBackgroundColor(colors.black)
- term.setCursorPos(string.len("Total Fuel Amount In System: ") + 1, 4)
- term.write(totalFuel);
- term.setCursorPos(1,6)
- if fuel[1] ~= nil then
- term.write(" -" .. fuel[1]);
- if fuel[2] ~= nil then
- term.setCursorPos(1,7)
- term.write(" -" .. fuel[2]);
- if fuel[3] ~= nil then
- term.setCursorPos(1,8)
- term.write(" -" .. fuel[3]);
- end
- end
- end
- if totalItems == 0 then
- term.setTextColor(colors.gray);
- term.setCursorPos(1,9);
- term.write("Total Items in system: ");
- term.setCursorPos(1, 10);
- term.write("Items In System: ");
- else
- term.setTextColor(colors.white);
- term.setCursorPos(1,9);
- term.write("Total Items in system: ");
- term.setCursorPos(1, 10);
- term.write("Items In System: ");
- end
- term.setCursorPos(string.len("Total Items in system: ") + 1, 9)
- term.write(totalItems);
- term.setCursorPos(1, 11)
- if items[1] ~= nil then
- term.write(" -" .. items[1]);
- if items[2] ~= nil then
- term.setCursorPos(1,12)
- term.write(" -" .. items[2]);
- if items[3] ~= nil then
- term.setCursorPos(1,13)
- term.write(" -" .. items[3]);
- end
- end
- end
- term.setTextColor(colors.white);
- end
- end
- function disconnectFurnace(id)
- furnacesConnected = furnacesConnected - 1;
- furnaces[id]["connectionStatus"] = "disconnected";
- end
- function updateData()
- totalFuel = 0;
- totalItems = 0;
- isBurning = "Idle "
- for t=1,32,1 do
- furnaces[t]["status"] = "idle";
- if furnaces[t]["connectionStatus"] == "connected" then
- if furnaces[t]["itemAmount"] > 0 and furnaces[t]["fuelAmount"] > 0 then isBurning = "Burning "; furnaces[t]["status"] = "burning";
- elseif furnaces[t]["itemAmount"] > 0 and furnaces[t]["fuelAmount"] == 0 then isBurning = "Needs Fuel "; furnaces[t]["status"] = "needs fuel";
- end
- if furnaces[t]["fuelAmount"] == 0 then furnaces[t]["status"] = "needs fuel"; end
- totalFuel = totalFuel + furnaces[t]["fuelAmount"];
- if furnaces[t]["fuelType"] ~= nil and furnaces[t]["fuelType"] ~= fuel[1] and furnaces[t]["fuelType"] ~= fuel[2] and furnaces[t]["fuelType"] ~= fuel[3] then
- if fuel[1] ~= furnaces[t]["fuelType"] and fuel[1] == nil then fuel[1] = furnaces[t]["fuelType"];
- elseif fuel[2] ~= furnaces[t]["fuelType"] and fuel[2] == nil then fuel[2] = furnaces[t]["fuelType"];
- elseif fuel[3] ~= furnaces[t]["fuelType"] and fuel[3] == nil then fuel[3] = furnaces[t]["fuelType"];
- end
- end
- totalItems = totalItems + furnaces[t]["itemAmount"];
- if furnaces[t]["itemType"] ~= nil and furnaces[t]["itemType"] ~= items[1] and furnaces[t]["itemType"] ~= items[2] and furnaces[t]["itemType"] ~= items[3] then
- if items[1] ~= furnaces[t]["itemType"] and items[1] == nil then items[1] = furnaces[t]["itemType"];
- elseif items[2] ~= furnaces[t]["itemType"] and items[2] == nil then items[2] = furnaces[t]["itemType"];
- elseif items[3] ~= furnaces[t]["itemType"] and items[3] == nil then items[3] = furnaces[t]["itemType"];
- end
- end
- end
- end
- updateScreen()
- end
- function getData()
- for i=1,32,1 do
- local furnace = rednet.lookup("furnace", "Furnace" .. i);
- if furnace ~= nil then
- if furnaces[i]["connectionStatus"] == "disconnected" then
- rednet.send(furnace, "iam Server");
- furnaces[i]["connectionStatus"] = "connected";
- furnacesConnected = furnacesConnected + 1;
- sleep(1);
- end
- rednet.send(furnace, "getFuelType");
- _, furnaces[i]["fuelType"] = rednet.receive(1);
- rednet.send(furnace, "getItem");
- _, furnaces[i]["itemType"] = rednet.receive(1);
- rednet.send(furnace, "getFuel");
- local _, fuelAmountTemp = rednet.receive(1);
- if fuelAmountTemp == nil then furnaces[i]["fuelAmount"] = 0;
- else furnaces[i]["fuelAmount"] = tonumber(fuelAmountTemp);
- end
- rednet.send(furnace, "getItemAmount");
- _, itemAmountTemp = rednet.receive(1);
- if itemAmountTemp == nil then furnaces[i]["itemAmount"] = 0;
- else furnaces[i]["itemAmount"] = tonumber(itemAmountTemp);
- end
- else
- if furnaces[i]["connectionStatus"] == "connected" then disconnectFurnace(i) end
- end
- end
- end
- getData();
- while true do
- parallel.waitForAll(getData, updateData)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement