Dimencia

Untitled

Mar 22nd, 2021
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 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 Succeeded") end
  27. elseif items[data.name] ~= nil and items[data.name] == slotNum then
  28. drop = false
  29. end
  30. if drop then
  31. -- If anything is left, or isn't in our map, turn to the side and drop it
  32. print("Transfer failed or item not recognized, dropping")
  33. turtle.turnRight()
  34. turtle.drop()
  35. turtle.turnLeft()
  36. end
  37. end
  38. end
  39.  
  40. turtle.refuel()
  41. while(true) do
  42. -- Check if there's a chest in front of it, to refuel or offload wheat
  43. success,data = turtle.inspect()
  44. if success then
  45. print("Looking for chest, name: ", data.name)
  46. for k,v in pairs(data.state) do
  47. print("data.state." .. k, v)
  48. end
  49. for k,v in pairs(data.tags) do
  50. print("data.tags." .. k,v)
  51. end
  52. if data.tags["forge:chests"] then -- quark:birchchest is mine... has to be a better way...
  53. -- Pick up whatever's in it into slot 4
  54. turtle.select(testSlot)
  55. turtle.suck()
  56. -- See what we picked up
  57. local slotdata = turtle.getItemDetail()
  58. if slotdata ~= nil then
  59. print("Slot name: ", slotdata.name)
  60. if slotdata.name == "minecraft:wheat" then
  61. -- Put it back, and put any wheat we have in there
  62. turtle.drop()
  63. turtle.select(wheatSlot)
  64. turtle.drop()
  65. elseif slotdata.name == "minecraft:coal" then
  66. if not turtle.transferTo(fuelSlot) then
  67. turtle.drop() -- Put any leftovers back
  68. end
  69. end
  70. else
  71. -- If there was nothing in the chest, put wheat and inferium in
  72. turtle.select(wheatSlot)
  73. turtle.drop()
  74. turtle.select(inferiumSlot)
  75. turtle.drop()
  76. end
  77. end
  78. end
  79. turtle.turnRight()
  80. -- Inspect the block in front of it
  81. local success, data = turtle.inspect()
  82. if success then
  83. -- data contains fields: name, tags, state
  84. print("Name: ", data.name)
  85. -- inferium_crop
  86. if data.name == "minecraft:wheat" or data.name == "mysticalagriculture:inferium_crop" then
  87. --if data.state.age == 7 then
  88. turtle.select(seedSlot)
  89. turtle.place()
  90. turtle.select(wheatSlot)
  91. turtle.suck()
  92. fixSlot()
  93. -- If this isn't wheat, try to move it to the right slot, and then drop it
  94. turtle.select(inferiumSlot)
  95. turtle.suck()
  96. fixSlot()
  97. turtle.select(seedSlot)
  98. turtle.suck()
  99. fixSlot()
  100. --end
  101. end
  102. turtle.turnLeft() -- Turn back forward
  103. end -- If there's nothing in front of it, it can just keep going that way.
  104. if not turtle.forward() then -- Do a 180
  105. turtle.turnLeft()
  106. turtle.turnLeft()
  107. end
  108.  
  109.  
  110. -- After everything, check all slots... if wheat is found, try to move to wheatslot
  111. -- etc
  112.  
  113. end
  114.  
  115. -- For wheat, an age of 7 is what we want. Name is "minecraft:wheat"
  116. -- We get that from data.state.age
  117.  
  118.  
  119.  
Add Comment
Please, Sign In to add comment