View difference between Paste ID: FfuqQ8XB and MtLj3MfZ
SHOW: | | - or go back to the newest paste.
1
-- Mastermine is a Master part of turtle swarm quarry made by PonyKuu
2-
-- It uses my master API 
2+
-- It uses my master API
3-
3+
4-
-- version 0.1
4+
-- Version 0.1(481): 1.481-compatible
5-
5+
6
os.loadAPI ("master")
7
 
8
local tArgs = {...}
9
 
10
if #tArgs ~= 5 then
11-
    print ("Usage: mastermine <xstart> <ystart> <zstart> <xsize> <zsize>")
11+
	print ("Usage: mastermine <xstart> <ystart> <zstart> <xsize> <zsize>")
12-
    return
12+
	return
13
end
14
 
15
-- set up a table with all the mining locations
16
local mineLocations = {}
17
local xstart, ystart, zstart, xsize, zsize = unpack (tArgs)
18
for i = 0, xsize/4 - 1 do
19-
    for j = 0, zsize/4 - 1 do
19+
	for j = 0, zsize/4 - 1 do
20-
        local x = xstart + i*4
20+
		local x = xstart + i*4
21-
        local z = zstart + j*4
21+
		local z = zstart + j*4
22-
        table.insert (mineLocations, {x = x, y = ystart, z = z, f = 0})
22+
		table.insert (mineLocations, {x = x, y = ystart, z = z, f = 0})
23-
    end
23+
	end
24
end
25-
25+
26
-- Calculate the navigation zones. The point that divides area into zones is in the middle of the mining area.
27
local naviX = xstart + xsize/2
28
local naviZ = zstart + zsize/2
29
local naviHeight = ystart + 2
30
master.setNavigation (naviX, naviZ, naviHeight)
31-
31+
32
local function mineMachine (ID)
33-
    -- If there are untouched locations
33+
	-- If there are untouched locations
34-
    if #mineLocations > 0 then
34+
	if #mineLocations > 0 then
35-
        master.setState (ID, "Mining")
35+
		master.setState (ID, "Mining")
36-
        -- remove one from table
36+
		-- remove one from table
37-
        local nextLocation = table.remove (mineLocations) 
37+
		local nextLocation = table.remove (mineLocations)
38-
        -- Some debug output
38+
		-- Some debug output
39-
        print ("Module ", ID, " is mining at {", nextLocation.x, " ,", nextLocation.y, " ,", nextLocation.z, "}")
39+
		print ("Module ", ID, " is mining at {", nextLocation.x, " ,", nextLocation.y, " ,", nextLocation.z, "}")
40-
        -- And make a task to mine that location
40+
		-- And make a task to mine that location
41-
        return master.makeTask ("Mine", nextLocation, {holeSize = 4}) 
41+
		return master.makeTask ("Mine", nextLocation, {holeSize = 4})
42-
    else
42+
	else
43-
        -- No locations. Return home.
43+
		-- No locations. Return home.
44-
        master.setState(ID, "Returning")
44+
		master.setState(ID, "Returning")
45-
        print ("Module ", ID, " is returning to Master")
45+
		print ("Module ", ID, " is returning to Master")
46-
        return master.makeReturnTask ()
46+
		return master.makeReturnTask ()
47-
    end
47+
	end
48
end
49-
49+
50
-- Associate this function with type "Miner"
51
master.setType("Miner", mineMachine)
52
-- And initialize the master
53-
master.init("modulemine", 100, 1000, #mineLocations)
53+
master.init("modulemine", 1000, #mineLocations)
54-
54+
55
local function stateFunction ()
56-
    if #mineLocations > 0 then
56+
	if #mineLocations > 0 then
57-
        return true
57+
		return true
58-
    else
58+
	else
59-
        return false
59+
		return false
60-
    end
60+
	end
61
end
62
master.operate (stateFunction)
63
print "Mining finished! Have a nice day!"