Compare commits
32 Commits
5fcd598067
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| b47a8ad4fa | |||
| a1bb89a4d2 | |||
| 53bfc85164 | |||
| bcbb419179 | |||
| e45b1ea995 | |||
| 4b4c656af1 | |||
| 1f593d0542 | |||
| ba51252476 | |||
| 5dd175bb00 | |||
| 9f2b3a8050 | |||
| c8806be02d | |||
| bc46c8adef | |||
| 78be72c4b1 | |||
| a72cd8bef5 | |||
| 164006f4b0 | |||
| b5ea97b5d9 | |||
| 75b9634ea9 | |||
| ff5ff86794 | |||
| 144b2b9ebb | |||
| 7853e6174e | |||
| c19888f597 | |||
| 1b38039f62 | |||
| bee8f740c6 | |||
| ba57f4a7ae | |||
| 8f7e7b4d01 | |||
| 76e0731ad1 | |||
| e120636ace | |||
| a643feafd9 | |||
| 946d96a6af | |||
| 8129f039cd | |||
| 294713ce56 | |||
| 53fe827e4d |
@@ -1,20 +1,32 @@
|
|||||||
-- See README for usage info
|
-- See README for usage info
|
||||||
-- https://git.desu.ltd/salt/mc-scripts/src/branch/master/stoneblock-3-chicken-breeder/README.md
|
-- https://git.desu.ltd/salt/mc-scripts/src/branch/master/stoneblock-3-chicken-breeder/README.md
|
||||||
|
|
||||||
-- Breaks and replaces the breeder on top of the turtle
|
|
||||||
-- This is called after every generation
|
|
||||||
function placeBreeder()
|
function placeBreeder()
|
||||||
print('Initializing breeder...')
|
print('Initializing breeder...')
|
||||||
breeder = peripheral.wrap('top')
|
breeder = peripheral.wrap('top')
|
||||||
-- This ensures that we have the new generation chicken in slot 1
|
-- First, we nab the new chicken in slot 1
|
||||||
turtle.select(1)
|
turtle.select(1)
|
||||||
turtle.suckUp()
|
-- Check to see if this iteration obtained a new chicken
|
||||||
-- Then we select the next slot and bop the breeder
|
if turtle.suckUp() then
|
||||||
turtle.select(2)
|
-- Then, we destroy the breeder
|
||||||
turtle.digUp()
|
print('Placing breeder with new chicken')
|
||||||
-- Why are we discarding slot 2? Because, by design, it MUST be the trash
|
turtle.select(2)
|
||||||
-- chicken from the last generation.
|
turtle.digUp()
|
||||||
breeder.pushItems('bottom', 2)
|
-- We are now in a position where we have:
|
||||||
|
-- 1: Good chicken
|
||||||
|
-- 2: Inferior chicken
|
||||||
|
-- 3: Seeds/second inferior chicken
|
||||||
|
-- 4: Breeder/seeds
|
||||||
|
-- 5: Null/breeder
|
||||||
|
-- In any case, discarding 1 item in slot 2 will eliminate poor genes
|
||||||
|
--turtle.select(2) -- Unnecessary due to previous instr
|
||||||
|
turtle.dropDown(1)
|
||||||
|
else
|
||||||
|
-- Just pop the breeder for consistency
|
||||||
|
print('Placing breeder from scratch')
|
||||||
|
turtle.select(2)
|
||||||
|
turtle.digUp()
|
||||||
|
end
|
||||||
|
-- Now we re set-up the breeder
|
||||||
selectItem('chickens:breeder')
|
selectItem('chickens:breeder')
|
||||||
turtle.placeUp()
|
turtle.placeUp()
|
||||||
selectItem('minecraft:wheat_seeds')
|
selectItem('minecraft:wheat_seeds')
|
||||||
@@ -74,7 +86,10 @@ function checkIfDone()
|
|||||||
for i = 1, output.size(), 1 do
|
for i = 1, output.size(), 1 do
|
||||||
if output.getItemDetail(i) then
|
if output.getItemDetail(i) then
|
||||||
item = output.getItemDetail(i)
|
item = output.getItemDetail(i)
|
||||||
if item.count == item.maxCount then
|
-- Magic number 3 here is determined as follows:
|
||||||
|
-- 1 from the offspring of this new generation
|
||||||
|
-- 2 from the breeding pair
|
||||||
|
if item.count == item.maxCount - 3 then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -82,6 +97,16 @@ function checkIfDone()
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function cleanup()
|
||||||
|
print('Cleaning up...')
|
||||||
|
turtle.digUp()
|
||||||
|
for i = 1, 16, 1 do
|
||||||
|
turtle.select(i)
|
||||||
|
turtle.dropDown()
|
||||||
|
end
|
||||||
|
print('Cleanup complete')
|
||||||
|
end
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
print('Initializing...')
|
print('Initializing...')
|
||||||
while not checkIfDone() do
|
while not checkIfDone() do
|
||||||
@@ -90,6 +115,7 @@ local function main()
|
|||||||
sleep()
|
sleep()
|
||||||
while peripheral.wrap('top').getItemDetail(4) == nil do sleep() end
|
while peripheral.wrap('top').getItemDetail(4) == nil do sleep() end
|
||||||
end
|
end
|
||||||
|
cleanup()
|
||||||
print('Breeding complete')
|
print('Breeding complete')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
1
storage-net/.gitignore
vendored
Normal file
1
storage-net/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.vscode
|
||||||
13
storage-net/README.md
Normal file
13
storage-net/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Computercraft Storage Network
|
||||||
|
|
||||||
|
This is an implementation of a centralized storage network architecture that uses just ComputerCraft and vanilla Minecraft.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
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
|
||||||
|
4. Install Basalt (`wget run https://basalt.madefor.cc/install.lua release latest.lua`)
|
||||||
|
5. Deploy the script (as `startup`, of course)
|
||||||
90
storage-net/common.lua
Normal file
90
storage-net/common.lua
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
-- Salt's ComputerCraft Storage Network Script
|
||||||
|
--
|
||||||
|
-- For information on this script, physical in-world setup, and configuration,
|
||||||
|
-- see: https://git.desu.ltd/salt/mc-scripts/src/branch/master/storage-net
|
||||||
|
|
||||||
|
-- Startup diagnostics
|
||||||
|
print("Salt's CC Storage Net")
|
||||||
|
|
||||||
|
-- Global scope locals
|
||||||
|
local output = peripheral.wrap("top") or error("Put a chest on top of this terminal for output items", 0)
|
||||||
|
|
||||||
|
-- Helper functions
|
||||||
|
function getDepositHoppers()
|
||||||
|
-- Get all connected inventories that push items into the system
|
||||||
|
return {peripheral.find("inventory", function(name,i)
|
||||||
|
return string.find(name, "minecraft:hopper")
|
||||||
|
end)}
|
||||||
|
end
|
||||||
|
function getConnectedChests()
|
||||||
|
-- Get all connected inventories that store items
|
||||||
|
return {peripheral.find("inventory", function(name,i)
|
||||||
|
return string.find(name, "minecraft:chest")
|
||||||
|
end)}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Common functions
|
||||||
|
function pushDepositsToChests()
|
||||||
|
-- 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
|
||||||
|
local hoppers = getDepositHoppers()
|
||||||
|
local chests = getConnectedChests()
|
||||||
|
-- For each hopper connected to the network...
|
||||||
|
for k,hopper in ipairs(hoppers) do
|
||||||
|
-- For each item in that hopper's inventory...
|
||||||
|
for hslot,hitem in pairs(hopper.list()) do
|
||||||
|
-- For each connected "chest"...
|
||||||
|
for k,chest in ipairs(chests) do
|
||||||
|
-- First, make an attempt to find slots that we can shove the item into
|
||||||
|
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
|
||||||
|
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
|
||||||
|
function main()
|
||||||
|
requestItem("minecraft:sandstone", 12)
|
||||||
|
while true do
|
||||||
|
-- Manage inventory cleanup tasks
|
||||||
|
pushDepositsToChests() -- Take all deposit terminals and push them into the inventory network
|
||||||
|
-- Sleep for a tick
|
||||||
|
sleep(0.05) -- This is to stop CC from killing us
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
main()
|
||||||
20
storage-net/deploy.sh
Executable file
20
storage-net/deploy.sh
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
#! /bin/sh
|
||||||
|
#
|
||||||
|
# deploy.sh
|
||||||
|
# Copyright (C) 2024 Jacob Babor <jacob@babor.tech>
|
||||||
|
#
|
||||||
|
# Distributed under terms of the MIT license.
|
||||||
|
#
|
||||||
|
|
||||||
|
mcroot="$HOME/.var/app/org.prismlauncher.PrismLauncher/data/PrismLauncher/instances/ComputerCraft Sandbox/"
|
||||||
|
world="New World"
|
||||||
|
|
||||||
|
masterid="0"
|
||||||
|
|
||||||
|
_ccroot="$mcroot/.minecraft/saves/$world/computercraft/computer"
|
||||||
|
echo "Root: $_ccroot"
|
||||||
|
for computer in "$masterid"; do
|
||||||
|
echo "Deploying to: $computer"
|
||||||
|
mkdir -p "$_ccroot/$computer"
|
||||||
|
cp common.lua "$_ccroot/$computer/startup"
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user