Compare commits

..

32 Commits

Author SHA1 Message Date
b47a8ad4fa Update shit 2024-02-26 02:58:42 -06:00
a1bb89a4d2 Remove extraneous code 2024-02-26 02:30:48 -06:00
53bfc85164 Improve algo for sorting items away 2024-02-26 02:25:39 -06:00
bcbb419179 Working on a bunch of things 2024-02-26 01:46:12 -06:00
e45b1ea995 Remove extraneous configs 2024-02-26 01:37:38 -06:00
4b4c656af1 Rework the script into something much simpler holy shit 2024-02-26 01:37:03 -06:00
1f593d0542 Add some specs idk it doesn't matter i just found out that a wired net does this a million times better lol 2024-02-26 01:03:04 -06:00
ba51252476 Minor spec revision 2024-02-26 00:41:44 -06:00
5dd175bb00 Minor cleanup 2024-02-26 00:40:16 -06:00
9f2b3a8050 Work on README, add duplicated logic for targeting 2024-02-26 00:30:44 -06:00
c8806be02d Remove sleep from loop func
This solves all our rednet issues, seemingly
2024-02-26 00:24:40 -06:00
bc46c8adef Remove sleeps from loops, as waitformessage will do that for us 2024-02-26 00:22:10 -06:00
78be72c4b1 Move to rednet
This sucks.
It has broadcast, which is required for the project, but if you're not listening when a packet ships then you drop it
2024-02-26 00:20:08 -06:00
a72cd8bef5 Work on init code 2024-02-25 23:33:32 -06:00
164006f4b0 Remove requirement for a GPS 2024-02-25 23:01:57 -06:00
b5ea97b5d9 More boilerplate 2024-02-25 23:01:37 -06:00
75b9634ea9 Minor polish 2024-02-25 22:47:00 -06:00
ff5ff86794 Add a bunch of proto functionality 2024-02-25 22:44:46 -06:00
144b2b9ebb Add initial stuff 2024-02-25 22:22:02 -06:00
7853e6174e Update deploy script 2024-02-25 22:15:30 -06:00
c19888f597 Update README 2024-02-25 22:14:08 -06:00
1b38039f62 Add deploy script 2024-02-25 22:14:04 -06:00
bee8f740c6 More fixes 2024-02-16 23:41:22 -06:00
ba57f4a7ae Fix formatting 2024-02-16 23:40:38 -06:00
8f7e7b4d01 Add prelim stuff 2024-02-16 23:39:52 -06:00
76e0731ad1 Account for overflow 2023-12-01 18:57:09 -06:00
e120636ace Actually clean up lmao 2023-12-01 17:38:13 -06:00
a643feafd9 Have thing cleanup 2023-12-01 17:00:25 -06:00
946d96a6af Add conditional 2023-12-01 12:14:25 -06:00
8129f039cd Rewrite chicken handler for a new shittier world where inventory indicies aren't a thing ig 2023-12-01 12:11:24 -06:00
294713ce56 Revert "Testing"
This reverts commit 445602b60d.
2023-12-01 12:03:18 -06:00
53fe827e4d Revert "Testing alternative chicken acquisition methods"
This reverts commit 5fcd598067.
2023-12-01 12:03:13 -06:00
5 changed files with 162 additions and 12 deletions

View File

@@ -1,20 +1,32 @@
-- See README for usage info
-- 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()
print('Initializing breeder...')
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.suckUp()
-- Then we select the next slot and bop the breeder
turtle.select(2)
turtle.digUp()
-- Why are we discarding slot 2? Because, by design, it MUST be the trash
-- chicken from the last generation.
breeder.pushItems('bottom', 2)
-- Check to see if this iteration obtained a new chicken
if turtle.suckUp() then
-- Then, we destroy the breeder
print('Placing breeder with new chicken')
turtle.select(2)
turtle.digUp()
-- 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')
turtle.placeUp()
selectItem('minecraft:wheat_seeds')
@@ -74,7 +86,10 @@ function checkIfDone()
for i = 1, output.size(), 1 do
if output.getItemDetail(i) then
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
end
end
@@ -82,6 +97,16 @@ function checkIfDone()
return false
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()
print('Initializing...')
while not checkIfDone() do
@@ -90,6 +115,7 @@ local function main()
sleep()
while peripheral.wrap('top').getItemDetail(4) == nil do sleep() end
end
cleanup()
print('Breeding complete')
end

1
storage-net/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.vscode

13
storage-net/README.md Normal file
View 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
View 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
View 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