wartos

bridge5

Apr 3rd, 2022
1,774
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.71 KB | None | 0 0
  1. -- WIP
  2. function file_exists(name)
  3.   local f=fs.open(name,"r")
  4.   if f~=nil then f.close(f) return true else return false end --f.close(f) muss direkt auf das Handle angewandt werden.
  5. end
  6.  
  7. lengthX = 3
  8. lengthY = 3
  9. lengthZ = 3
  10. step = 0
  11.  
  12. matFloor = "minecraft:cobblestone"
  13. matWall = "minecraft:cobblestone"
  14. matFuel = "minecraft:coal"
  15. matFuelSlot = 1
  16. matFloorCount = 0 --counter, not realy used
  17. matFloorSlot = 2  --active slot for floor material
  18. matWallCount = 0  --counter, not realy used
  19. matWallSlot = 3   -- active slot for wall material
  20. matFloorSlotCount = 0
  21. matWallSlotCount = 0
  22.  
  23. if file_exists("myf") == true then
  24.   os.loadAPI("myf")
  25. else
  26.   print("Missing functions: please download from pastebin 6P9Bjq2p as myf")
  27.   return
  28. end
  29.  
  30. print("Please enter the slot number for each item. (The numbers start with 1)")
  31. print("Slot for fuel:")
  32. matFuelSlot=tonumber(read())
  33. print("Slot for floor:")
  34. matFloorSlot=tonumber(read())
  35. print("Slot for wall:")
  36. matWallSlot=tonumber(read())
  37.  
  38. -- input values for X, Y, Z
  39. print("Set X("..lengthX.."):")
  40. lengthX=tonumber(read())
  41. print("Set Y("..lengthY.."):")
  42. lengthY=tonumber(read())
  43. print("Set Z("..lengthZ.."):")
  44. lengthZ=tonumber(read())
  45.  
  46. function invCheck()
  47.   if turtle.getItemDetail(matFloorSlot) ~= nil then
  48.     matFloor = turtle.getItemDetail(matFloorSlot)
  49.   else
  50.     print("No floor material in slot "..matFloorSlot)
  51.   end
  52.  
  53.   if turtle.getItemDetail(matFloorSlot) ~= nil then
  54.     matWall  = turtle.getItemDetail(matWallSlot)
  55.   else
  56.     print("No wall material in slot "..matWallSlot)
  57.   end  
  58.  
  59.   if turtle.getItemDetail(matFloorSlot) ~= nil then
  60.     matFuel = turtle.getItemDetail(matFuelSlot)
  61.   else
  62.     print("No fuel in slot "..matFuelSlot)
  63.   end
  64.  
  65.  
  66.   return matWall, matFloor, matFuel
  67. end
  68.  
  69. function fuelCheck()
  70.     if turtle.getFuelLevel() < 80 then
  71.       print("Fuel level is low: "..turtle.getFuelLevel())
  72.       if turtle.getItemCount(matFuelSlot) >=1 then
  73.         turtle.select(matFuelSlot)
  74.         turtle.refuel(1)
  75.       else
  76.         print("low on fuel")
  77.         os.shutdown()
  78.       end
  79.     else
  80.       print("Fuel level is ok: "..turtle.getFuelLevel())
  81.     end
  82. end
  83.  
  84. function matCount()
  85.   -- check each inventory slot for wall or floor material and add it to its counter
  86.   for i=1,16 do
  87.     if turtle.getItemDetail(i) ~= nil then
  88.       if turtle.getItemDetail(i).name == matFloor.name then
  89.         matFloorCount = matFloorCount + turtle.getItemCount(i)
  90.       end
  91.       if turtle.getItemDetail(i).name == matWall.name then
  92.         matWallCount = matWallCount + turtle.getItemCount(i)
  93.       end
  94.     end
  95.   end
  96.   return matFloorCount, matWallCount
  97. end
  98.  
  99. function matSlot(itemName)
  100.  
  101.   -- select a inventory slot for item name
  102.   for i=1,16 do
  103.     if turtle.getItemDetail(i) ~= nil then
  104.       if turtle.getItemDetail(i).name == itemName then
  105.         return i
  106.       end
  107.     end
  108.   end
  109.  
  110. --  if slotNr == nil then
  111. --    print ("oops, no " .. itemName .. " left in inventory")
  112. --    err = true
  113. --    return
  114. --  end
  115. end
  116.  
  117.  
  118. function report()
  119.   print ("Selected floor material: "..matFloor.name)
  120.   print ("Number of floor material: "..matFloorCount)
  121.   print ("Number of floor material in active slot: "..matFloorSlotCount)
  122.   print ("Selected wall material: "..matWall.name)
  123.   print ("Number of wall material: "..matWallCount)
  124.   print ("Number of wall material in slot ".. ": "..matWallSlotCount)
  125.   print ("Fuel level is: "..turtle.getFuelLevel())
  126. end
  127.  
  128. function xLineStep()
  129.   -- bottom line, but only if floor material is set
  130.   if (_y == _yMin) and (matFloor ~= nil) then
  131.     matFloorSlot = matSlot(matFloor.name)
  132.     myf.tpd(matFloorSlot)
  133.   end
  134.   -- top line, but only if floor material is set
  135.   if (_y == _yMax) and (matFloor ~= nil) then
  136.     matFloorSlot = matSlot(matFloor.name)
  137.     myf.tpu(matFloorSlot)
  138.   end
  139. end
  140.  
  141.  
  142. function xLine(_yMin,_yMax,_y)
  143.   local x = 1
  144.   myf.ttl()
  145.   -- if walls have a matieral
  146.   if matWall ~= nil then
  147.     matWallSlot = matSlot(matWall.name)
  148.     myf.tpf(matWallSlot)
  149.   end
  150.   myf.ttr()
  151.   myf.ttr()
  152.   xLineStep()
  153.   while x <= lengthX do
  154.     myf.tmf()
  155.     xLineStep()
  156.     x = x + 1
  157.   end
  158.  
  159.   if matWall ~= nil then
  160.     matWallSlot = matSlot(matWall.name)
  161.     myf.tpf(matWallSlot)
  162.   end
  163.  
  164.  
  165.   -- hier geht es weiter !!!!!!!!!
  166.  
  167. end
  168.  
  169.  
  170. function xLineBottom()
  171.   print("starting bottom Line")
  172.   local x = 1
  173.   myf.ttl()
  174.   myf.tpf(matWallSlot)
  175.   matWallSlot = matSlot(matWall.name)
  176.   myf.ttr()
  177.   myf.ttr()
  178.   print("starting x-line")
  179.   myf.tpd(matFloorSlot)
  180.   while x < lengthX do
  181.     print("x-line forward")
  182.     myf.tmf()
  183.     print("x-line place down")
  184.     myf.tpd(matFloorSlot)
  185.     matFloorSlot = matSlot(matFloor.name)
  186.     x = x + 1
  187.   end
  188.   myf.tpd(matFloorSlot)
  189.   matFloorSlot = matSlot(matFloor.name)
  190.   myf.tpf(matWallSlot)
  191.   matWallSlot = matSlot(matWall.name)
  192.   myf.goback(lengthX-1)
  193.   myf.ttr()
  194.   x = nil    
  195. end
  196.  
  197. function xLineMiddle()
  198.   -- X not top, not bottom line
  199.   print("starting not bottom, not top Line")
  200.   local x = 1
  201.   myf.ttl()
  202.   myf.tpf(matWallSlot)
  203.   matWallSlot = matSlot(matWall.name)
  204.   myf.ttr()
  205.   myf.ttr()
  206.   while x < lengthX do
  207.     myf.tmf()
  208.     x = x + 1
  209.   end
  210.   myf.tpf(matWallSlot)
  211.   matWallSlot = matSlot(matWall.name)
  212.   myf.goback(lengthX - 1)
  213.   myf.ttr()
  214.   x = nil
  215. end
  216.  
  217. function xLineTop()
  218.   print("starting top Line")
  219.   local x = 1
  220.   myf.ttl()
  221.   myf.tpf(matWallSlot)
  222.   matWallSlot = matSlot(matWall.name)
  223.   myf.ttr()
  224.   myf.ttr()
  225.   print("starting x-line")
  226.   while x < lengthX do
  227.     print("x-line place up")
  228.     myf.tpu(matFloorSlot)
  229.     matFloorSlot = matSlot(matFloor.name)
  230.     print("x-line forward")
  231.     myf.tmf()
  232.     x = x + 1
  233.   end
  234.   myf.tpu(matFloorSlot)
  235.   matFloorSlot = matSlot(matFloor.name)
  236.   myf.tpf(matWallSlot)
  237.   myf.goback(lengthX-1)
  238.   myf.ttr()
  239.   x = nil  
  240. end
  241.  
  242.  
  243. function yLine()
  244.   -- the Y-line
  245.   local y = 1
  246.   while y <= lengthY do
  247.     fuelCheck()
  248.     if y == 1 then
  249.       -- X bottom line
  250.       xLineBottom()
  251.     elseif y == lengthY then    
  252.       -- X top line
  253.       xLineTop()
  254.     else
  255.       xLineMiddle()
  256.     end
  257.    
  258.     if y < lengthY then
  259.       myf.tmu()
  260.     end
  261.    
  262.     y = y + 1
  263.    
  264.   end
  265.   print("go down "..y-1)
  266.   myf.godown(y-1)
  267.  
  268.  
  269. end
  270.  
  271.  
  272. function doWork()
  273.   invCheck()
  274.   matCount()
  275.   fuelCheck()
  276.  
  277.   -- number of items in selected material slot
  278.   matFloorSlotCount = turtle.getItemCount(matSlot(matFloor.name))
  279.   matWallSlotCount = turtle.getItemCount(matSlot(matWall.name))
  280.  
  281.   report()
  282.  
  283.   -- the Z line
  284.   local z = 1
  285.   while z <= lengthZ do
  286.     fuelCheck()
  287.    
  288.     if z <= lengthZ then      
  289.       yLine()
  290.       myf.tmf()
  291.     end
  292.    
  293.     z = z + 1
  294.    
  295.   end
  296.   print("go back "..z-1)
  297.   myf.goback(z-1)
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304. end
  305.      
  306.  
  307. doWork()
  308.  
  309.  
Advertisement
Add Comment
Please, Sign In to add comment