init
This commit is contained in:
commit
12ffbdc45d
76 changed files with 79368 additions and 0 deletions
47
computer/0/startup.lua
Normal file
47
computer/0/startup.lua
Normal file
|
@ -0,0 +1,47 @@
|
|||
noteblock = peripheral.wrap("right")
|
||||
speaker = peripheral.wrap("left")
|
||||
instruments = {
|
||||
"harp",
|
||||
"bass",
|
||||
"didgeridoo",
|
||||
"xylophone",
|
||||
"iron_xylophone",
|
||||
"snare",
|
||||
"hat",
|
||||
"basedrum",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit",
|
||||
"bit"
|
||||
}
|
||||
mobs = {
|
||||
"skeleton",
|
||||
"zombie",
|
||||
"pig",
|
||||
"cow",
|
||||
"spider"
|
||||
}
|
||||
function sound()
|
||||
while true do
|
||||
if math.random(10)>5 then
|
||||
speaker.playSound("entity."..mobs[math.random(#mobs)]..".ambient")
|
||||
elseif math.random(100) < 95 then
|
||||
noteblock.setInstrument(instruments[math.random(#instruments)])
|
||||
noteblock.play()
|
||||
noteblock.setNote(math.random(24))
|
||||
elseif math.random(100) < 50 then
|
||||
for i = 1,5 do
|
||||
speaker.playSound("entity.creeper.step")
|
||||
sleep(0.05)
|
||||
end
|
||||
speaker.playSound("entity.creeper.primed")
|
||||
else
|
||||
--speaker.playSound("BOOM")
|
||||
end
|
||||
sleep(math.random(1,20))
|
||||
--os.reboot()
|
||||
end
|
||||
end
|
||||
parallel.waitForAll(sound,sound,sound,sound,sound)
|
||||
peripheral.call("top","turnOn")
|
||||
-- os.reboot()
|
53
computer/10/clear.lua
Normal file
53
computer/10/clear.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
areaYSize = 3*5
|
||||
areaXSize = 3*5
|
||||
areaZSize = 20
|
||||
forward = true
|
||||
|
||||
for z=1,areaZSize do
|
||||
for y=1,areaYSize do
|
||||
for x=1,areaXSize do
|
||||
turtle.dig()
|
||||
if not turtle.forward() then
|
||||
turtle.refuel()
|
||||
turtle.forward()
|
||||
end
|
||||
end
|
||||
if forward then
|
||||
if not turtle.turnRight() then
|
||||
turtle.refuel()
|
||||
turtle.turnRight()
|
||||
end
|
||||
turtle.dig()
|
||||
if not turtle.forward() then
|
||||
turtle.refuel()
|
||||
turtle.forward()
|
||||
end
|
||||
if not turtle.turnRight() then
|
||||
turtle.refuel()
|
||||
turtle.turnRight()
|
||||
end
|
||||
forward = false
|
||||
else
|
||||
if not turtle.turnLeft() then
|
||||
turtle.refuel()
|
||||
turtle.turnLeft()
|
||||
end
|
||||
turtle.dig()
|
||||
if not turtle.forward() then
|
||||
turtle.refuel()
|
||||
turtle.forward()
|
||||
end
|
||||
if not turtle.turnLeft() then
|
||||
turtle.refuel()
|
||||
turtle.turnLeft()
|
||||
end
|
||||
forward = true
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
if not turtle.up() then
|
||||
turtle.refuel()
|
||||
turtle.up()
|
||||
end
|
||||
forward = not forward
|
||||
end
|
1
computer/11/aaa
Normal file
1
computer/11/aaa
Normal file
|
@ -0,0 +1 @@
|
|||
true
|
12
computer/11/follow_rail.lua
Normal file
12
computer/11/follow_rail.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
function step()
|
||||
exists, data = turtle.inspectDown()
|
||||
if exists then
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
function follow_rail()
|
||||
while true do
|
||||
step()
|
||||
end
|
||||
end
|
0
computer/11/miscrent
Normal file
0
computer/11/miscrent
Normal file
5
computer/11/ob_mine.lua
Normal file
5
computer/11/ob_mine.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
while true do
|
||||
turtle.dig()
|
||||
sleep(1)
|
||||
end
|
||||
|
55
computer/11/test.txt
Normal file
55
computer/11/test.txt
Normal file
|
@ -0,0 +1,55 @@
|
|||
<!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>
|
166
computer/11/torment_nexus.lua
Normal file
166
computer/11/torment_nexus.lua
Normal file
|
@ -0,0 +1,166 @@
|
|||
require("follow_rail")
|
||||
|
||||
PROGRESS_FILE = "torment_progress.txt"
|
||||
|
||||
function turnCW(dir)
|
||||
if dir == 1 then
|
||||
turtle.turnRight()
|
||||
elseif dir == -1 then
|
||||
turtle.turnLeft()
|
||||
else
|
||||
error("bad dir " .. tostring(dir))
|
||||
end
|
||||
end
|
||||
|
||||
function station_wheels()
|
||||
print("beginning wheel building step")
|
||||
local file = fs.open(PROGRESS_FILE, "r")
|
||||
local progress = tonumber(file.readAll())
|
||||
file.close()
|
||||
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
|
||||
print(progress, "levels already done")
|
||||
for i = 1,(progress*4) do
|
||||
turtle.down()
|
||||
end
|
||||
|
||||
print("right gear gutter")
|
||||
for i = 1,4 do
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
turtle.dig()
|
||||
end
|
||||
turtle.forward()
|
||||
-- currently under gears, at the bottom of the layer
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.digUp()
|
||||
turtle.up()
|
||||
turtle.turnLeft()
|
||||
turtle.turnLeft()
|
||||
-- cunter right side of wheel section
|
||||
print("cutting wheel section")
|
||||
local dir = 1
|
||||
for slice = 1,16 do
|
||||
for x = 1,6 do
|
||||
turtle.digUp()
|
||||
turtle.digDown()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.digUp()
|
||||
turtle.digDown()
|
||||
turnCW(dir)
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turnCW(dir)
|
||||
dir = -dir
|
||||
end
|
||||
|
||||
print("placing right wheels")
|
||||
turtle.turnLeft()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
-- TODO select wheels
|
||||
turtle.select(1)
|
||||
for w = 1,16 do
|
||||
turtle.back()
|
||||
turtle.place()
|
||||
end
|
||||
print("placing right cogs")
|
||||
-- TODO select cogs
|
||||
turtle.select(2)
|
||||
turtle.back()
|
||||
turtle.place()
|
||||
turtle.up()
|
||||
turtle.place()
|
||||
turtle.up()
|
||||
turtle.place()
|
||||
turtle.down()
|
||||
turtle.down()
|
||||
turtle.down()
|
||||
turtle.place()
|
||||
turtle.up()
|
||||
print("moving to left gutter")
|
||||
turtle.turnLeft()
|
||||
for i = 1, 4 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnRight()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
-- now in a wheel center
|
||||
print("digging water gutter")
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
turtle.down()
|
||||
turtle.digDown()
|
||||
for i = 1,15 do
|
||||
turtle.forward()
|
||||
turtle.digDown()
|
||||
end
|
||||
print("placing left wheels")
|
||||
turtle.up()
|
||||
turtle.turnLeft()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
-- TODO select wheels
|
||||
turtle.select(1)
|
||||
for i = 1,16 do
|
||||
turtle.back()
|
||||
turtle.place()
|
||||
end
|
||||
turtle.back()
|
||||
-- TODO select cogs
|
||||
turtle.select(2)
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
print("placing left cogs")
|
||||
for y = 1,4 do
|
||||
turtle.dig()
|
||||
turtle.place()
|
||||
turtle.digUp()
|
||||
turtle.up()
|
||||
end
|
||||
|
||||
print("returning to start")
|
||||
for i = 1,(progress*4) do
|
||||
turtle.up()
|
||||
end
|
||||
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
|
||||
file = fs.open(PROGRESS_FILE, "w")
|
||||
file.write(tostring(progress + 1))
|
||||
file.close()
|
||||
end
|
||||
function station_wood() end
|
||||
function station_andesite() end
|
||||
|
||||
function run()
|
||||
--station_wood()
|
||||
--follow_rail()
|
||||
station_wheels()
|
||||
--follow_rail()
|
||||
--station_andesite()r
|
||||
--follow_rail()
|
||||
end
|
||||
|
||||
run()
|
1
computer/11/torment_progress.txt
Normal file
1
computer/11/torment_progress.txt
Normal file
|
@ -0,0 +1 @@
|
|||
13
|
8
computer/12/startup.lua
Normal file
8
computer/12/startup.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
s = peripheral.wrap("left")
|
||||
while 1 do
|
||||
sleep(10 + math.random(10))
|
||||
for i = 0, math.random(3) + 2 do
|
||||
s.playSound("block.gravel.break")
|
||||
sleep(math.random(10)/20 + 0.2)
|
||||
end
|
||||
end
|
3
computer/13/.settings
Normal file
3
computer/13/.settings
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
[ "motd.enable" ] = false,
|
||||
}
|
101
computer/13/inventory.lua
Normal file
101
computer/13/inventory.lua
Normal file
|
@ -0,0 +1,101 @@
|
|||
pp = require("cc.pretty")
|
||||
|
||||
pFront = peripheral.wrap("front")
|
||||
pDown = peripheral.wrap("bottom")
|
||||
|
||||
function findItems(item_list, target)
|
||||
for i, v in pairs(item_list) do
|
||||
if stripModname(v.name) == target then
|
||||
return i
|
||||
end
|
||||
end
|
||||
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 insertForwardDepot(count)
|
||||
turtle.dropDown(count)
|
||||
peripheral.call("front", "pullItem", "bottom")
|
||||
end
|
||||
|
||||
function takeForwardDepot()
|
||||
-- pDown.pullItems("front", slot, 64, 1)
|
||||
peripheral.call("front", "pushItem", "bottom")
|
||||
turtle.suckDown()
|
||||
end
|
||||
|
||||
|
||||
function takeItems(type, count)
|
||||
item_list = pFront.list()
|
||||
slot = findItems(item_list, type)
|
||||
|
||||
if slot == nil then
|
||||
printError("could not find item " .. type .. " in chest")
|
||||
return false
|
||||
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
|
||||
if turtle.getItemCount(i) == 0 then
|
||||
turtle.select(i)
|
||||
return
|
||||
end
|
||||
end
|
||||
printError("no empty slot found")
|
||||
return
|
||||
end
|
||||
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
|
||||
turtle.select(i)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
printError("missing item", name, "nbt=", has_nbt)
|
||||
end
|
||||
|
||||
function getMissing(needed_items)
|
||||
missing = {}
|
||||
for name,count in pairs(needed_items) do
|
||||
missing[name] = count
|
||||
end
|
||||
target_contents = peripheral.call("front", "list")
|
||||
|
||||
for _, target_item in pairs(target_contents) do
|
||||
for name, missing_count in pairs(missing) do
|
||||
if stripModname(target_item.name) == name then
|
||||
missing[name] = missing_count - target_item.count
|
||||
if missing[name] < 1 then
|
||||
missing[name] = nil
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
pp.pretty_print(missing)
|
||||
return missing
|
||||
end
|
||||
|
4
computer/13/keep_stocked.lua
Normal file
4
computer/13/keep_stocked.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
keep_stocked = {
|
||||
kelp = 10,
|
||||
flint = 10
|
||||
}
|
111
computer/13/machines.lua
Normal file
111
computer/13/machines.lua
Normal file
|
@ -0,0 +1,111 @@
|
|||
require("inventory")
|
||||
require("pathfinding")
|
||||
|
||||
function mill(extra_items)
|
||||
-- 0.4 second/item
|
||||
go_to(vector.new(-4,0,0),"south")
|
||||
item_count = 0
|
||||
if turtle.getItemCount() ~= 0 then
|
||||
item_count = 1
|
||||
end
|
||||
insertForward(1, 1)
|
||||
for _,item in pairs(extra_items) do
|
||||
item_count = item_count + item.count
|
||||
selectItem(item.name)
|
||||
insertForward(1, item.count)
|
||||
end
|
||||
print(item_count,"items")
|
||||
sleep(0.5)
|
||||
sleep(0.4 * item_count)
|
||||
for i = 1, 10 do
|
||||
takeForward(i)
|
||||
end
|
||||
end
|
||||
function deploy(extra_items, nbt)
|
||||
-- extra_items should only be one item
|
||||
go_to(vector.new(2,0,0), "south")
|
||||
insertForwardDepot(1)
|
||||
goUp()
|
||||
goUp()
|
||||
selectItem(extra_items[1].name, nbt)
|
||||
turtle.dropUp(1)
|
||||
peripheral.call("front", "pullItem", "top")
|
||||
|
||||
goDown()
|
||||
goDown()
|
||||
takeForwardDepot()
|
||||
end
|
||||
function deploy_tool(extra_items)
|
||||
deploy(extra_items, true)
|
||||
goUp()
|
||||
goUp()
|
||||
peripheral.call("front", "pushItem", "top")
|
||||
turtle.suckUp()
|
||||
end
|
||||
function furnace(extra_items)
|
||||
go_to(vector.new(1,0,0), "south")
|
||||
item_count = 0
|
||||
if turtle.getItemCount() ~= 0 then
|
||||
item_count = 1
|
||||
end
|
||||
insertForward(1, 1)
|
||||
for _,item in pairs(extra_items) do
|
||||
item_count = item_count + item.count
|
||||
selectItem(item.name)
|
||||
insertForward(1, item.count)
|
||||
end
|
||||
wait_time = 10 * item_count
|
||||
-- peripheral.call("front", "")
|
||||
-- TODO refuel
|
||||
sleep(wait_time)
|
||||
takeForward(3)
|
||||
end
|
||||
function press(_)
|
||||
go_to(vector.new(-1,0,0), "south")
|
||||
insertForwardDepot(1)
|
||||
sleep(1)
|
||||
takeForwardDepot()
|
||||
end
|
||||
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)
|
||||
insertForward(nil, item.count)
|
||||
end
|
||||
goUp()
|
||||
goUp()
|
||||
goDown()
|
||||
goDown()
|
||||
sleep(10)
|
||||
-- todo wait until ingredients are gone
|
||||
takeForward(10)
|
||||
end
|
||||
function craft(extra_items)
|
||||
slot = 5
|
||||
for _, item in pairs(extra_items) do
|
||||
slot = slot + 1
|
||||
if slot == 9 then
|
||||
slot = 10
|
||||
elseif slot == 13 then
|
||||
slot = 14
|
||||
end
|
||||
if item.name ~= "nil" then
|
||||
selectItem(item.name)
|
||||
turtle.transferTo(slot, 1)
|
||||
end
|
||||
end
|
||||
turtle.craft()
|
||||
end
|
||||
|
||||
return {
|
||||
mill = mill,
|
||||
deploy = deploy,
|
||||
deploy_tool = deploy_tool,
|
||||
furnace = furnace,
|
||||
press = press,
|
||||
compact = compact,
|
||||
mix = mix,
|
||||
craft = craft
|
||||
}
|
60
computer/13/make_belts.lua
Normal file
60
computer/13/make_belts.lua
Normal file
|
@ -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")
|
128
computer/13/pathfinding.lua
Normal file
128
computer/13/pathfinding.lua
Normal file
|
@ -0,0 +1,128 @@
|
|||
pp = require("cc.pretty")
|
||||
|
||||
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)
|
||||
|
||||
local rightOf = {
|
||||
south = "west",
|
||||
west = "north",
|
||||
north = "east",
|
||||
east = "south"
|
||||
}
|
||||
|
||||
local leftOf = {
|
||||
west = "south",
|
||||
north = "west",
|
||||
east = "north",
|
||||
south = "east"
|
||||
}
|
||||
|
||||
local vecOf = {
|
||||
north = vector.new(0,0,-1),
|
||||
south = vector.new(0,0,1),
|
||||
east = vector.new(1,0,0),
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
function goDown()
|
||||
if turtle.down() then
|
||||
_G.pos.y = _G.pos.y - 1
|
||||
savePos()
|
||||
else
|
||||
printError("failed to go down")
|
||||
printError(pos)
|
||||
end
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
function goBack()
|
||||
if turtle.back() then
|
||||
_G.pos = _G.pos - vecOf[_G.facing]
|
||||
savePos()
|
||||
else
|
||||
printError("failed to go backward")
|
||||
printError(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function stepTo(target)
|
||||
local delta = target - _G.pos
|
||||
-- print(delta)
|
||||
if delta.y > 0 then
|
||||
goUp()
|
||||
elseif delta.y < 0 then
|
||||
goDown()
|
||||
elseif delta:dot(vecOf[_G.facing]) > 0 then
|
||||
goForward()
|
||||
elseif delta:dot(vecOf[_G.facing]:cross(up)) > 0 then
|
||||
goRight()
|
||||
else
|
||||
goLeft()
|
||||
end
|
||||
end
|
||||
|
||||
function go_to(target, face)
|
||||
while target ~= _G.pos do
|
||||
stepTo(target)
|
||||
-- print(_G.pos, _G.facing, target, face)
|
||||
print(_G.pos, _G.facing)
|
||||
end
|
||||
if face and face ~= _G.facing then
|
||||
if rightOf[_G.facing] == face then
|
||||
goRight()
|
||||
elseif leftOf[_G.facing] == face then
|
||||
goLeft()
|
||||
else
|
||||
goRight()
|
||||
goRight()
|
||||
end
|
||||
end
|
||||
end
|
1
computer/13/pos.txt
Normal file
1
computer/13/pos.txt
Normal file
|
@ -0,0 +1 @@
|
|||
0 0 0 south
|
83
computer/13/recipes.lua
Normal file
83
computer/13/recipes.lua
Normal file
|
@ -0,0 +1,83 @@
|
|||
pp = require("cc.pretty")
|
||||
require("stringshit")
|
||||
recipes = {}
|
||||
|
||||
function read_recipe(file)
|
||||
product = file.readLine()
|
||||
if product == nil then return nil end
|
||||
base = nil
|
||||
intermediate = nil
|
||||
repeats = 1
|
||||
while 1 do
|
||||
line = file.readLine()
|
||||
if string.sub(line, 1, 5) == "base " then
|
||||
base = string.sub(line, 6)
|
||||
elseif string.sub(line, 1, 13) == "intermediate " then
|
||||
intermediate = string.sub(line, 14)
|
||||
elseif string.sub(line, 1, 7) == "repeat " then
|
||||
repeats = tonumber(string.sub(line, 8))
|
||||
elseif line == "steps:" then
|
||||
break
|
||||
end
|
||||
end
|
||||
steps = {}
|
||||
while 1 do
|
||||
line = file.readLine()
|
||||
if line == "" or line == nil then
|
||||
break
|
||||
end
|
||||
|
||||
words = splitString(line)
|
||||
extra_items = {}
|
||||
for i = 2, #words do
|
||||
itemdata = splitString(words[i], ":")
|
||||
table.insert(extra_items, {
|
||||
name = itemdata[1],
|
||||
count = tonumber(itemdata[2] or 1)
|
||||
})
|
||||
end
|
||||
table.insert(steps, {
|
||||
machine = words[1],
|
||||
extra_items = extra_items
|
||||
})
|
||||
end
|
||||
return {
|
||||
product = product,
|
||||
base = base,
|
||||
intermediate = intermediate or base,
|
||||
repeats = repeats,
|
||||
steps = steps
|
||||
}
|
||||
end
|
||||
|
||||
function load_recipes()
|
||||
file = fs.open("recipes.txt", "r")
|
||||
if not file then
|
||||
print("error: no recipes found")
|
||||
return
|
||||
end
|
||||
recipes = {}
|
||||
while 1 do
|
||||
r = read_recipe(file)
|
||||
if r == nil then break end
|
||||
recipes[r.product] = r
|
||||
end
|
||||
return recipes
|
||||
end
|
||||
|
||||
function ingredientsOf(recipe)
|
||||
items = {}
|
||||
for step_index = 1,#recipe.steps do
|
||||
step = recipe.steps[step_index]
|
||||
for _,item in pairs(step.extra_items) do
|
||||
if item.name ~= "nil" then
|
||||
old_sum = items[item.name] or 0
|
||||
items[item.name] = old_sum + item.count * recipe.repeats
|
||||
end
|
||||
end
|
||||
end
|
||||
if recipe.base then
|
||||
items[recipe.base] = (items[recipe.base] or 0) + 1
|
||||
end
|
||||
return items
|
||||
end
|
117
computer/13/recipes.txt
Normal file
117
computer/13/recipes.txt
Normal file
|
@ -0,0 +1,117 @@
|
|||
belt_connector
|
||||
base dried_kelp
|
||||
intermediate dried_kelp
|
||||
repeat 3
|
||||
steps:
|
||||
deploy rubber
|
||||
press
|
||||
deploy dried_kelp
|
||||
press
|
||||
|
||||
dried_kelp
|
||||
steps:
|
||||
furnace kelp:8
|
||||
|
||||
rubber
|
||||
steps:
|
||||
mix sap:2
|
||||
|
||||
polished_rose_quartz
|
||||
base rose_quartz
|
||||
steps:
|
||||
deploy_tool sand_paper
|
||||
|
||||
rose_quartz
|
||||
steps:
|
||||
mix quartz redstone:8
|
||||
|
||||
sand_paper
|
||||
steps:
|
||||
craft sand paper
|
||||
|
||||
paper
|
||||
base sugar_cane
|
||||
steps:
|
||||
press
|
||||
|
||||
glass
|
||||
steps:
|
||||
furnace sand:8
|
||||
|
||||
sand
|
||||
steps:
|
||||
mill gravel:2
|
||||
|
||||
fluid_pipe
|
||||
steps:
|
||||
craft nil copper_sheet nil rubber rubber rubber nil copper_sheet
|
||||
|
||||
copper_sheet
|
||||
base copper_ingot
|
||||
steps:
|
||||
press
|
||||
|
||||
andesite_alloy
|
||||
steps:
|
||||
craft andesite_alloy_block
|
||||
|
||||
note_block
|
||||
steps:
|
||||
craft birch_planks birch_planks birch_planks birch_planks redstone birch_planks birch_planks birch_planks birch_planks
|
||||
|
||||
birch_planks
|
||||
steps:
|
||||
craft birch_log
|
||||
|
||||
redstone
|
||||
steps:
|
||||
craft redstone_block
|
||||
|
||||
speaker
|
||||
steps:
|
||||
craft andesite_alloy andesite_alloy andesite_alloy andesite_alloy note_block andesite_alloy andesite_alloy polished_rose_quartz andesite_alloy
|
||||
|
||||
gearbox
|
||||
steps:
|
||||
craft nil cogwheel nil cogwheel andesite_casing cogwheel nil cogwheel
|
||||
|
||||
andesite_casing
|
||||
base stripped_birch_log
|
||||
steps:
|
||||
deploy andesite_alloy
|
||||
|
||||
stripped_birch_log
|
||||
base birch_log
|
||||
steps:
|
||||
deploy_tool flint_knife
|
||||
|
||||
stick
|
||||
steps:
|
||||
craft birch_planks nil nil birch_planks
|
||||
|
||||
iron_sheet
|
||||
base iron_ingot
|
||||
steps:
|
||||
press
|
||||
|
||||
iron_ingot
|
||||
steps:
|
||||
craft iron_block
|
||||
|
||||
cogwheel
|
||||
steps:
|
||||
craft andesite_alloy bronze_sheet
|
||||
|
||||
flint_knife
|
||||
steps:
|
||||
craft flint nil nil stick
|
||||
|
||||
flint
|
||||
base gravel
|
||||
steps:
|
||||
deploy_tool flint_knife
|
||||
|
||||
gravel
|
||||
base cobblestone
|
||||
steps:
|
||||
mill
|
17
computer/13/sfx.lua
Normal file
17
computer/13/sfx.lua
Normal file
|
@ -0,0 +1,17 @@
|
|||
speaker = peripheral.wrap("left")
|
||||
volume = 2
|
||||
|
||||
return {
|
||||
success = function ()
|
||||
speaker.playNote("pling",volume,4)
|
||||
sleep(0.1)
|
||||
speaker.playNote("pling",volume,8)
|
||||
sleep(0.1)
|
||||
speaker.playNote("pling",volume,16)
|
||||
end,
|
||||
fail = function ()
|
||||
speaker.playNote("didgeridoo", volume, 6)
|
||||
sleep(0.2)
|
||||
speaker.playNote("didgeridoo", volume, 3)
|
||||
end
|
||||
}
|
25
computer/13/stringshit.lua
Normal file
25
computer/13/stringshit.lua
Normal file
|
@ -0,0 +1,25 @@
|
|||
function splitString(source, sep)
|
||||
sep = sep or " "
|
||||
elements = {}
|
||||
for str in string.gmatch(source, "([^"..sep.."]+)") do
|
||||
table.insert(elements, str)
|
||||
end
|
||||
return elements
|
||||
end
|
||||
|
||||
function stripModname(name)
|
||||
parts = splitString(name, ":")
|
||||
if #parts ~= 2 then
|
||||
printError("modname split failed")
|
||||
printError(name)
|
||||
end
|
||||
return parts[2]
|
||||
end
|
||||
|
||||
function len(table)
|
||||
l = 0
|
||||
for _, _ in pairs(table) do
|
||||
l = l + 1
|
||||
end
|
||||
return l
|
||||
end
|
3
computer/13/test.lua
Normal file
3
computer/13/test.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
s = require("sfx")
|
||||
-- s.success()
|
||||
s.fail()
|
154
computer/13/work.lua
Normal file
154
computer/13/work.lua
Normal file
|
@ -0,0 +1,154 @@
|
|||
pp = require("cc.pretty")
|
||||
require("keep_stocked")
|
||||
require("recipes")
|
||||
sfx = require("sfx")
|
||||
require("pathfinding")
|
||||
use_machine = require("machines")
|
||||
require("inventory")
|
||||
|
||||
go_to(vector.new(0,0,0), "south")
|
||||
recipes = load_recipes()
|
||||
|
||||
print("known recipes:\n")
|
||||
for k,_ in pairs(recipes) do
|
||||
write(k)
|
||||
write(", ")
|
||||
end
|
||||
write("\nchoose one: ")
|
||||
function completion(partial)
|
||||
list = {}
|
||||
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]
|
||||
copies = input[2] or 1
|
||||
|
||||
|
||||
if recipes[target_product] == nil then
|
||||
print("I don't know how to make that, sorry")
|
||||
return
|
||||
end
|
||||
|
||||
-- pp.pretty_print(ingredientsOf(recipes[target_product]))
|
||||
-- pp.pretty_print(recipes)
|
||||
|
||||
|
||||
function doRecipe(recipe)
|
||||
inited = false
|
||||
for i = 1, recipe.repeats do
|
||||
for _, step in pairs(recipe.steps) do
|
||||
if inited then
|
||||
selectItem(recipe.intermediate, true)
|
||||
else
|
||||
inited = true
|
||||
selectItem(recipe.base, false)
|
||||
end
|
||||
use_machine[step.machine](step.extra_items)
|
||||
-- read()
|
||||
end
|
||||
end
|
||||
go_to(vector.new(0,0,0), "south")
|
||||
for i = 1, 16 do
|
||||
if turtle.getItemCount(i) ~= 0 then
|
||||
turtle.select(i)
|
||||
turtle.drop()
|
||||
end
|
||||
end
|
||||
turtle.select(1)
|
||||
end
|
||||
|
||||
|
||||
todo = {}
|
||||
for i = 1,copies do
|
||||
table.insert(todo, recipes[target_product])
|
||||
end
|
||||
|
||||
function listUncraftable(ingredients)
|
||||
wait_for = {}
|
||||
if len(ingredients) == 0 then
|
||||
return wait_for
|
||||
end
|
||||
for name, count in pairs(ingredients) do
|
||||
print("missing", count, name)
|
||||
if recipes[name] == nil then
|
||||
wait_for[name] = count
|
||||
end
|
||||
end
|
||||
return wait_for
|
||||
end
|
||||
|
||||
function tryCreating(recipe)
|
||||
ingredients = ingredientsOf(recipe)
|
||||
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
|
||||
return nil
|
||||
end
|
||||
return missing_ingredients
|
||||
end
|
||||
|
||||
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 = todo[#todo]
|
||||
-- ingredients = ingredientsOf(current_recipe)
|
||||
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
|
||||
print("please supply", count, name, "manually")
|
||||
end
|
||||
print("press return to continue, q to quit")
|
||||
sfx.fail()
|
||||
if read() == "q" then
|
||||
return
|
||||
end
|
||||
missing_ingredients = getMissing(ingredients)
|
||||
wait_for = listUncraftable(missing_ingredients)
|
||||
end
|
||||
for name, count in pairs(missing_ingredients) do
|
||||
if recipes[name] then
|
||||
print("first making", count, name)
|
||||
-- for i = 1,count do
|
||||
table.insert(todo, recipes[name])
|
||||
-- end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- print("aaa")
|
||||
-- read()
|
||||
end
|
||||
print("done!")
|
||||
sfx.success()
|
||||
|
13
computer/14/startup.lua
Normal file
13
computer/14/startup.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
while true do
|
||||
tanks = peripheral.call("right","tanks")
|
||||
lava = 0
|
||||
for i,v in pairs(tanks) do
|
||||
if v.name == "minecraft:lava" then
|
||||
lava = lava + v.amount
|
||||
end
|
||||
end
|
||||
|
||||
if lava > 300 then
|
||||
peripheral.call("right","pushFluid","left",lava - 300)
|
||||
end
|
||||
end
|
4
computer/15/startup.lua
Normal file
4
computer/15/startup.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
while true do
|
||||
peripheral.call("bottom","turnOn")
|
||||
sleep(0.05)
|
||||
end
|
9
computer/2/steal.lua
Normal file
9
computer/2/steal.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
local goal = vector.new(-313, 103, 192)
|
||||
print("where am i?")
|
||||
|
||||
local coords = read(
|
||||
|
||||
|
||||
|
||||
|
||||
|
9
computer/3/automine.lua
Normal file
9
computer/3/automine.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
while true do
|
||||
shell.execute("mine")
|
||||
if turtle.getFuelLevel() > 100 then
|
||||
shell.execute("clear")
|
||||
else
|
||||
return
|
||||
end
|
||||
sleep(1)
|
||||
end
|
116
computer/3/build.lua
Normal file
116
computer/3/build.lua
Normal file
|
@ -0,0 +1,116 @@
|
|||
sf = require("structure")
|
||||
local pf = require("pathfinding")
|
||||
local im = require("inventorymanager")
|
||||
local origin = vector.new(-15,235,120)
|
||||
function build(x,y,z)
|
||||
store = {height = 0}
|
||||
grocerylist = {}
|
||||
for h = 1,8 do
|
||||
store[h] = {width = 0}
|
||||
for w = 1,8 do
|
||||
store[h][w] = {depth = 0}
|
||||
for d = 1,8 do
|
||||
bool, data = sf.blockat(x+w,z+d,y+h)
|
||||
if bool then
|
||||
store[h][w][d] = data
|
||||
store[h][w].depth = d
|
||||
grocerylist[store[h][w][d]] =
|
||||
(grocerylist[store[h][w][d]] or 0)+1
|
||||
end
|
||||
end
|
||||
if store[h][w].depth>0 then
|
||||
store[h].width = w
|
||||
end
|
||||
end
|
||||
if store[h].width>0 then
|
||||
store.height = h
|
||||
end
|
||||
end
|
||||
if store.height==0 then
|
||||
--print("cell at",x,y,z,"is done")
|
||||
removechunk(x,y,z)
|
||||
return true
|
||||
|
||||
end
|
||||
flag = false
|
||||
for k,v in pairs(grocerylist) do
|
||||
if im.count(k) < v then
|
||||
print("not enough "..k.." need "..v.." of it")
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
if turtle.getFuelLevel() < 2000 then
|
||||
print("too lazy for that")
|
||||
flag = true
|
||||
end
|
||||
if flag then
|
||||
pf.to(vector.new(pf.home.x,position.y+8,pf.home.z))
|
||||
pf.returnHome()
|
||||
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
|
||||
if store[h][w][d] then
|
||||
pf.to(origin+vector.new(x+w,y+h,z+d))
|
||||
im.select(store[h][w][d])
|
||||
turtle.placeDown()
|
||||
end
|
||||
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)
|
||||
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)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
8
computer/3/clear.lua
Normal file
8
computer/3/clear.lua
Normal file
|
@ -0,0 +1,8 @@
|
|||
pf = require("pathfinding")
|
||||
chest = vector.new(-251,96,99)
|
||||
pf.to(chest)
|
||||
for i = 1,16 do
|
||||
turtle.select(i)
|
||||
turtle.dropDown()
|
||||
end
|
||||
pf.returnHome()
|
9
computer/3/copyfile.lua
Normal file
9
computer/3/copyfile.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
file = fs.open("tobuild","r")
|
||||
line = file.readLine()
|
||||
while line do
|
||||
rednet.send(4,line)
|
||||
line = file.readLine()
|
||||
end
|
||||
write("line".."\n")
|
||||
rednet.send(4,"done")
|
||||
file.close()
|
45
computer/3/felling.lua
Normal file
45
computer/3/felling.lua
Normal file
|
@ -0,0 +1,45 @@
|
|||
trees = {
|
||||
vector.new(-261, 95, 119),
|
||||
vector.new(-258, 95, 124),
|
||||
vector.new(-264, 95, 124),
|
||||
vector.new(-265, 95, 121),
|
||||
vector.new(-263, 94, 116),
|
||||
vector.new(-265, 94, 107),
|
||||
vector.new(-263, 94, 104),
|
||||
vector.new(-261,94,94),
|
||||
vector.new(-259,94,100),
|
||||
vector.new(-257,94,103)
|
||||
}
|
||||
pf = require("pathfinding")
|
||||
im = require("inventorymanager")
|
||||
function fell(index)
|
||||
im.select("minecraft:birch_sapling")
|
||||
print("going towards tree")
|
||||
pf.lookat(trees[index or math.random(#trees)])
|
||||
has, data = turtle.inspect()
|
||||
print(has,data)
|
||||
if
|
||||
has and data.name ==
|
||||
"minecraft:birch_log"
|
||||
then
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
height = 0
|
||||
while turtle.digUp() do
|
||||
turtle.up()
|
||||
height = height + 1
|
||||
end
|
||||
for i = 1,height do
|
||||
turtle.down()
|
||||
end
|
||||
turtle.back()
|
||||
end
|
||||
turtle.place()
|
||||
end
|
||||
|
||||
for i = 1,#trees do
|
||||
fell(i)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
||||
|
2
computer/3/gohome.lua
Normal file
2
computer/3/gohome.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
pf = require("pathfinding")
|
||||
pf.returnHome()
|
89
computer/3/inventorymanager.lua
Normal file
89
computer/3/inventorymanager.lua
Normal file
|
@ -0,0 +1,89 @@
|
|||
function count(name)
|
||||
local value = 0
|
||||
for i = 1,16 do
|
||||
local item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
value = value + item.count
|
||||
end
|
||||
if item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(.1)
|
||||
pack = peripheral.wrap("top")
|
||||
items = pack.list()
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
value = value + v.count
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
function select(name)
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if not item then
|
||||
flag = true
|
||||
end
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if flag and item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(0.1)
|
||||
items = peripheral.call("top","list")
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
turtle.suckUp(64)
|
||||
break
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
print("no"..name.."found")
|
||||
return false
|
||||
end
|
||||
|
||||
function pull(name, slot)
|
||||
slot = slot or turtle.getSelectedSlot()
|
||||
turtle.select(slot)
|
||||
i = 1
|
||||
item = turtle.getItemDetail(slot)
|
||||
while item and item.name~=name and i <=16 do
|
||||
turtle.transferTo(i)
|
||||
item = turtle.getItemDetail(slot)
|
||||
i = i+1
|
||||
end
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
turtle.transferTo(slot)
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
turtle.select(slot)
|
||||
if flag then
|
||||
return turtle.getItemCount(slot)
|
||||
end
|
||||
return error("there is no '"..name.."' in my inventory")
|
||||
end
|
||||
|
||||
return {pull=pull,count=count,select=select}
|
79
computer/3/mine.lua
Normal file
79
computer/3/mine.lua
Normal file
|
@ -0,0 +1,79 @@
|
|||
im = require("inventorymanager")
|
||||
local height = 0
|
||||
function mineLayer()
|
||||
rednet.broadcast("i can halt now")
|
||||
id, message = rednet.receive(nil, 5)
|
||||
if message == "halt" then
|
||||
print("was ordered to stop")
|
||||
return false
|
||||
end
|
||||
if turtle.getFuelLevel() < 500 then
|
||||
print("too tired to mine")
|
||||
return false
|
||||
end
|
||||
local slots = 0
|
||||
for i = 1,16 do
|
||||
if turtle.getItemCount(i) == 0 then
|
||||
slots = slots +1
|
||||
end
|
||||
end
|
||||
|
||||
if slots < 8 then
|
||||
print("not confident i can pick it all up :(")
|
||||
return false
|
||||
end
|
||||
status = "dropping down"
|
||||
print(status)
|
||||
while turtle.down() do
|
||||
height = height+1
|
||||
end
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
height = height+1
|
||||
status = "mining layer:"..height
|
||||
print(status)
|
||||
for i = 1,16 do
|
||||
|
||||
for j = 1,15 do
|
||||
hit, below = turtle.inspectDown()
|
||||
if below.name == "minecraft:water" then
|
||||
im.pull("minecraft:cobblestone")
|
||||
turtle.placeDown()
|
||||
end
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
end
|
||||
if( math.mod(i,2) == 0) then
|
||||
turtle.turnLeft()
|
||||
turtle.dig()
|
||||
turtle.placeDown()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
else
|
||||
turtle.turnRight()
|
||||
turtle.dig()
|
||||
turtle.placeDown()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
end
|
||||
end
|
||||
turtle.turnLeft()
|
||||
for i = 1,16 do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnRight()
|
||||
return true
|
||||
end
|
||||
function gohome()
|
||||
status = "resurfacing"
|
||||
print(status)
|
||||
for i = 1,height do
|
||||
turtle.up()
|
||||
end
|
||||
turtle.back()
|
||||
end
|
||||
turtle.forward()
|
||||
while mineLayer() do
|
||||
|
||||
end
|
||||
gohome()
|
92
computer/3/moss.lua
Normal file
92
computer/3/moss.lua
Normal file
|
@ -0,0 +1,92 @@
|
|||
function plant()
|
||||
im = require("inventorymanager")
|
||||
mosscount = im.pull("minecraft:moss_block",1)
|
||||
mealcount = im.pull("minecraft:bone_meal",2)
|
||||
if mosscount <= 1 then
|
||||
return false, "not enough moss"
|
||||
end
|
||||
if mealcount <= 16 then
|
||||
return false, "not enough bone meal"
|
||||
end
|
||||
if turtle.getFuelLevel() < 500 then
|
||||
return false, "not enough fuel"
|
||||
end
|
||||
while turtle.down() do
|
||||
height = height+1
|
||||
end
|
||||
turtle.up()
|
||||
for i = 1,4 do
|
||||
for j = 1,5 do
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.select(1)
|
||||
turtle.placeUp()
|
||||
turtle.select(2)
|
||||
turtle.placeUp()
|
||||
turtle.digUp()
|
||||
turtle.forward()
|
||||
--turtle.forward()
|
||||
end
|
||||
if math.mod(i,2) == 1 then
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
else
|
||||
turtle.turnLeft()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
end
|
||||
end
|
||||
turtle.turnLeft()
|
||||
for i = 1,16 do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnRight()
|
||||
return true
|
||||
end
|
||||
function clear()
|
||||
turtle.digDown()
|
||||
turtle.down()
|
||||
for i = 1,16 do
|
||||
for j = 1,15 do
|
||||
turtle.dig()
|
||||
turtle.digDown()
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.digDown()
|
||||
if math.mod(i,2) == 1 then
|
||||
turtle.turnRight()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.turnRight()
|
||||
else
|
||||
turtle.turnLeft()
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.turnLeft()
|
||||
end
|
||||
end
|
||||
turtle.turnLeft()
|
||||
for i = 1,16 do
|
||||
turtle.forward()
|
||||
end
|
||||
turtle.turnRight()
|
||||
return true
|
||||
end
|
||||
|
||||
height = 0
|
||||
turtle.forward()
|
||||
if plant() then
|
||||
clear()
|
||||
end
|
||||
for i = 1,height do
|
||||
turtle.up()
|
||||
end
|
||||
turtle.back()
|
||||
|
113
computer/3/pathfinding.lua
Normal file
113
computer/3/pathfinding.lua
Normal file
|
@ -0,0 +1,113 @@
|
|||
home = vector.new(-250, 96, 108)
|
||||
up = vector.new(0,1,0)
|
||||
south = vector.new(0,0,1)
|
||||
east = vector.new(1,0,0)
|
||||
function greedystep(target)
|
||||
if (target-position):dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
position = position + facing
|
||||
elseif position + facing ==target then
|
||||
return false, "the target is occupied"
|
||||
else
|
||||
|
||||
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp>0 then
|
||||
turtle.turnRight()
|
||||
facing = facing:cross(up)
|
||||
elseif temp<0 then
|
||||
turtle.turnLeft()
|
||||
facing = - facing:cross(up)
|
||||
else
|
||||
temp = (target-position):dot(up)
|
||||
if temp>0 then
|
||||
if turtle.up() then
|
||||
position = position+up
|
||||
end
|
||||
elseif temp<0 then
|
||||
if turtle.down() then
|
||||
position = position-up
|
||||
end
|
||||
else
|
||||
error("help me im stuck")
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
--we did not need to move in that direction
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp > 0 then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
elseif temp < 0 then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
else
|
||||
if (target-position):dot(facing) == 0 then
|
||||
temp = (target-position):dot(up)
|
||||
if temp == 0 then
|
||||
return false,"the target has been reached"
|
||||
else
|
||||
if temp > 0 then
|
||||
if turtle.up() then
|
||||
position:add(up)
|
||||
else
|
||||
position.sub(up)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(position,facing)
|
||||
_G.position = position
|
||||
_G.facing = facing
|
||||
return true
|
||||
end
|
||||
greedystep = require("pathfinding2").greedystep
|
||||
function to(target)
|
||||
print(tostring(target))
|
||||
while greedystep(target) do
|
||||
end
|
||||
end
|
||||
function returnhome()
|
||||
to(home)
|
||||
if facing == south then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
end
|
||||
if facing == east then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
if facing == -south then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
_G.facing = facing
|
||||
_G.position = position
|
||||
end
|
||||
function lookat(target)
|
||||
print("lookat")
|
||||
while (position+facing).x ~= target.x
|
||||
or (position+facing).z ~= target.z do
|
||||
greedystep(target)
|
||||
end
|
||||
print("temp")
|
||||
temp = target.y-position.y
|
||||
while target.y > position.y do
|
||||
turtle.up()
|
||||
position = position+up
|
||||
end
|
||||
while target.y < position.y do
|
||||
turtle.down()
|
||||
position = position-up
|
||||
end
|
||||
_G.position = position
|
||||
end
|
||||
return {to = to,
|
||||
returnHome=returnhome,
|
||||
lookat = lookat,
|
||||
home = home}
|
40
computer/3/pathfinding2.lua
Normal file
40
computer/3/pathfinding2.lua
Normal file
|
@ -0,0 +1,40 @@
|
|||
up = vector.new(0,1,0)
|
||||
function greedystep(target)
|
||||
--rednet.broadcast(position)
|
||||
vec = target-position
|
||||
if target == position then
|
||||
return false
|
||||
end
|
||||
if vec.y > 0 then
|
||||
if turtle.up() then
|
||||
_G.position = position + up
|
||||
return true
|
||||
end
|
||||
elseif vec.y < 0 then
|
||||
if turtle.down() then
|
||||
_G.position = position - up
|
||||
return true
|
||||
end
|
||||
end
|
||||
if vec:dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
_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()
|
||||
_G.facing = facing:cross(up)
|
||||
return true
|
||||
else
|
||||
turtle.turnLeft()
|
||||
_G.facing = - facing:cross(up)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return {greedystep = greedystep}
|
53
computer/3/removeemptychunks.lua
Normal file
53
computer/3/removeemptychunks.lua
Normal file
|
@ -0,0 +1,53 @@
|
|||
|
||||
function stringtovec(str)
|
||||
parts = {}
|
||||
for part in string.gmatch(str,"([^,])") do
|
||||
table.insert(parts,part)
|
||||
end
|
||||
return vector.new(unpack(parts))
|
||||
end
|
||||
sf = require("structure")
|
||||
|
||||
function removechunks()
|
||||
file = fs.open("tobuild","r")
|
||||
lines = {}
|
||||
line = file.readLine()
|
||||
|
||||
while line do
|
||||
i = math.mod((i or 0)+1,100)
|
||||
if i == 0 then sleep(0.05) end
|
||||
xyz = stringtovec(line)
|
||||
if not chunkisempty(xyz) then
|
||||
table.insert(lines,line)
|
||||
print(line)
|
||||
end
|
||||
line = file.readLine()
|
||||
end
|
||||
file.close()
|
||||
fs.delete("tobuildcopy")
|
||||
file = fs.open("tobuildcopy","w")
|
||||
for i,line in ipairs(lines) do
|
||||
file.writeLine(line)
|
||||
print(line)
|
||||
if math.mod(i,100) == 0 then sleep(0.05) end
|
||||
end
|
||||
file.close()
|
||||
end
|
||||
function chunkisempty(vec)
|
||||
x,y,z = vec.x,vec.y,vec.z
|
||||
for w = 1,8 do
|
||||
for h = 1,8 do
|
||||
for d = 1,8 do
|
||||
bool,block = sf.blockat(x+w,z+d,y+h)
|
||||
if bool then
|
||||
print(block)
|
||||
return false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
--print(chunkisempty(vector.new(-150,0,0)))
|
||||
removechunks()
|
2
computer/3/report.lua
Normal file
2
computer/3/report.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
print("i believe i am at", position)
|
||||
print("and looking", facing)
|
9
computer/3/schematicbuilder.lua
Normal file
9
computer/3/schematicbuilder.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
file = fs.open("tobuild","w")
|
||||
for i = -80,80,8 do
|
||||
for j = -150,150,8 do
|
||||
for k = -150,150,8 do
|
||||
file.writeLine(j..","..i..","..k)
|
||||
end
|
||||
end
|
||||
end
|
||||
file.close()
|
14
computer/3/startup.lua
Normal file
14
computer/3/startup.lua
Normal file
|
@ -0,0 +1,14 @@
|
|||
_G.position = vector.new(-250,96,108)
|
||||
_G.facing = vector.new(-1,0,0)
|
||||
rednet.open("left")
|
||||
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
|
||||
|
106
computer/3/structure
Normal file
106
computer/3/structure
Normal file
|
@ -0,0 +1,106 @@
|
|||
v = 0.55
|
||||
X = vector.new(0,-0.92836897,0.28899258)
|
||||
Y = vector.new(-0.94538565,0.06753674,0.21695717)
|
||||
Z = vector.new(0.23369713,0.28899258,0.92836897)
|
||||
r1 = 40
|
||||
r2 = 10
|
||||
a = {1,-2,3,1,0,-1,-1,2,0,0}
|
||||
b = {-1.2314479651658854,-1.5872747213793104,0.04683103835434217,1.9674748180974897,1.153043896136355,-0.10238369338887907,1.7042206782594087,-1.242120063575402,0.5603127510670854,2.66234724349466}
|
||||
c = {4.321312860949716,2.116116100402904,2.7194094703705165,3.0821962706516177,5.994638109825947,0.8990716738267982,0.06271719387139103,0.7355961093238955,2.1949825399445198,5.522266625688897}
|
||||
l = vector.new(0.57735027,0.57735027,0.57735027)
|
||||
function surface(uv)
|
||||
--print("surface")
|
||||
total = 0
|
||||
for i = 1,#a do
|
||||
total = total + math.sin(a[i]*uv.x+math.floor(.5+b[i])*uv.y+c[i])
|
||||
end
|
||||
return math.pow(math.mod(total,2)-1,2)
|
||||
end
|
||||
function map(xyz)
|
||||
--print("map")
|
||||
local u = math.atan2(
|
||||
xyz:dot(X),xyz:dot(Y)
|
||||
)
|
||||
local v = math.atan2(
|
||||
xyz:dot(Z:normalize()),
|
||||
math.sqrt(
|
||||
xyz:dot(X)^2+xyz:dot(X)^2
|
||||
)
|
||||
-r1
|
||||
)
|
||||
return vector.new(u,v)
|
||||
end
|
||||
function lerp(x,y,t)
|
||||
--print("lerp")
|
||||
return x - (x-y)*t
|
||||
end
|
||||
function project(x,y)
|
||||
--print("project x:",x," y:",y)
|
||||
return x-(
|
||||
y*(
|
||||
(
|
||||
x:dot(
|
||||
y
|
||||
)
|
||||
)/(
|
||||
y:dot(
|
||||
y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
function setmag(x,y)
|
||||
--print("setmag")
|
||||
return x:normalize()*y
|
||||
end
|
||||
function f(x,y,z)
|
||||
--print("f")
|
||||
xyz = vector.new(x,y,z)
|
||||
dist = (xyz-setmag(project(xyz,Z),r1)):length()-r2
|
||||
detail = lerp(5*surface(map(xyz)),r1,v)
|
||||
return dist-detail
|
||||
end
|
||||
function blockat(x,y,z)
|
||||
--print("blockat")
|
||||
if f(x,y,z) < 0 then
|
||||
flag = false
|
||||
for k,v in pairs({
|
||||
{1,0,0},
|
||||
{0,1,0},
|
||||
{0,0,1},
|
||||
{-1,0,0},
|
||||
{0,-1,0},
|
||||
{0,0,-1}
|
||||
})do
|
||||
flag = f(x+v[1],y+v[2],z+v[3])>0 or flag
|
||||
end
|
||||
if flag then
|
||||
dx = f(x+0.1,y,z)-f(x-0.1,y,z)
|
||||
dy = f(x,y+0.1,z)-f(x,y-0.1,z)
|
||||
dz = f(x,y,z+0.1)-f(x,y,z-0.1)
|
||||
normal = vector.new(dx,dy,dz):normalize()
|
||||
if normal:dot(vector.new(0,0,1)) > 0.5 then
|
||||
return true, "minecraft:moss_block"
|
||||
end
|
||||
dot = normal:dot(l)
|
||||
lighttable = {
|
||||
{-.7,"minecraft:cobbled_deepslate"},
|
||||
{-.5,"minecraft:andesite"},
|
||||
{-.3,"minecraft:tuff"},
|
||||
{0,"minecraft:cobblestone"},
|
||||
{.5,"minecraft:diorite"},
|
||||
{.7,"create:cut_limestone"},
|
||||
{2,"minecraft:calcite"}
|
||||
}
|
||||
for i,v in ipairs(lighttable) do
|
||||
if dot < v[1] then
|
||||
return true, v[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(x,y,z,"is not part of the set")
|
||||
return false
|
||||
end
|
||||
return {blockat = blockat}
|
23772
computer/3/tobuild
Normal file
23772
computer/3/tobuild
Normal file
File diff suppressed because it is too large
Load diff
23772
computer/3/tobuildcopy
Normal file
23772
computer/3/tobuildcopy
Normal file
File diff suppressed because it is too large
Load diff
1
computer/3/tocopycopy
Normal file
1
computer/3/tocopycopy
Normal file
File diff suppressed because one or more lines are too long
2
computer/3/treelocations.lua
Normal file
2
computer/3/treelocations.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
return
|
||||
vector.new(0,0,0)
|
34
computer/4/bake.lua
Normal file
34
computer/4/bake.lua
Normal file
|
@ -0,0 +1,34 @@
|
|||
chest = peripheral.wrap("front")
|
||||
|
||||
local function bake()
|
||||
for i = 2,16 do
|
||||
turtle.select(i)
|
||||
turtle.drop()
|
||||
end
|
||||
turtle.suck()
|
||||
items = chest.list()
|
||||
local pretty = require "cc.pretty"
|
||||
pretty.pretty_print(items)
|
||||
for k,v in pairs(items) do
|
||||
if v.name == "minecraft:wheat" then
|
||||
chest.pushItems("front",k,64,1)
|
||||
end
|
||||
end
|
||||
turtle.drop()
|
||||
turtle.select(2)
|
||||
count = chest.getItemDetail(1).count/3
|
||||
turtle.suck(count)
|
||||
turtle.select(5)
|
||||
turtle.suck(count)
|
||||
turtle.select(6)
|
||||
turtle.suck(count)
|
||||
for i = 1, count do
|
||||
turtle.select(1)
|
||||
turtle.placeDown()
|
||||
turtle.craft()
|
||||
turtle.select(3)
|
||||
turtle.drop()
|
||||
end
|
||||
end
|
||||
bake()
|
||||
|
116
computer/4/build.lua
Normal file
116
computer/4/build.lua
Normal file
|
@ -0,0 +1,116 @@
|
|||
sf = require("structure")
|
||||
local pf = require("pathfinding")
|
||||
local im = require("inventorymanager")
|
||||
local origin = vector.new(-15,235,120)
|
||||
function build(x,y,z)
|
||||
store = {height = 0}
|
||||
grocerylist = {}
|
||||
for h = 1,8 do
|
||||
store[h] = {width = 0}
|
||||
for w = 1,8 do
|
||||
store[h][w] = {depth = 0}
|
||||
for d = 1,8 do
|
||||
bool, data = sf.blockat(x+w,z+d,y+h)
|
||||
if bool then
|
||||
store[h][w][d] = data
|
||||
store[h][w].depth = d
|
||||
grocerylist[store[h][w][d]] =
|
||||
(grocerylist[store[h][w][d]] or 0)+1
|
||||
end
|
||||
end
|
||||
if store[h][w].depth>0 then
|
||||
store[h].width = w
|
||||
end
|
||||
end
|
||||
if store[h].width>0 then
|
||||
store.height = h
|
||||
end
|
||||
end
|
||||
if store.height==0 then
|
||||
--print("cell at",x,y,z,"is done")
|
||||
removechunk(x,y,z)
|
||||
return true
|
||||
|
||||
end
|
||||
flag = false
|
||||
for k,v in pairs(grocerylist) do
|
||||
if im.count(k) < v then
|
||||
print("not enough "..k.." need "..v.." of it")
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
if turtle.getFuelLevel() < 2000 then
|
||||
print("too lazy for that")
|
||||
flag = true
|
||||
end
|
||||
if flag then
|
||||
pf.to(vector.new(pf.home.x,position.y+8,pf.home.z))
|
||||
pf.returnHome()
|
||||
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
|
||||
if store[h][w][d] then
|
||||
pf.to(origin+vector.new(x+w,y+h,z+d))
|
||||
im.select(store[h][w][d])
|
||||
turtle.placeDown()
|
||||
end
|
||||
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)
|
||||
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)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
13
computer/4/copyfile.lua
Normal file
13
computer/4/copyfile.lua
Normal file
|
@ -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
|
9
computer/4/drain.lua
Normal file
9
computer/4/drain.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
while true do
|
||||
turtle.dig()
|
||||
turtle.place()
|
||||
--sleep(1.5)
|
||||
--turtle.turnLeft()
|
||||
turtle.digUp()
|
||||
turtle.placeUp()
|
||||
--turtle.turnRight()
|
||||
end
|
45
computer/4/felling
Normal file
45
computer/4/felling
Normal file
|
@ -0,0 +1,45 @@
|
|||
trees = {
|
||||
vector.new(-261, 95, 119),
|
||||
vector.new(-258, 95, 124),
|
||||
vector.new(-264, 95, 124),
|
||||
vector.new(-265, 95, 121),
|
||||
vector.new(-263, 94, 116),
|
||||
vector.new(-265, 94, 107),
|
||||
vector.new(-263, 94, 104),
|
||||
vector.new(-261,94,94),
|
||||
vector.new(-259,94,100),
|
||||
vector.new(-257,94,103)
|
||||
}
|
||||
pf = require("pathfinding")
|
||||
im = require("inventorymanager")
|
||||
function fell(index)
|
||||
im.select("techreborn:rubber_sapling")
|
||||
print("going towards tree")
|
||||
pf.lookat(trees[index or math.random(#trees)])
|
||||
has, data = turtle.inspect()
|
||||
print(has,data)
|
||||
if
|
||||
has and data.name ==
|
||||
"techreborn:rubber_log"
|
||||
then
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
height = 0
|
||||
while turtle.digUp() do
|
||||
turtle.up()
|
||||
height = height + 1
|
||||
end
|
||||
for i = 1,height do
|
||||
turtle.down()
|
||||
end
|
||||
turtle.back()
|
||||
end
|
||||
turtle.place()
|
||||
end
|
||||
|
||||
for i = 1,#trees do
|
||||
fell(i)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
||||
|
89
computer/4/inventorymanager.lua
Normal file
89
computer/4/inventorymanager.lua
Normal file
|
@ -0,0 +1,89 @@
|
|||
function count(name)
|
||||
local value = 0
|
||||
for i = 1,16 do
|
||||
local item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
value = value + item.count
|
||||
end
|
||||
if item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(.1)
|
||||
pack = peripheral.wrap("top")
|
||||
items = pack.list()
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
value = value + v.count
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
function select(name)
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if not item then
|
||||
flag = true
|
||||
end
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if flag and item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(0.1)
|
||||
items = peripheral.call("top","list")
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
turtle.suckUp(64)
|
||||
break
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
print("no"..name.."found")
|
||||
return false
|
||||
end
|
||||
|
||||
function pull(name, slot)
|
||||
slot = slot or turtle.getSelectedSlot()
|
||||
turtle.select(slot)
|
||||
i = 1
|
||||
item = turtle.getItemDetail(slot)
|
||||
while item and item.name~=name and i <=16 do
|
||||
turtle.transferTo(i)
|
||||
item = turtle.getItemDetail(slot)
|
||||
i = i+1
|
||||
end
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
turtle.transferTo(slot)
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
turtle.select(slot)
|
||||
if flag then
|
||||
return turtle.getItemCount(slot)
|
||||
end
|
||||
return error("there is no '"..name.."' in my inventory")
|
||||
end
|
||||
|
||||
return {pull=pull,count=count,select=select}
|
113
computer/4/pathfinding.lua
Normal file
113
computer/4/pathfinding.lua
Normal file
|
@ -0,0 +1,113 @@
|
|||
home = vector.new(-250, 96, 106)
|
||||
up = vector.new(0,1,0)
|
||||
south = vector.new(0,0,1)
|
||||
east = vector.new(1,0,0)
|
||||
function greedystep(target)
|
||||
if (target-position):dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
position = position + facing
|
||||
elseif position + facing ==target then
|
||||
return false, "the target is occupied"
|
||||
else
|
||||
|
||||
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp>0 then
|
||||
turtle.turnRight()
|
||||
facing = facing:cross(up)
|
||||
elseif temp<0 then
|
||||
turtle.turnLeft()
|
||||
facing = - facing:cross(up)
|
||||
else
|
||||
temp = (target-position):dot(up)
|
||||
if temp>0 then
|
||||
if turtle.up() then
|
||||
position = position+up
|
||||
end
|
||||
elseif temp<0 then
|
||||
if turtle.down() then
|
||||
position = position-up
|
||||
end
|
||||
else
|
||||
error("help me im stuck")
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
--we did not need to move in that direction
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp > 0 then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
elseif temp < 0 then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
else
|
||||
if (target-position):dot(facing) == 0 then
|
||||
temp = (target-position):dot(up)
|
||||
if temp == 0 then
|
||||
return false,"the target has been reached"
|
||||
else
|
||||
if temp > 0 then
|
||||
if turtle.up() then
|
||||
position:add(up)
|
||||
else
|
||||
position.sub(up)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(position,facing)
|
||||
_G.position = position
|
||||
_G.facing = facing
|
||||
return true
|
||||
end
|
||||
greedystep = require("pathfinding2").greedystep
|
||||
function to(target)
|
||||
print(tostring(target))
|
||||
while greedystep(target) do
|
||||
end
|
||||
end
|
||||
function returnhome()
|
||||
to(home)
|
||||
if facing == south then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
end
|
||||
if facing == east then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
if facing == -south then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
_G.facing = facing
|
||||
_G.position = position
|
||||
end
|
||||
function lookat(target)
|
||||
print("lookat")
|
||||
while (position+facing).x ~= target.x
|
||||
or (position+facing).z ~= target.z do
|
||||
greedystep(target)
|
||||
end
|
||||
print("temp")
|
||||
temp = target.y-position.y
|
||||
while target.y > position.y do
|
||||
turtle.up()
|
||||
position = position+up
|
||||
end
|
||||
while target.y < position.y do
|
||||
turtle.down()
|
||||
position = position-up
|
||||
end
|
||||
_G.position = position
|
||||
end
|
||||
return {to = to,
|
||||
returnHome=returnhome,
|
||||
lookat = lookat,
|
||||
home = home}
|
35
computer/4/pathfinding2.lua
Normal file
35
computer/4/pathfinding2.lua
Normal file
|
@ -0,0 +1,35 @@
|
|||
up = vector.new(0,1,0)
|
||||
function greedystep(target)
|
||||
--rednet.broadcast(position)
|
||||
vec = target-position
|
||||
if target == position then
|
||||
return false
|
||||
end
|
||||
if vec.y > 0 then
|
||||
if turtle.up() then
|
||||
_G.position = position + up
|
||||
return true
|
||||
end
|
||||
elseif vec.y < 0 then
|
||||
if turtle.down() then
|
||||
_G.position = position - up
|
||||
return true
|
||||
end
|
||||
end
|
||||
if vec:dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
_G.position = position + facing
|
||||
return true
|
||||
end
|
||||
end
|
||||
if vec:dot(facing:cross(up)) > 0 then
|
||||
turtle.turnRight()
|
||||
_G.facing = facing:cross(up)
|
||||
return true
|
||||
else
|
||||
turtle.turnLeft()
|
||||
_G.facing = - facing:cross(up)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return {greedystep = greedystep}
|
2
computer/4/rednerd.lua
Normal file
2
computer/4/rednerd.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
while true do
|
||||
{os.pullEvent("rednet_message")}
|
2
computer/4/report.lua
Normal file
2
computer/4/report.lua
Normal file
|
@ -0,0 +1,2 @@
|
|||
print("i believe i am at", position)
|
||||
print("and looking", facing)
|
19
computer/4/startup.lua
Normal file
19
computer/4/startup.lua
Normal file
|
@ -0,0 +1,19 @@
|
|||
_G.position = vector.new(-250,96,106)
|
||||
_G.facing = vector.new(-1,0,0)
|
||||
rednet.open("left")
|
||||
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
|
||||
while true do
|
||||
parallel.waitForAny(
|
||||
require("rednerd")
|
||||
--shell.run("shell")
|
||||
)
|
||||
end
|
106
computer/4/structure
Normal file
106
computer/4/structure
Normal file
|
@ -0,0 +1,106 @@
|
|||
v = 0.55
|
||||
X = vector.new(0,-0.92836897,0.28899258)
|
||||
Y = vector.new(-0.94538565,0.06753674,0.21695717)
|
||||
Z = vector.new(0.23369713,0.28899258,0.92836897)
|
||||
r1 = 40
|
||||
r2 = 10
|
||||
a = {1,-2,3,1,0,-1,-1,2,0,0}
|
||||
b = {-1.2314479651658854,-1.5872747213793104,0.04683103835434217,1.9674748180974897,1.153043896136355,-0.10238369338887907,1.7042206782594087,-1.242120063575402,0.5603127510670854,2.66234724349466}
|
||||
c = {4.321312860949716,2.116116100402904,2.7194094703705165,3.0821962706516177,5.994638109825947,0.8990716738267982,0.06271719387139103,0.7355961093238955,2.1949825399445198,5.522266625688897}
|
||||
l = vector.new(0.57735027,0.57735027,0.57735027)
|
||||
function surface(uv)
|
||||
--print("surface")
|
||||
total = 0
|
||||
for i = 1,#a do
|
||||
total = total + math.sin(a[i]*uv.x+math.floor(.5+b[i])*uv.y+c[i])
|
||||
end
|
||||
return math.pow(math.mod(total,2)-1,2)
|
||||
end
|
||||
function map(xyz)
|
||||
--print("map")
|
||||
local u = math.atan2(
|
||||
xyz:dot(X),xyz:dot(Y)
|
||||
)
|
||||
local v = math.atan2(
|
||||
xyz:dot(Z:normalize()),
|
||||
math.sqrt(
|
||||
xyz:dot(X)^2+xyz:dot(X)^2
|
||||
)
|
||||
-r1
|
||||
)
|
||||
return vector.new(u,v)
|
||||
end
|
||||
function lerp(x,y,t)
|
||||
--print("lerp")
|
||||
return x - (x-y)*t
|
||||
end
|
||||
function project(x,y)
|
||||
--print("project x:",x," y:",y)
|
||||
return x-(
|
||||
y*(
|
||||
(
|
||||
x:dot(
|
||||
y
|
||||
)
|
||||
)/(
|
||||
y:dot(
|
||||
y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
function setmag(x,y)
|
||||
--print("setmag")
|
||||
return x:normalize()*y
|
||||
end
|
||||
function f(x,y,z)
|
||||
--print("f")
|
||||
xyz = vector.new(x,y,z)
|
||||
dist = (xyz-setmag(project(xyz,Z),r1)):length()-r2
|
||||
detail = lerp(5*surface(map(xyz)),r1,v)
|
||||
return dist-detail
|
||||
end
|
||||
function blockat(x,y,z)
|
||||
--print("blockat")
|
||||
if f(x,y,z) < 0 then
|
||||
flag = false
|
||||
for k,v in pairs({
|
||||
{1,0,0},
|
||||
{0,1,0},
|
||||
{0,0,1},
|
||||
{-1,0,0},
|
||||
{0,-1,0},
|
||||
{0,0,-1}
|
||||
})do
|
||||
flag = f(x+v[1],y+v[2],z+v[3])>0 or flag
|
||||
end
|
||||
if flag then
|
||||
dx = f(x+0.1,y,z)-f(x-0.1,y,z)
|
||||
dy = f(x,y+0.1,z)-f(x,y-0.1,z)
|
||||
dz = f(x,y,z+0.1)-f(x,y,z-0.1)
|
||||
normal = vector.new(dx,dy,dz):normalize()
|
||||
if normal:dot(vector.new(0,0,1)) > 0.5 then
|
||||
return true, "minecraft:moss_block"
|
||||
end
|
||||
dot = normal:dot(l)
|
||||
lighttable = {
|
||||
{-.7,"minecraft:cobbled_deepslate"},
|
||||
{-.5,"minecraft:andesite"},
|
||||
{-.3,"minecraft:tuff"},
|
||||
{0,"minecraft:cobblestone"},
|
||||
{.5,"minecraft:diorite"},
|
||||
{.7,"create:cut_limestone"},
|
||||
{2,"minecraft:calcite"}
|
||||
}
|
||||
for i,v in ipairs(lighttable) do
|
||||
if dot < v[1] then
|
||||
return true, v[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(x,y,z,"is not part of the set")
|
||||
return false
|
||||
end
|
||||
return {blockat = blockat}
|
3841
computer/4/tobuild
Normal file
3841
computer/4/tobuild
Normal file
File diff suppressed because it is too large
Load diff
3
computer/5/eraselogs.lua
Normal file
3
computer/5/eraselogs.lua
Normal file
|
@ -0,0 +1,3 @@
|
|||
fs.delete("logs")
|
||||
fs.open("logs","w").close()
|
||||
|
5
computer/5/halt.lua
Normal file
5
computer/5/halt.lua
Normal file
|
@ -0,0 +1,5 @@
|
|||
|
||||
while message~="i can halt now" do
|
||||
rednet.send(id,"halt")
|
||||
id,message = rednet.receve()
|
||||
end
|
15251
computer/5/logs
Normal file
15251
computer/5/logs
Normal file
File diff suppressed because one or more lines are too long
12
computer/5/report.lua
Normal file
12
computer/5/report.lua
Normal file
|
@ -0,0 +1,12 @@
|
|||
while true do
|
||||
id,mess,dist = rednet.receive()
|
||||
_,_,_,_,_,dist = os.pullEvent("modem_message")
|
||||
print(id..":"..tostring(mess)..tostring(dist))
|
||||
--str = mess.x..","..mess.y..","..mess.z
|
||||
--print(str)
|
||||
file = fs.open("logs","a")
|
||||
file.write(tostring(mess).."\n")
|
||||
file.close()
|
||||
|
||||
--term.clear()
|
||||
end
|
11
computer/5/startup.lua
Normal file
11
computer/5/startup.lua
Normal file
|
@ -0,0 +1,11 @@
|
|||
rednet.open("back")
|
||||
--shell.run("report")
|
||||
func1 = function()
|
||||
sleep(2)
|
||||
print("func1 terminate")
|
||||
end
|
||||
func2 = function()
|
||||
sleep(1)
|
||||
print("func2 teminate")
|
||||
end
|
||||
parallel.waitForAny(func1,func2)
|
4
computer/6/programs/test.lua
Normal file
4
computer/6/programs/test.lua
Normal file
|
@ -0,0 +1,4 @@
|
|||
while true do
|
||||
redstone.setOutput("left", not redstone.getOutput("left"))
|
||||
sleep(0.5)
|
||||
end
|
116
disk/0/build
Normal file
116
disk/0/build
Normal file
|
@ -0,0 +1,116 @@
|
|||
sf = require("structure")
|
||||
local pf = require("pathfinding")
|
||||
local im = require("inventorymanager")
|
||||
local origin = vector.new(-15,235,120)
|
||||
function build(x,y,z)
|
||||
store = {height = 0}
|
||||
grocerylist = {}
|
||||
for h = 1,8 do
|
||||
store[h] = {width = 0}
|
||||
for w = 1,8 do
|
||||
store[h][w] = {depth = 0}
|
||||
for d = 1,8 do
|
||||
bool, data = sf.blockat(x+w,z+d,y+h)
|
||||
if bool then
|
||||
store[h][w][d] = data
|
||||
store[h][w].depth = d
|
||||
grocerylist[store[h][w][d]] =
|
||||
(grocerylist[store[h][w][d]] or 0)+1
|
||||
end
|
||||
end
|
||||
if store[h][w].depth>0 then
|
||||
store[h].width = w
|
||||
end
|
||||
end
|
||||
if store[h].width>0 then
|
||||
store.height = h
|
||||
end
|
||||
end
|
||||
if store.height==0 then
|
||||
--print("cell at",x,y,z,"is done")
|
||||
removechunk(x,y,z)
|
||||
return true
|
||||
|
||||
end
|
||||
flag = false
|
||||
for k,v in pairs(grocerylist) do
|
||||
if im.count(k) < v then
|
||||
print("not enough "..k.." need "..v.." of it")
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
if turtle.getFuelLevel() < 2000 then
|
||||
print("too lazy for that")
|
||||
flag = true
|
||||
end
|
||||
if flag then
|
||||
pf.to(vector.new(pf.home.x,position.y+8,pf.home.z))
|
||||
pf.returnHome()
|
||||
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
|
||||
if store[h][w][d] then
|
||||
pf.to(origin+vector.new(x+w,y+h,z+d))
|
||||
im.select(store[h][w][d])
|
||||
turtle.placeDown()
|
||||
end
|
||||
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)
|
||||
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)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
45
disk/0/felling
Normal file
45
disk/0/felling
Normal file
|
@ -0,0 +1,45 @@
|
|||
trees = {
|
||||
vector.new(-261, 95, 119),
|
||||
vector.new(-258, 95, 124),
|
||||
vector.new(-264, 95, 124),
|
||||
vector.new(-265, 95, 121),
|
||||
vector.new(-263, 94, 116),
|
||||
vector.new(-265, 94, 107),
|
||||
vector.new(-263, 94, 104),
|
||||
vector.new(-261,94,94),
|
||||
vector.new(-259,94,100),
|
||||
vector.new(-257,94,103)
|
||||
}
|
||||
pf = require("pathfinding")
|
||||
im = require("inventorymanager")
|
||||
function fell(index)
|
||||
im.select("minecraft:birch_sapling")
|
||||
print("going towards tree")
|
||||
pf.lookat(trees[index or math.random(#trees)])
|
||||
has, data = turtle.inspect()
|
||||
print(has,data)
|
||||
if
|
||||
has and data.name ==
|
||||
"minecraft:birch_log"
|
||||
then
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
height = 0
|
||||
while turtle.digUp() do
|
||||
turtle.up()
|
||||
height = height + 1
|
||||
end
|
||||
for i = 1,height do
|
||||
turtle.down()
|
||||
end
|
||||
turtle.back()
|
||||
end
|
||||
turtle.place()
|
||||
end
|
||||
|
||||
for i = 1,#trees do
|
||||
fell(i)
|
||||
end
|
||||
pf.returnHome()
|
||||
|
||||
|
89
disk/0/im
Normal file
89
disk/0/im
Normal file
|
@ -0,0 +1,89 @@
|
|||
function count(name)
|
||||
local value = 0
|
||||
for i = 1,16 do
|
||||
local item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
value = value + item.count
|
||||
end
|
||||
if item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(.1)
|
||||
pack = peripheral.wrap("top")
|
||||
items = pack.list()
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
value = value + v.count
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
end
|
||||
end
|
||||
return value
|
||||
end
|
||||
function select(name)
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if not item then
|
||||
flag = true
|
||||
end
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if flag and item and item.name == "packages:package" then
|
||||
turtle.select(i)
|
||||
turtle.placeUp()
|
||||
sleep(0.1)
|
||||
items = peripheral.call("top","list")
|
||||
for i,v in pairs(items) do
|
||||
if v.name == name then
|
||||
turtle.suckUp(64)
|
||||
break
|
||||
end
|
||||
end
|
||||
turtle.digUp()
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
print("no"..name.."found")
|
||||
return false
|
||||
end
|
||||
|
||||
function pull(name, slot)
|
||||
slot = slot or turtle.getSelectedSlot()
|
||||
turtle.select(slot)
|
||||
i = 1
|
||||
item = turtle.getItemDetail(slot)
|
||||
while item and item.name~=name and i <=16 do
|
||||
turtle.transferTo(i)
|
||||
item = turtle.getItemDetail(slot)
|
||||
i = i+1
|
||||
end
|
||||
local flag = false
|
||||
for i = 1,16 do
|
||||
item = turtle.getItemDetail(i)
|
||||
if item and item.name == name then
|
||||
turtle.select(i)
|
||||
turtle.transferTo(slot)
|
||||
flag = true
|
||||
end
|
||||
end
|
||||
turtle.select(slot)
|
||||
if flag then
|
||||
return turtle.getItemCount(slot)
|
||||
end
|
||||
return error("there is no '"..name.."' in my inventory")
|
||||
end
|
||||
|
||||
return {pull=pull,count=count,select=select}
|
113
disk/0/pf
Normal file
113
disk/0/pf
Normal file
|
@ -0,0 +1,113 @@
|
|||
home = vector.new(-250, 96, 108)
|
||||
up = vector.new(0,1,0)
|
||||
south = vector.new(0,0,1)
|
||||
east = vector.new(1,0,0)
|
||||
function greedystep(target)
|
||||
if (target-position):dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
position = position + facing
|
||||
elseif position + facing ==target then
|
||||
return false, "the target is occupied"
|
||||
else
|
||||
|
||||
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp>0 then
|
||||
turtle.turnRight()
|
||||
facing = facing:cross(up)
|
||||
elseif temp<0 then
|
||||
turtle.turnLeft()
|
||||
facing = - facing:cross(up)
|
||||
else
|
||||
temp = (target-position):dot(up)
|
||||
if temp>0 then
|
||||
if turtle.up() then
|
||||
position = position+up
|
||||
end
|
||||
elseif temp<0 then
|
||||
if turtle.down() then
|
||||
position = position-up
|
||||
end
|
||||
else
|
||||
error("help me im stuck")
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
--we did not need to move in that direction
|
||||
temp = (target-position):dot(facing:cross(up))
|
||||
if temp > 0 then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
elseif temp < 0 then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
else
|
||||
if (target-position):dot(facing) == 0 then
|
||||
temp = (target-position):dot(up)
|
||||
if temp == 0 then
|
||||
return false,"the target has been reached"
|
||||
else
|
||||
if temp > 0 then
|
||||
if turtle.up() then
|
||||
position:add(up)
|
||||
else
|
||||
position.sub(up)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(position,facing)
|
||||
_G.position = position
|
||||
_G.facing = facing
|
||||
return true
|
||||
end
|
||||
greedystep = require("pathfinding2").greedystep
|
||||
function to(target)
|
||||
print(tostring(target))
|
||||
while greedystep(target) do
|
||||
end
|
||||
end
|
||||
function returnhome()
|
||||
to(home)
|
||||
if facing == south then
|
||||
turtle.turnRight()
|
||||
facing=facing:cross(up)
|
||||
end
|
||||
if facing == east then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
if facing == -south then
|
||||
turtle.turnLeft()
|
||||
facing=facing:cross(-up)
|
||||
end
|
||||
_G.facing = facing
|
||||
_G.position = position
|
||||
end
|
||||
function lookat(target)
|
||||
print("lookat")
|
||||
while (position+facing).x ~= target.x
|
||||
or (position+facing).z ~= target.z do
|
||||
greedystep(target)
|
||||
end
|
||||
print("temp")
|
||||
temp = target.y-position.y
|
||||
while target.y > position.y do
|
||||
turtle.up()
|
||||
position = position+up
|
||||
end
|
||||
while target.y < position.y do
|
||||
turtle.down()
|
||||
position = position-up
|
||||
end
|
||||
_G.position = position
|
||||
end
|
||||
return {to = to,
|
||||
returnHome=returnhome,
|
||||
lookat = lookat,
|
||||
home = home}
|
35
disk/0/pf2
Normal file
35
disk/0/pf2
Normal file
|
@ -0,0 +1,35 @@
|
|||
up = vector.new(0,1,0)
|
||||
function greedystep(target)
|
||||
--rednet.broadcast(position)
|
||||
vec = target-position
|
||||
if target == position then
|
||||
return false
|
||||
end
|
||||
if vec.y > 0 then
|
||||
if turtle.up() then
|
||||
_G.position = position + up
|
||||
return true
|
||||
end
|
||||
elseif vec.y < 0 then
|
||||
if turtle.down() then
|
||||
_G.position = position - up
|
||||
return true
|
||||
end
|
||||
end
|
||||
if vec:dot(facing) > 0 then
|
||||
if turtle.forward() then
|
||||
_G.position = position + facing
|
||||
return true
|
||||
end
|
||||
end
|
||||
if vec:dot(facing:cross(up)) > 0 then
|
||||
turtle.turnRight()
|
||||
_G.facing = facing:cross(up)
|
||||
return true
|
||||
else
|
||||
turtle.turnLeft()
|
||||
_G.facing = - facing:cross(up)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return {greedystep = greedystep}
|
2
disk/0/report
Normal file
2
disk/0/report
Normal file
|
@ -0,0 +1,2 @@
|
|||
print("i believe i am at", position)
|
||||
print("and looking", facing)
|
14
disk/0/startup
Normal file
14
disk/0/startup
Normal file
|
@ -0,0 +1,14 @@
|
|||
_G.position = vector.new(-250,96,108)
|
||||
_G.facing = vector.new(-1,0,0)
|
||||
rednet.open("left")
|
||||
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
|
||||
|
106
disk/0/structure
Normal file
106
disk/0/structure
Normal file
|
@ -0,0 +1,106 @@
|
|||
v = 0.55
|
||||
X = vector.new(0,-0.92836897,0.28899258)
|
||||
Y = vector.new(-0.94538565,0.06753674,0.21695717)
|
||||
Z = vector.new(0.23369713,0.28899258,0.92836897)
|
||||
r1 = 40
|
||||
r2 = 10
|
||||
a = {1,-2,3,1,0,-1,-1,2,0,0}
|
||||
b = {-1.2314479651658854,-1.5872747213793104,0.04683103835434217,1.9674748180974897,1.153043896136355,-0.10238369338887907,1.7042206782594087,-1.242120063575402,0.5603127510670854,2.66234724349466}
|
||||
c = {4.321312860949716,2.116116100402904,2.7194094703705165,3.0821962706516177,5.994638109825947,0.8990716738267982,0.06271719387139103,0.7355961093238955,2.1949825399445198,5.522266625688897}
|
||||
l = vector.new(0.57735027,0.57735027,0.57735027)
|
||||
function surface(uv)
|
||||
--print("surface")
|
||||
total = 0
|
||||
for i = 1,#a do
|
||||
total = total + math.sin(a[i]*uv.x+math.floor(.5+b[i])*uv.y+c[i])
|
||||
end
|
||||
return math.pow(math.mod(total,2)-1,2)
|
||||
end
|
||||
function map(xyz)
|
||||
--print("map")
|
||||
local u = math.atan2(
|
||||
xyz:dot(X),xyz:dot(Y)
|
||||
)
|
||||
local v = math.atan2(
|
||||
xyz:dot(Z:normalize()),
|
||||
math.sqrt(
|
||||
xyz:dot(X)^2+xyz:dot(X)^2
|
||||
)
|
||||
-r1
|
||||
)
|
||||
return vector.new(u,v)
|
||||
end
|
||||
function lerp(x,y,t)
|
||||
--print("lerp")
|
||||
return x - (x-y)*t
|
||||
end
|
||||
function project(x,y)
|
||||
--print("project x:",x," y:",y)
|
||||
return x-(
|
||||
y*(
|
||||
(
|
||||
x:dot(
|
||||
y
|
||||
)
|
||||
)/(
|
||||
y:dot(
|
||||
y
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
end
|
||||
function setmag(x,y)
|
||||
--print("setmag")
|
||||
return x:normalize()*y
|
||||
end
|
||||
function f(x,y,z)
|
||||
--print("f")
|
||||
xyz = vector.new(x,y,z)
|
||||
dist = (xyz-setmag(project(xyz,Z),r1)):length()-r2
|
||||
detail = lerp(5*surface(map(xyz)),r1,v)
|
||||
return dist-detail
|
||||
end
|
||||
function blockat(x,y,z)
|
||||
--print("blockat")
|
||||
if f(x,y,z) < 0 then
|
||||
flag = false
|
||||
for k,v in pairs({
|
||||
{1,0,0},
|
||||
{0,1,0},
|
||||
{0,0,1},
|
||||
{-1,0,0},
|
||||
{0,-1,0},
|
||||
{0,0,-1}
|
||||
})do
|
||||
flag = f(x+v[1],y+v[2],z+v[3])>0 or flag
|
||||
end
|
||||
if flag then
|
||||
dx = f(x+0.1,y,z)-f(x-0.1,y,z)
|
||||
dy = f(x,y+0.1,z)-f(x,y-0.1,z)
|
||||
dz = f(x,y,z+0.1)-f(x,y,z-0.1)
|
||||
normal = vector.new(dx,dy,dz):normalize()
|
||||
if normal:dot(vector.new(0,0,1)) > 0.5 then
|
||||
return true, "minecraft:moss_block"
|
||||
end
|
||||
dot = normal:dot(l)
|
||||
lighttable = {
|
||||
{-.7,"minecraft:cobbled_deepslate"},
|
||||
{-.5,"minecraft:andesite"},
|
||||
{-.3,"minecraft:tuff"},
|
||||
{0,"minecraft:cobblestone"},
|
||||
{.5,"minecraft:diorite"},
|
||||
{.7,"create:cut_limestone"},
|
||||
{2,"minecraft:calcite"}
|
||||
}
|
||||
for i,v in ipairs(lighttable) do
|
||||
if dot < v[1] then
|
||||
return true, v[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- print(x,y,z,"is not part of the set")
|
||||
return false
|
||||
end
|
||||
return {blockat = blockat}
|
9619
disk/0/tobuild
Normal file
9619
disk/0/tobuild
Normal file
File diff suppressed because it is too large
Load diff
1
disk/1/tobuild
Normal file
1
disk/1/tobuild
Normal file
File diff suppressed because one or more lines are too long
4
ids.json
Normal file
4
ids.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"computer": 15,
|
||||
"disk": 1
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue