Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Slot settings
- local slotFuel = 1;
- local slotRail = 2;
- local slotPoweredRail = 3;
- local slotRedTorch = 4;
- local slotFoundament = 5;
- local slotTorch = 6;
- local minFuelLevel = 10;
- local minResourcesCount = 3;
- local poweredRailDistance = 16; -- place powered rail each X blocks on LEFT side
- local torchDistance = 8; -- place Torch each X blocks on RIGHT side
- local roadLength = 64;
- -- Проверим уровень топлива и заправимся, пока не будет достигнут минимальный уровень
- function checkFuel()
- while turtle.getFuelLevel() < minFuelLevel do
- if turtle.getItemCount(slotFuel) < 1 then
- -- Топливо закончилось
- return 0;
- end
- turtle.select(slotFuel);
- turtle.refuel(1);
- end
- return 1;
- end
- -- Проверка ресурсов в ячейках 1-6 и пополнение их из другиз ячеек, если найден ресурс
- function checkResources()
- -- 6 resources for check
- for i = 1, 6 do
- turtle.select(i);
- if turtle.getItemCount(i) < minResourcesCount then
- -- find resoirces in cell 7-16
- for c = 7, 16 do
- if turtle.compareTo(c) then
- turtle.select(c);
- turtle.transferTo(i);
- break;
- end
- end
- -- Ресурсы так и не были найдены. Остановим работу.
- if turtle.getItemCount(i) < minResourcesCount then
- return 0;
- end
- end
- end
- return 1;
- end
- -- Установить рельсы
- function placeRail()
- turtle.select(slotRail);
- turtle.placeDown();
- end
- -- Установить электрорельсы
- function placePoweredRail()
- turtle.select(slotPoweredRail);
- turtle.placeDown();
- end
- -- Установить фундамент (подразумевается, что черепаха уже опущена для установки)
- function placeFoundament()
- turtle.select(slotFoundament);
- turtle.placeDown();
- end
- -- Установить факел (установить сбоку фундамент и на него факел)
- function placeTorch()
- turtle.turnRight();
- if turtle.detect() then
- turtle.dig();
- end
- turtle.forward();
- if turtle.detectDown() then
- turtle.digDown();
- end
- turtle.down();
- if turtle.detectDown() then
- turtle.digDown();
- end
- -- place foundament
- turtle.select(slotFoundament);
- turtle.placeDown();
- turtle.up();
- turtle.select(slotTorch);
- turtle.placeDown();
- turtle.turnRight();
- turtle.turnRight();
- turtle.forward();
- turtle.turnRight();
- end
- -- Установить красный факел (сбоку фундамент и на него факел)
- function placeRedTorch()
- turtle.turnLeft();
- if turtle.detect() then
- turtle.dig();
- end
- turtle.forward();
- if turtle.detectDown() then
- turtle.digDown();
- end
- turtle.down();
- if turtle.detectDown() then
- turtle.digDown();
- end
- -- place foundament
- turtle.select(slotFoundament);
- turtle.placeDown();
- turtle.up();
- turtle.select(slotRedTorch);
- turtle.placeDown();
- turtle.turnRight();
- turtle.turnRight();
- turtle.forward();
- turtle.turnLeft();
- end
- -- Основной рабочий цикл
- function doWork()
- local flagPoweredRailDistance = 0;
- local flagTorchDistance = 0;
- for i = 0, roadLength do
- -- Check fuel and resources. Refuel and get resources from cells
- if checkFuel() == 0 then
- print "Warning! Fuel empty";
- print "Stop";
- return 0;
- end
- if checkResources() == 0 then
- print ("Warning! Check resources in slot: ", i);
- print "Stop";
- return 0;
- end
- flagPoweredRailDistance = flagPoweredRailDistance + 1;
- flagTorchDistance = flagTorchDistance + 1;
- -- Clear blocks
- if turtle.detect() then
- turtle.dig();
- end
- turtle.forward();
- if turtle.detectDown() then
- turtle.digDown();
- end
- turtle.down();
- if turtle.detectDown() then
- turtle.digDown();
- end
- --
- placeFoundament();
- turtle.up();
- if flagTorchDistance > torchDistance then
- flagTorchDistance = 0;
- placeTorch();
- end
- if flagPoweredRailDistance > poweredRailDistance then
- flagPoweredRailDistance = 0;
- placePoweredRail();
- placeRedTorch();
- else
- placeRail();
- end
- end
- print "Road complete";
- print "Stop";
- return 1;
- end
- -- Запуск программы
- print "Monorails v1.0";
- print "Run...";
- doWork();
Advertisement
Add Comment
Please, Sign In to add comment