Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WIP
- function file_exists(name)
- local f=fs.open(name,"r")
- if f~=nil then f.close(f) return true else return false end --f.close(f) muss direkt auf das Handle angewandt werden.
- end
- lengthX = 3
- lengthY = 3
- lengthZ = 3
- step = 0
- matFloor = "minecraft:cobblestone"
- matWall = "minecraft:cobblestone"
- matFuel = "minecraft:coal"
- matFuelSlot = 1
- matFloorCount = 0 --counter, not realy used
- matFloorSlot = 2 --active slot for floor material
- matWallCount = 0 --counter, not realy used
- matWallSlot = 3 -- active slot for wall material
- matFloorSlotCount = 0
- matWallSlotCount = 0
- if file_exists("myf") == true then
- os.loadAPI("myf")
- else
- print("Missing functions: please download from pastebin 6P9Bjq2p as myf")
- return
- end
- print("Please enter the slot number for each item. (The numbers start with 1)")
- print("Slot for fuel:")
- matFuelSlot=tonumber(read())
- print("Slot for floor:")
- matFloorSlot=tonumber(read())
- print("Slot for wall:")
- matWallSlot=tonumber(read())
- -- input values for X, Y, Z
- print("Set X("..lengthX.."):")
- lengthX=tonumber(read())
- print("Set Y("..lengthY.."):")
- lengthY=tonumber(read())
- print("Set Z("..lengthZ.."):")
- lengthZ=tonumber(read())
- function invCheck()
- if turtle.getItemDetail(matFloorSlot) ~= nil then
- matFloor = turtle.getItemDetail(matFloorSlot)
- else
- print("No floor material in slot "..matFloorSlot)
- end
- if turtle.getItemDetail(matFloorSlot) ~= nil then
- matWall = turtle.getItemDetail(matWallSlot)
- else
- print("No wall material in slot "..matWallSlot)
- end
- if turtle.getItemDetail(matFloorSlot) ~= nil then
- matFuel = turtle.getItemDetail(matFuelSlot)
- else
- print("No fuel in slot "..matFuelSlot)
- end
- return matWall, matFloor, matFuel
- end
- function fuelCheck()
- if turtle.getFuelLevel() < 80 then
- print("Fuel level is low: "..turtle.getFuelLevel())
- if turtle.getItemCount(matFuelSlot) >=1 then
- turtle.select(matFuelSlot)
- turtle.refuel(1)
- else
- print("low on fuel")
- os.shutdown()
- end
- else
- print("Fuel level is ok: "..turtle.getFuelLevel())
- end
- end
- function matCount()
- -- check each inventory slot for wall or floor material and add it to its counter
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil then
- if turtle.getItemDetail(i).name == matFloor.name then
- matFloorCount = matFloorCount + turtle.getItemCount(i)
- end
- if turtle.getItemDetail(i).name == matWall.name then
- matWallCount = matWallCount + turtle.getItemCount(i)
- end
- end
- end
- return matFloorCount, matWallCount
- end
- function matSlot(itemName)
- -- select a inventory slot for item name
- for i=1,16 do
- if turtle.getItemDetail(i) ~= nil then
- if turtle.getItemDetail(i).name == itemName then
- return i
- end
- end
- end
- -- if slotNr == nil then
- -- print ("oops, no " .. itemName .. " left in inventory")
- -- err = true
- -- return
- -- end
- end
- function report()
- print ("Selected floor material: "..matFloor.name)
- print ("Number of floor material: "..matFloorCount)
- print ("Number of floor material in active slot: "..matFloorSlotCount)
- print ("Selected wall material: "..matWall.name)
- print ("Number of wall material: "..matWallCount)
- print ("Number of wall material in slot ".. ": "..matWallSlotCount)
- print ("Fuel level is: "..turtle.getFuelLevel())
- end
- function xLineStep()
- -- bottom line, but only if floor material is set
- if (_y == _yMin) and (matFloor ~= nil) then
- matFloorSlot = matSlot(matFloor.name)
- myf.tpd(matFloorSlot)
- end
- -- top line, but only if floor material is set
- if (_y == _yMax) and (matFloor ~= nil) then
- matFloorSlot = matSlot(matFloor.name)
- myf.tpu(matFloorSlot)
- end
- end
- function xLine(_yMin,_yMax,_y)
- local x = 1
- myf.ttl()
- -- if walls have a matieral
- if matWall ~= nil then
- matWallSlot = matSlot(matWall.name)
- myf.tpf(matWallSlot)
- end
- myf.ttr()
- myf.ttr()
- xLineStep()
- while x <= lengthX do
- myf.tmf()
- xLineStep()
- x = x + 1
- end
- if matWall ~= nil then
- matWallSlot = matSlot(matWall.name)
- myf.tpf(matWallSlot)
- end
- -- hier geht es weiter !!!!!!!!!
- end
- function xLineBottom()
- print("starting bottom Line")
- local x = 1
- myf.ttl()
- myf.tpf(matWallSlot)
- matWallSlot = matSlot(matWall.name)
- myf.ttr()
- myf.ttr()
- print("starting x-line")
- myf.tpd(matFloorSlot)
- while x < lengthX do
- print("x-line forward")
- myf.tmf()
- print("x-line place down")
- myf.tpd(matFloorSlot)
- matFloorSlot = matSlot(matFloor.name)
- x = x + 1
- end
- myf.tpd(matFloorSlot)
- matFloorSlot = matSlot(matFloor.name)
- myf.tpf(matWallSlot)
- matWallSlot = matSlot(matWall.name)
- myf.goback(lengthX-1)
- myf.ttr()
- x = nil
- end
- function xLineMiddle()
- -- X not top, not bottom line
- print("starting not bottom, not top Line")
- local x = 1
- myf.ttl()
- myf.tpf(matWallSlot)
- matWallSlot = matSlot(matWall.name)
- myf.ttr()
- myf.ttr()
- while x < lengthX do
- myf.tmf()
- x = x + 1
- end
- myf.tpf(matWallSlot)
- matWallSlot = matSlot(matWall.name)
- myf.goback(lengthX - 1)
- myf.ttr()
- x = nil
- end
- function xLineTop()
- print("starting top Line")
- local x = 1
- myf.ttl()
- myf.tpf(matWallSlot)
- matWallSlot = matSlot(matWall.name)
- myf.ttr()
- myf.ttr()
- print("starting x-line")
- while x < lengthX do
- print("x-line place up")
- myf.tpu(matFloorSlot)
- matFloorSlot = matSlot(matFloor.name)
- print("x-line forward")
- myf.tmf()
- x = x + 1
- end
- myf.tpu(matFloorSlot)
- matFloorSlot = matSlot(matFloor.name)
- myf.tpf(matWallSlot)
- myf.goback(lengthX-1)
- myf.ttr()
- x = nil
- end
- function yLine()
- -- the Y-line
- local y = 1
- while y <= lengthY do
- fuelCheck()
- if y == 1 then
- -- X bottom line
- xLineBottom()
- elseif y == lengthY then
- -- X top line
- xLineTop()
- else
- xLineMiddle()
- end
- if y < lengthY then
- myf.tmu()
- end
- y = y + 1
- end
- print("go down "..y-1)
- myf.godown(y-1)
- end
- function doWork()
- invCheck()
- matCount()
- fuelCheck()
- -- number of items in selected material slot
- matFloorSlotCount = turtle.getItemCount(matSlot(matFloor.name))
- matWallSlotCount = turtle.getItemCount(matSlot(matWall.name))
- report()
- -- the Z line
- local z = 1
- while z <= lengthZ do
- fuelCheck()
- if z <= lengthZ then
- yLine()
- myf.tmf()
- end
- z = z + 1
- end
- print("go back "..z-1)
- myf.goback(z-1)
- end
- doWork()
Advertisement
Add Comment
Please, Sign In to add comment