By Guest

Unnamed Paste

Auto Detect 2.07 KiB 26 one month ago
assert(turtle, "This must be ran on an TURTLE") assert(os.getComputerID() ~= 0, "This cannot be ran on ID 0") local skyrtle = require("skyrtle") local turtlePost = { name = "", id = 0, pos = { x = 0, y = 0, z = 0, r = 0 }, selectedSlot = 0, inventory = { }, } local worldPost = { { name = "", pos = { x = 0, y = 0, z = 0, }, data = {}, } } local function getInventory() for i = 1, 16 do turtle.select(i) turtlePost.inventory[i]= turtle.getItemDetail(i, true) end turtle.select(turtlePost.selectedSlot) end local function getData() turtlePost.id = os.getComputerID() local label = os.getComputerLabel() if label and not label == "" then turtlePost.name = label else os.setComputerLabel(tostring(turtlePost.id)) turtlePost.name = tostring(turtlePost.id) end local x,y,z = skyrtle.getPosition() local r = skyrtle.getFacing() turtlePost.pos.x = x turtlePost.pos.y = y turtlePost.pos.z = z turtlePost.pos.r = r turtlePost.selectedSlot = turtle.getSelectedSlot() getInventory() -- inspect up down and front local up, upData = turtle.inspectUp() local down, downData = turtle.inspectDown() local front, frontData = turtle.inspect() if front then local front = worldPost[1] -- calculate block position relative to turtle local r, rname = skyrtle.getFacing() if rname == "north" then front.pos.z = z + 1 elseif rname == "south" then front.pos.z = z - 1 elseif rname == "east" then front.pos.x = x + 1 elseif rname == "west" then front.pos.x = x - 1 end front.data = frontData print(rname) end end getData() local TurtleData = textutils.serializeJSON(turtlePost) local file = fs.open("/TurtleData.json", "w") file.write(TurtleData) file.close() local _, inspect = turtle.inspect() local WorldData = textutils.serialize(worldPost) local file = fs.open("/WorldData.lua", "w") file.write("local data = " .. WorldData) file.close() http.post("http://localhost:3300/api/v1/turtle/"..tostring(turtlePost.id), TurtleData)