feat: Forward discovered blocks to server; log block details and handle errors
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user