Advertisement
HappySunChild

Barrel Bunching

Sep 30th, 2022 (edited)
903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | Source Code | 0 0
  1. local sortLocations = {
  2.     up = { "minecraft:apple", "minecraft:pufferfish", "minecraft:cookie" },
  3.     down = { "minecraft:paper", "minecraft:barrel" }
  4. }
  5.  
  6. local function InTable(t, value)
  7.     for i, v in pairs(t) do
  8.         if v == value then
  9.             return true
  10.         end
  11.     end
  12.  
  13.     return false
  14. end
  15.  
  16. local function GetBarrel()
  17.     -- get the correct barrel based off of its lore tag
  18.     for slot = 1, 16 do
  19.         if turtle.getItemCount(slot) > 0 then
  20.             local data = turtle.getItemDetail(slot, true)
  21.  
  22.             if data.lore ~= nil and (data.lore[1] == "The fabled prize awaits at the bottom...") then
  23.                 turtle.select(slot)
  24.                 turtle.transferTo(1)
  25.                 turtle.select(1)
  26.  
  27.                 return true
  28.             end
  29.         end
  30.     end
  31.  
  32.     return false
  33. end
  34.  
  35. local function SortDrops()
  36.     -- sort drops from barrel into other barrels (up for cookies and apples and pufferfish bottom for papers and barrels)
  37.     for slot = 1, 16 do
  38.         if turtle.getItemCount(slot) > 0 then
  39.             local data = turtle.getItemDetail(slot, true)
  40.  
  41.             if not (data.lore ~= nil and data.lore[1] == "The fabled prize awaits at the bottom...") then
  42.                 if InTable(sortLocations.down, data.name) then
  43.                     turtle.select(slot)
  44.                     turtle.dropDown()
  45.                 end
  46.  
  47.                 if InTable(sortLocations.up, data.name) then
  48.                     turtle.select(slot)
  49.                     turtle.dropUp()
  50.                 end
  51.             end
  52.         end
  53.     end
  54. end
  55.  
  56. while true do
  57.     if turtle.detect() then
  58.         turtle.dig()
  59.  
  60.         SortDrops()
  61.     end
  62.  
  63.     if GetBarrel() then
  64.         turtle.place()
  65.     end
  66. end
  67.  
Tags: Barrel
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement