Update client, server
This commit is contained in:
parent
7a61b20e63
commit
f09e85b1fe
246
dominic/5
246
dominic/5
@ -1,246 +0,0 @@
|
||||
args = {...}
|
||||
|
||||
function noop() end
|
||||
|
||||
function pair(x, y)
|
||||
return math.floor((x + y) * (x + y + 1)/2 + y)
|
||||
end
|
||||
|
||||
function unpairX(z)
|
||||
local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
||||
return j - (z - j*(j+1)/2)
|
||||
end
|
||||
|
||||
|
||||
function unpairZ(z)
|
||||
local j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
||||
return z - j * (j+1)/2;
|
||||
end
|
||||
|
||||
lookup = {4, 1, 3, 0, 2}
|
||||
local function isDiggingSpot(x, y)
|
||||
local val = lookup[(y % 5) + 1]
|
||||
return (x % 5) == val
|
||||
end
|
||||
|
||||
offset = 10
|
||||
function ithSpot(i)
|
||||
j = offset
|
||||
while true do
|
||||
x, z = unpairX(j), unpairZ(j)
|
||||
if isDiggingSpot(x, z) then
|
||||
if i <= 1 then
|
||||
return x, z
|
||||
else
|
||||
i = i - 1
|
||||
end
|
||||
end
|
||||
j = j + 1
|
||||
end
|
||||
end
|
||||
|
||||
function digTo(x, z)
|
||||
print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")")
|
||||
while z > 0 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.digUp()
|
||||
z = z - 1
|
||||
end
|
||||
turtle.turnRight()
|
||||
while x > 0 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.digUp()
|
||||
x = x - 1
|
||||
end
|
||||
end
|
||||
|
||||
-- If the block in front of the turtle is desired, take it.
|
||||
function grabOres()
|
||||
local status, block = turtle.inspect()
|
||||
if status and block["name"]:lower():find("ore") then
|
||||
turtle.dig()
|
||||
end
|
||||
end
|
||||
|
||||
-- dig all the way down to bedrock, collect ores
|
||||
-- Parameters:
|
||||
-- * moveAction: the **vertical** move action, eg turtle.down
|
||||
-- * digAction: the **vertical** dig action, eg turtle.digDown
|
||||
-- * inpectAction: the **vertical** inspect action, eg turtle.inspectDown
|
||||
-- * limit: if >= 0 * the number of blocks to dig
|
||||
-- * dig until bedrock is hit
|
||||
--
|
||||
--
|
||||
-- Returns: the depth dug
|
||||
function digDeep(moveAction, digAction, inspectAction, limit)
|
||||
local depth = 0
|
||||
grabOres()
|
||||
while true do
|
||||
-- termination condition:
|
||||
-- * if limit != -1: limit > 0
|
||||
-- * otherwise : bedrock beneath
|
||||
if limit < 0 then
|
||||
local status, nextblock = inspectAction()
|
||||
if status and nextblock["name"] == "minecraft:bedrock" then
|
||||
return depth
|
||||
end
|
||||
else
|
||||
if limit == 0 then
|
||||
return depth
|
||||
end
|
||||
end
|
||||
-- Limit not reached: keep digging
|
||||
depth = depth + 1
|
||||
limit = limit - 1
|
||||
digAction()
|
||||
moveAction()
|
||||
grabOres() -- inspect block in front of turtle, take if neccessary
|
||||
end
|
||||
end
|
||||
|
||||
function selectCobble()
|
||||
for i = 1,16 do
|
||||
turtle.select(i)
|
||||
item = turtle.getItemDetail()
|
||||
if item and item["name"] == "minecraft:cobblestone" then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function digShaft()
|
||||
turtle.digDown()
|
||||
selectCobble()
|
||||
turtle.placeUp()
|
||||
turtle.down()
|
||||
print("Starting to dig shaft")
|
||||
depth = digDeep(turtle.down, turtle.digDown, turtle.inspectDown, -1)
|
||||
print("Dug the first shaft (depth = "..tostring(depth)..")")
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.down, noop, noop, depth)
|
||||
turtle.turnLeft()
|
||||
digDeep(turtle.up, noop, noop, depth)
|
||||
selectCobble()
|
||||
turtle.placeDown()
|
||||
turtle.up()
|
||||
turtle.digUp()
|
||||
turtle.up()
|
||||
end
|
||||
|
||||
function digTo(x, z)
|
||||
print("Digging to rel. coord ("..tostring(x)..", "..tostring(z)..")")
|
||||
while z > 0 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.digUp()
|
||||
z = z - 1
|
||||
end
|
||||
turtle.turnRight()
|
||||
while x > 0 do
|
||||
turtle.dig()
|
||||
turtle.forward()
|
||||
turtle.digUp()
|
||||
x = x - 1
|
||||
end
|
||||
end
|
||||
|
||||
-- move safely into the direction, not hurting other turtles, but freeing the path if needed.
|
||||
function moveSafe(moveAction, inspectAction, digAction)
|
||||
while true do
|
||||
local status, block = inspectAction()
|
||||
if status then
|
||||
if block["name"]:lower():find("turtle") then
|
||||
-- turtle in front of me. lets wait for it to move
|
||||
sleep(0.6)
|
||||
else
|
||||
digAction()
|
||||
end
|
||||
else
|
||||
-- nothing in the way, try to move
|
||||
if moveAction() then
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function goToSpawn(x, z)
|
||||
turtle.digUp()
|
||||
turtle.up()
|
||||
while z > 0 do
|
||||
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||
z = z - 1
|
||||
end
|
||||
turtle.turnRight()
|
||||
while x > 0 do
|
||||
moveSafe(turtle.forward, turtle.inspect, turtle.dig)
|
||||
x = x - 1
|
||||
end
|
||||
end
|
||||
|
||||
function moveSafeForward()
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
end
|
||||
|
||||
function goToBarrel()
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
turtle.turnRight()
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
turtle.turnLeft()
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
moveSafe(turtle.forward, turtle.inspect, noop)
|
||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||
end
|
||||
|
||||
function reportDuty(id)
|
||||
turtle.turnRight()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
turtle.turnRight()
|
||||
moveSafeForward()
|
||||
turtle.turnRight()
|
||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||
moveSafe(turtle.down, turtle.inspectDown, noop)
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
moveSafeForward()
|
||||
rednet.open("bottom")
|
||||
rednet.broadcast(tostring(id), "imdone")
|
||||
end
|
||||
|
||||
function enqueueTurtle()
|
||||
moveSafe(turtle.up, turtle.inspectUp, noop)
|
||||
moveSafe(turtle.up, turtle.inspectUp, noop)
|
||||
moveSafe(turtle.up, turtle.inspectUp, noop)
|
||||
turtle.turnLeft()
|
||||
end
|
||||
|
||||
function emptyToBarrel()
|
||||
for i = 1,16 do
|
||||
select(i)
|
||||
turtle.dropDown()
|
||||
end
|
||||
end
|
||||
|
||||
spotNum = tonumber(args[1])
|
||||
if spotNum then
|
||||
x, z = ithSpot(spotNum)
|
||||
digTo(x,z)
|
||||
digShaft()
|
||||
goToSpawn(x, z)
|
||||
goToBarrel()
|
||||
emptyToBarrel()
|
||||
reportDuty()
|
||||
enqueueTurtle()
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
while true do
|
||||
status, block = turtle.inspect()
|
||||
sleep(1)
|
||||
if not status then
|
||||
succ = turtle.forward()
|
||||
print(succ)
|
||||
end
|
||||
end
|
@ -1 +0,0 @@
|
||||
print("Kai is pleased!")
|
@ -1 +0,0 @@
|
||||
print("Kai is pleased!")
|
33
dominic/pairingtool.py
Normal file
33
dominic/pairingtool.py
Normal file
@ -0,0 +1,33 @@
|
||||
import math
|
||||
|
||||
def pair(x, y):
|
||||
return math.floor((x + y) * (x + y + 1)/2 + y)
|
||||
|
||||
def unpairX(z):
|
||||
j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
||||
return j - (z - j*(j+1)/2)
|
||||
|
||||
|
||||
def unpairZ(z):
|
||||
j = math.floor(math.sqrt(0.25 + 2*z) - 0.5)
|
||||
return z - j * (j+1)/2;
|
||||
|
||||
lookup = [-10, 4, 1, 3, 0, 2]
|
||||
def isDiggingSpot(x, y):
|
||||
val = lookup[(y % 5) + 1]
|
||||
return (x % 5) == val
|
||||
|
||||
global offset
|
||||
offset = 10
|
||||
def ithSpot(i):
|
||||
global offset
|
||||
j = offset
|
||||
while True:
|
||||
x, z = int(unpairX(j)), int(unpairZ(j))
|
||||
if isDiggingSpot(x, z):
|
||||
if i <= 1:
|
||||
return x, z
|
||||
else:
|
||||
i = i - 1
|
||||
j = j + 1
|
||||
|
@ -1,44 +0,0 @@
|
||||
x = 0
|
||||
y = 0
|
||||
lookup = {4, 1, 3, 0, 2}
|
||||
local function test()
|
||||
local val = lookup[(y % 5) + 1]
|
||||
return (x % 5) == val
|
||||
end
|
||||
|
||||
local function run()
|
||||
for i = 1,3 do
|
||||
for j = 1,6 do
|
||||
turtle.forward()
|
||||
x = x + 1
|
||||
if test() then
|
||||
turtle.digDown()
|
||||
end
|
||||
end
|
||||
turtle.turnRight()
|
||||
turtle.forward()
|
||||
y = y + 1
|
||||
if test() then
|
||||
turtle.digDown()
|
||||
end
|
||||
turtle.turnRight()
|
||||
for j = 1,6 do
|
||||
turtle.forward()
|
||||
x = x - 1
|
||||
if test() then
|
||||
turtle.digDown()
|
||||
end
|
||||
if test() then
|
||||
turtle.digDown()
|
||||
end
|
||||
end
|
||||
turtle.turnLeft()
|
||||
turtle.forward()
|
||||
y = y + 1
|
||||
if test() then
|
||||
turtle.digDown()
|
||||
end
|
||||
turtle.turnLeft()
|
||||
end
|
||||
end
|
||||
run()
|
@ -13,7 +13,7 @@ end
|
||||
|
||||
function getNextJob()
|
||||
curjob = curjob + 1
|
||||
return curjob
|
||||
return curjob - 1
|
||||
end
|
||||
|
||||
while true do
|
||||
@ -21,6 +21,7 @@ while true do
|
||||
if not message then
|
||||
sleep(0.6)
|
||||
else
|
||||
print("> raw: "..message)
|
||||
if message == "gibjob" then
|
||||
if rs.getInput("right") then
|
||||
job = getNextJob()
|
||||
@ -35,8 +36,11 @@ while true do
|
||||
if fuelmessage then
|
||||
fuelused = fuelmessage
|
||||
end
|
||||
print("Job "..tostring(completejob).." was completed, "..fu elused.." fuel was used")
|
||||
print("Job "..tostring(completejob).." was completed, "..fuelused.." fuel was used")
|
||||
rednet.broadcast("thanks", "jobcomplete")
|
||||
log = io.open("jobs.log","a")
|
||||
log:write(tostring(completejob),"\n")
|
||||
log:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user