Advertisement
Marnty

TableSidePoop

Oct 26th, 2021 (edited)
825
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.17 KB | None | 0 0
  1. --getting started and resetting some shit
  2. term.clear()
  3. turtle.select(1)
  4. --declaring globals maybe!?
  5.  
  6. --Initialise functions
  7.  
  8. function turtRefuel(amount) --function to refuel
  9.     turtle.select(16)
  10.     if turtle.refuel(0) == true then
  11.         if amount < 64 then
  12.             turtle.refuel(amount)
  13.         else
  14.             turtle.refuel(64)
  15.         end
  16.     else
  17.         print("This item cannot be used to refuel!\n")
  18.     end
  19. end
  20.  
  21. function yesNo() --function to get user to answer yes/no
  22.     tmp = ""
  23.     term.write("Are you ready? (y/n): ")
  24.     tmp = io.read()
  25.     while true do
  26.         if (string.lower(tmp) == "y") or (string.lower(tmp) == "yes") then
  27.             term.clear()
  28.             break
  29.         elseif (string.lower(tmp) == "n") or (string.lower(tmp) == "no") then
  30.             print("\nOkay, byebye...\n")
  31.             os.sleep(1)
  32.             print(".")
  33.             os.sleep(1)
  34.             term.write(".")
  35.             os.sleep(1)
  36.             term.write(".")
  37.             os.reboot()
  38.         else
  39.             print("\nI didn't understand that\n")
  40.             term.write("Are you ready? (y/n): ")
  41.             tmp = io.read()
  42.         end
  43.         end
  44. end
  45.  
  46. function nth(n) --Nth triangle shit cus math library sucks ass
  47.     if (n == 0) then
  48.         return 1
  49.     else
  50.         return ((n * (n + 1)) / 2)
  51.     end
  52. end
  53.  
  54. function initCheckBuckets() -- to check if there are 15 buckets to start and disperse them equally
  55.     trip = 0
  56.     for i=1,15 do
  57.         nameItem = turtle.getItemDetail(i)
  58.         if nameItem ~= nil then
  59.             if (nameItem["name"] == "minecraft:bucket") and (nameItem["count"] == 1) then
  60.                 trip = trip + 1
  61.             end
  62.         end
  63.     end
  64.     if trip == 15 then
  65.         --continue out of this function
  66.     else
  67.         nameItem = turtle.getItemDetail(1)
  68.         if (nameItem["name"] == "minecraft:bucket") and (nameItem["count"] ~= 15) then --determines if there's the right amount of buckets in the first slot
  69.             print("Buckets are present in slot 1 but not 15!!!\n\nTurtle will now restart, fix ur shit")
  70.             yesNo()
  71.             os.reboot()
  72.         else
  73.             for i=2,15 do
  74.                 nameItem = turtle.getItemDetail(i)
  75.                 if nameItem ~= nil then
  76.                     print("Something is obstructing the buckets to be equally dispearsed!!!\n\nTurtle will now restart, fix ur shit")
  77.                     yesNo()
  78.                     os.reboot()
  79.                 end
  80.             end
  81.             nameItem = turtle.getItemDetail(1)
  82.             bucketCount = nameItem["count"]
  83.             if (bucketCount == 15) then -- for loop that equally spreads out the 15 buckets excluding the last slot reserved for fuel
  84.                 turtle.select(1)
  85.                 for i=2,bucketCount do
  86.                     turtle.transferTo(i, 1)
  87.                 end
  88.             end
  89.         end
  90.     end
  91. end
  92. function refillPoop()
  93.     print("NEED MORE SHIT\n")
  94.     for i=1, 15 do
  95.         turtle.select(i)
  96.         nameItem = {}
  97.         nameItem = turtle.getItemDetail()
  98.         if (nameItem ~= nil) then
  99.             if nameItem["name"] == "minecraft:bucket" then
  100.                 turtle.drop()
  101.                 turtle.suck()
  102.             end
  103.         else
  104.             print("Slot is empty\n")
  105.         end
  106.     end
  107. end
  108.  
  109. function rePoop(xPaced, zPaced, yPaced, direction)
  110.     print("Returning for more shite :)\n")
  111.     if yPaced == 0 then --if its on the top layer
  112.         if direction == 1 then -- if its travelling/facing away
  113.             if zPaced == 0 then -- if turtle on the same Z axis as home point
  114.                 turtle.turnLeft()
  115.                 turtle.turnLeft()
  116.                 for i=1,xPaced do
  117.                     turtle.forward()
  118.                 end
  119.                 refillPoop()
  120.                 turtle.turnLeft()
  121.                 turtle.turnLeft()
  122.                 for i=1,xPaced do
  123.                     turtle.forward()
  124.                 end
  125.                 return
  126.             else -- if turtle is away from home points Z axis
  127.                 turtle.turnLeft()
  128.                 for i=1,zPaced do
  129.                     turtle.forward()
  130.                 end
  131.                 turtle.turnLeft()
  132.                 for i=1,xPaced do
  133.                     turtle.forward()
  134.                 end
  135.                 refillPoop()
  136.                 turtle.turnLeft()
  137.                 turtle.turnLeft()
  138.                 for i=1,xPaced do
  139.                     turtle.forward()
  140.                 end
  141.                 turtle.turnRight()
  142.                 for i=1,zPaced do
  143.                     turtle.forward()
  144.                 end
  145.                 turtle.turnLeft()
  146.                 return
  147.             end
  148.         else -- if its travelling/facing towards homepoint
  149.             if xPaced == 0 then -- if turtle on the same X axis as home point
  150.                 turtle.turnRight()
  151.                 for i=1,zPaced do
  152.                     turtle.forward()
  153.                 end
  154.                 turtle.turnLeft()
  155.                 refillPoop()
  156.                 turtle.turnLeft()
  157.                 turtle.turnLeft()
  158.                 for i=1,zPaced do
  159.                     turtle.forward()
  160.                 end
  161.                 turtle.turnRight()
  162.                 return
  163.             else -- if turtle is away from home points X axis
  164.                 turtle.turnRight()
  165.                 for i=1,zPaced do
  166.                     turtle.forward()
  167.                 end
  168.                 turtle.turnLeft()
  169.                 for i=1,xPaced do
  170.                     turtle.forward()
  171.                 end
  172.                 refillPoop()
  173.                 turtle.turnLeft()
  174.                 turtle.turnLeft()
  175.                 for i=1,xPaced do
  176.                     turtle.forward()
  177.                 end
  178.                 turtle.turnRight()
  179.                 for i=1,zPaced do
  180.                     turtle.forward()
  181.                 end
  182.                 turtle.turnRight()
  183.                 return
  184.             end
  185.         end
  186.     else --if its below the top layer
  187.         if direction == 1 then -- if its travelling/facing away
  188.             if zPaced == 0 then -- if turtle on the same Z axis as home point
  189.                 for i=1,yPaced do
  190.                     turtle.up()
  191.                 end
  192.                 turtle.turnLeft()
  193.                 turtle.turnLeft()
  194.                 for i=1,xPaced do
  195.                     turtle.forward()
  196.                 end
  197.                 refillPoop()
  198.                 turtle.turnLeft()
  199.                 turtle.turnLeft()
  200.                 for i=1,xPaced do
  201.                     turtle.forward()
  202.                 end
  203.                 for i=1,yPaced do
  204.                     turtle.down()
  205.                 end
  206.                 return
  207.             else -- if turtle is away from home points Z axis
  208.                 for i=1,yPaced do
  209.                     turtle.up()
  210.                 end
  211.                 turtle.turnLeft()
  212.                 for i=1,zPaced do
  213.                     turtle.forward()
  214.                 end
  215.                 turtle.turnLeft()
  216.                 for i=1,xPaced do
  217.                     turtle.forward()
  218.                 end
  219.                 refillPoop()
  220.                 turtle.turnLeft()
  221.                 turtle.turnLeft()
  222.                 for i=1,xPaced do
  223.                     turtle.forward()
  224.                 end
  225.                 turtle.turnRight()
  226.                 for i=1,zPaced do
  227.                     turtle.forward()
  228.                 end
  229.                 turtle.turnLeft()
  230.                 for i=1,yPaced do
  231.                     turtle.down()
  232.                 end
  233.                 return
  234.             end
  235.         else -- if its travelling/facing towards homepoint
  236.             if xPaced == 0 then -- if turtle on the same X axis as home point
  237.                 for i=1,yPaced do
  238.                     turtle.up()
  239.                 end
  240.                 turtle.turnRight()
  241.                 for i=1,zPaced do
  242.                     turtle.forward()
  243.                 end
  244.                 turtle.turnLeft()
  245.                 refillPoop()
  246.                 turtle.turnLeft()
  247.                 for i=1,zPaced do
  248.                     turtle.forward()
  249.                 end
  250.                 turtle.turnRight()
  251.                 for i=1,yPaced do
  252.                     turtle.down()
  253.                 end
  254.                 return
  255.             else -- if turtle is away from home points X axis
  256.                 for i=1,yPaced do
  257.                     turtle.up()
  258.                 end
  259.                 turtle.turnRight()
  260.                 for i=1,zPaced do
  261.                     turtle.forward()
  262.                 end
  263.                 turtle.turnLeft()
  264.                 for i=1,xPaced do
  265.                     turtle.forward()
  266.                 end
  267.                 refillPoop()
  268.                 turtle.turnLeft()
  269.                 turtle.turnLeft()
  270.                 for i=1,xPaced do
  271.                     turtle.forward()
  272.                 end
  273.                 turtle.turnRight()
  274.                 for i=1,zPaced do
  275.                     turtle.forward()
  276.                 end
  277.                 turtle.turnRight()
  278.                 for i=1,yPaced do
  279.                     turtle.down()
  280.                 end
  281.                 return
  282.             end
  283.         end
  284.     end
  285. end
  286.  
  287. function poopin()
  288.     if turtle.detectDown() == false then
  289.         turtle.placeDown()
  290.         return true
  291.     end
  292.         return false
  293. end
  294.  
  295.  
  296. --  ################################
  297. --  ########### STARTING ###########
  298. --  ################################
  299. term.setCursorPos(1, 1)
  300. print("============ TableSidePoop ============\n")
  301. print("This program will fill a hole with \ncomplete shite... literally\n\n")
  302. os.sleep(3)
  303.  
  304. --disclaimer/EULA type beat
  305. print("Please insert 15 empty buckets into slot 1 :)")
  306. yesNo()
  307. term.clear()
  308. term.setCursorPos(1, 1)
  309. initCheckBuckets()
  310. print("The dumpy turtle will need to be facing the direction of the hole to fill and placed above the hole not on the block on the walls of the hole\n")
  311. os.sleep(2)
  312. print("A tank of some sort should be placed to its back and a chest to dump excess shit\n")
  313. os.sleep(2)
  314. print("The dumpy turtle should also be on the left corner of the hole to fill")
  315. os.sleep(2)
  316. yesNo()
  317.  
  318. --getting dims
  319. term.setCursorPos(1,1)
  320. print("What dimensions would you like to fill?\n")
  321.  
  322. os.sleep(1)
  323. term.write("Length: ")
  324. x = math.floor(math.abs(tonumber(io.read()) or x))
  325. term.write("Width: ")
  326. z = math.floor(math.abs(tonumber(io.read()) or z))
  327. term.write("Depth: ")
  328. y = math.floor(math.abs(tonumber(io.read()) or y))
  329.  
  330. --print(x,z,y)
  331.  
  332. os.sleep(1)
  333. --get fuel needed for complete operation
  334. area = (x * z) * y --get area
  335. maxBack = (x + z) * y --get max perimeter and times needed to get back
  336.  
  337. fuelNeeded = area + maxBack + nth(y) --adds all together and nth triangle shit of y cus it will need to go up multiple times init remember why this is right you shithead
  338.  
  339. -- add a EULA/NOTICE type beat for how many buckets of liquid will be needed
  340. term.clear()
  341. term.setCursorPos(1,1)
  342. print(string.format("The amount of liquid needed to complete this job is going to be: %d buckets\n", area))
  343. os.sleep(1)
  344. print("make sure to have enough before continuing...")
  345. os.sleep(1)
  346. yesNo()
  347.  
  348. term.clear()
  349. term.setCursorPos(1,1)
  350. print("\namount of fuel needed to complete \nthis order of shite:", fuelNeeded)
  351. os.sleep(3)
  352. --check if already enough fuel
  353. tmp= fuelNeeded
  354. fuelLevel = turtle.getFuelLevel()
  355. if fuelLevel > tmp then
  356.     print("\nThere's already enough fuel to get to shittin'\n\n")
  357. else
  358.     --start refuelling
  359.     turtle.select(16)
  360.     term.clear()
  361.     term.setCursorPos(1, 1)
  362.     print("Starting Refueling process...\n")
  363.     i=0
  364.     while fuelLevel <= tmp do
  365.         i = i + 1
  366.         if tmp < 64 then
  367.             turtRefuel(tmp)
  368.         else
  369.             turtRefuel(tmp)
  370.             tmp = tmp - 64
  371.         end
  372.         fuelLevel = turtle.getFuelLevel()
  373.         term.clear()
  374.         term.setCursorPos(1, 1)
  375.         print("Starting Refueling process...\n")
  376.         print(string.format("Fuel still needed!"))
  377.         if i == 1 then
  378.             print(".")
  379.         else if i == 2 then
  380.             print("..")
  381.         else if i == 3 then
  382.             print("...")
  383.             i = 0
  384.         end
  385.         end
  386.         end
  387.     end
  388.     term.clear()
  389.     term.setCursorPos(1, 1)
  390.     print("Refueling Complete, dumping access fuel if any...\n")
  391.     -- drop remainging fuel if any is present in inv (IN FUTURE MAKE THIS DUMP INTO AN INV OR SMTH)
  392.         turtle.select(16)
  393.         if turtle.refuel(0) == true then
  394.             turtle.turnLeft()
  395.             turtle.drop(64)
  396.             turtle.turnRight()
  397.         end
  398.     turtle.select(1)
  399. end
  400.  
  401. --fill the first wave of buckets
  402. turtle.turnLeft()
  403. turtle.turnLeft()
  404. for i=1, 15 do
  405.     turtle.select(i)
  406.     itemNamed = {}
  407.     itemNamed = turtle.getItemDetail()
  408.     if (itemNamed ~= nil) then
  409.         if itemNamed["name"] == "minecraft:bucket" then
  410.             turtle.drop()
  411.             turtle.suck()
  412.         end
  413.     else
  414.         print("Slot is empty\n")
  415.     end
  416. end
  417. turtle.select(1)
  418. turtle.turnLeft()
  419. turtle.turnLeft()
  420.  
  421. --movement phases debug
  422. term.clear()
  423. term.setCursorPos(1, 1)
  424. print("Starting movement phase!!!\n")
  425. tmpY = y-1
  426. placed = 1
  427. for i3=1,y do -- go to lowest layer first then up more layer first
  428.     xPaced = 0 --amount of blocks moved to use to return etc
  429.     zPaced = 0
  430.     yPaced = 0
  431.     tmpSlot = 1
  432.     if y > 1 then
  433.         for i4=1,tmpY do
  434.             turtle.down()
  435.             yPaced = yPaced + 1
  436.             print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  437.         end
  438.     end
  439.     for i=1,z do --Iterate over the width
  440.         if placed == 16 then -- this sees the last block has been placed so trigger the rePoop function to refill the buckets and return to the same spot to continue
  441.             rePoop(xPaced, zPaced, yPaced, math.fmod(i, 2))
  442.             placed = 1
  443.             turtle.select(placed)
  444.             poopin()
  445.             placed = placed + 1
  446.         else -- this places the block then iterates placed by one to move the slot along
  447.             turtle.select(placed)
  448.             poopin()
  449.             placed = placed + 1
  450.         end
  451.         for i2=1,x-1 do --Iterate over the length
  452.             turtle.forward()
  453.             --place place function here
  454.             if placed == 16 then -- this sees the last block has been placed so trigger the rePoop function to refill the buckets and return to the same spot to continue
  455.                 if math.fmod(i, 2) == 1 then --Decided whether travelling forwards or backwards
  456.                     xPaced = xPaced + 1
  457.                     print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  458.                 else
  459.                     xPaced = xPaced - 1
  460.                     print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  461.                 end
  462.                 rePoop(xPaced, zPaced, yPaced, math.fmod(i, 2))
  463.                 placed = 1
  464.                 turtle.select(placed)
  465.                 poopin()
  466.                 placed = placed + 1
  467.             else -- this places the block then iterates placed by one to move the slot along
  468.                 turtle.select(placed)
  469.                 poopin()
  470.                 placed = placed + 1
  471.                 if math.fmod(i, 2) == 1 then --Decided whether travelling forwards or backwards
  472.                     xPaced = xPaced + 1
  473.                     print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  474.                 else
  475.                     xPaced = xPaced - 1
  476.                     print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  477.                 end
  478.             end
  479.         end
  480.         if math.fmod(i, 2) == 1 then --Decided whether to turn left or right
  481.             if i ~= z then
  482.                 turtle.turnRight()
  483.                 turtle.forward()
  484.                 turtle.turnRight()
  485.                 zPaced = zPaced + 1
  486.                 print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  487.             end
  488.         else
  489.             if i ~= z then
  490.                 turtle.turnLeft()
  491.                 turtle.forward()
  492.                 turtle.turnLeft()
  493.                 zPaced = zPaced + 1
  494.                 print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  495.             end
  496.         end
  497.     end
  498.     --start return to home point
  499.     if math.fmod(z, 2) == 1 then --if the turtle finished the y axis away from the starting point
  500.         turtle.turnLeft()
  501.         for p=1,z-1 do
  502.             turtle.forward()
  503.             zPaced = zPaced - 1
  504.             print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  505.         end
  506.         turtle.turnLeft()
  507.         for p=1,x-1 do
  508.             turtle.forward()
  509.             xPaced = xPaced - 1
  510.             print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  511.         end
  512.         turtle.turnLeft()
  513.         turtle.turnLeft()
  514.     else --if the turtle finished the y axis on line with the starting point
  515.         turtle.turnRight()
  516.         for p=1,z-1 do
  517.             turtle.forward()
  518.             zPaced = zPaced - 1
  519.             print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  520.         end
  521.         turtle.turnRight()
  522.     end
  523.     --raises it back to home point layer
  524.     if y > 1 then
  525.         for i4=1,tmpY do
  526.             turtle.up()
  527.             yPaced = yPaced - 1
  528.             print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  529.         end
  530.     end
  531.     print(string.format("[%d,%d,%d] %d\n",xPaced,zPaced,yPaced,placed))
  532.     --remove 1 from y access
  533.     tmpY = tmpY-1
  534. end
  535.  
  536. --dumping left over inv
  537. term.clear()
  538. term.setCursorPos(1,1)
  539. i=0
  540. turtle.turnLeft()
  541. for finish_it=1,16 do
  542.     turtle.select(finish_it)
  543.     turtle.drop(64)
  544.    
  545.     i=i+1
  546.     term.clear()
  547.     term.setCursorPos(1, 1)
  548.     print("Cleaning up...\nDumping excess shit into chest!")
  549.     if i == 1 then
  550.         print(".")
  551.     else if i == 2 then
  552.         print("..")
  553.     else if i == 3 then
  554.         print("...")
  555.         i = 0
  556.     end
  557.     end
  558.     end
  559. end
  560. turtle.turnRight()
  561. os.sleep(1)
  562.  
  563. term.clear()
  564. term.setCursorPos(1,1)
  565. print("\n\n\n\n\n=======================================\n========== FINISHED SHITTIN' ==========\n=======================================\n\n\n\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement