View difference between Paste ID: 0CpP3Jzy and LiUNDnUB
SHOW: | | - or go back to the newest paste.
1
--pastebin get -f 0CpP3Jzy mine.lua
2
local robot=require("robot")
3
local component=require("component")
4
local computer=require("computer")
5
local ic = component.inventory_controller
6
local a = {...}
7
local xLength=tonumber(a[1]) or 48
8
local yLength=tonumber(a[2]) or 48
9
local zDepth=tonumber(a[3]) or 7
10
local dLayer=tonumber(a[4]) or 3
11
local nStart=5
12
local tDumpster ={
13
"minecraft:cobblestone",
14
"minecraft:dirt",
15
"minecraft:gravel",
16
"chisel:granite",
17
"chisel:limestone",
18
"chisel:andesite",
19
"chisel:diorite"
20
                 }
21
if component.isAvailable("chunkloader")
22
    then
23
    component.chunkloader.setActive(true)
24
end
25
-- Добыча 1 столба
26
local function prey()
27
while not robot.forward() do robot.swing() os.sleep(0,5) end
28
while robot.swingUp() do os.sleep(0,5) end
29
robot.swingDown()
30
end
31
-- Спуск на заданную глубину
32
local function preyDown(dLL)
33
for dLLL=1,dLL do
34
while not robot.down() do robot.swingDown() end
35
end
36
end
37
-- Добыча 1 траншеи
38
local function trench(ll)
39
for lll=1,ll do
40
prey() 
41
-- while robot.durability()*1000000<100 do os.sleep(180) end 
42
end
43
end
44
-- Перемещение на заданное расстояние
45
local function moveLine(ll)
46
while ll>1 do while not robot.forward() do robot.swing() os.sleep(0,5) end ll=ll-1 end
47
end
48
-- 1 слот - кирка
49
local nKir=1
50
-- 2 слот - рычаг
51
local nRyc=2
52
-- 3 слот - зарядник
53
local nZar=3
54
-- 4 слот - трансивер
55
local nTra=4
56
local function goForward()
57
while not robot.forward() do robot.swing() os.sleep(0,5) end
58
robot.suck()
59
return true
60
end
61
local function goUp()
62
while not robot.up() do robot.swingUp() end
63
end
64
local function goDown()
65
while not robot.down() do robot.swingDown() end
66
end
67
local function goBack()
68
if not robot.back() then robot.turnAround() goForward() robot.turnAround() end
69
end
70
local function doPlace(nSlot)
71
robot.select(nSlot)
72
while not robot.place() do robot.select(nStart) goForward() goBack() robot.select(nSlot) end
73
robot.select(nStart)
74
end
75
local function suckDrill()
76
ll=false
77
for jj=9,16 do if ic.getStackInSlot(3,jj) ~= nil then if ic.getStackInSlot(3,jj).label=="bamik_drill" then ic.suckFromSlot(3,jj) ll=true end end end
78
return ll
79
end
80
-- Проверка на мусор
81
local function dumpster(sNN)
82
local log=false
83
local i,j=1,#tDumpster
84
repeat 
85
if sNN==tDumpster[i] then log=true end
86
i=i+1
87
until log or i>j 
88
return log
89
end
90
-- Выгрузка инвентаря в указанную сторону. Если нет сундука, то выброс мусора и уплотнение. 
91
-- Слоты до указанного не трогаются.
92
local function drop()
93
  if ic.getInventorySize(3) ~= nil then
94
    for i = robot.inventorySize(), nStart, -1 do
95
    robot.select(i)
96
	while robot.count()>0 do robot.drop() end
97
	end
98
  else
99
	local i,j=nStart, robot.inventorySize()
100
    while i ~= j do
101
    robot.select(j)
102
    local t = ic.getStackInInternalSlot(j)
103
    if t ~= nil then 
104
	local sN = t.name
105
	  if dumpster(sN)	then robot.drop() j=j-1
106
	  else robot.transferTo(i) i=i+1
107
      end
108
	else
109
	  j=j-1
110
	end
111
    end
112
  end
113
end
114
local function zaryad()
115
goForward()
116
-- Устанавливаем трансивер
117
doPlace(nTra)
118-
robot.select(nKir) ic.equip() robot.drop() drop() robot.select(nKir) while not suckDrill() do os.sleep(10) end ic.equip() robot.select(nStart)
118+
119
robot.select(nKir) ic.equip() robot.drop() drop() robot.select(nKir) os.sleep(120) ic.equip() robot.select(nStart)
120
-- Устанавливаем зарядник
121
goUp() doPlace(nZar) 
122
-- Устанавливаем рычаг и включаем его
123
goUp() robot.select(nRyc) robot.placeDown(3) ic.equip() robot.useDown(3) ic.equip() robot.select(nStart)
124
-- Встаем на зарядку
125
goForward() while computer.energy()<0.99* computer.maxEnergy() do os.sleep(15) end
126
-- Снимаем
127
robot.select(nKir)
128
goBack() goDown() goForward() 
129
goBack() goDown() goForward()
130
goBack() goBack() robot.select(nStart)
131
end
132
local function servicing()
133
-- Если инвентарь заполнился, то выброс мусора. 
134
-- Свободного места до переполнения, должно хватить от проверки до проверки. Оставляем 5 слотов.
135
-- Для добычи в ваниле, можно оставить 2.
136
robot.select(1) ic.equip() 
137
local tL=ic.getStackInInternalSlot(1) 
138
ic.equip()
139
local robEn=computer.energy()/computer.maxEnergy()
140
local lasDm=tL.damage/tL.maxDamage
141
-- Если разрядился робот, бур или заполнился инвентарь, то проводим обслуживание.
142
if (robot.count(robot.inventorySize()-5)>0) or (robEn<0.1) or (lasDm>0.9) then zaryad() end
143
end
144
-- Тело программы
145
-- Текущая глубина копания
146
local zD=zDepth
147
-- Текущая толщина слоя копания
148
local dL=dLayer
149
repeat
150
print(zD,dL)  
151
xL=xLength
152
yL=yLength-1
153
repeat
154
trench(xL)
155
xL=xL-1
156
servicing()
157
robot.turnRight()
158
trench(yL)
159
yL=yL-1
160
servicing()
161
robot.turnRight()
162
until xL<1 or yL<0
163
-- Очищаемся от мусора перед возвратом в исходную позицию.
164
-- drop()
165
-- Вычисление длины "обратного" хода
166
local xyBack=math.ceil((math.min(xLength, yLength)-1)/2)+1
167
if math.min(xLength, yLength)%2 == 0 then
168
yBack=xyBack
169
xBack=yBack
170
else
171
robot.turnAround()
172
if xLength-yLength<=0 then
173
yBack=yLength-xyBack+1
174
xBack=xyBack+1
175
else
176
xBack=xLength-xyBack+2
177
yBack=xyBack
178
end
179
end
180
robot.turnLeft()
181
moveLine(yBack)
182
robot.turnLeft()
183
moveLine(xBack)
184
robot.turnAround()
185
186
zD=zD-dL
187
dL=math.min(zD,dL)
188
preyDown(dL)
189
until dL<1
190
for k=1,zDepth do goUp() end
191
zaryad()