fluid things
This commit is contained in:
parent
7694798ad0
commit
ad6af0fa35
21 changed files with 608 additions and 183 deletions
|
@ -50,6 +50,6 @@ while true do
|
|||
sleep(random(1,4))
|
||||
end
|
||||
end
|
||||
--parallel.waitForAll(sound,sound,sound,sound,sound)
|
||||
parallel.waitForAll(sound,sound,sound,sound,sound)
|
||||
peripheral.call("top","turnOn")
|
||||
-- os.reboot()
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>something silly - index</title>
|
||||
<link rel="stylesheet" href="/style.css">
|
||||
<link rel="icon" type="image/x-icon" href="/creacher.png">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<main>
|
||||
<h1 id="meow">meow</h1>
|
||||
<p>
|
||||
hello i might write some words here from time to time<br>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/">this</a> <a href="https://git.crispypin.cc/CrispyPin/blug">website</a> is running on my own <a href="https://git.crispypin.cc/CrispyPin/webserver">webserver</a> and generated with my <a href="https://git.crispypin.cc/CrispyPin/htmd">static site builder</a><br>
|
||||
this means it is<br>
|
||||
[✓] scuffed<br>
|
||||
[✓] non-compliant<br>
|
||||
[✓] transgener<br>
|
||||
[✔] no tracking or javascipt<br>
|
||||
[✅] silly<br>
|
||||
</p>
|
||||
<h2 id="content">"content"</h2>
|
||||
<p>
|
||||
- <a href="/awful_software/unity-on-linux">unity on linux sucks</a><br>
|
||||
- <a href="/vent/dead-trees">dead trees</a><br>
|
||||
- <a href="/horological-crimes">horological crimes</a><br>
|
||||
- <a href="/snad">snad</a><br>
|
||||
- <a href="/keyboards-are-fun">keyboar</a><br>
|
||||
- <a href="/vent/distracting">distracting</a><br>
|
||||
- <a href="/blender">blender</a><br>
|
||||
- <a href="/old-projects/old-project-list">old projects</a><br>
|
||||
- todo: put more words in the computer<br>
|
||||
</p>
|
||||
<p>
|
||||
<a href="/lists/me">me elsewhere</a> | <a href="/photos">photos</a> | <a href="/portfolio">portfolio</a><br>
|
||||
<a href="/lists/bookmarks">bookmarks</a> | <a href="/lists/music">music</a><br>
|
||||
</p>
|
||||
<div class="flags">
|
||||
<div id="pan"></div><br>
|
||||
<div id="enby"></div><br>
|
||||
<div id="trans"></div><br>
|
||||
<div id="pride"></div><br>
|
||||
<div id="lesbian"></div><br>
|
||||
</div>
|
||||
<a rel="me" href="https://cathode.church/@crispy"></a>
|
||||
|
||||
</main>
|
||||
</body>
|
||||
|
||||
</html>
|
|
@ -1 +1 @@
|
|||
13
|
||||
13
|
||||
|
|
0
computer/13/current_fluids
Normal file
0
computer/13/current_fluids
Normal file
40
computer/13/fluid_state.lua
Normal file
40
computer/13/fluid_state.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
return {
|
||||
{
|
||||
connected = false,
|
||||
name = "water",
|
||||
amount = 13100,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
name = "blood",
|
||||
amount = 100,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
{
|
||||
connected = false,
|
||||
amount = 0,
|
||||
},
|
||||
}
|
172
computer/13/fluids.lua
Normal file
172
computer/13/fluids.lua
Normal file
|
@ -0,0 +1,172 @@
|
|||
require("pathfinding")
|
||||
pretty = require("cc.pretty")
|
||||
pp = pretty.pretty_print()
|
||||
|
||||
isFluid = {
|
||||
water = true,
|
||||
lava = true,
|
||||
milk = true,
|
||||
blood = true,
|
||||
molten_rose_gold = true,
|
||||
molten_copper = true,
|
||||
molten_gold = true,
|
||||
molten_bronze = true,
|
||||
molten_tin = true,
|
||||
molten_zinc = true,
|
||||
compound_mixture = true,
|
||||
}
|
||||
|
||||
fluidDevicePos = {
|
||||
trash = vector.new(2, 0, -1),
|
||||
water_source = vector.new(0, 0, -1),
|
||||
mixer = vector.new(-1, 0, -1),
|
||||
compactor = vector.new(-2, 0, -1),
|
||||
spout = vector.new(-3, 0, -1),
|
||||
melter = vector.new(-4, 0, -1),
|
||||
}
|
||||
|
||||
tankPos = {
|
||||
vector.new(4, 0, -3),
|
||||
vector.new(3, 0, -3),
|
||||
vector.new(2, 0, -3),
|
||||
vector.new(1, 0, -3),
|
||||
vector.new(0, 0, -3),
|
||||
vector.new(-1, 0, -3),
|
||||
vector.new(-2, 0, -3),
|
||||
vector.new(-3, 0, -3),
|
||||
vector.new(-4, 0, -3),
|
||||
}
|
||||
|
||||
function setRedRouter(state)
|
||||
peripheral.call("bottom", "setOutput", "bottom", state)
|
||||
peripheral.call("bottom", "setOutput", "front", state)
|
||||
end
|
||||
|
||||
function loadFluidInventory()
|
||||
return require("fluid_state")
|
||||
end
|
||||
|
||||
function saveFluids()
|
||||
fs.delete("fluid_state.lua")
|
||||
repeat
|
||||
file = fs.open("fluid_state.lua", "w")
|
||||
until file
|
||||
file.write("return ")
|
||||
file.write(textutils.serialise(_G.fluidTanks))
|
||||
file.close()
|
||||
end
|
||||
|
||||
function getFluidAmount(type)
|
||||
for index, tank in pairs(_G.fluidTanks) do
|
||||
if tank.name == type then
|
||||
return tank.amount
|
||||
end
|
||||
end
|
||||
return 0
|
||||
end
|
||||
|
||||
function pumpToDevices(enable)
|
||||
goTo(vector.new(4, 0, -1))
|
||||
-- clutches invert the signal
|
||||
setRedRouter(not enable)
|
||||
end
|
||||
|
||||
function pumpToTanks(enable)
|
||||
goTo(vector.new(3, 0, -1))
|
||||
-- clutches invert the signal
|
||||
setRedRouter(not enable)
|
||||
end
|
||||
|
||||
function resetAllFluidDevices()
|
||||
pumpToDevices(false)
|
||||
pumpToTanks(false)
|
||||
-- for name, pos in pairs(fluidDevicePos) do
|
||||
-- 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
|
||||
end
|
||||
|
||||
function selectFluidDevice(name)
|
||||
if fluidDevicePos[name] == nil then
|
||||
error("selectFluidDevice(" .. name .. "); not a known fluid device", 2)
|
||||
end
|
||||
|
||||
if _G.activeFluidDevice ~= nil then
|
||||
goTo(fluidDevicePos[_G.activeFluidDevice])
|
||||
_G.activeFluidDevice = nil
|
||||
setRedRouter(false)
|
||||
end
|
||||
goTo(fluidDevicePos[name])
|
||||
setRedRouter(true)
|
||||
_G.activeFluidDevice = name
|
||||
end
|
||||
|
||||
function connectTankOrAssign(fluid)
|
||||
local has_fluid = false
|
||||
for index, tank in pairs(_G.fluidTanks) do
|
||||
if tank.name == fluid then
|
||||
has_fluid = true
|
||||
print(fluid, "already assigned to", index)
|
||||
end
|
||||
end
|
||||
if not has_fluid then
|
||||
print(fluid, "not in tanks, assigning new")
|
||||
for index = 1, 9 do
|
||||
if _G.fluidTanks[index].name == nil or _G.fluidTanks[index].amount == 0 then
|
||||
_G.fluidTanks[index] = {
|
||||
name = fluid,
|
||||
amount = 0,
|
||||
connected = false
|
||||
}
|
||||
print("assigned tank", index, "to", fluid)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
connectTanks({ fluid })
|
||||
end
|
||||
|
||||
function connectTanks(fluid_list)
|
||||
print("connecting tanks")
|
||||
pp(fluid_list)
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function fluidInvAdd(name, amount)
|
||||
print("added", amount, "to", name)
|
||||
for index, tank in pairs(_G.fluidTanks) do
|
||||
if tank.name == name then
|
||||
tank.amount = tank.amount + amount
|
||||
-- TODO limit capacity
|
||||
end
|
||||
end
|
||||
saveFluids()
|
||||
end
|
||||
|
||||
_G.fluidTanks = _G.fluidTanks or loadFluidInventory()
|
|
@ -1,4 +1,5 @@
|
|||
pp = require("cc.pretty")
|
||||
pp = require("cc.pretty").pretty_print
|
||||
require("fluids")
|
||||
|
||||
function pFront(fn, ...)
|
||||
return peripheral.call("front", fn, unpack(arg))
|
||||
|
@ -31,22 +32,10 @@ function takeItems(type, count)
|
|||
end
|
||||
|
||||
if slot ~= 1 then
|
||||
local size = pFront("size")
|
||||
local empty_slot = nil
|
||||
for i = 1, size do
|
||||
if pFront("getItemDetail", i) == nil then
|
||||
empty_slot = i
|
||||
break
|
||||
end
|
||||
end
|
||||
if empty_slot == nil then
|
||||
printError("no empty slot in chest, pls fix")
|
||||
exit()
|
||||
end
|
||||
if empty_slot ~= 1 then
|
||||
pFront("pullItems", "front", 1, 64, empty_slot) -- empty first slot
|
||||
end
|
||||
local empty_slot = pFront("size")
|
||||
pFront("pullItems", "front", 1, 64, empty_slot) -- empty first slot
|
||||
pFront("pullItems", "front", slot, 64, 1) -- get target item to first slot
|
||||
pFront("pullItems", "front", empty_slot, 64, slot) -- empty last slot for next time
|
||||
end
|
||||
return turtle.suck(count)
|
||||
end
|
||||
|
@ -93,7 +82,15 @@ function getMissing(needed_items)
|
|||
end
|
||||
end
|
||||
end
|
||||
pp.pretty_print(missing)
|
||||
|
||||
for name, amount in pairs(missing) do
|
||||
if isFluid[name] then
|
||||
missing [name] = amount - getFluidAmount(name)
|
||||
if missing[name] < 1 then
|
||||
missing[name] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
return missing
|
||||
end
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
require("inventory")
|
||||
require("pathfinding")
|
||||
require("fluids")
|
||||
sfx = require("sfx")
|
||||
|
||||
press_pos = vector.new(1,0,0)
|
||||
deployer_pos = vector.new(2,0,0)
|
||||
furnace_pos = vector.new(3,0,0)
|
||||
furnace_pos = vector.new(4,2,0)
|
||||
saw_pos = vector.new(3,1,0)
|
||||
saw_out_pos = vector.new(2,0,0)
|
||||
mill_pos = vector.new(4,0,0)
|
||||
mixer_pos = vector.new(-1,0,0)
|
||||
compactor_pos = vector.new(-2,0,0)
|
||||
|
@ -11,11 +15,34 @@ spout_pos = vector.new(-3,0,0)
|
|||
melter_pos = vector.new(-4,1,-3)
|
||||
casting_table_pos = vector.new(-3,0,-3)
|
||||
|
||||
-- fluid_tanks = {
|
||||
-- water = vector.new(0,0,-1),
|
||||
-- lava = vector.new(0,0,-1)
|
||||
-- }
|
||||
|
||||
function spout(extra_items)
|
||||
local fluid = extra_items[1]
|
||||
if not fluid then
|
||||
error("no fluid specified")
|
||||
end
|
||||
goTo(spout_pos, "south")
|
||||
insertDepot(1)
|
||||
selectFluidDevice("spout")
|
||||
connectTanks({fluid.name})
|
||||
pumpToDevices(true)
|
||||
sleep(10)
|
||||
pumpToDevices(false)
|
||||
goTo(spout_pos, "south")
|
||||
takeDepot()
|
||||
fluidInvAdd(fluid.name, -fluid.count)
|
||||
pumpToTanks(true)
|
||||
goTo(spout_pos, "south")
|
||||
while #pFront("tanks")[1].amount > 0 do
|
||||
sleep(0.5)
|
||||
end
|
||||
pumpToTanks(false)
|
||||
end
|
||||
function saw(_)
|
||||
goTo(saw_pos, "south")
|
||||
turtle.drop()
|
||||
goTo(saw_out_pos, "south")
|
||||
takeDepot()
|
||||
end
|
||||
function mill(extra_items)
|
||||
goTo(mill_pos,"south")
|
||||
item_count = 0
|
||||
|
@ -36,13 +63,13 @@ function mill(extra_items)
|
|||
takeForward(i)
|
||||
end
|
||||
end
|
||||
function deploy(extra_items, nbt)
|
||||
function deploy(extra_items)
|
||||
-- extra_items should only be one item
|
||||
goTo(deployer_pos, "south")
|
||||
insertDepot(1)
|
||||
goUp()
|
||||
goUp()
|
||||
selectItem(extra_items[1].name, nbt)
|
||||
selectItem(extra_items[1].name)
|
||||
turtle.dropUp(1)
|
||||
pFront("pullItem", "top")
|
||||
|
||||
|
@ -51,7 +78,18 @@ function deploy(extra_items, nbt)
|
|||
takeDepot()
|
||||
end
|
||||
function deploy_tool(extra_items)
|
||||
deploy(extra_items, true)
|
||||
-- extra_items should only be one item
|
||||
goTo(deployer_pos, "south")
|
||||
insertDepot(1)
|
||||
goUp()
|
||||
goUp()
|
||||
selectItem(extra_items[1].name)
|
||||
turtle.dropUp(1)
|
||||
pFront("pullItem", "top")
|
||||
|
||||
goDown()
|
||||
goDown()
|
||||
takeDepot()
|
||||
goUp()
|
||||
goUp()
|
||||
pFront("pushItem", "top")
|
||||
|
@ -82,9 +120,63 @@ function press(_)
|
|||
end
|
||||
function compact(extra_items)
|
||||
printError("unimplemented :3")
|
||||
fail()
|
||||
sfx.fail()
|
||||
end
|
||||
function mix(extra_items)
|
||||
function alloy(parts, product)
|
||||
for _, item in pairs(parts) do
|
||||
if not isFluid[item.name] then
|
||||
error(item.name .. " is not a known fluid, but was used in alloy")
|
||||
end
|
||||
end
|
||||
selectFluidDevice("mixer")
|
||||
connectTanks(parts)
|
||||
pumpToDevices(true)
|
||||
goTo(mixer_pos, "south")
|
||||
-- TODO
|
||||
--[[
|
||||
wait until at least one input fluid is used up
|
||||
if two remain, it needs to keep track of which tank gets what when draining
|
||||
]]
|
||||
|
||||
-- while true do
|
||||
|
||||
-- end
|
||||
pumpToDevices(false)
|
||||
end
|
||||
function melt(_, product, yield)
|
||||
goTo(melter_pos, "north")
|
||||
goUp()
|
||||
turtle.drop()
|
||||
selectFluidDevice("melter")
|
||||
connectTankOrAssign(product)
|
||||
pumpToTanks(true)
|
||||
goTo(melter_pos, "north")
|
||||
while #pFront("items") > 0 do
|
||||
sleep(1)
|
||||
end
|
||||
pumpToTanks(false)
|
||||
fluidInvAdd(product, yield)
|
||||
end
|
||||
function mix(extra_items, product, yield)
|
||||
-- prepare fluids
|
||||
local fluids = {}
|
||||
for index, item in pairs(extra_items) do
|
||||
if isFluid[item.name] then
|
||||
table.insert(fluids, item)
|
||||
extra_items[index] = nil
|
||||
end
|
||||
end
|
||||
if #fluids > 0 then
|
||||
print("mixing with fluids", fluids[1])
|
||||
selectFluidDevice("mixer")
|
||||
connectTanks({fluids[1].name})
|
||||
pumpToDevices(true)
|
||||
sleep(10)
|
||||
pumpToDevices(false)
|
||||
end
|
||||
-- print("aaa")
|
||||
-- read()
|
||||
-- mix
|
||||
goTo(mixer_pos, "south")
|
||||
insertForward(1, 1)
|
||||
for _, item in pairs(extra_items) do
|
||||
|
@ -98,6 +190,7 @@ function mix(extra_items)
|
|||
sleep(10)
|
||||
-- todo wait until ingredients are gone
|
||||
takeForward(10)
|
||||
-- todo empty fluids
|
||||
end
|
||||
function craft(extra_items)
|
||||
local slot = 0
|
||||
|
@ -124,5 +217,9 @@ return {
|
|||
press = press,
|
||||
compact = compact,
|
||||
mix = mix,
|
||||
craft = craft
|
||||
craft = craft,
|
||||
alloy = alloy,
|
||||
melt = melt,
|
||||
saw = saw,
|
||||
spout = spout,
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
pp = require("cc.pretty").pretty_print
|
||||
|
||||
_G.facing = "south"
|
||||
_G.pos = vector.new(0,0,0)
|
||||
_G.facing = _G.facing or "south"
|
||||
_G.pos = _G.pos or vector.new(0,0,0)
|
||||
|
||||
local up = vector.new(0,1,0)
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ function read_recipe(file)
|
|||
base = nil
|
||||
intermediate = nil
|
||||
repeats = 1
|
||||
yield = 1
|
||||
while 1 do
|
||||
line = file.readLine()
|
||||
if string.sub(line, 1, 5) == "base " then
|
||||
|
@ -16,6 +17,8 @@ function read_recipe(file)
|
|||
intermediate = string.sub(line, 14)
|
||||
elseif string.sub(line, 1, 7) == "repeat " then
|
||||
repeats = tonumber(string.sub(line, 8))
|
||||
elseif string.sub(line, 1, 6) == "yield " then
|
||||
yield = tonumber(string.sub(line, 7))
|
||||
elseif line == "steps:" then
|
||||
break
|
||||
end
|
||||
|
@ -44,6 +47,7 @@ function read_recipe(file)
|
|||
return {
|
||||
product = product,
|
||||
base = base,
|
||||
yield = yield,
|
||||
intermediate = intermediate or base,
|
||||
repeats = repeats,
|
||||
steps = steps
|
||||
|
|
|
@ -177,6 +177,78 @@ steps:
|
|||
deploy rubber
|
||||
deploy copper_sheet
|
||||
|
||||
redrouter_block
|
||||
steps:
|
||||
craft andesite_alloy redstone_torch andesite_alloy redstone_torch monitor_normal redstone_torch andesite_alloy redstone_torch andesite_alloy
|
||||
|
||||
monitor_normal
|
||||
steps:
|
||||
craft andesite_alloy andesite_alloy andesite_alloy andesite_alloy glass_pane andesite_alloy andesite_alloy andesite_alloy andesite_alloy
|
||||
|
||||
torch
|
||||
yield 4
|
||||
steps:
|
||||
craft charcoal nil nil stick
|
||||
|
||||
kelp
|
||||
steps:
|
||||
mix water kelp bone_meal:2
|
||||
|
||||
electron_tube
|
||||
base polished_rose_quartz
|
||||
steps:
|
||||
spout molten_rose_gold:111
|
||||
|
||||
molten_rose_gold
|
||||
steps:
|
||||
alloy molten_copper molten_gold
|
||||
|
||||
molten_copper
|
||||
yield 111
|
||||
base copper_ingot
|
||||
steps:
|
||||
melt
|
||||
|
||||
molten_gold
|
||||
yield 111
|
||||
base gold_ingot
|
||||
steps:
|
||||
melt
|
||||
|
||||
cow_jar
|
||||
base milk_jar
|
||||
steps:
|
||||
deploy beef
|
||||
deploy leather
|
||||
spout blood:100
|
||||
|
||||
beef
|
||||
base seitan
|
||||
intermediate protobeef
|
||||
steps:
|
||||
deploy moss_carpet
|
||||
spout blood:100
|
||||
press
|
||||
saw
|
||||
|
||||
seitan
|
||||
base dough
|
||||
repeat 2
|
||||
steps:
|
||||
spout water:100
|
||||
press
|
||||
saw
|
||||
|
||||
dough
|
||||
steps:
|
||||
mix wheat_flour water:1000
|
||||
|
||||
wheat_flour
|
||||
steps:
|
||||
mill wheat
|
||||
|
||||
blood
|
||||
yield 50
|
||||
base rotten_flesh
|
||||
steps:
|
||||
melt
|
||||
|
|
12
computer/13/test.lua
Normal file
12
computer/13/test.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
function bar()
|
||||
error("mmm", 4)
|
||||
end
|
||||
|
||||
function foo()
|
||||
bar()
|
||||
end
|
||||
|
||||
while true do
|
||||
foo()
|
||||
-- error("aaaaa")
|
||||
end
|
|
@ -1,4 +1,4 @@
|
|||
pp = require("cc.pretty")
|
||||
pp = require("cc.pretty").pretty_print
|
||||
require("recipes")
|
||||
sfx = require("sfx")
|
||||
require("pathfinding")
|
||||
|
@ -10,23 +10,25 @@ keep_stocked = {
|
|||
flint = 10
|
||||
}
|
||||
|
||||
resetAllFluidDevices()
|
||||
goHome()
|
||||
|
||||
print("known recipes:\n")
|
||||
for k,_ in pairs(recipes) do
|
||||
for k, _ in pairs(recipes) do
|
||||
write(k)
|
||||
write(", ")
|
||||
end
|
||||
write("\nchoose one: ")
|
||||
function completion(partial)
|
||||
list = {}
|
||||
for k,_ in pairs(recipes) do
|
||||
for k, _ in pairs(recipes) do
|
||||
if string.sub(k, 1, #partial) == partial then
|
||||
table.insert(list, string.sub(k, #partial + 1))
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
input = splitString(read(nil, nil, completion))
|
||||
|
||||
target_product = input[1]
|
||||
|
@ -52,7 +54,7 @@ function doRecipe(recipe)
|
|||
inited = true
|
||||
selectItem(recipe.base, false)
|
||||
end
|
||||
use_machine[step.machine](step.extra_items)
|
||||
use_machine[step.machine](step.extra_items, recipe.product, recipe.yield)
|
||||
-- read()
|
||||
end
|
||||
end
|
||||
|
@ -66,10 +68,9 @@ function doRecipe(recipe)
|
|||
turtle.select(1)
|
||||
end
|
||||
|
||||
|
||||
todo = {}
|
||||
for i = 1,copies do
|
||||
table.insert(todo, recipes[target_product])
|
||||
work_queue = {}
|
||||
for i = 1, copies do
|
||||
table.insert(work_queue, recipes[target_product])
|
||||
end
|
||||
|
||||
function listUncraftable(ingredients)
|
||||
|
@ -90,10 +91,12 @@ function tryCreating(recipe)
|
|||
ingredients = ingredientsOf(recipe)
|
||||
missing_ingredients = getMissing(ingredients)
|
||||
if len(missing_ingredients) == 0 then
|
||||
todo[#todo] = nil
|
||||
work_queue[#work_queue] = nil
|
||||
turtle.select(1)
|
||||
-- todo exclude deploy_tool too and make it get its own tool
|
||||
if recipe.steps[1].machine ~= "craft" then
|
||||
if recipe.steps[1].machine ~= "craft" and
|
||||
recipe.steps[1].machine ~= "alloy"
|
||||
then
|
||||
for item, count in pairs(ingredients) do
|
||||
takeItems(item, count)
|
||||
end
|
||||
|
@ -104,19 +107,19 @@ function tryCreating(recipe)
|
|||
return missing_ingredients
|
||||
end
|
||||
|
||||
while #todo > 0 do
|
||||
while #work_queue > 0 do
|
||||
-- for item, _count in pairs(getMissing(keep_stocked)) do
|
||||
-- print("creating", item, "to keep stock up")
|
||||
-- tryCreating(recipes[item])
|
||||
-- end
|
||||
current_recipe = todo[#todo]
|
||||
current_recipe = work_queue[#work_queue]
|
||||
-- ingredients = ingredientsOf(current_recipe)
|
||||
pp.pretty_print(ingredients)
|
||||
pp(ingredients)
|
||||
missing_ingredients = tryCreating(current_recipe)
|
||||
if missing_ingredients then
|
||||
wait_for = listUncraftable(missing_ingredients)
|
||||
while len(wait_for) > 0 do
|
||||
for name,count in pairs(wait_for) do
|
||||
for name, count in pairs(wait_for) do
|
||||
print("please supply", count, name, "manually")
|
||||
end
|
||||
print("press return to continue, q to quit")
|
||||
|
@ -130,11 +133,10 @@ while #todo > 0 do
|
|||
for name, count in pairs(missing_ingredients) do
|
||||
if recipes[name] then
|
||||
print("first making", count, name)
|
||||
table.insert(todo, recipes[name])
|
||||
table.insert(work_queue, recipes[name])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
print("done!")
|
||||
sfx.success()
|
||||
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -1,3 +1,44 @@
|
|||
rednet.open("back")
|
||||
shell.run("report")
|
||||
--parallel.waitForAny(func1,func2)
|
||||
completion = require("cc.completion")
|
||||
local function splitprefixes(str,prefixes)
|
||||
for i,v in ipairs(prefixes) do
|
||||
if string.sub(str,1,string.len(v[2])) == v[2] then
|
||||
return v[2],string.sub(str,string.len(v[2])+2,string.len(str)),v[1]
|
||||
end
|
||||
end
|
||||
end
|
||||
while true do
|
||||
thing = read( nil, nil,
|
||||
function(str)
|
||||
copy = require("rednetcopy")
|
||||
turts = copy.lookup("tomfoolery")
|
||||
turtlenames = {}
|
||||
--print(turts)
|
||||
for i,v in pairs(
|
||||
turts
|
||||
) do
|
||||
table.insert(turtlenames,v[2])
|
||||
end
|
||||
choices = completion.choice(str,turtlenames)
|
||||
--print(#choices)
|
||||
if #choices > 0 then
|
||||
return choices
|
||||
end
|
||||
|
||||
|
||||
name,sub,id = splitprefixes(str,turts)
|
||||
--print(name,sub,id)
|
||||
--print(sub)
|
||||
if not id then return end
|
||||
rednet.send(id,sub,"complete")
|
||||
_,message = rednet.receive("completed",0.2)
|
||||
return message
|
||||
end
|
||||
)
|
||||
turts = copy.lookup("tomfoolery")
|
||||
name, sub,id = splitprefixes(thing,turts)
|
||||
rednet.send(id,sub,"run")
|
||||
end
|
||||
--shell.run("report")
|
||||
|
||||
--parallel.waitForAny(func1,func2)
|
||||
|
|
4
ids.json
4
ids.json
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"computer": 15,
|
||||
"disk": 1
|
||||
"computer": 17,
|
||||
"disk": 2
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue