Shaka01

full remote receiver_sophisticated

Jan 27th, 2024 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.66 KB | None | 0 0
  1. if not fs.exists("API") then
  2.     shell.run("pastebin", "get", "EzkfU5ZM", "API")
  3. end
  4. shaka = require("API")
  5. shaka.connectModem()
  6. direction = nil
  7. compFound = false --- CHANGE THIS TO FALSE
  8. dropped = 0
  9. speaker = peripheral.find("speaker")
  10. -- speaker.playSound("entity.lightning_bolt.impact")
  11.  
  12.  
  13. local args = { ... }
  14.  
  15. args = tonumber(args[1])
  16. local moveSetFileName = "newMoveSet"
  17.  
  18.  
  19.  
  20. local function generateMoveSetFiles()
  21.     local counter = 0
  22.     local newFileName = nil
  23.     if fs.exists(moveSetFileName) then
  24.         while true do
  25.             newFileName = moveSetFileName..counter
  26.             if fs.exists(newFileName) then
  27.                 print(newFileName, "exists -", counter)
  28.                 counter = counter + 1
  29.             else
  30.                 return newFileName, counter
  31.             end
  32.         end
  33.     end
  34. end
  35.  
  36. -- print(generateMoveSetFiles())
  37.  
  38. local function findPocketComputer()
  39.     id = nil --- change this to nil !!!!!!!!!!!!!!!!!!!!!!!!
  40.     while not compFound do
  41.         shaka.clearScreen()
  42.         shaka.changeColors(colors.gray, colors.yellow)
  43.         textutils.slowPrint("Searching for transmitter..\n")
  44.         rednet.broadcast("anybody out there?", "transporterPing")
  45.         local id, msg = rednet.receive("transporterAnswer", 0.1)
  46.         if id then
  47.             shaka.changeColors(colors.black, colors.green)
  48.             textutils.slowPrint("Success..\n")
  49.             print("Connected to PocketPC ID: "..id..".")
  50.             term.setTextColor(colors.yellow)
  51.             print("Ready to receive commands.")
  52.             compFound = true
  53.             break
  54.         end
  55.     end
  56. end
  57.  
  58. local function leftTurn()
  59.     turtle.turnLeft()
  60.     if direction == "north" then
  61.         direction = "west"
  62.     elseif direction == "west" then
  63.         direction = "south"
  64.     elseif direction == "south" then
  65.         direction = "east"
  66.     elseif direction == "east" then
  67.         direction = "north"
  68.     end
  69.     return true
  70. end
  71.  
  72. function rightTurn()
  73.     turtle.turnRight()
  74.     if direction == "north" then
  75.         direction = "east"
  76.     elseif direction == "east" then
  77.         direction = "south"
  78.     elseif direction == "south" then
  79.         direction = "west"
  80.     elseif direction == "west" then
  81.         direction = "north"
  82.     end
  83.     return true
  84. end
  85.  
  86.  
  87. local function findDirection()
  88.     print("Finding direction..")
  89.     shaka.turtleResetRedstone()
  90.     local x, y, z = gps.locate()
  91.    
  92.     local leftTurns = 0
  93.     local upLock = false
  94.     local downLock = false
  95.     local upCount = 0
  96.     local downCount = 0
  97.    
  98.     --find spot to move forward
  99.     if not turtle.forward() then
  100.         repeat
  101.             leftTurns = leftTurns + 1
  102.             turtle.turnLeft()
  103.             if leftTurns == 4 then
  104.                 if turtle.up() then
  105.                     upCount = upCount + 1
  106.                 else
  107.                     for i = 1, upCount do
  108.                         turtle.down()
  109.                     end
  110.                     upCount = 0
  111.                     upLock = true
  112.                 end
  113.                 if upLock then
  114.                     if turtle.down() then
  115.                         downCount = downCount + 1
  116.                     else
  117.                         downLock = true
  118.                     end
  119.                 end
  120.                 leftTurns = 0
  121.             end
  122.             if downLock then
  123.                 return false
  124.             end
  125.         until turtle.forward()
  126.     end
  127.    
  128.     --determine direction
  129.     local aNew, b, zNew = gps.locate()
  130.     if zNew < z then
  131.         direction = "north"
  132.     elseif zNew > z then
  133.         direction = "south"
  134.     elseif aNew < x then
  135.         direction = "west"
  136.     elseif aNew > x then
  137.         direction = "east"
  138.     end
  139.    
  140.     --go back to original position
  141.     repeat until turtle.back()
  142.    
  143.     for i = 1, leftTurns do
  144.         rightTurn()
  145.     end
  146.    
  147.     for i = 1, upCount do
  148.         repeat sleep(0.1) until turtle.down()
  149.     end
  150.    
  151.     for i = 1, downCount do
  152.         repeat sleep(0.1) until turtle.up()
  153.     end
  154.     -- print("yay")
  155.     return direction
  156. end
  157.  
  158. function getTotalInvSize()
  159.     local totalSize = 0
  160.     for i = 1, 16 do
  161.         totalSize = totalSize + turtle.getItemCount(i)
  162.     end
  163.     return totalSize
  164. end
  165.  
  166. local function suckItems(suckDir, amount)
  167.     local startingInv = getTotalInvSize()
  168.     local x, y = term.getCursorPos()
  169.     local missingAmount = 0
  170.     local currentInv = 0
  171.     turtle.select(1)
  172.     -- local itemsAfterAction = 0
  173.     local amount = tonumber(amount)
  174.     -- print(amount)
  175.     local turtleDir = nil
  176.     if suckDir == "front" then
  177.         turtleDir = turtle.suck
  178.     elseif suckDir == "up" then
  179.         turtleDir = turtle.suckUp
  180.     elseif suckDir == "down" then
  181.         turtleDir = turtle.suckDown
  182.     end
  183.    
  184.     if amount ~= nil then
  185.         repeat
  186.             currentInv = getTotalInvSize() - startingInv
  187.             missingAmount = amount - currentInv
  188.             if turtleDir(missingAmount) == false then
  189.                 currentInv = getTotalInvSize() - startingInv
  190.                 if currentInv ~= amount then
  191.                     term.setCursorPos(x, y - 1)
  192.                     term.clearLine()
  193.                     textutils.slowPrint("Still missing "..missingAmount.." items.")
  194.                 end
  195.                 sleep(0.1)
  196.             end
  197.         until currentInv == amount
  198.     else
  199.         repeat sleep(0.1) until turtleDir() == false
  200.         amount = getTotalInvSize() - startingInv
  201.     end
  202.    
  203.     term.setCursorPos(x, y - 1)
  204.     term.clearLine()
  205.     shaka.changeColors(colors.black, colors.lightBlue)
  206.     term.write("- Sucked items: ")
  207.     shaka.changeColors(colors.black, colors.orange)
  208.     term.write(amount)
  209.     shaka.changeColors(colors.black, colors.white)
  210.     shaka.nextLine()
  211. end
  212.  
  213.  
  214.  
  215. -- Function to drop items from turtle's inventory
  216. function dropItems(dropDir, amount, itemName)
  217.   -- Determine which direction to drop items
  218.   local x, y = term.getCursorPos()
  219.   local dropAmount = 0
  220.   local dropFunc = nil
  221.   local amount = tonumber(amount) or 10000
  222.   if dropDir == "front" then
  223.     dropFunc = turtle.drop
  224.   elseif dropDir == "up" then
  225.     dropFunc = turtle.dropUp
  226.   elseif dropDir == "down" then
  227.     dropFunc = turtle.dropDown
  228.   end
  229.  
  230.   -- Loop through turtle's inventory and drop specified items
  231.   for i = 1, 16 do
  232.     local itemDetail = turtle.getItemDetail(i)
  233.     if itemDetail and itemDetail.count > 0 then
  234.     if itemName == nil or itemDetail.name == itemName then
  235.       turtle.select(i)
  236.       if turtle.getItemCount() < amount then
  237.         dropAmount = turtle.getItemCount()
  238.       else
  239.         dropAmount = amount
  240.       end
  241.      
  242.       local currentSlotCount = turtle.getItemCount(i)
  243.       local success, reason = dropFunc(dropAmount)
  244.       if success then
  245.           dropped = dropped + currentSlotCount - turtle.getItemCount(i)
  246.           amount = amount and amount - currentSlotCount + turtle.getItemCount(i) ---
  247.       else
  248.         term.setCursorPos(x, y - 1)
  249.         term.clearLine()
  250.         shaka.changeColors(colors.black, colors.red)
  251.         textutils.slowPrint("No space in inventory, retrying..")
  252.         shaka.changeColors(colors.black, colors.white)
  253.         dropItems(dropDir, amount, itemName)
  254.       end
  255.       if amount ~= nil and amount <= 0 then
  256.         break
  257.       elseif amount ~= nil and amount > 0 then
  258.         dropItems(dropDir, amount, itemName)
  259.         return
  260.       end
  261.     end
  262.     end
  263.   end
  264.  
  265.   turtle.select(1)
  266.   term.setCursorPos(x, y - 1)
  267.   term.clearLine()
  268.   if not itemName then
  269.   shaka.changeColors(colors.black, colors.magenta)
  270.     term.write("- Dropped items: ")
  271.     shaka.changeColors(colors.black, colors.orange)
  272.     term.write(dropped)
  273.   else
  274.     local prettyName = shaka.prettyName(itemName)
  275.     shaka.changeColors(colors.black, colors.magenta)
  276.     term.write("- Dropped items ")
  277.     shaka.changeColors(colors.black, colors.yellow)
  278.     term.write("["..prettyName.."]")
  279.     shaka.changeColors(colors.black, colors.white)
  280.     term.write(": ")
  281.     shaka.changeColors(colors.black, colors.orange)
  282.     term.write(dropped)
  283.     shaka.changeColors(colors.black, colors.white)
  284.   end
  285.   shaka.nextLine()
  286.   dropped = 0
  287. end
  288.  
  289. local function removeNada(inputString)
  290.     -- Split the input string by space into words
  291.     local words = {}
  292.     for word in inputString:gmatch("%S+") do
  293.         table.insert(words, word)
  294.     end
  295.  
  296.     -- Check if the last word is "nada"
  297.     if words[#words] == "nada" then
  298.         -- Remove the last word
  299.         table.remove(words, #words)
  300.     end
  301.  
  302.     -- Join the words back into a single string
  303.     local outputString = table.concat(words, " ")
  304.     return outputString
  305. end
  306.  
  307.  
  308. local function displayItems(ID)
  309.     avItems = {}
  310.     for i =1, 16 do
  311.         if turtle.getItemCount(i) > 0 then
  312.             local data = turtle.getItemDetail(i)
  313.             local itemName = data.name
  314.             table.insert(avItems, itemName)
  315.         end
  316.     end
  317.     avItems = textutils.serialize(avItems)
  318.     rednet.send(ID, avItems, "showAvailableItems")
  319. end
  320.  
  321. local function display_externalItems(side, receiver)
  322.     local items = {}
  323.     local inventory = peripheral.wrap(side)
  324.     local availableItems = inventory.list()
  325.     for k, v in pairs(availableItems) do
  326.         if not shaka.tableContains(items, v.name) then
  327.             table.insert(items, v.name)
  328.         end
  329.     end
  330.     items = textutils.serialize(items)
  331.     rednet.send(receiver, items, "items_Available")
  332. end
  333.  
  334. local function determinePosition(savedLocationsFile)
  335.     if direction == nil then direction = findDirection() end
  336.     local xPos, yPos, zPos = gps.locate()
  337.     local knownPositions = shaka.readFile(savedLocationsFile)
  338.     for i =1, #knownPositions do
  339.         shaka.split(knownPositions[i], " ")
  340.         local savedX = tonumber(result[2])
  341.         local savedY = tonumber(result[3])
  342.         local savedZ = tonumber(result[4])
  343.         local savedDirection = result[5]
  344.         if xPos == savedX and yPos == savedY and zPos == savedZ and direction == savedDirection then
  345.             workPosition = i
  346.             return workPosition
  347.         end
  348.     end
  349.     print("yo")
  350.     return false
  351. end
  352.  
  353.   -- Function to reverse a command
  354. local function reverseCommand(command, redstoneSide, pulse)
  355.     if command == "forward" then
  356.       shaka.turtleBack()
  357.     elseif command == "back" then
  358.       shaka.turtleForward()
  359.     elseif command == "up" then
  360.       shaka.turtleDown()
  361.     elseif command == "down" then
  362.       shaka.turtleUp()
  363.     elseif command == "left" then
  364.       rightTurn()
  365.     elseif command == "right" then
  366.       leftTurn()
  367.     elseif command == "redstone" and pulse ~= "pulse" then
  368.         if redstone.getInput(redstoneSide) then
  369.             redstone.setOutput(redstoneSide, false)
  370.         else
  371.             redstone.setOutput(redstoneSide, true)
  372.         end
  373.     else
  374.       return nil
  375.     end
  376. end
  377.  
  378. local function redstoneTrigger(side, state)
  379.     local state = tonumber(state)
  380.     if state == 1 then
  381.         repeat
  382.         os.pullEvent("redstone")
  383.         until redstone.getInput(side)
  384.     elseif state == 2 then
  385.         repeat
  386.         os.pullEvent("redstone")
  387.         until redstone.getInput(side) == false
  388.     end
  389. end
  390.  
  391. local function returnToStart(moveFile, positionSupply)
  392.     local moveSet = nil
  393.     local position = nil
  394.    
  395.     if positionSupply == nil then
  396.         moveSet = shaka.readFile(moveFile)
  397.         position = determinePosition(moveFile)
  398.     else
  399.         moveSet = moveFile
  400.         position = positionSupply
  401.     end
  402.  
  403.     shaka.changeColors(colors.black, colors.orange)
  404.     local x, y = term.getCursorPos()
  405.     print("- Returning to start")
  406.    
  407.     for i = position, 1, -1 do
  408.         shaka.split(moveSet[i], " ")
  409.         local commandName = result[1]
  410.         local side = result[2]
  411.         local pulse = result[3]
  412.         if commandName == "goToStart" then
  413.             break
  414.         end
  415.         reverseCommand(commandName, side, pulse)
  416.     end
  417.    
  418.     term.setCursorPos(1, y)
  419.     term.clearLine()
  420.     shaka.changeColors(colors.black, colors.green)
  421.     print("- Returned to start")
  422.     if positionSupply == nil then
  423.         shaka.writeFile(".startLocation", "yep") --indicate turtle is in starting position
  424.     end
  425. end
  426.  
  427. local function countItem(side, itemName) --- returns total amount of a certain item in inventory
  428.     local inv = peripheral.wrap(side)
  429.     local invCount = 0
  430.     local tasks = {}
  431.     for k, v in pairs(inv.list()) do
  432.         tasks[#tasks+1] = function()
  433.             if itemName then
  434.                 if v.name == itemName then -- if itemName is specified look only for that
  435.                     invCount = invCount + v.count
  436.                 end
  437.             else -- if no itemName then return count of all items
  438.                 invCount = invCount + v.count
  439.             end
  440.         end
  441.     end
  442.     parallel.waitForAll(unpack(tasks))
  443.     return invCount
  444. end
  445.  
  446. local function getFillPercent(side) -- doesnt work with drawers!
  447.     local inv = peripheral.wrap(side)
  448.     local inventory_slots = inv.size()
  449.     local inventory_maxItems = 0
  450.     local tasks = {}
  451.     local slotSizes = {}
  452.     -- print(inventory_slots)
  453.     for i = 1, inventory_slots do -- write all slot sizes to a table
  454.         tasks[#tasks+1] = function()
  455.             local itemDetail = inv.getItemDetail(i)
  456.             if itemDetail then
  457.                 slotSizes[i] = itemDetail.maxCount -- use max stack of item if one is in the slot
  458.             else
  459.                 slotSizes[i] = inv.getItemLimit(i) -- use the max size the slot can hold
  460.             end
  461.         end
  462.     end
  463.     parallel.waitForAll(unpack(tasks))
  464.    
  465.     for k, v in pairs(slotSizes) do -- add all sizes together
  466.         inventory_maxItems = inventory_maxItems + tonumber(v)
  467.     end
  468.  
  469.     local percentage = countItem(side) / inventory_maxItems * 100 -- total fill percentage
  470.     return math.floor(percentage)
  471. end
  472.  
  473. local function detectBlock(side)
  474.     local turtleDir = nil
  475.     local blockData = {}
  476.     if side == "front" then
  477.         turtleDir = turtle.inspect
  478.     elseif side == "up" then
  479.         turtleDir = turtle.inspectUp
  480.     elseif side == "down" then
  481.         turtleDir = turtle.inspectDown
  482.     end
  483.    
  484.     local success, data = turtleDir()
  485.     -- print(data.name)
  486.     table.insert(blockData, "name " ..data.name)
  487.     for k, v in pairs(data) do
  488.         if k == "state" then
  489.             for a, b in pairs(v) do
  490.                 -- print(a, b)
  491.                 table.insert(blockData, a.." "..tostring(b))
  492.             end
  493.         end
  494.     end
  495.     shaka.writeFile("blockData", blockData)
  496.     return blockData
  497. end
  498.  
  499. local function receiveRednetCommand(nameOfFile)
  500.     shaka.clearScreen()
  501.     shaka.turtleResetRedstone()
  502.     if direction == nil then findDirection() end
  503.     if compFound == false then findPocketComputer() end
  504.    
  505.     local moveTable = {}
  506.     quitAll = false
  507.    
  508.     local startX, startY, startZ = gps.locate()
  509.     local startDir = direction
  510.     table.insert(moveTable, "start " ..startX.. " " ..startY.. " " ..startZ.. " " ..direction)
  511.    
  512.     local possibleKeys = { --possible movement commands
  513.         forward = turtle.forward,
  514.         left = turtle.turnLeft,
  515.         right = turtle.turnRight,
  516.         back = turtle.back,
  517.         up = turtle.up,
  518.         down = turtle.down
  519.     }
  520.    
  521.     while not quitAll do
  522.         local senderID, key = rednet.receive("recordRemote")
  523.         -- print("here?")
  524.         shaka.split(key, " ")
  525.         local order = result[1]
  526.         local order2 = result[2]
  527.         local order3 = result[3]
  528.         -- Check if the key is valid
  529.         local validKey = possibleKeys[key] ~= nil
  530.         -- Perform action based on key
  531.         if validKey then
  532.             local action = possibleKeys[key]
  533.            
  534.             if action == turtle.turnLeft then
  535.                 action = leftTurn
  536.             elseif action == turtle.turnRight then
  537.                 action = rightTurn
  538.             end
  539.            
  540.             if action() then
  541.                 local x, y, z = gps.locate()
  542.                 table.insert(moveTable, key.. " " ..x.. " " ..y.. " " ..z.. " " ..direction)
  543.                 shaka.changeColors(colors.black, colors.white)
  544.                 print("New move: "..key)
  545.                 if x == startX and z == startZ and y == startY and direction == startDir then
  546.                     rednet.send(senderID, "start", "positionUpdate")
  547.                 else
  548.                     rednet.send(senderID, "noStart", "positionUpdate")
  549.                 end
  550.             else
  551.                 shaka.changeColors(colors.black, colors.orange)
  552.                 print("Not saving: "..key)
  553.             end
  554.         elseif key == "allDone" then
  555.             local curX, curY, curZ = gps.locate()
  556.             -- print("x", curX, startX, "Z", curZ, startZ, "y", curY, startY, direction, startDir)
  557.             if curX == startX and curZ == startZ and curY == startY and direction == startDir then
  558.                 rednet.send(senderID, "yep", "remoteEnd")
  559.                 shaka.changeColors(colors.black, colors.orange)
  560.                 print("Recording finished..")
  561.                 quitAll = true
  562.                 break
  563.             else
  564.                 rednet.send(senderID, "nope", "remoteEnd")
  565.                 local sender, msg = rednet.receive("remoteEnd")
  566.                 if msg == "y" then
  567.                     returnToStart(moveTable, #moveTable)
  568.                     table.insert(moveTable, "goToStart")
  569.                     rednet.send(sender, "done", "arrivedAtStart")
  570.                 end
  571.             end
  572.         elseif key == "delete" then
  573.             shaka.split(moveTable[#moveTable], " ")
  574.             local command = result[1]
  575.             local side = result[2]
  576.             local pulse = result[3]
  577.             shaka.changeColors(colors.black, colors.red)
  578.             if #moveTable > 1 then
  579.                 print("Undoing last move: "..command)
  580.                 reverseCommand(command, side, pulse)
  581.                 if #moveTable == 2 then
  582.                     rednet.send(senderID, "start", "positionUpdate")
  583.                 end
  584.                 moveTable[#moveTable] = nil
  585.             else
  586.                 print("Already at start, can't undo more.")
  587.                 rednet.send(senderID, "start", "positionUpdate")
  588.             end
  589.             rednet.send(senderID, command, "instructionDeleteConfirm")
  590.         elseif key == "showAvailable" then
  591.             displayItems(senderID)
  592.         elseif order == "blockInformation" then
  593.             rednet.send(senderID, detectBlock(order2), "blockAnswer")
  594.         elseif key == "displayExternal" then
  595.             rednet.send(senderID, "which side?", "sideQuestion")
  596.             local sender, msg = rednet.receive("sideAnswer")
  597.             display_externalItems(msg, sender)
  598.         elseif validKey == false then
  599.             shaka.split(key, " ")
  600.             local order = result[1]
  601.             local orderInput2 = result[2]
  602.             local orderInput3 = result[3]
  603.             local orderInput4 = result[4]
  604.             local orderInput5 = result[5]
  605.            
  606.             if orderInput2 == nil then
  607.                 table.insert(moveTable, key)
  608.             elseif orderInput2 and orderInput3 == nil then
  609.                 table.insert(moveTable, order.." "..orderInput2)
  610.             elseif order == "redstone" then
  611.                 table.insert(moveTable, order.." "..orderInput2.." "..orderInput3.." "..orderInput4)
  612.                 if orderInput3 == "on" then
  613.                     orderInput3 = true
  614.                 elseif orderInput3 == "off" then
  615.                     orderInput3 = false
  616.                 end
  617.                 if type(orderInput3) == "boolean" then
  618.                     redstone.setOutput(orderInput2, orderInput3)
  619.                 elseif orderInput3 == "pulse" then
  620.                     redstone.setOutput(orderInput2, true)
  621.                     sleep(1)
  622.                     redstone.setOutput(orderInput2, false)
  623.                 end
  624.             elseif orderInput3 and (orderInput4 == nil or orderInput4 == "nada") then
  625.                 table.insert(moveTable, order.." "..orderInput2.." "..orderInput3)
  626.             elseif orderInput4 and orderInput5 == nil then
  627.                 table.insert(moveTable, order.." "..orderInput2.." "..orderInput3.." "..orderInput4)
  628.             elseif orderInput5 then
  629.                 table.insert(moveTable, order.." "..orderInput2.." "..orderInput3.." "..orderInput4.." "..orderInput5)
  630.             end
  631.             shaka.changeColors(colors.black, colors.lightBlue)
  632.             key = removeNada(key)
  633.             print("New instruction: "..key)
  634.         end
  635.     end
  636.    
  637.     -- shaka.writeFile(".startLocation", "yep") --indicate turtle is in starting position
  638.    
  639.     -- Write moveTable to a local file
  640.     local file = fs.open(nameOfFile, "w") -- Open a file in write mode
  641.     file.write(textutils.serialize(moveTable)) -- Serialize moveTable and write to file
  642.     file.close() -- Close the file
  643.     shaka.changeColors(colors.black, colors.yellow)
  644.     print("\nSaved instructions to file: " ..nameOfFile)
  645.     moveTable = {} -- reset table for next set of commands
  646. end
  647.  
  648. local function replayMovesFromFile(fileName)
  649.     local pos = nil
  650.     local moves = shaka.readFile(fileName)
  651.     local startLocation = shaka.readFile(".startLocation")
  652.     if startLocation ~= "yep" then
  653.         shaka.clearScreen()
  654.         print("Determining location..\n")
  655.         pos = determinePosition(fileName)
  656.     else
  657.         pos = 1
  658.         shaka.split(moves[1], " ")
  659.         direction = result[5]
  660.     end
  661.     -- Replay the moves
  662.     shaka.writeFile(".startLocation", "nope")
  663.     shaka.clearScreen()
  664.     shaka.changeColors(colors.gray, colors.yellow)
  665.     term.clearLine()
  666.     print("* Starting route..\n")
  667.     shaka.changeColors(colors.black, colors.white)
  668.     if pos ~= #moves then
  669.         for i = pos + 1, #moves do
  670.             shaka.split(moves[i], " ")
  671.             local move = result[1] --main order
  672.             local input2 = result[2] --rs direction, sleep time, drop/suck direction
  673.             local input3 = result[3] --rs state, amount of items
  674.             local input4 = result[4] --item name, redstone pulse sleep time,
  675.             local input5 = result[5] --inventory item count
  676.             if move == "forward" then
  677.                 shaka.turtleForward()
  678.             elseif move == "left" then
  679.                 leftTurn()
  680.             elseif move == "back" then
  681.                 shaka.turtleBack()
  682.             elseif move == "right" then
  683.                 rightTurn()
  684.             elseif move == "up" then
  685.                 shaka.turtleUp()
  686.             elseif move == "down" then
  687.                 shaka.turtleDown()
  688.                
  689.             elseif move == "dropFiltered" or move == "drop" then
  690.                 shaka.changeColors(colors.black, colors.yellow)
  691.                 print("- Dropping items: "..input2..": "..input3)
  692.                 dropItems(input2, input3, input4)
  693.                
  694.                
  695.             elseif move == "suck" then
  696.                 shaka.changeColors(colors.black, colors.yellow)
  697.                 print("- Sucking items: " ..input2..": "..input3)
  698.                 suckItems(input2, input3)
  699.                
  700.                
  701.             elseif move == "redstone" then
  702.            
  703.                 if input3 == "on" then
  704.                     input3 = true
  705.                 elseif input3 == "off" then
  706.                     input3 = false
  707.                 end
  708.                
  709.                 if input3 ~= "pulse" then
  710.                     shaka.changeColors(colors.black, colors.red)
  711.                     term.write("- Changed RS")
  712.                     shaka.changeColors(colors.black, colors.yellow)
  713.                     term.write(" ["..input2.."]")
  714.                     shaka.changeColors(colors.black, colors.white)
  715.                     term.write(": ")
  716.                     shaka.changeColors(colors.black, colors.orange)
  717.                     term.write(input3)
  718.                     shaka.changeColors(colors.black, colors.white)
  719.                     shaka.nextLine()
  720.                     redstone.setOutput(input2, input3)
  721.                 else
  722.                     shaka.changeColors(colors.black, colors.red)
  723.                     term.write("- Pulsing RS")
  724.                     shaka.changeColors(colors.black, colors.yellow)
  725.                     term.write(" ["..input2.."]")
  726.                     shaka.changeColors(colors.black, colors.white)
  727.                     term.write(":")
  728.                     shaka.changeColors(colors.black, colors.orange)
  729.                     term.write(" "..input4.."s")
  730.                     shaka.changeColors(colors.black, colors.white)
  731.                     shaka.nextLine()
  732.                     redstone.setOutput(input2, true)
  733.                     sleep(tonumber(input4))
  734.                     redstone.setOutput(input2, false)
  735.                 end
  736.                
  737.                
  738.             elseif move == "sleep" then
  739.                 print("- Waiting for " ..input2.." seconds.")
  740.                 input2 = tonumber(input2)
  741.                 sleep(input2)
  742.                
  743.             elseif move == "goToStart" then
  744.                 returnToStart(fileName)
  745.                
  746.             elseif move == "redstoneTrigger" then
  747.                 local displayState = nil
  748.                 input3 = tonumber(input3)
  749.                 if input3 == 1 then
  750.                     displayState = "on"
  751.                 elseif input3 == 2 then
  752.                     displayState = "off"
  753.                 end
  754.                 shaka.changeColors(colors.black, colors.yellow)
  755.                 print("- Waiting for rs "..displayState.. " - side: " ..input2..".")
  756.                 redstoneTrigger(input2, input3)
  757.                 shaka.changeColors(colors.black, colors.green)
  758.                 local x, y = term.getCursorPos()
  759.                 term.setCursorPos(x, y - 1)
  760.                 term.clearLine()
  761.                 print("- Redstone triggered successfully")
  762.             elseif move == "inventoryTrigger" then
  763.                 repeatCounter = 0
  764.                 local _, startingY = term.getCursorPos()
  765.                 if input3 == "fillPercent" then
  766.                     local percent = getFillPercent(input2)
  767.                     if input4 == "above" then
  768.                         repeat
  769.                             percent = getFillPercent(input2)
  770.                             term.setCursorPos(1, startingY)
  771.                             shaka.changeColors(colors.black, colors.yellow)
  772.                             term.clearLine()
  773.                             print("Waiting for inv: "..percent.."% > "..input5.."%")
  774.                             repeatCounter = repeatCounter + 1
  775.                             if repeatCounter < 10 then
  776.                                 -- sleep(0.1)
  777.                             else
  778.                                 sleep(1)
  779.                             end
  780.                         until percent > tonumber(input5)
  781.                         shaka.changeColors(colors.black, colors.green)
  782.                         term.setCursorPos(1, startingY)
  783.                         term.clearLine()
  784.                         print("- Inv: [" ..input2.. "]", input4, input5.."%")
  785.                     elseif input4 == "below" then
  786.                         repeat
  787.                             percent = getFillPercent(input2)
  788.                             term.setCursorPos(1, startingY)
  789.                             shaka.changeColors(colors.black, colors.yellow)
  790.                             term.clearLine()
  791.                             print("Waiting for inv : "..percent.."% < "..input5.."%")
  792.                             if repeatCounter < 10 then
  793.                                 -- sleep(0.1)
  794.                             else
  795.                                 sleep(1)
  796.                             end
  797.                         until percent < tonumber(input5)   
  798.                         shaka.changeColors(colors.black, colors.green)
  799.                         term.setCursorPos(1, startingY)
  800.                         term.clearLine()
  801.                         print("- Inv: [" ..input2.. "]", input4, input5.."%")                      
  802.                     end
  803.                 else
  804.                     local itemCount = countItem(input2, input3)
  805.                     if input4 == "above" then
  806.                         repeat
  807.                             itemCount = countItem(input2, input3)
  808.                             term.setCursorPos(1, startingY)
  809.                             shaka.changeColors(colors.black, colors.yellow)
  810.                             term.clearLine()
  811.                             print("Waiting for item: ", shaka.prettyName(input3), itemCount.." > "..input5)
  812.                             repeatCounter = repeatCounter + 1
  813.                             if repeatCounter < 10 then
  814.                                 -- sleep(0.1)
  815.                             else
  816.                                 sleep(1)
  817.                             end
  818.                         until itemCount > tonumber(input5)
  819.                     elseif input4 == "below" then
  820.                         repeat
  821.                             itemCount = countItem(input2, input3)
  822.                             term.setCursorPos(1, startingY)
  823.                             shaka.changeColors(colors.black, colors.yellow)
  824.                             term.clearLine()
  825.                             print("Waiting for item: ", shaka.prettyName(input3), itemCount.." < "..input5)
  826.                             repeatCounter = repeatCounter + 1
  827.                             if repeatCounter < 10 then
  828.                                 -- sleep(0.1)
  829.                             else
  830.                                 sleep(1)
  831.                             end
  832.                         until itemCount < tonumber(input5)
  833.                     end
  834.                     shaka.changeColors(colors.black, colors.green)
  835.                     term.setCursorPos(1, startingY)
  836.                     term.clearLine()
  837.                     term.write("- Inv: [" ..shaka.prettyName(input3).. "] ".. input4.. " ".. input5)
  838.                     shaka.nextLine()
  839.                 end
  840.             elseif move == "blockTrigger" then
  841.                 local stopper = false
  842.                 shaka.changeColors(colors.black, colors.yellow)
  843.                 term.write("Waiting for block state: "..input3..": "..input4)
  844.                 shaka.nextLine()
  845.                 while stopper == false do
  846.                     local data = detectBlock(input2)
  847.                     for i = 1, #data do
  848.                         shaka.split(data[i], " ")
  849.                         if result[1] == input3 then
  850.                             if result[2] == input4 then
  851.                                 stopper = true
  852.                                 local x, y = term.getCursorPos()
  853.                                 term.setCursorPos(1, y - 1)
  854.                                 term.clearLine()
  855.                                 shaka.changeColors(colors.black, colors.green)
  856.                                 term.write("- Block "..input2.." ["..input3..":".. input4.."], success!")
  857.                                 shaka.nextLine()
  858.                             else
  859.                                 sleep(0.5)
  860.                             end
  861.                         end
  862.                     end
  863.                 end
  864.                
  865.             elseif false == false then ---marker to insert new stuff
  866.                
  867.                
  868.                
  869.             end
  870.         end
  871.     end
  872.     shaka.changeColors(colors.gray, colors.green)
  873.     shaka.nextLine()
  874.     print("* Finished route.")
  875.     shaka.changeColors(colors.black, colors.white)
  876.     shaka.writeFile(".startLocation", "yep")
  877.     dropped = 0
  878. end
  879.  
  880.  
  881.  
  882.  
  883.  
  884. if args == 1 then
  885.     receiveRednetCommand(moveSetFileName)
  886. elseif args == 2 then
  887.     -- while true do
  888.     replayMovesFromFile(moveSetFileName)
  889.     -- sleep(3)
  890.     -- end
  891. elseif args == 3 then
  892.     returnToStart(moveSetFileName)
  893. elseif args == 4 then
  894.     -- print(countItem("front", "minecraft:oak_log"))
  895.     -- print(countItem("front"))
  896.     -- print(getFillPercent("front"))
  897.     -- test("top")
  898.     -- display_externalItems("front")
  899.     detectBlock("down")
  900. end
  901.  
  902.  
  903.  
Add Comment
Please, Sign In to add comment