Lanzr

tmpwork

Feb 27th, 2026 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.26 KB | None | 0 0
  1. local ccm = require "cc.completion"
  2. local completion = require("cc.shell.completion")
  3. function startup()
  4. local function l_completion(shell, index, partial, previousArgs)
  5. if index == 1 then
  6. return ccm.choice(partial, {"tstOut", "combine", "saw", "press", "deployer", "spout"})
  7. end
  8. return nil
  9. end
  10.  
  11. shell.setCompletionFunction("work.lua", l_completion)
  12. end
  13.  
  14. startup()
  15. -- create ?????????
  16. local saw = peripheral.find("create:saw")
  17. local deployer = peripheral.find("create:deployer")
  18. local spout = peripheral.find("create:spout")
  19. local tanks = {peripheral.find("fluidTank")}
  20. local depots = {peripheral.find("create:depot")}
  21.  
  22. local box_input = peripheral.find("minecraft:chest")
  23.  
  24.  
  25.  
  26. -- ??????????????????
  27. -- ???edit???????????????arg
  28. -- arg = {"tstOut",1}
  29.  
  30. local depot_deployer = depots[4]
  31. local depot_saw = depots[3]
  32. local depot_press = depots[1]
  33. local depot_spout = depots[2]
  34.  
  35.  
  36. --[[ ??????,?????????handler,??????handler????,
  37. ??????,??????????,?????????? ]]
  38.  
  39.  
  40.  
  41. local lastNbt = ""
  42. local itemMap = {}
  43. local ingredient = ""
  44. local recipe_ls = {}
  45.  
  46.  
  47. local recipe_map = {
  48. ["create:mechanical_press"] = function (input_inv, input_slot)
  49. return process_combine_press(input_inv, input_slot, depot_press)
  50. end,
  51. ["create:mechanical_saw"] = function (input_inv, input_slot)
  52. return process_combine_saw(input_inv, input_slot, depot_saw)
  53. end,
  54. }
  55.  
  56. local fluidBucketMap = {
  57. ["minecraft:water_bucket"] = "minecraft:water",
  58. ["minecraft:lava_bucket"] = "minecraft:lava",
  59. ["immersiveengineering:redstone_acid_bucket"] = "immersiveengineering:redstone_acid"
  60. }
  61.  
  62. -- --------------------------------------------------------------------
  63. -- tools
  64. function pgn(peri)
  65. return peripheral.getName(peri)
  66. end
  67.  
  68. function findItemSlot(itemType, inv)
  69. for index,item in pairs(inv.list()) do
  70. if item.name == itemType then
  71. return index
  72. end
  73. end
  74. return false
  75. end
  76. function findFluidInv(fluidType)
  77. print("fluitypes:",fluidType)
  78. for periindex,tankperi in pairs(tanks) do
  79. for tankindex,tank in pairs(tankperi.tanks()) do
  80. if tank.name == fluidType then
  81. if tank.amount > 1000 then
  82. return periindex
  83. end
  84. end
  85. end
  86. end
  87. return false
  88. end
  89. function invClean(inv)
  90. if inv then
  91. for index,item in pairs(inv.list()) do
  92. inv.pushItems(pgn(box_input),index)
  93. end
  94. end
  95.  
  96. end
  97. -- --------------------------------------------------------------------
  98. -- init
  99. function cleanllSlot()
  100. invClean(saw)
  101. invClean(deployer)
  102. if depots then
  103. for index,depot in pairs(depots) do
  104. invClean(depot)
  105. end
  106. end
  107. end
  108. function initRecipe(startIndex)
  109. recipe_ls = {}
  110. turtle.select(1)
  111. ret = turtle.getItemDetail()
  112. if ret~= nil then
  113. ingredient = ret.name
  114. else
  115. return false
  116. end
  117. for i = startIndex, 16, 1 do
  118. turtle.select(i)
  119. ret = turtle.getItemDetail()
  120. if ret~= nil then
  121. table.insert(recipe_ls, ret.name)
  122. else
  123. return true
  124. end
  125. end
  126. end
  127.  
  128.  
  129. -- --------------------------------------------------------------------
  130. -- combine process
  131.  
  132. function process_combine_saw(input_inv, input_slot, out_inv)
  133. input_inv.pushItems(pgn(saw),input_slot,1)
  134. while true do
  135. if #(out_inv.list()) ~= 0 then
  136. return out_inv
  137. end
  138. end
  139. end
  140.  
  141. function process_combine_press(input_inv, input_slot, out_inv)
  142. lastNbt = input_inv.getItemDetail(input_slot).nbt
  143. input_inv.pushItems(pgn(out_inv),input_slot,1)
  144. while true do
  145. if out_inv.getItemDetail(1).nbt ~= lastNbt then
  146. return out_inv
  147. end
  148. end
  149. end
  150.  
  151. function process_combine_deployer(itemType, input_inv, input_slot, out_inv)
  152. lastNbt = input_inv.getItemDetail(input_slot).nbt
  153. input_inv.pushItems(pgn(out_inv),input_slot,1)
  154. while true do
  155. itemSlot = findItemSlot(itemType, box_input)
  156. if itemSlot ~= false then
  157. box_input.pushItems(pgn(deployer),itemSlot,1)
  158. break
  159. end
  160. sleep(5)
  161. end
  162. while true do
  163. if out_inv.getItemDetail(1).nbt ~= lastNbt then
  164. invClean(deployer)
  165. return out_inv
  166. end
  167. end
  168. end
  169.  
  170.  
  171. function process_combine_spout(fluidType,input_inv, input_slot, out_inv)
  172. lastNbt = input_inv.getItemDetail(input_slot).nbt
  173. input_inv.pushItems(pgn(out_inv),input_slot,1)
  174. while true do
  175. tankIndex = findFluidInv(fluidType)
  176. if tankIndex ~= false then
  177. tanks[tankIndex].pushFluid(pgn(spout),1000)
  178. break
  179. end
  180. sleep(5)
  181. end
  182. while true do
  183. if out_inv.getItemDetail(1).nbt ~= lastNbt then
  184. spout.pushFluid(pgn(tanks[tankIndex]),1000)
  185. return out_inv
  186. end
  187. end
  188. end
  189.  
  190. -- --------------------------------------------------------------------
  191. -- singleProcess
  192. -- ???????? ?????,????????????
  193. function process_single_saw(input_inv, input_slot, out_inv)
  194. input_inv.pushItems(pgn(saw),input_slot)
  195. while true do
  196. if #(saw.list()) == 0 then
  197. invClean(out_inv)
  198. return true
  199. end
  200. end
  201. end
  202. function process_single_press(input_inv, input_slot, out_inv)
  203. origName = input_inv.getItemDetail(input_slot).name
  204. input_inv.pushItems(pgn(out_inv),input_slot)
  205.  
  206. repeat
  207. local retFlag = true
  208. for i,item in pairs(out_inv.list()) do
  209. if item.name == origName then
  210. retFlag = false
  211. end
  212. end
  213. until retFlag
  214. invClean(out_inv)
  215. end
  216.  
  217. function process_single_spout(fluidType, input_inv, input_slot, out_inv)
  218. origName = input_inv.getItemDetail(input_slot).name
  219. input_inv.pushItems(pgn(out_inv),input_slot)
  220. while true do
  221. tankIndex = findFluidInv(fluidType)
  222. if tankIndex ~= false then
  223. tanks[tankIndex].pushFluid(pgn(spout),1000)
  224. break
  225. end
  226. sleep(5)
  227. local retFlag = true
  228. for i,item in pairs(out_inv.list()) do
  229. if item.name == origName then
  230. retFlag = false
  231. end
  232. end
  233. if retFlag then
  234. break
  235. end
  236. end
  237. invClean(out_inv)
  238. end
  239.  
  240. function process_single_deployer(itemType, input_inv, input_slot, out_inv)
  241.  
  242. origName = input_inv.getItemDetail(input_slot).name
  243. -- ????????
  244. input_inv.pushItems(pgn(out_inv),input_slot)
  245. repeat
  246. local retFlag = true
  247. -- ??????????
  248. if #(deployer.list()) == 0 then
  249. while true do
  250. itemSlot = findItemSlot(itemType, box_input)
  251. if itemSlot ~= false then
  252. box_input.pushItems(pgn(deployer),itemSlot)
  253. break
  254. end
  255. sleep(5)
  256. end
  257. end
  258. for i,item in pairs(out_inv.list()) do
  259. if item.name == origName then
  260. retFlag = false
  261. end
  262. end
  263. until retFlag
  264. print("process end ")
  265. invClean(out_inv)
  266. invClean(deployer)
  267.  
  268. end
  269.  
  270. -- --------------------------------------------------------------------
  271.  
  272. function singleTask()
  273. cleanllSlot()
  274. turtle.select(1)
  275. ret = turtle.getItemDetail()
  276. if not initRecipe(1) then
  277. print(" no appoint recipe")
  278. return false
  279. end
  280. cb = nil
  281. if arg[1] == "saw" then
  282. cb = function (input_slot)
  283. process_single_saw(box_input,input_slot,depot_saw)
  284. end
  285. elseif arg[1] == "press" then
  286. cb = function (input_slot)
  287. process_single_press(box_input,input_slot,depot_press)
  288. end
  289. elseif arg[1] == "deployer" then
  290. cb = function (input_slot)
  291. process_single_deployer(ingredient, box_input, input_slot, depot_deployer)
  292. end
  293. initRecipe(2)
  294. elseif arg[1] == "spout" then
  295. cb = function (input_slot)
  296. fluidType = fluidBucketMap[ingredient]
  297. process_single_spout(fluidType, box_input, input_slot, box_input)
  298. end
  299. initRecipe(2)
  300. else
  301. print(" no appoint process")
  302. return false
  303. end
  304.  
  305. input_inv = box_input
  306. repeat
  307. local retFlag = true
  308. for index, value in pairs(recipe_ls) do
  309. inputSlot = findItemSlot(value, box_input)
  310. if inputSlot == false then
  311. -- print("no find any ",value)
  312. else
  313. retFlag = false
  314. cb(inputSlot)
  315. end
  316. end
  317. until retFlag
  318. print("process done!")
  319. end
  320.  
  321. function serialCombine()
  322. cleanllSlot()
  323. if not initRecipe(2) then
  324. print(" no appoint recipe")
  325. return false
  326. end
  327.  
  328. while true do
  329. input_inv = box_input
  330. inputSlot = findItemSlot(ingredient, box_input)
  331. if inputSlot == false then
  332. print("no find any ",ingredient)
  333. return false
  334. end
  335. while true do
  336.  
  337. for index, value in pairs(recipe_ls) do
  338. if recipe_map[value] ~= nil then
  339. input_inv = recipe_map[value](input_inv, inputSlot)
  340. inputSlot = 1
  341. elseif fluidBucketMap[value] ~= nil then
  342. input_inv = process_combine_spout(fluidBucketMap[value], input_inv, inputSlot, depot_spout)
  343. inputSlot = 1
  344. else
  345. input_inv = process_combine_deployer(value, input_inv, inputSlot, depot_deployer)
  346. inputSlot = 1
  347. end
  348.  
  349. end
  350.  
  351. if input_inv.getItemDetail(inputSlot).nbt == nil then
  352. input_inv.pushItems(pgn(box_input),inputSlot)
  353. break
  354. end
  355. end
  356.  
  357. end
  358. end
  359.  
  360. function mainloop()
  361. if arg[1] == "tstOut" then
  362. -- ???????? ???,?????????
  363. box_input.pushItems(pgn(depots[tonumber(arg[2])]),1)
  364. elseif arg[1] == "combine" then
  365. -- ????
  366. serialCombine()
  367. else
  368. singleTask()
  369. end
  370. end
  371.  
  372.  
  373. mainloop()
  374.  
Advertisement
Add Comment
Please, Sign In to add comment