-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphone.lua
More file actions
125 lines (87 loc) · 3.55 KB
/
phone.lua
File metadata and controls
125 lines (87 loc) · 3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
local id = 0
local idTable = {}
local areaTable = {}
rednet.open("back") --opening wireless capabilities for the pocket computer (must be wireless/ender)
print(rednet.isOpen("back"))
-- determining location and dimensions
local locationVector = vector.new(gps.locate())
locationVector.x = math.floor(locationVector.x)
locationVector.y = math.floor(locationVector.y)
locationVector.z = math.floor(locationVector.z)
print("Turtle ID(s):")
print("(-1) to stop")
while id ~= -1 do
id = tonumber(io.read())
table.insert(idTable, id)
end
table.remove(idTable, #idTable)
print("Length: ")
local length = tonumber(io.read()) --z value
print("Height: ")
local height = tonumber(io.read()) --y value
print("Width: ")
local width = tonumber(io.read()) --x value
local volume = vector.new(length, height, width)
--sub area calculations
local numTurtles = #idTable
local XBlocksRemaining = 0
local XPreviousMining = 0
local previousClear = 0
local startingBlock = vector.new(locationVector.x, (locationVector.y - 1), locationVector.z)
local finalBlock = vector.new(startingBlock.x - (volume.z - 1), startingBlock.y - volume.y, locationVector.z - (volume.x - 1))
local XBlocksRemaining = width
local sectionSizeX = math.floor(((startingBlock.x - finalBlock.x)) / numTurtles)
local sectionSizeZ = finalBlock.z - (startingBlock.z + 1)
print("Section Size X: ", sectionSizeX)
local function calculateSubArea(turtleIndex)
local subAreaStartX = startingBlock.x - (turtleIndex - 1) * (sectionSizeX + 1)
local subAreaEndX = subAreaStartX - sectionSizeX
if turtleIndex == 1 then
table.insert(areaTable, subAreaStartX)
end
return subAreaStartX, startingBlock.z, subAreaEndX, finalBlock.z
end
local function calculateRemaining(subStart, remainder)
local finalValue = subStart - remainder
table.insert(areaTable, finalValue)
return finalValue
end
-- -1, -4
--wirelessly sending coordinates
local function sendSegment(x, y, z, idNum, turtleOrder)
local segmentStart = vector.new(x, y, z)
if turtleOrder > 1 then
segmentStart.x = calculateRemaining(areaTable[turtleOrder - 1], sectionSizeX)
print("Next Starting Segment:", segmentStart.x)
end
local sizeVector = vector.new(length, height, sectionSizeX)
if XBlocksRemaining >= sectionSizeX then
XBlocksRemaining = XBlocksRemaining - (sectionSizeX)
end
if XBlocksRemaining ~= 0 and turtleOrder == #idTable then
sizeVector.z = XBlocksRemaining + sectionSizeX
end
print("Blocks left over:", XBlocksRemaining)
print("Turtle " .. turtleOrder .. " will mine " .. sizeVector.z .. " blocks.")
rednet.send(idNum, segmentStart, "locationVector")
print(segmentStart.x, segmentStart.y, segmentStart.z)
rednet.send(idNum, sizeVector, "dimVector")
end
for i = 1, numTurtles do
local subAreaStartX, subAreaStartZ, subAreaEndX, subAreaEndZ, dimX = calculateSubArea(i)
if i ~= numTurtles then
local turtleID = tonumber(idTable[i])
print("Turtle " .. i .. " Sub-Area: (" .. subAreaStartX .. "," .. subAreaStartZ .. ") to (" .. subAreaEndX .. "," .. subAreaEndZ .. ")")
sendSegment(subAreaStartX, startingBlock.y, subAreaStartZ, turtleID, i)
end
if i == numTurtles then
print("Turtle " .. i .. " Sub-Area: (" .. subAreaStartX .. "," .. subAreaStartZ .. ") to (" .. finalBlock.x .. "," .. finalBlock.z .. ")")
local turtleID = tonumber(idTable[i])
sendSegment(subAreaStartX, startingBlock.y, subAreaStartZ, turtleID, i)
end
end
--[[
local volume = vector.new(length, height, width)
rednet.send(id, location, "locationVector")
rednet.send(id, volume, "dimVector")
]]--