MrFinn

Untitled

Nov 7th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.67 KB | None | 0 0
  1. -- Define a flag to control debug prints
  2. local debugMode = true -- Set to 'false' to disable prints
  3.  
  4. -- Define slots for each ingredient
  5. local slots = {
  6. tomato = 1,
  7. onion = 2,
  8. beef_patty = 3,
  9. cabbage = 5,
  10. bread = 6
  11. }
  12.  
  13. -- Define item names for easy reference
  14. local items = {
  15. tomato = "farmersdelight:tomato",
  16. onion = "farmersdelight:onion",
  17. beef_patty = "farmersdelight:beef_patty",
  18. cabbage = "farmersdelight:cabbage",
  19. bread = "minecraft:bread",
  20. hamburger = "farmersdelight:hamburger"
  21. }
  22.  
  23. -- Get Vault
  24. local modem = peripheral.wrap("front")
  25. local turtleName = modem.getNameLocal()
  26. local vault = peripheral.find("create:item_vault")
  27.  
  28. -- Function to print messages if debug mode is active
  29. local function debugPrint(message)
  30. if debugMode then
  31. print(message)
  32. end
  33. end
  34.  
  35. -- Function to check if a slot is full
  36. local function isSlotFull(slot)
  37. local itemDetail = turtle.getItemDetail(slot)
  38. if itemDetail then
  39. debugPrint("Slot " .. slot .. " contains " .. itemDetail.count .. " items.")
  40. return itemDetail.count >= 64
  41. else
  42. debugPrint("Slot " .. slot .. " is empty.")
  43. return false
  44. end
  45. end
  46.  
  47. -- Function to check if a specific item exists in the neighboring inventory
  48. local function checkNeighborInventory(itemName)
  49. -- Iterate through the slots in the neighboring inventory
  50. for i = 1, vault.size() do
  51. local item = vault.getItemDetail(i)
  52. if item and item.name == itemName then
  53. debugPrint("Found " .. itemName .. " in neighbor inventory slot " .. i)
  54. return true, i
  55. end
  56. end
  57. debugPrint(itemName .. " not found in neighbor inventory.")
  58. return false, nil
  59. end
  60.  
  61. -- Function to refill turtle's inventory from the neighboring inventory
  62. local function refillFromNeighbor()
  63. for item, slot in pairs(slots) do
  64. if not isSlotFull(slot) then
  65. local hasItem, neighborSlot = checkNeighborInventory(items[item])
  66. if hasItem then
  67. debugPrint("Refilling slot " .. slot .. " with " .. items[item])
  68. turtle.select(slot)
  69. local pulledCount = 64 - (turtle.getItemCount(slot) or 0)
  70. vault.pushItems(turtleName, neighborSlot, pulledCount, slot)
  71. debugPrint("Pulled " .. pulledCount .. " " .. items[item] .. " into slot " .. slot)
  72. end
  73. else
  74. debugPrint("Slot " .. slot .. " is already full with " .. (turtle.getItemCount(slot) or 0) .. " items.")
  75. end
  76. end
  77. end
  78.  
  79. -- Function to craft and store hamburgers back into the neighboring inventory
  80. local function craftAndStoreHamburgers()
  81. debugPrint("Attempting to craft hamburger.")
  82. turtle.craft() -- Attempt to craft
  83.  
  84. -- Check for any hamburgers in inventory
  85. for slot = 1, 16 do
  86. local itemDetail = turtle.getItemDetail(slot)
  87. if itemDetail and itemDetail.name == items.hamburger then
  88. debugPrint("Hamburger found in slot " .. slot)
  89. turtle.select(slot)
  90. vault.pullItems(turtleName, slot)
  91. debugPrint("Dropped hamburger from slot " .. slot .. " to neighbor inventory.")
  92. end
  93. end
  94. end
  95.  
  96. -- Main function to run the turtle's operations
  97. local function runTurtle()
  98. while true do
  99. debugPrint("Refilling from neighbor inventory.")
  100. refillFromNeighbor() -- Refill ingredients if needed
  101. debugPrint("Crafting and storing hamburgers.")
  102. craftAndStoreHamburgers() -- Craft and store hamburgers
  103. os.sleep(5) -- Wait before checking again
  104. end
  105. end
  106.  
  107. -- Run the turtle's program
  108. runTurtle()
  109.  
Add Comment
Please, Sign In to add comment