This commit is contained in:
Crispy 2025-05-22 20:51:25 +02:00
commit 12ffbdc45d
76 changed files with 79368 additions and 0 deletions

34
computer/4/bake.lua Normal file
View 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
View 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
View 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
View 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
View 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()

View 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
View 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}

View 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
View file

@ -0,0 +1,2 @@
while true do
{os.pullEvent("rednet_message")}

2
computer/4/report.lua Normal file
View file

@ -0,0 +1,2 @@
print("i believe i am at", position)
print("and looking", facing)

19
computer/4/startup.lua Normal file
View 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
View 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

File diff suppressed because it is too large Load diff