Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- magas = 10
- szeles = 100
- hosszu = 300
- jobbOldal = true
- fent = false
- tCoordx_int = 0
- tCoordy_int = 0
- tCoordz_int = 0
- chestX = 0
- chestY = 0
- chestZ = 0
- fChest = false
- fChestX = 0
- fChestY = 0
- fChestZ = 0
- lavaRefuel_bln = true
- coalRefuel_bln = false
- doDumping_bln = true
- orientation_int = 1 --north 1, east 2, south3, west 4
- ------------------------------------------------------
- --function definialas
- orientations = {"north","east","south","west"}
- zDiff = {-1,0,1,0}
- xDiff = {0,1,0,-1}
- -------------------------------------------
- function dumping_fcn()
- workX = tCoordx_int
- workY = tCoordy_int
- workZ = tCoordz_int
- workLook = orientation_int
- goTo_fcn(chestX, chestY, chestZ)
- for i = 1,numberOfUseableSlots do
- turtle.select(i)
- turtle.dropDown()
- end
- goTo_fcn(workX, workY, workZ)
- look_fcn(1)
- end
- function checkInventory_fcn()
- j = 1
- IsThereEmptySlot_bln = false
- while j <= numberOfUseableSlots and not(IsThereEmptySlot_bln) do
- if turtle.getItemCount(j) == 0 then
- IsThereEmptySlot_bln = true
- end
- if j == numberOfUseableSlots and IsThereEmptySlot_bln == false and coalRefuel_bln then
- for j1 = 1,numberOfUseableSlots do
- turtle.select(j1)
- if turtle.refuel(turtle.getItemCount(j1)) then
- IsThereEmptySlot_bln = true
- print("fl+:"..turtle.getFuelLevel())
- print("wl:"..workLevel.."%")
- end
- end
- end
- j = j + 1
- end
- if false == IsThereEmptySlot_bln then
- dumping_fcn()
- end
- end
- function checkFuel()
- if fChest then
- fworkX = tCoordx_int
- fworkY = tCoordy_int
- fworkZ = tCoordz_int
- fworkLook = orientation_int
- pillUt = math.abs(tCoordx_int - chestX) + math.abs(tCoordy_int - chestY) + math.abs(tCoordz_int - chestZ) + math.abs(chestX - fChestX) + math.abs(chestY - fChestY) + math.abs(chestZ - fChestZ) + 2
- if turtle.getFuelLevel() < pillUt then
- goTo_fcn(chestX, chestY, chestZ)
- dumping_fcn()
- goTo_fcn(fChestX, fChestY, fChestZ)
- doneBefore = false
- chestEmpty = false
- while turtle.getFuelLevel() < pillUt + 10000 or chestEmpty == false do
- for i = 1,numberOfUseableSlots do
- turtle.select(i)
- if turtle.suckDown() then
- turtle.refuel(turtle.getItemCount(i))
- else
- chestEmpty = true
- end
- end
- print("fl: "..turtle.getFuelLevel())
- if chestEmpty then
- doneBefore = true
- end
- for i = 1,numberOfUseableSlots do
- if turtle.getItemCount(i) ~= 0 then
- dumping_fcn()
- break
- end
- end
- if doneBefore and chestEmpty then
- print("uzemanyagra varok")
- os.sleep(60)
- chestEmpty = false
- end
- end
- print("ujra toltve")
- print("wl: "..workLevel)
- goTo_fcn(fworkX, fworkY, fworkZ)
- look_fcn(fworkLook)
- end
- end
- end
- ---------------------------
- function dig_fcn()
- if lavaRefuel_bln then
- if false == turtle.dig() then
- turtle.select(16)
- if turtle.place() then
- if turtle.refuel() == false then
- turtle.place()
- else
- print("fl+:"..turtle.getFuelLevel())
- print("wl:"..workLevel.."%")
- end
- end
- turtle.select(1)
- end
- else
- turtle.dig()
- end
- if doDumping_bln then
- checkInventory_fcn()
- end
- end
- function digUp_fcn()
- turtle.digUp()
- checkInventory_fcn()
- end
- function digDown_fcn()
- turtle.digDown()
- checkInventory_fcn()
- end
- ---------------------------
- function moveForward_fcn()
- moveF_bln = false
- while not(moveF_bln) do
- turtle.dig()
- turtle.attack()
- moveF_bln = turtle.forward()
- end
- tCoordx_int = tCoordx_int + xDiff[orientation_int]
- tCoordz_int = tCoordz_int + zDiff[orientation_int]
- end
- function moveDown_fcn()
- moveD_bln = false
- while not(moveD_bln) do
- turtle.digDown()
- turtle.attackDown()
- moveD_bln = turtle.down()
- end
- tCoordy_int = tCoordy_int - 1
- end
- function moveUp_fcn()
- moveU_bln = false
- while not(moveU_bln) do
- turtle.digUp()
- turtle.attackUp()
- moveU_bln = turtle.up()
- end
- tCoordy_int = tCoordy_int + 1
- end
- -------------------------------------
- function turnRight_fcn()
- orientation_int = orientation_int - 1
- orientation_int = (orientation_int + 1) % 4
- orientation_int = orientation_int + 1
- turtle.turnRight()
- end
- function turnLeft_fcn()
- orientation_int = orientation_int - 1
- orientation_int = (orientation_int - 1) % 4
- orientation_int = orientation_int + 1
- turtle.turnLeft()
- end
- function look_fcn( direction )
- if direction > orientation_int then
- if direction == 4 and orientation_int == 1 then
- turnLeft_fcn()
- else
- while direction > orientation_int do
- turnRight_fcn()
- end
- end
- elseif direction < orientation_int then
- if direction == 1 and orientation_int == 4 then
- turnRight_fcn()
- else
- while direction < orientation_int do
- turnLeft_fcn()
- end
- end
- end
- end
- function goTo_fcn( xTarget, yTarget, zTarget )
- if xTarget > tCoordx_int then
- look_fcn( 2 )
- while xTarget > tCoordx_int do
- moveForward_fcn()
- end
- elseif xTarget < tCoordx_int then
- look_fcn( 4 )
- while xTarget < tCoordx_int do
- moveForward_fcn()
- end
- end
- if zTarget > tCoordz_int then
- look_fcn( 3 )
- while zTarget > tCoordz_int do
- moveForward_fcn()
- end
- elseif zTarget < tCoordz_int then
- look_fcn( 1 )
- while zTarget < tCoordz_int do
- moveForward_fcn()
- end
- end
- if yTarget > tCoordy_int then
- while yTarget > tCoordy_int do
- moveUp_fcn()
- end
- elseif yTarget < tCoordy_int then
- while yTarget < tCoordy_int do
- moveDown_fcn()
- end
- end
- end
- function felas_fcn ()
- for i = 1,magas do
- dig_fcn()
- if not(i==magas) then
- checkFuel()
- moveUp_fcn()
- end
- end
- fent = true
- end
- function leas_fcn()
- for i1 = 1,magas do
- dig_fcn()
- if not(i1==magas) then
- checkFuel()
- moveDown_fcn()
- end
- end
- fent = false
- end
- function left_fcn()
- turnLeft_fcn()
- checkFuel()
- moveForward_fcn()
- turnRight_fcn()
- end
- function right_fcn()
- turnRight_fcn()
- checkFuel()
- moveForward_fcn()
- turnLeft_fcn()
- end
- function ellenorzes_fcn() --ellenorzi hogy minden meg van e a feladathoz
- eredmeny = true
- fuel = turtle.getFuelLevel()
- ut = magas*szeles*hosszu
- print("uzemanyag szint: "..fuel)
- if doDumping_bln then
- print("nem tudom mennyi uzemanyag kell o.0")
- if lavaRefuel_bln or coalRefuel_bln then
- print("nem tudom mennyi uzemanyag marad o.0")
- eredmeny = true
- else
- print("min. kell: "..ut)
- if ut > fuel then
- eredmeny = false
- print("tul keves az uzemanyag")
- end
- end
- else
- print("ennyi uzemanyag kell: "..ut)
- if lavaRefuel_bln or coalRefuel_bln then
- print("nem tudom mennyi uzemanyag marad o.0")
- eredmeny = true
- else
- if ut > fuel then
- eredmeny = false
- print("tul keves az uzemanyag")
- else
- eredmeny = true
- print("ennyi uzemanyag marad: "..fuel-ut)
- end
- end
- end
- if fChest then
- if not( fChestX == chestX and fChestY == chestY and fChestZ == chestZ) then
- eredmeny = true
- print("van fChest ujra tudok tolteni!")
- else
- eredmeny = false
- print("a ket chest koordinataja nem lehet ugyan az!")
- end
- end
- if lavaRefuel_bln then
- turtle.select(16)
- data = turtle.getItemDetail()
- if turtle.getItemCount() == 1 then
- if data.name == "minecraft:bucket" then
- eredmeny = true
- else
- eredmeny = false
- print("az utolso (16.) slot-ba kell EGY vodor!")
- end
- else
- eredmeny = false
- print("az utolso (16.) slot-ba kell EGY vodor!")
- end
- end
- --wl worklevel es fl fuel level
- return eredmeny
- end
- function jobbLayer_fcn()
- for i2=1,szeles do
- if fent then
- leas_fcn()
- else
- felas_fcn()
- end
- if not(i2==szeles) then
- left_fcn()
- end
- end
- jobbOldal = false
- end
- function balLayer_fcn()
- for i3=1,szeles do
- if fent then
- leas_fcn()
- else
- felas_fcn()
- end
- if not(i3==szeles) then
- right_fcn()
- end
- end
- jobbOldal = true
- end
- --main
- workLevel = 0
- if lavaRefuel_bln then
- numberOfUseableSlots = 15
- else
- numberOfUseableSlots = 16
- end
- if ellenorzes_fcn() then
- for i2 = 1,hosszu do
- if jobbOldal then
- jobbLayer_fcn()
- else
- balLayer_fcn()
- end
- checkFuel()
- moveForward_fcn()
- print("fl:"..turtle.getFuelLevel())
- workLevel = i2/(hosszu*0.01)
- print("wl:"..workLevel.."%")
- end
- goTo_fcn(chestX, chestY, chestZ)
- dumping_fcn()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement