View difference between Paste ID: PqY5Krk3 and aHGbFWPV
SHOW: | | - or go back to the newest paste.
1
os.loadAPI("turtleManualOneTrip.lua")
2
--start with pick in left and geoscanner in right of turtle, and modem in first slot
3
4-
function getSearchItem()
4+
function scan()
5-
	print("Please Insert Item to Mine in Second Slot")
5+
	scanner = peripheral.wrap("right")
6-
	print("Then Press Enter")
6+
	if scanner.cost(15) > scanner.getFuelLevel() then
7-
	read()
7+
		print("Not Enough Fuel")
8-
	desireditem = turtle.getItemDetail(2)
8+
		print("Cost: " .. scanner.cost(15))
9-
	return desireditem.name
9+
		print("Fuel Level: " .. scanner.getFuelLevel() .. "/" .. scanner.getMaxFuelLevel())
10
		os.exit(1)
11
	end
12-
scanner = peripheral.wrap("right")
12+
13-
if scanner.cost(15) > scanner.getFuelLevel() then
13+
	turtle.equipRight()
14-
	print("Not Enough Fuel")
14+
	rednet.open("right")
15-
	print("Cost: " .. scanner.cost(15))
15+
	cx, cy, cz = gps.locate()
16-
	print("Fuel Level: " .. scanner.getFuelLevel() .. "/" .. scanner.getMaxFuelLevel())
16+
	if cx == nil and cy == nil and cz == nil then
17-
	os.exit(1)
17+
		print("GPS Error")
18
		os.exit(1)
19
	end
20-
turtle.equipRight()
20+
	turtle.equipRight()
21-
rednet.open("right")
21+
22-
cx, cy, cz = gps.locate()
22+
	if not item and choice == 2 then
23-
if cx == nil and cy == nil and cz == nil then
23+
		print("No Name Inputted")
24-
	print("GPS Error")
24+
		os.exit(1)
25-
	os.exit(1)
25+
26
27-
turtle.equipRight()
27+
	return scanner.scan(15)
28
end
29-
print("Item or Name? (1 or 2)")
29+
30-
choice = tonumber(read())
30+
function findItemSlot(itemName)
31-
if choice ~= nil and choice == 1 then
31+
    for slot = 1, 16 do
32-
	item = getSearchItem()
32+
        local itemDetail = turtle.getItemDetail(slot)
33-
elseif choice ~= nil and choice == 2 then
33+
        if itemDetail and itemDetail.name == itemName then
34-
	print("Please input item in game name (with library included)")
34+
            return slot
35-
	item = read()
35+
        end
36
    end
37
    return nil
38-
if not item and choice == 1 then
38+
39-
	print("No Item Inserted")
39+
40-
	os.exit(1)
40+
function splitPairs(pairsArray)
41-
elseif not item and choice == 2 then
41+
    local keys = {}
42-
	print("No Name Inputted")
42+
    local values = {}
43-
	os.exit(1)
43+
44
    for _, pair in ipairs(pairsArray) do
45
        table.insert(keys, pair[1]) 
46-
blocks = scanner.scan(15)
46+
        table.insert(values, pair[2]) 
47
    end
48
49-
if blocks ~= nil then
49+
    return keys, values
50-
	for _, block in pairs(blocks) do
50+
51-
		if block.name == item then
51+
52-
			x = cx + block.x
52+
function dropUnwantedItems(allowedItems)
53-
			y = cy + (block.y + 1)
53+
	table.insert(allowedItems, "computercraft:wireless_modem_normal")
54-
			z = cz + block.z
54+
    for slot = 1, 16 do
55-
			turtleManualOneTrip.goToCordsMine(x, y, z)
55+
        local itemDetail = turtle.getItemDetail(slot)
56
        if itemDetail then
57
            local isAllowed = false
58-
	turtleManualOneTrip.goToCordsMine(cx, cy, cz)
58+
            -- Check if the item is in the allowed list
59-
else
59+
            for _, allowedItem in ipairs(allowedItems) do
60-
    print("Couldnt Scan")
60+
                if itemDetail.name == allowedItem then
61
                    isAllowed = true
62
                    break
63
                end
64
            end
65
            -- Drop the item if it's not allowed
66
            if not isAllowed then
67
                turtle.select(slot)
68
                turtle.drop()
69
                print("Dropped unwanted item: " .. itemDetail.name)
70
            end
71
        end
72
    end
73
end
74
75
function geoMineItem(item)
76
	blocks = scan()
77
	if blocks ~= nil then
78
		for _, block in pairs(blocks) do
79
			if block.name == item then
80
				x = cx + block.x
81
				y = cy + (block.y + 1)
82
				z = cz + block.z
83
				turtleManualOneTrip.goToCordsMine(x, y, z)
84
			end
85
		end
86
		turtleManualOneTrip.goToCordsMine(cx, cy, cz)
87
	else
88
	    print("Couldnt Scan")
89
	end
90
end
91
92
function geoMineList(itemlist)
93
	itemlist, matlist = splitPairs(itemlist)
94
	found = false
95
	if itemlist ~= nil then
96
		blocks = scan()
97
	else
98
		print("Itemlist no found")
99
		os.exit(1)
100
	end
101
	if blocks ~= nil and itemlist ~= nil then
102
		for _, block in pairs(blocks) do
103
			for _, item in pairs(itemlist) do
104
				if block.name == item then
105
					x = cx + block.x
106
					y = cy + (block.y + 1)
107
					z = cz + block.z
108
					slot = findItemSlot("computercraft:wireless_modem_normal")
109
					if slot ~= nil then
110
						turtle.select(slot)
111
					end
112
					turtleManualOneTrip.goToCordsMine(x, y, z)
113
					dropUnwantedItems(matlist)
114
					found = true
115
				end
116
			end
117
		end
118
		if found then
119
			dropUnwantedItems(matlist)
120
			slot = findItemSlot("computercraft:wireless_modem_normal")
121
			if slot ~= nil then
122
				turtle.select(slot)
123
			end
124
			turtleManualOneTrip.goToCordsMine(cx, cy, cz)
125
			dropUnwantedItems(matlist)
126
			turtle.digUp()
127
			turtle.up()
128
		end
129
	elseif blocks == nil  then
130
	    print("Couldnt Scan")
131
	elseif itemlist == nil then
132
		print("Itemlist no found")
133
	end
134
end