read if gay
This commit is contained in:
parent
4f2631b349
commit
61eefcba8c
24 changed files with 21871 additions and 4224 deletions
65
computer/18/rail.lua
Normal file
65
computer/18/rail.lua
Normal file
|
@ -0,0 +1,65 @@
|
|||
_G.facing = "south"
|
||||
|
||||
local rightOf = {
|
||||
south = "west",
|
||||
west = "north",
|
||||
north = "east",
|
||||
east = "south"
|
||||
}
|
||||
|
||||
local leftOf = {
|
||||
west = "south",
|
||||
north = "west",
|
||||
east = "north",
|
||||
south = "east"
|
||||
}
|
||||
|
||||
local opposite = {
|
||||
west = "east",
|
||||
east = "west",
|
||||
south = "north",
|
||||
north = "south"
|
||||
}
|
||||
|
||||
function step()
|
||||
-- exists, block = turtle.inspectDown()
|
||||
--if not exists then
|
||||
repeat
|
||||
turtle.down()
|
||||
exists, block = turtle.inspectDown()
|
||||
until exists
|
||||
-- end
|
||||
if block.name == "minecraft:rail" then
|
||||
shape = block.state.shape
|
||||
if shape == "ascending_" .. _G.facing then
|
||||
turtle.up()
|
||||
turtle.forward()
|
||||
elseif string.match(shape, _G.facing) or shape == "ascending_" .. opposite[_G.facing] then
|
||||
turtle.forward()
|
||||
elseif string.match(shape, leftOf[_G.facing]) then
|
||||
_G.facing = leftOf[_G.facing]
|
||||
turtle.turnLeft()
|
||||
elseif string.match(shape, rightOf[_G.facing]) then
|
||||
_G.facing = rightOf[_G.facing]
|
||||
turtle.turnRight()
|
||||
else
|
||||
error("i'm lost\n".. shape)
|
||||
end
|
||||
return false
|
||||
elseif block.name == "minecraft:iron_block" then
|
||||
return "done"
|
||||
else
|
||||
return "lost"
|
||||
end
|
||||
end
|
||||
|
||||
function follow_rail(init_dir)
|
||||
_G.facing = init_dir
|
||||
repeat
|
||||
state = step()
|
||||
until state
|
||||
print(state)
|
||||
end
|
||||
|
||||
print("what direction am i facing?")
|
||||
follow_rail(read())
|
Loading…
Add table
Add a link
Reference in a new issue