Dimencia

Untitled

Mar 22nd, 2021
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.56 KB | None | 0 0
  1. local fuelSlot = 1
  2. local seedSlot = 2
  3. -- Wheat has all other slots? Or just 3, idk
  4. local wheatSlot = 3
  5. local testSlot = 4
  6. local inferiumSlot = 5
  7.  
  8. local items = {}
  9. items["minecraft:wheat"] = 3
  10. items["mysticalagriculture:inferium_crop"] = 5
  11. items["minecraft:wheat_seeds"] = 2
  12.  
  13. -- Note, a working version is at pastebin.com/XwrptbCf
  14.  
  15. function fixSlot(slotNum)
  16. -- Checks the item in the selected slot...
  17. -- If it's one of the items that we track, make sure it's in the right slot...
  18. if slotNum == nil then slotNum = turtle.getSelectedSlot() end -- Just for my purposes, it would have worked in getItemDetail
  19. local data = turtle.getItemDetail(slotNum)
  20. local drop = true
  21. if data ~= nil then
  22. print("Slot " .. slotNum .. " has item named ", data.name)
  23. if items[data.name] ~= nil and items[data.name] ~= slotNum then
  24. -- It's an item we track, and it's in the wrong slot. Try to move it
  25. print("Transferring from current to ", items[data.name])
  26. if turtle.transferTo(items[data.name]) then drop = false print("Transfer failed") end
  27. end
  28. if drop then
  29. -- If anything is left, or isn't in our map, turn to the side and drop it
  30. print("Transfer failed or item not recognized, dropping")
  31. turtle.turnRight()
  32. turtle.drop()
  33. turtle.turnLeft()
  34. end
  35. end
  36. end
  37.  
  38. turtle.refuel()
  39. while(true) do
  40. -- Check if there's a chest in front of it, to refuel or offload wheat
  41. success,data = turtle.inspect()
  42. if success then
  43. print("Looking for chest, name: ", data.name)
  44. for k,v in pairs(data.state) do
  45. print("data.state." .. k, v)
  46. end
  47. for k,v in pairs(data.tags) do
  48. print("data.tags." .. k,v)
  49. end
  50. if data.tags["forge:chests"] then -- quark:birchchest is mine... has to be a better way...
  51. -- Pick up whatever's in it into slot 4
  52. turtle.select(testSlot)
  53. turtle.suck()
  54. -- See what we picked up
  55. local slotdata = turtle.getItemDetail()
  56. if slotdata ~= nil then
  57. print("Slot name: ", slotdata.name)
  58. if slotdata.name == "minecraft:wheat" then
  59. -- Put it back, and put any wheat we have in there
  60. turtle.drop()
  61. turtle.select(wheatSlot)
  62. turtle.drop()
  63. elseif slotdata.name == "minecraft:coal" then
  64. if not turtle.transferTo(fuelSlot) then
  65. turtle.drop() -- Put any leftovers back
  66. end
  67. end
  68. else
  69. -- If there was nothing in the chest, put wheat and inferium in
  70. turtle.select(wheatSlot)
  71. turtle.drop()
  72. turtle.select(inferiumSlot)
  73. turtle.drop()
  74. end
  75. end
  76. end
  77. turtle.turnRight()
  78. -- Inspect the block in front of it
  79. local success, data = turtle.inspect()
  80. if success then
  81. -- data contains fields: name, tags, state
  82. print("Name: ", data.name)
  83. -- inferium_crop
  84. if data.name == "minecraft:wheat" or data.name == "mysticalagriculture:inferium_crop" then
  85. --if data.state.age == 7 then
  86. turtle.select(seedSlot)
  87. turtle.place()
  88. turtle.select(wheatSlot)
  89. turtle.suck()
  90. fixSlot()
  91. -- If this isn't wheat, try to move it to the right slot, and then drop it
  92. turtle.select(inferiumSlot)
  93. turtle.suck()
  94. fixSlot()
  95. turtle.select(seedSlot)
  96. turtle.suck()
  97. fixSlot()
  98. --end
  99. end
  100. turtle.turnLeft() -- Turn back forward
  101. end -- If there's nothing in front of it, it can just keep going that way.
  102. if not turtle.forward() then -- Do a 180
  103. turtle.turnLeft()
  104. turtle.turnLeft()
  105. end
  106.  
  107.  
  108. -- After everything, check all slots... if wheat is found, try to move to wheatslot
  109. -- etc
  110.  
  111. end
  112.  
  113. -- For wheat, an age of 7 is what we want. Name is "minecraft:wheat"
  114. -- We get that from data.state.age
  115.  
  116.  
  117.  
Add Comment
Please, Sign In to add comment