Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Barrel Tracking
- -- ----------------------------------------------------------
- -- Returns information about barrels in my network, such as
- -- where a given resource is kept and if a barrel is full.
- -- ----------------------------------------------------------
- -- Initialise important values:
- local side = {{"back",-2},{"bottom",-2},{"top",-1},{"right",-1}}
- local combbarrel = {{{"tin comb", 4,4}, -- Row 1 (top left)
- {"bronze comb", 3,4},
- {"platinum comb", 2,7},
- {"radioactive comb", 2,5},
- {"lapis comb", 4,9, 4,10},
- {"diamond comb", 1,7}},
- {{"copper comb", 3,1}, -- Row 2 (bottom left)
- {"titanium comb", 1,15},
- {"gold comb", 2,15},
- {"fossilised comb", 4,8},
- {"iron comb", 4,1},
- {"ruby comb", 1,5}},
- {{"simmering comb", 4,7, 4,16}, -- Row 3 (top right)
- {"propolis", 3,12},
- {"stringy comb", 3,12},
- {"leaden comb", 2,12},
- {"invar comb", 2,9},
- {"silver comb", 1,12}},
- {{"dripping comb", 3,16}, -- Row 4 (bottom right)
- {"static comb", 3,14, 2,6},
- {"clay comb", 4,12},
- {"brazen comb", 3,7},
- {"glowing comb", 2,6},
- {"electrum comb", 1,9}}}
- local barrel = {{{"cobble", 1,2}, -- Row 1 (top left)
- {"stone", 1,3},
- {"stone brick", 1,4},
- {"chiseled stone brick"},
- {"tiny pile of ruby dust", 1,6},
- {"ruby dust"},
- {"tiny pile of diamond dust", 1,8},
- {"diamond dust"},
- {"tiny pile of electrum dust", 1,10},
- {"electrum dust", 1,11},
- {"electrum ingot"},
- {"tiny pile of silver dust", 1,13},
- {"silver dust", 1,14},
- {"silver ingot"},
- {"tiny pile of titanium dust", 1,16},
- {"titanium dust", 1,17},
- {"titanium ingot"}},
- {{""}, -- Row 2 (bottom left)
- {""},
- {""},
- {""},
- {"uranium"},
- {"redstone"},
- {"tiny pile of platinum dust", 2,8},
- {"platinum dust"},
- {"tiny pile of invar dust", 2,10},
- {"invar dust", 2,11},
- {"invar ingot"},
- {"tiny pile of lead dust", 2,13},
- {"lead dust", 2,14},
- {"lead ingot"},
- {"tiny pile of gold dust", 2,16},
- {"gold dust", 2,17},
- {"gold ingot"}},
- {{"tiny pile of copper dust", 3,2}, -- Row 3 (top right)
- {"copper dust", 3,3},
- {"copper ingot"},
- {"tiny pile of bronze dust", 3,5},
- {"bronze dust", 3,6},
- {"bronze ingot"},
- {"tiny pile of brass dust", 3,8},
- {"brass dust", 3,9},
- {"brass ingot"},
- {"glowstone dust", 3,11},
- {"glowstone"},
- {"sticky resin", 3,13},
- {"rubber"},
- {"energy drop"},
- {"honey drop"},
- {"honeydew"},
- {"pollen"}},
- {{"tiny pile of iron dust", 4,2}, -- Row 4 (bottom right)
- {"iron dust", 4,3},
- {"iron ingot"},
- {"tiny pile of tin dust", 4,5},
- {"tin dust", 4,6},
- {"tin ingot"},
- {"phosphor"},
- {"coal dust"},
- {"lazurite dust"},
- {"lapis lazuli", 4,11},
- {"lapis lazuli block"},
- {"clay dust", 4,13},
- {"clay"},
- {"magic wax"},
- {"beeswax"},
- {"refractory wax"},
- {"royal jelly"}}}
- local result = {0,0,0,0,false}
- local sender = 0
- local incoming = ""
- local found = false
- rednet.open("left")
- print("")
- print("I'm an inventory server.")
- print("Other computers talk to me over rednet.")
- print("")
- print("Go find something else to play with and leave me alone!")
- print("")
- while true do
- sender, incoming = rednet.receive()
- if incoming == "Hello InvServer" then
- -- A new client wants to know my ID.
- sleep(1) -- Give the client time to switch to receiving mode.
- rednet.send(sender,"Hello yourself!")
- else
- -- Client should be asking about a barrel.
- sleep(1) -- Give the client time to switch to receiving mode.
- found = false
- for i=1,4 do
- for j=1,6 do
- if incoming == combbarrel[i][j][1] then
- result[2] = 593 -- X co-ord of barrel.
- if i > 2 then result[2] = 600 end
- result[3] = -236 - j -- Y co-ord of barrel.
- result[4] = 66 -- Z co-ord of barrel.
- if i==2 or i==4 then result[4] = 63 end
- result[1] = 1 -- Node closest to barrel.
- result[5] = true -- Whether the barrels that hold the resources
- -- produced from the contents of THIS barrel
- -- can take more produce.
- if table.getn(combbarrel[i][j]) > 1 then
- result[5] = false
- for k=1,((table.getn(combbarrel[i][j])-1)/2) do
- if bit.band(rs.getBundledInput(side[combbarrel[i][j][k*2]][1]),2^(combbarrel[i][j][(k*2)+1]+side[combbarrel[i][j][k*2]][2])) == 2^(combbarrel[i][j][(k*2)+1]+side[combbarrel[i][j][k*2]][2]) then result[5] = true end
- end
- end
- found = true
- i = 4
- j = 6
- end
- end
- end
- if not found then
- for i=1,4 do
- for j=1,17 do
- if incoming == barrel[i][j][1] then
- result[2] = 575 + j -- X co-ord of barrel.
- if i > 2 then result[2] = result[2] + 25 end
- result[3] = -236 -- Y co-ord of barrel.
- result[4] = 66 -- Z co-ord of barrel.
- if i==2 or i==4 then result[4] = 63 end
- result[1] = 12 -- Node closest to barrel.
- if result[2] > 584 then result[1] = 10 end
- if result[2] > 592 then result[1] = 3 end
- if result[2] > 606 then result[1] = 5 end
- result[5] = true -- Whether the barrels that hold the resources
- -- produced from the contents of THIS barrel
- -- can take more produce.
- if table.getn(barrel[i][j]) > 1 then
- result[5] = false
- for k=1,((table.getn(barrel[i][j])-1)/2) do
- if bit.band(rs.getBundledInput(side[barrel[i][j][k*2]][1]),2^(barrel[i][j][(k*2)+1]+side[barrel[i][j][k*2]][2])) == 2^(barrel[i][j][(k*2)+1]+side[barrel[i][j][k*2]][2]) then result[5] = true end
- end
- end
- found = true
- i = 4
- j = 17
- end
- end
- end
- end
- if found then
- rednet.send(sender,textutils.serialize(result))
- else
- print("Got a signal I didn't recognise: "..incoming)
- print("")
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement