Advertisement
mathiaas

depot

Apr 12th, 2024 (edited)
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.73 KB | None | 0 0
  1. assert(loadfile("utils"))()
  2.  
  3. local custom_items = {
  4.     cobblestone = "minecraft:cobblestone",
  5.     dirt = "minecraft:dirt",
  6.     lava_bucket = "minecraft:lava_bucket",
  7.     bucket = "minecraft:bucket"
  8. }
  9.  
  10. local dropDirections = {
  11.     [custom_items.cobblestone] = {turns = 1, direction = 'right', dropAction = turtle.drop},
  12.     [custom_items.dirt] = {turns = 2, direction = 'left', dropAction = turtle.drop},
  13.     [custom_items.lava_bucket] = {dropAction = turtle.dropUp}, -- Drop up for lava buckets
  14.     [custom_items.bucket] = {dropAction = turtle.dropUp}     -- Drop up for empty buckets
  15. }
  16.  
  17. local function handleDrop(item, slot)
  18.     local direction = dropDirections[item.name]
  19.     if direction then
  20.         if direction.direction then
  21.             local turnFunction = direction.direction == 'right' and turtle.turnRight or turtle.turnLeft
  22.             for i = 1, direction.turns or 0 do
  23.                 turnFunction()
  24.             end
  25.         end
  26.  
  27.         turtle.select(slot)
  28.         do (direction.dropAction or turtle.dropDown)() end
  29.  
  30.         if direction.direction then
  31.             local turnBackFunction = direction.direction == 'right' and turtle.turnLeft or turtle.turnRight
  32.             for i = 1, direction.turns or 0 do
  33.                 turnBackFunction()
  34.             end
  35.         end
  36.     else
  37.         turtle.select(slot)
  38.         turtle.dropDown()
  39.     end
  40. end
  41.  
  42. -- Main run function
  43. local function main()
  44.     while true do
  45.         while turtle.suckUp() do end -- Continuously suck items from above
  46.         local inventory = getInventory()
  47.  
  48.         for k, v in pairs(inventory) do
  49.             handleDrop(v, v.slot)
  50.         end
  51.         sleep(1) -- Throttle the loop to prevent excessive resource usage
  52.     end
  53. end
  54.  
  55. main()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement