diff --git a/computer/0/startup.lua b/computer/0/startup.lua index 6cf3aad..051f6a9 100644 --- a/computer/0/startup.lua +++ b/computer/0/startup.lua @@ -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() diff --git a/computer/11/test.txt b/computer/11/test.txt new file mode 100644 index 0000000..11d79ca --- /dev/null +++ b/computer/11/test.txt @@ -0,0 +1,55 @@ + + + + + + + something silly - index + + + + + +
+

meow

+

+hello i might write some words here from time to time
+

+

+this website is running on my own webserver and generated with my static site builder
+this means it is
+[✓] scuffed
+[✓] non-compliant
+[✓] transgener
+[✔] no tracking or javascipt
+[✅] silly
+

+

"content"

+

+- unity on linux sucks
+- dead trees
+- horological crimes
+- snad
+- keyboar
+- distracting
+- blender
+- old projects
+- todo: put more words in the computer
+

+

+me elsewhere | photos | portfolio
+bookmarks | music
+

+
+

+

+

+

+

+
+ + +
+ + + \ No newline at end of file diff --git a/computer/11/torment_progress.txt b/computer/11/torment_progress.txt index b1bd38b..ca7bf83 100644 --- a/computer/11/torment_progress.txt +++ b/computer/11/torment_progress.txt @@ -1 +1 @@ -13 +13 \ No newline at end of file diff --git a/computer/13/fluid_state.lua b/computer/13/fluid_state.lua deleted file mode 100644 index 07a81e4..0000000 --- a/computer/13/fluid_state.lua +++ /dev/null @@ -1,40 +0,0 @@ -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, - }, -} \ No newline at end of file diff --git a/computer/13/fluids.lua b/computer/13/fluids.lua deleted file mode 100644 index 3d1a85a..0000000 --- a/computer/13/fluids.lua +++ /dev/null @@ -1,172 +0,0 @@ -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() diff --git a/computer/13/garbage/evil.lua b/computer/13/garbage/evil.lua deleted file mode 100644 index 8f437c3..0000000 --- a/computer/13/garbage/evil.lua +++ /dev/null @@ -1,21 +0,0 @@ -sfx = require("sfx") -return -parallel.waitForAll( - function() - while true do - sleep(math.random(10, 100)) - if math.random(10) > 5 then - sfx.fail() - else - sfx.success() - end - event = { os.pullEventRaw() } - if event[1] == "terminate" then - shell.exit() - os.shutdown() - end - end - end, function() - term.setCursorPos(1, 1) - shell.run("shell") - end) diff --git a/computer/13/inventory.lua b/computer/13/inventory.lua index 67572cc..edfca6f 100644 --- a/computer/13/inventory.lua +++ b/computer/13/inventory.lua @@ -1,17 +1,7 @@ -pp = require("cc.pretty").pretty_print -require("fluids") +pp = require("cc.pretty") -function pFront(fn, ...) - return peripheral.call("front", fn, unpack(arg)) -end - -function pBottom(fn, ...) - return peripheral.call("bottom", fn, unpack(arg)) -end - -function pTop(fn, ...) - return peripheral.call("top", fn, unpack(arg)) -end +pFront = peripheral.wrap("front") +pDown = peripheral.wrap("bottom") function findItems(item_list, target) for i, v in pairs(item_list) do @@ -22,8 +12,31 @@ function findItems(item_list, target) return nil end +-- uses selected item +function insertForward(slot, count) + turtle.dropDown(count) + pFront.pullItems("bottom", 1, 64, slot) +end + +function takeForward(slot) + -- pDown.pullItems("front", slot, 64, 1) + peripheral.call("bottom", "pullItems", "front", slot or 1) + turtle.suckDown() +end + +function insertDepot(count) + turtle.dropDown(count) + peripheral.call("front", "pullItem", "bottom") +end + +function takeDepot() + peripheral.call("front", "pushItem", "bottom") + turtle.suckDown() +end + + function takeItems(type, count) - local item_list = pFront("list") + local item_list = pFront.list() local slot = findItems(item_list, type) if slot == nil then @@ -31,19 +44,18 @@ function takeItems(type, count) return false end - if slot ~= 1 then - 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 + empty_slot = pFront.size() + -- todo error if not empty + 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 return turtle.suck(count) end function selectItem(name, has_nbt) has_nbt = has_nbt or false if name == nil or name == "nil" then - for i = 1, 16 do + for i = 1,16 do if turtle.getItemCount(i) == 0 then turtle.select(i) return @@ -52,7 +64,7 @@ function selectItem(name, has_nbt) printError("no empty slot found") return end - for i = 1, 16 do + for i = 1,16 do detail = turtle.getItemDetail(i, true); if detail and stripModname(detail.name) == name then if has_nbt == (detail.nbt ~= nil) then @@ -66,10 +78,10 @@ end function getMissing(needed_items) missing = {} - for name, count in pairs(needed_items) do + for name,count in pairs(needed_items) do missing[name] = count end - target_contents = pFront("list") + target_contents = peripheral.call("front", "list") for _, target_item in pairs(target_contents) do for name, missing_count in pairs(missing) do @@ -82,35 +94,7 @@ function getMissing(needed_items) end end end - - 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 + pp.pretty_print(missing) return missing end -function insertForward(slot, count) - turtle.dropDown(count) - pFront("pullItems", "bottom", 1, 64, slot) -end - -function takeForward(slot) - pBottom("pullItems", "front", slot or 1) - turtle.suckDown() -end - -function insertDepot(count) - turtle.dropDown(count) - pFront("pullItem", "bottom") -end - -function takeDepot() - pFront("pushItem", "bottom") - turtle.suckDown() -end - diff --git a/computer/13/keep_stocked.lua b/computer/13/keep_stocked.lua new file mode 100644 index 0000000..f0520ab --- /dev/null +++ b/computer/13/keep_stocked.lua @@ -0,0 +1,4 @@ +keep_stocked = { + kelp = 10, + flint = 10 +} \ No newline at end of file diff --git a/computer/13/machines.lua b/computer/13/machines.lua index 0bbe08b..4df90fa 100644 --- a/computer/13/machines.lua +++ b/computer/13/machines.lua @@ -1,50 +1,8 @@ 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(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) -spout_pos = vector.new(-3,0,0) -melter_pos = vector.new(-4,1,-3) -casting_table_pos = vector.new(-3,0,-3) - -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") + go_to(vector.new(-4,0,0),"south") item_count = 0 if turtle.getItemCount() ~= 0 then item_count = 1 @@ -56,47 +14,36 @@ function mill(extra_items) insertForward(1, item.count) end print(item_count,"items") - while pFront("getItemDetail", 1) do + while peripheral.call("front", "getItemDetail", 1) do sleep(0.1) end for i = 2, 10 do takeForward(i) end end -function deploy(extra_items) +function deploy(extra_items, nbt) -- extra_items should only be one item - goTo(deployer_pos, "south") + go_to(vector.new(2,0,0), "south") insertDepot(1) goUp() goUp() - selectItem(extra_items[1].name) + selectItem(extra_items[1].name, nbt) turtle.dropUp(1) - pFront("pullItem", "top") + peripheral.call("front", "pullItem", "top") goDown() goDown() takeDepot() end function deploy_tool(extra_items) - -- extra_items should only be one item - goTo(deployer_pos, "south") - insertDepot(1) + deploy(extra_items, true) goUp() goUp() - selectItem(extra_items[1].name) - turtle.dropUp(1) - pFront("pullItem", "top") - - goDown() - goDown() - takeDepot() - goUp() - goUp() - pFront("pushItem", "top") + peripheral.call("front", "pushItem", "top") turtle.suckUp() end function furnace(extra_items) - goTo(furnace_pos, "south") + go_to(vector.new(1,0,0), "south") item_count = 0 if turtle.getItemCount() ~= 0 then item_count = 1 @@ -108,76 +55,20 @@ function furnace(extra_items) insertForward(1, item.count) end wait_time = 10 * item_count + -- peripheral.call("front", "") -- TODO refuel sleep(wait_time) takeForward(3) end function press(_) - goTo(press_pos, "south") + go_to(vector.new(-1,0,0), "south") insertDepot(1) sleep(1) takeDepot() end -function compact(extra_items) - printError("unimplemented :3") - sfx.fail() -end -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") +function compact(extra_items) end +function mix(extra_items) + go_to(vector.new(-3,0,0), "south") insertForward(1, 1) for _, item in pairs(extra_items) do selectItem(item.name) @@ -190,10 +81,16 @@ function mix(extra_items, product, yield) sleep(10) -- todo wait until ingredients are gone takeForward(10) - -- todo empty fluids end function craft(extra_items) + -- for i = 1, 16 do + -- if turtle.getItemCount(i) ~= 0 then + -- turtle.select(i) + -- turtle.drop() + -- end + -- end local slot = 0 + print(len(extra_items), "extra items") for _, item in pairs(extra_items) do slot = slot + 1 if slot == 4 then @@ -217,9 +114,5 @@ return { press = press, compact = compact, mix = mix, - craft = craft, - alloy = alloy, - melt = melt, - saw = saw, - spout = spout, + craft = craft } \ No newline at end of file diff --git a/computer/13/main.lua b/computer/13/main.lua deleted file mode 100644 index eaf9080..0000000 --- a/computer/13/main.lua +++ /dev/null @@ -1,13 +0,0 @@ -pretty = require("cc.pretty").pretty_print - -require("recipes") -sfx = require("sfx") -require("pathfinding") -require("inventory") - -keep_stocked = { - kelp = 10, - flint = 10 -} - -goHome() diff --git a/computer/13/make_belts.lua b/computer/13/make_belts.lua new file mode 100644 index 0000000..83024e1 --- /dev/null +++ b/computer/13/make_belts.lua @@ -0,0 +1,60 @@ +require("recipes") +require("pathfinding") +iv = require("inventory") + + +-- belt recipe +getItems("minecraft:kelp", 4) +getItems("minecraft:charcoal", 1) +getItems("techreborn:rubber", 3) +-- furnace +go_to(vector.new(1,0,0), "south") +selectItem("minecraft:charcoal") +iv.insertForward(2) +selectItem("minecraft:kelp") +iv.insertForward(1) + +sleep(40) +iv.takeForward(3) + +selectItem("minecraft:dried_kelp") + +for i = 1,3 do +-- deployer +go_to(vector.new(2,0,0), "south") +iv.insertForwardDepot(1) +go_to(vector.new(2,1,0), "south") +selectItem("techreborn:rubber") +turtle.dropUp(1) +goDown() +sleep(1) +iv.takeForwardDepot() +-- press +go_to(vector.new(-1,0,0), "south") +selectItem("minecraft:dried_kelp", true) +iv.insertForwardDepot(1) +sleep(1) +iv.takeForwardDepot() +-- deployer 2 +selectItem("minecraft:dried_kelp", true) +print("selected partial belt") +go_to(vector.new(2,0,0), "south") +iv.insertForwardDepot(1) +go_to(vector.new(2,1,0), "south") +selectItem("minecraft:dried_kelp", false) +turtle.dropUp(1) +goDown() +sleep(1) +iv.takeForwardDepot() +-- press 2 +selectItem("minecraft:dried_kelp", true) +go_to(vector.new(-1,0,0), "south") +iv.insertForwardDepot(1) +sleep(1) +iv.takeForwardDepot() + +selectItem("minecraft:dried_kelp", true) + +end + +go_to(vector.new(0,0,0), "south") diff --git a/computer/13/pathfinding.lua b/computer/13/pathfinding.lua index 1a5aa39..56cac54 100644 --- a/computer/13/pathfinding.lua +++ b/computer/13/pathfinding.lua @@ -1,7 +1,15 @@ -pp = require("cc.pretty").pretty_print +pp = require("cc.pretty") -_G.facing = _G.facing or "south" -_G.pos = _G.pos or vector.new(0,0,0) +-- if _G.pos == nil then +_G.facing = "south" +_G.pos = vector.new(0,0,0) +-- file = fs.open("pos.txt", "r") +-- data = splitString(file.readAll()) +-- _G.pos.x = tonumber(data[1]) +-- _G.pos.y = tonumber(data[2]) +-- _G.pos.z = tonumber(data[3]) +-- _G.facing = data[4] +-- end local up = vector.new(0,1,0) @@ -26,9 +34,17 @@ local vecOf = { west = vector.new(-1,0,0), } +function savePos() + -- fs.delete("pos.txt") + -- file = fs.open("pos.txt", "w") + -- file.write(_G.pos.x .. " " .. _G.pos.y .. " " .. _G.pos.z .. " " .. _G.facing) +end + + function goUp() if turtle.up() then _G.pos.y = _G.pos.y + 1 + savePos() else printError("failed to go up") printError(pos) @@ -38,6 +54,7 @@ end function goDown() if turtle.down() then _G.pos.y = _G.pos.y - 1 + savePos() else printError("failed to go down") printError(pos) @@ -47,16 +64,19 @@ end function goLeft() turtle.turnLeft() _G.facing = leftOf[_G.facing] + savePos() end function goRight() turtle.turnRight() _G.facing = rightOf[_G.facing] + savePos() end function goForward() if turtle.forward() then _G.pos = _G.pos + vecOf[_G.facing] + savePos() else printError("failed to go forward") printError(pos) @@ -66,6 +86,7 @@ end function goBack() if turtle.back() then _G.pos = _G.pos - vecOf[_G.facing] + savePos() else printError("failed to go backward") printError(pos) @@ -88,9 +109,10 @@ function stepTo(target) end end -function goTo(target, face) +function go_to(target, face) while target ~= _G.pos do stepTo(target) + -- print(_G.pos, _G.facing) end if face and face ~= _G.facing then if rightOf[_G.facing] == face then @@ -103,7 +125,3 @@ function goTo(target, face) end end end - -function goHome() - goTo(vector.new(0,0,0), "south") -end \ No newline at end of file diff --git a/computer/13/current_fluids b/computer/13/pos.txt similarity index 100% rename from computer/13/current_fluids rename to computer/13/pos.txt diff --git a/computer/13/recipes.lua b/computer/13/recipes.lua index d625c45..b9faacf 100644 --- a/computer/13/recipes.lua +++ b/computer/13/recipes.lua @@ -1,4 +1,4 @@ -pp = require("cc.pretty").pretty_print +pp = require("cc.pretty") require("stringshit") recipes = {} @@ -8,7 +8,6 @@ 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 @@ -17,8 +16,6 @@ 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 @@ -47,7 +44,6 @@ function read_recipe(file) return { product = product, base = base, - yield = yield, intermediate = intermediate or base, repeats = repeats, steps = steps @@ -55,17 +51,18 @@ function read_recipe(file) end function load_recipes() - local file = fs.open("recipes.txt", "r") + file = fs.open("recipes.txt", "r") if not file then print("error: no recipes found") return end recipes = {} while 1 do - local r = read_recipe(file) + r = read_recipe(file) if r == nil then break end recipes[r.product] = r end + return recipes end function ingredientsOf(recipe) @@ -83,6 +80,4 @@ function ingredientsOf(recipe) items[recipe.base] = (items[recipe.base] or 0) + 1 end return items -end - -load_recipes() +end \ No newline at end of file diff --git a/computer/13/recipes.txt b/computer/13/recipes.txt index 69af36e..d9f1a45 100644 --- a/computer/13/recipes.txt +++ b/computer/13/recipes.txt @@ -160,95 +160,3 @@ craft birch_planks birch_slab birch_planks birch_planks nil birch_planks birch_p birch_slab steps: craft birch_planks birch_planks birch_planks - -computer_normal -steps: -craft andesite_alloy andesite_alloy andesite_alloy andesite_alloy polished_rose_quartz andesite_alloy andesite_alloy glass_pane andesite_alloy - -glass_pane -steps: -craft glass glass glass glass glass glass - -copper_casing -base andesite_casing -intermediate incomplete_copper_casing -repeat 3 -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 diff --git a/computer/13/stringshit.lua b/computer/13/stringshit.lua index 2c2f634..9b4cbbe 100644 --- a/computer/13/stringshit.lua +++ b/computer/13/stringshit.lua @@ -1,4 +1,3 @@ - function splitString(source, sep) sep = sep or " " elements = {} diff --git a/computer/13/test.lua b/computer/13/test.lua index 3860de3..8d73ea6 100644 --- a/computer/13/test.lua +++ b/computer/13/test.lua @@ -1,12 +1,3 @@ -function bar() - error("mmm", 4) -end - -function foo() - bar() -end - -while true do -foo() - -- error("aaaaa") -end +s = require("sfx") +s.success() +--s.fail() diff --git a/computer/13/todo.txt b/computer/13/todo.txt deleted file mode 100644 index 9f3e4e0..0000000 --- a/computer/13/todo.txt +++ /dev/null @@ -1,12 +0,0 @@ -sw: fluid basin -hw: spout -sw: spout -casting -stock keeping -multi-item crafting -push items into existing stacks in chest -pull items from multiple stacks if necessary -refuel self -refuel furnace - -delivery turtle diff --git a/computer/13/work.lua b/computer/13/work.lua index c278086..437d8fd 100644 --- a/computer/13/work.lua +++ b/computer/13/work.lua @@ -1,34 +1,29 @@ -pp = require("cc.pretty").pretty_print +pp = require("cc.pretty") +require("keep_stocked") require("recipes") sfx = require("sfx") require("pathfinding") use_machine = require("machines") require("inventory") -keep_stocked = { - kelp = 10, - flint = 10 -} - -resetAllFluidDevices() -goHome() +go_to(vector.new(0,0,0), "south") +recipes = load_recipes() 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] @@ -54,11 +49,11 @@ function doRecipe(recipe) inited = true selectItem(recipe.base, false) end - use_machine[step.machine](step.extra_items, recipe.product, recipe.yield) + use_machine[step.machine](step.extra_items) -- read() end end - goHome() + go_to(vector.new(0,0,0), "south") for i = 1, 16 do if turtle.getItemCount(i) ~= 0 then turtle.select(i) @@ -68,9 +63,10 @@ function doRecipe(recipe) turtle.select(1) end -work_queue = {} -for i = 1, copies do - table.insert(work_queue, recipes[target_product]) + +todo = {} +for i = 1,copies do + table.insert(todo, recipes[target_product]) end function listUncraftable(ingredients) @@ -91,35 +87,47 @@ function tryCreating(recipe) ingredients = ingredientsOf(recipe) missing_ingredients = getMissing(ingredients) if len(missing_ingredients) == 0 then - work_queue[#work_queue] = nil + todo[#todo] = nil turtle.select(1) - -- todo exclude deploy_tool too and make it get its own tool - if recipe.steps[1].machine ~= "craft" and - recipe.steps[1].machine ~= "alloy" - then + if recipe.steps[1].machine ~= "craft" then for item, count in pairs(ingredients) do takeItems(item, count) end end doRecipe(current_recipe) + -- for item, min_count in pairs(getMissing(keep_stocked)) do + -- table.insert(todo, recipes[item]) + -- end return nil end return missing_ingredients end -while #work_queue > 0 do +while #todo > 0 do -- for item, _count in pairs(getMissing(keep_stocked)) do -- print("creating", item, "to keep stock up") -- tryCreating(recipes[item]) -- end - current_recipe = work_queue[#work_queue] + current_recipe = todo[#todo] -- ingredients = ingredientsOf(current_recipe) - pp(ingredients) + pp.pretty_print(ingredients) missing_ingredients = tryCreating(current_recipe) if missing_ingredients then + -- missing_ingredients = getMissing(ingredients) + -- if len(missing_ingredients) == 0 then + -- todo[#todo] = nil + -- turtle.select(1) + -- for item, count in pairs(ingredients) do + -- takeItems(item, count) + -- end + -- doRecipe(current_recipe) + -- for item, min_count in pairs(getMissing(keep_stocked)) do + -- table.insert(todo, recipes[item]) + -- end + -- else 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") @@ -133,10 +141,16 @@ while #work_queue > 0 do for name, count in pairs(missing_ingredients) do if recipes[name] then print("first making", count, name) - table.insert(work_queue, recipes[name]) + -- for i = 1,count do + table.insert(todo, recipes[name]) + -- end end end end + + -- print("aaa") + -- read() end print("done!") sfx.success() + diff --git a/computer/4/build.lua b/computer/4/build.lua index 0a1f97e..6bbb42d 100644 --- a/computer/4/build.lua +++ b/computer/4/build.lua @@ -2,8 +2,7 @@ sf = require("structure") local pf = require("pathfinding") local im = require("inventorymanager") local origin = vector.new(-15,235,120) -function build(chunk) - local x,y,z = stringtovec(chunk) +function build(x,y,z) store = {height = 0} grocerylist = {} for h = 1,8 do @@ -29,13 +28,13 @@ function build(chunk) 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 (count[k] or -1) < v then + if im.count(k) < v then print("not enough "..k.." need "..v.." of it") flag = true end @@ -50,9 +49,11 @@ function build(chunk) return false end pf.to(origin + vector.new(x+1,y+8,z+1)) - for w = 1,8 do - for h = 1,8 do - for d = 1,8 do + 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 if store[h][w][d] then pf.to(origin+vector.new(x+w,y+h,z+d)) im.select(store[h][w][d]) @@ -61,23 +62,55 @@ function build(chunk) 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, tonumber(part)) + table.insert(parts, part) end - return unpack(parts) + 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) end - -repeat - rednet.send(1,nil,"getnexttobuild") - _,chunk = rednet.receive("nexttobuild") -until not build(chunk) - -rednet.send(1,chunk,"failedtobuild") - pf.returnHome() diff --git a/computer/4/copyfile.lua b/computer/4/copyfile.lua new file mode 100644 index 0000000..216705b --- /dev/null +++ b/computer/4/copyfile.lua @@ -0,0 +1,13 @@ +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 diff --git a/computer/4/inventorymanager.lua b/computer/4/inventorymanager.lua index 5ae3504..2656f8e 100644 --- a/computer/4/inventorymanager.lua +++ b/computer/4/inventorymanager.lua @@ -21,29 +21,6 @@ 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 @@ -109,4 +86,4 @@ function pull(name, slot) return error("there is no '"..name.."' in my inventory") end -return {pull=pull,count=count,select=select,countinventory = countinventory} +return {pull=pull,count=count,select=select} diff --git a/computer/4/pathfinding.lua b/computer/4/pathfinding.lua index c0ed19f..dbc3ac0 100644 --- a/computer/4/pathfinding.lua +++ b/computer/4/pathfinding.lua @@ -1,4 +1,4 @@ -home = vector.new(-1, 186, 126) +home = vector.new(-250, 96, 106) up = vector.new(0,1,0) south = vector.new(0,0,1) east = vector.new(1,0,0) diff --git a/computer/4/pathfinding2.lua b/computer/4/pathfinding2.lua index 95e8348..9ce56c6 100644 --- a/computer/4/pathfinding2.lua +++ b/computer/4/pathfinding2.lua @@ -21,11 +21,6 @@ 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() diff --git a/computer/4/startup.lua b/computer/4/startup.lua index 7224ac4..3a4daef 100644 --- a/computer/4/startup.lua +++ b/computer/4/startup.lua @@ -1,84 +1,23 @@ -_G.position = vector.new(-1,186,126) +_G.position = vector.new(-250,96,106) _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]] ---_G.print = new_print ---rednet.host("tomfoolery",os.computerLabel()) ---while true do -function append(tbl,value) - table.insert(tbl,value) - return tbl end -rednet.host("tomfoolery",os.getComputerLabel()) -queue = {} -history = {} -if true then +--_G.print = new_print +rednet.host("tomfoolery",os.computerLabel()) +--while true do +if not _G.thing or true then + _G.thing = true parallel.waitForAll( - 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 + function() while true do read() end end, + function() shell.run("felling") end, + function() while true do id,message = rednet.receive() print(message) end end ) end -rednet.receive() diff --git a/computer/5/startup.lua b/computer/5/startup.lua index 2350f51..35bb202 100644 --- a/computer/5/startup.lua +++ b/computer/5/startup.lua @@ -1,44 +1,3 @@ rednet.open("back") -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) +shell.run("report") +--parallel.waitForAny(func1,func2) diff --git a/ids.json b/ids.json index 59f0513..e019a96 100644 --- a/ids.json +++ b/ids.json @@ -1,4 +1,4 @@ { - "computer": 17, - "disk": 2 + "computer": 15, + "disk": 1 } \ No newline at end of file