fluid things

This commit is contained in:
Crispy 2025-05-25 03:02:48 +02:00
parent 7694798ad0
commit ad6af0fa35
21 changed files with 608 additions and 183 deletions

View file

@ -2,7 +2,8 @@ sf = require("structure")
local pf = require("pathfinding")
local im = require("inventorymanager")
local origin = vector.new(-15,235,120)
function build(x,y,z)
function build(chunk)
local x,y,z = stringtovec(chunk)
store = {height = 0}
grocerylist = {}
for h = 1,8 do
@ -28,13 +29,13 @@ function build(x,y,z)
end
if store.height==0 then
--print("cell at",x,y,z,"is done")
removechunk(x,y,z)
return true
end
flag = false
count = im.countinventory()
for k,v in pairs(grocerylist) do
if im.count(k) < v then
if (count[k] or -1) < v then
print("not enough "..k.." need "..v.." of it")
flag = true
end
@ -49,11 +50,9 @@ function build(x,y,z)
return false
end
pf.to(origin + vector.new(x+1,y+8,z+1))
for h = 1,8 do
print(store[h].width)
for w = 1,store[h].width do
print(store[h][w].depth)
for d = 1,store[h][w].depth do
for w = 1,8 do
for h = 1,8 do
for d = 1,8 do
if store[h][w][d] then
pf.to(origin+vector.new(x+w,y+h,z+d))
im.select(store[h][w][d])
@ -62,55 +61,23 @@ function build(x,y,z)
end
end
end
removechunk(x,y,z)
return true
end
function removechunk(x,y,z)
--::success::
local file = fs.open("tobuild","r")
local rest = {}
line = file.readLine()
while line do
table.insert(rest,line)
line = file.readLine()
end
file.close()
file = fs.open("tobuild","w")
str = tostring(vector.new(x,y,z))
for _,v in ipairs(rest) do
if v ~= str then
file.writeLine(v)
end
end
file.close()
end
function stringtovec(str)
parts = {}
for part in string.gmatch(str, "([^,]+)") do
table.insert(parts, part)
table.insert(parts, tonumber(part))
end
return vector.new(unpack(parts))
end
--pf.to(origin)
file=fs.open("tobuild","r")
chunk = file.readLine()
file.close()
print(chunk)
vec = stringtovec(chunk)
X1,Y1,Z1 = vec.x,vec.y,vec.z
print(X1,Y1,Z1)
while build(X1,Y1,Z1) do
-- term.clear()
print(X1,Y1,Z1)
file = fs.open("tobuild","r")
chunk = file.readLine()
vec = stringtovec(chunk)
X1,Y1,Z1 = vec.x,vec.y,vec.z
file.close()
--term.clear()
sleep(0)
return unpack(parts)
end
repeat
rednet.send(1,nil,"getnexttobuild")
_,chunk = rednet.receive("nexttobuild")
until not build(chunk)
rednet.send(1,chunk,"failedtobuild")
pf.returnHome()

View file

@ -1,13 +0,0 @@
file = fs.open("tobuild","w")
while true do
id,message = rednet.receive()
if id == 3 then
if message=="done" then
file.close()
return
else
print(message)
file.writeLine(message)
end
end
end

View file

@ -21,6 +21,29 @@ function count(name)
end
return value
end
function countinventory()
counts = {}
for i = 1,16 do
item = turtle.getItemDetail(i)
if item then
if item.name == "packages:package" then
turtle.select(i)
turtle.placeUp()
sleep(0.1)
for i,item2 in pairs(peripheral.call("top","list")) do
write(item2.name,item2.count)
counts[item2.name] =
(counts[item2.name] or 0)
+ item2.count
print(counts[item2.name])
end
turtle.digUp()
else
counts[item.name] = counts[item.name] or 0 + item.count
end end
end
return counts
end
function select(name)
local flag = false
for i = 1,16 do
@ -86,4 +109,4 @@ function pull(name, slot)
return error("there is no '"..name.."' in my inventory")
end
return {pull=pull,count=count,select=select}
return {pull=pull,count=count,select=select,countinventory = countinventory}

View file

@ -1,4 +1,4 @@
home = vector.new(-250, 96, 106)
home = vector.new(-1, 186, 126)
up = vector.new(0,1,0)
south = vector.new(0,0,1)
east = vector.new(1,0,0)

View file

@ -21,6 +21,11 @@ function greedystep(target)
_G.position = position + facing
return true
end
elseif vec:dot(facing) < 0 then
if turtle.back() then
_G.position = position - facing
return true
end
end
if vec:dot(facing:cross(up)) > 0 then
turtle.turnRight()

View file

@ -1,23 +1,84 @@
_G.position = vector.new(-250,96,106)
_G.position = vector.new(-1,186,126)
_G.facing = vector.new(-1,0,0)
rednet.open("left")
old_print = _G.print
new_print = function(...)
--old_print = _G.print
--[[new_print = function(...)
x = ""
for i,v in ipairs(arg) do
x = x..tostring(v).." "
end
old_print(x)
rednet.broadcast(x)
end
end]]
--_G.print = new_print
rednet.host("tomfoolery",os.computerLabel())
--rednet.host("tomfoolery",os.computerLabel())
--while true do
if not _G.thing or true then
_G.thing = true
function append(tbl,value)
table.insert(tbl,value)
return tbl
end
rednet.host("tomfoolery",os.getComputerLabel())
queue = {}
history = {}
if true then
parallel.waitForAll(
function() while true do read() end end,
function() shell.run("felling") end,
function() while true do id,message = rednet.receive() print(message) end end
function()
while true do
--print("reading")
while running do
coroutine.yield()
end
write(
shell.dir().."> "
)
table.insert(
queue,
append(
history,
not running and read(
nil,
history,
shell.complete
)
)[#history]
)
sleep(0.05)--coroutine.yield()
end
end,
function()
while true do
--print("attempting to run shell on :"..(queue[1] or ""))
running = true
shell.run(
table.remove(
queue,
1
)
)
running = false
--term.clear()
for i,v in pairs(queue) do
--print(v)
end
sleep(0.05)
end
end,
function()
while true do
--print("recieving")
id,mess,kind = rednet.receive()
if kind == "complete" then
rednet.send(id,shell.complete(mess),"completed")
elseif kind == "run" then
print("recieved")
print(id, mess, kind)
table.insert(queue,mess)
sleep(0.05)
else
end
end
end
)
end
rednet.receive()