This commit is contained in:
Crispy 2025-05-26 02:36:15 +02:00
parent fe086e3a0c
commit 1ff3cea4d6
29 changed files with 3206 additions and 79 deletions

View file

@ -1,11 +1,11 @@
require("pathfinding")
pretty = require("cc.pretty")
pp = pretty.pretty_print()
pp = pretty.pretty_print
isFluid = {
water = true,
lava = true,
milk = true,
still_milk = true,
blood = true,
molten_rose_gold = true,
molten_copper = true,
@ -17,7 +17,7 @@ isFluid = {
}
fluidDevicePos = {
trash = vector.new(2, 0, -1),
trash = vector.new(1, 0, -1),
water_source = vector.new(0, 0, -1),
mixer = vector.new(-1, 0, -1),
compactor = vector.new(-2, 0, -1),
@ -84,18 +84,10 @@ function resetAllFluidDevices()
-- goTo(pos)
-- setRedRouter(false)
-- end
for x = 2, -4, -1 do
goTo(vector.new(x, 0, -1))
setRedRouter(false)
end
for x = -4, 4 do
goTo(vector.new(x, 0, -3))
setRedRouter(false)
end
_G.activeFluidDevice = nil
for i = 1, 9 do
_G.fluidTanks[i].connected = false
end
-- for x = 2, -4, -1 do
-- goTo(vector.new(x, 0, -1))
-- setRedRouter(false)
-- end
end
function selectFluidDevice(name)
@ -103,14 +95,14 @@ function selectFluidDevice(name)
error("selectFluidDevice(" .. name .. "); not a known fluid device", 2)
end
if _G.activeFluidDevice ~= nil then
goTo(fluidDevicePos[_G.activeFluidDevice])
_G.activeFluidDevice = nil
setRedRouter(false)
if _G.activeFluidDevice ~= name then
print("set active fluid device", name)
_G.activeFluidDevice = name
goTo(fluidDevicePos[name])
redstone.setOutput("bottom", true)
sleep(0.1)
redstone.setOutput("bottom", false)
end
goTo(fluidDevicePos[name])
setRedRouter(true)
_G.activeFluidDevice = name
end
function connectTankOrAssign(fluid)
@ -135,27 +127,27 @@ function connectTankOrAssign(fluid)
end
end
end
connectTanks({ fluid })
connectTank(fluid)
end
function connectTanks(fluid_list)
print("connecting tanks")
pp(fluid_list)
function connectTank(name)
-- TODO only single tank, otherwise pipes break
for index, tank in pairs(_G.fluidTanks) do
should_be_connected = false
for _, fluid in pairs(fluid_list) do
if tank.name == fluid then
should_be_connected = true
break
if tank.name == name then
if index == _G.connectTank then
print("tank", name, index, "already connected")
return
end
end
if should_be_connected ~= tank.connected then
print("setting", tank.name, index, "to", should_be_connected)
goTo(tankPos[index])
setRedRouter(should_be_connected)
_G.fluidTanks[index].connected = should_be_connected
redstone.setOutput("bottom", true)
sleep(0.1)
redstone.setOutput("bottom", false)
_G.connectedTank = index
print("tank", name, index, "already connected")
return
end
end
saveFluids()
end
function fluidInvAdd(name, amount)
@ -163,6 +155,9 @@ function fluidInvAdd(name, amount)
for index, tank in pairs(_G.fluidTanks) do
if tank.name == name then
tank.amount = tank.amount + amount
if tank.amount < 1 then
tank.amount = 0
end
-- TODO limit capacity
end
end