feat: Forward discovered blocks to server; log block details and handle errors

This commit is contained in:
MayaTheShy
2026-02-20 01:06:09 -05:00
parent 8d66ef637e
commit 4bd999d394

View File

@@ -509,6 +509,42 @@ while true do
})
addLog(" -> Server error, local only", colors.red)
end
elseif message.type == "blocks_discovered" then
-- Turtle discovered new blocks - forward to server
local turtleID = message.turtleID
local blocks = message.blocks or {}
if #blocks > 0 then
print("📦 Turtle #" .. turtleID .. " discovered " .. #blocks .. " blocks")
-- Send each block to the server
for _, block in ipairs(blocks) do
local success = pcall(function()
local response = http.post(
SERVER_URL .. "/api/world/blocks",
textutils.serializeJSON({
x = block.x,
y = block.y,
z = block.z,
blockName = block.name,
metadata = block.metadata or 0,
discoveredBy = turtleID
}),
{["Content-Type"] = "application/json"}
)
if response then
response.close()
end
end)
if not success then
stats.errors = stats.errors + 1
end
end
addLog(" -> Sent " .. #blocks .. " blocks to server", colors.lime)
end
end
end
elseif channel == POCKET_CHANNEL then