Compare commits
4 Commits
e45b1ea995
...
master
Author | SHA1 | Date | |
---|---|---|---|
b47a8ad4fa | |||
a1bb89a4d2 | |||
53bfc85164 | |||
bcbb419179 |
@@ -4,7 +4,10 @@ This is an implementation of a centralized storage network architecture that use
|
|||||||
|
|
||||||
## Deployment
|
## Deployment
|
||||||
|
|
||||||
|
First, consider using [someone else's project](https://github.com/lewark/inv.lua) instead of this one. It's liable to be a lot better than mine.
|
||||||
|
|
||||||
1. Deploy a Smart Computer
|
1. Deploy a Smart Computer
|
||||||
2. Connect the computer to at least 1 chest and 1 hopper via physical modem lines. Chests need to be attached from the bottom and hoppers from their output direction
|
2. Connect the computer to at least 1 chest and 1 hopper via physical modem lines. Chests need to be attached from the bottom and hoppers from their output direction
|
||||||
3. Put a chest on top of the Smart Computer
|
3. Put a chest on top of the Smart Computer
|
||||||
4. Deploy the script
|
4. Install Basalt (`wget run https://basalt.madefor.cc/install.lua release latest.lua`)
|
||||||
|
5. Deploy the script (as `startup`, of course)
|
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
-- Startup diagnostics
|
-- Startup diagnostics
|
||||||
print("Salt's CC Storage Net")
|
print("Salt's CC Storage Net")
|
||||||
print("Computer " .. os.getComputerID() .. " configured as " .. mode)
|
|
||||||
|
|
||||||
-- Global scope locals
|
-- Global scope locals
|
||||||
local output = peripheral.wrap("top") or error("Put a chest on top of this terminal for output items", 0)
|
local output = peripheral.wrap("top") or error("Put a chest on top of this terminal for output items", 0)
|
||||||
@@ -29,22 +28,57 @@ function pushDepositsToChests()
|
|||||||
-- Take all the contents of all connected hoppers and stuff them into any other connected inventory
|
-- Take all the contents of all connected hoppers and stuff them into any other connected inventory
|
||||||
-- These things are wrapped into tables because that's how you take multiple return values and stuff them in a table, apparently
|
-- These things are wrapped into tables because that's how you take multiple return values and stuff them in a table, apparently
|
||||||
local hoppers = getDepositHoppers()
|
local hoppers = getDepositHoppers()
|
||||||
local chests = {peripheral.find("inventory", function(name,i) return string.find(name, "minecraft:chest") end)}
|
local chests = getConnectedChests()
|
||||||
-- For each hopper connected to the network...
|
-- For each hopper connected to the network...
|
||||||
for k,hopper in ipairs(hoppers) do
|
for k,hopper in ipairs(hoppers) do
|
||||||
-- For each item in that hopper's inventory...
|
-- For each item in that hopper's inventory...
|
||||||
for hslot,hitem in pairs(hopper.list()) do
|
for hslot,hitem in pairs(hopper.list()) do
|
||||||
-- For each connected "chest"...
|
-- For each connected "chest"...
|
||||||
for k,chest in ipairs(chests) do
|
for k,chest in ipairs(chests) do
|
||||||
-- Attempt to push our items in
|
-- First, make an attempt to find slots that we can shove the item into
|
||||||
hopper.pushItems(peripheral.getName(chest),hslot)
|
for cslot,citem in pairs(chest.list()) do
|
||||||
|
if
|
||||||
|
citem["name"] == hitem["name"] and -- We have the same item
|
||||||
|
citem["count"] < chest.getItemLimit(cslot) -- There's space in this slot
|
||||||
|
then
|
||||||
|
hopper.pushItems(peripheral.getName(chest),hslot,hitem["count"],cslot)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- We've fallen through trying to fill up existing stacks. Fragmentation is not a concern, put it wherever
|
||||||
|
if hopper.getItemDetail(hslot) then
|
||||||
|
for k,chest in ipairs(chests) do
|
||||||
|
hopper.pushItems(peripheral.getName(chest),hslot)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
function requestItem(name, count)
|
||||||
|
-- Pull a number of an item into the output chest above the machine
|
||||||
|
remaining = count
|
||||||
|
local chests = getConnectedChests()
|
||||||
|
-- For each chest on the network...
|
||||||
|
for k,chest in ipairs(chests) do
|
||||||
|
-- For each slot in that chest...
|
||||||
|
for cslot,citem in pairs(chest.list()) do
|
||||||
|
if
|
||||||
|
citem["name"] == name and
|
||||||
|
citem["count"] > 0
|
||||||
|
then
|
||||||
|
desired = math.max(remaining, citem["count"])
|
||||||
|
output.pullItems(peripheral.getName(chest),cslot,desired)
|
||||||
|
remaining = remaining - desired
|
||||||
|
end
|
||||||
|
if remaining <= 0 then return true end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if remaining > 0 then return false end
|
||||||
|
end
|
||||||
|
|
||||||
-- Application entrypoint
|
-- Application entrypoint
|
||||||
function main()
|
function main()
|
||||||
|
requestItem("minecraft:sandstone", 12)
|
||||||
while true do
|
while true do
|
||||||
-- Manage inventory cleanup tasks
|
-- Manage inventory cleanup tasks
|
||||||
pushDepositsToChests() -- Take all deposit terminals and push them into the inventory network
|
pushDepositsToChests() -- Take all deposit terminals and push them into the inventory network
|
||||||
|
@@ -16,5 +16,5 @@ echo "Root: $_ccroot"
|
|||||||
for computer in "$masterid"; do
|
for computer in "$masterid"; do
|
||||||
echo "Deploying to: $computer"
|
echo "Deploying to: $computer"
|
||||||
mkdir -p "$_ccroot/$computer"
|
mkdir -p "$_ccroot/$computer"
|
||||||
cp common.lua "$_ccroot/$computer/autostart"
|
cp common.lua "$_ccroot/$computer/startup"
|
||||||
done
|
done
|
Reference in New Issue
Block a user