Advertisement
Jenkins1337

test

Aug 30th, 2022 (edited)
775
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.15 KB | None | 0 0
  1. function isInventoryFull()
  2.     for i=1, 16 do
  3.         if turtle.getItemCount(i) == 0 then
  4.             return false
  5.         end
  6.     end
  7.    
  8.     return true
  9. end
  10.  
  11. -- Fixes inventory scattering.
  12. function stackItems()
  13.     -- Remember seen items
  14.     m = {}
  15.            
  16.     for i=1, 16 do
  17.         local this = turtle.getItemDetail(i)
  18.        
  19.         if this ~= nil then
  20.             -- Slot is not empty
  21.        
  22.             local saved = m[this.name .. this.damage]
  23.        
  24.             if saved ~= nil then
  25.                 -- We've seen this item before in the inventory
  26.            
  27.                 local ammount = this.count
  28.            
  29.                 turtle.select(i)
  30.                 turtle.transferTo(saved.slot)
  31.            
  32.                 if ammount > saved.space then
  33.                     -- We have leftovers, and now the
  34.                     -- saved slot is full, so we replace
  35.                     -- it by the current one
  36.                
  37.                     saved.slot = i
  38.                     saved.count = ammount - saved.space
  39.                     -- Update on table.
  40.                     m[this.name .. this.damage] = saved
  41.            
  42.                 elseif ammount == saved.space then
  43.                     -- Just delete the entry
  44.                    
  45.                     m[this.name .. this.damage] = nil
  46.                    
  47.                 end
  48.                
  49.             else
  50.                 -- There isn't another slot with this
  51.                 -- item so far, so sign this one up.
  52.            
  53.             this.slot = i
  54.             this.space = turtle.getItemSpace(i)
  55.            
  56.             m[this.name .. this.damage] = this
  57.            
  58.             end
  59.         end
  60.     end
  61. end
  62.  
  63. function selectItem(name)
  64.     for i=1, 16 do
  65.         local data = turtle.getItemDetail(i)
  66.         if data and data.name == name then
  67.             turtle.select(i)
  68.             return true
  69.         end
  70.     end
  71.     return false
  72. end
  73.  
  74. function getItemCount(name)
  75.     local count = 0
  76.     for i=1, 16 do
  77.         local data = turtle.getItemDetail(i)
  78.         if data and data.name == name then
  79.             count = count + data.count
  80.         end
  81.     end
  82.     return count
  83. end
  84.  
  85. function dropThrash()
  86.     local thrash = {"minecraft:stone", "minecraft:dirt", "minecraft:gravel", "minecraft:sand", "minecraft:cobblestone", "minecraft:sandstone", "minecraft:bedrock", "chisel:limestone", "chisel:marble", "chisel:diorite", "chisel:granite", "chisel:andesite", "harvestcraft:salt"}
  87.  
  88.     for i=1, 16 do
  89.    
  90.         details = turtle.getItemDetail(i)
  91.        
  92.         if details then
  93.        
  94.             for j=1, #thrash do
  95.                 if details.name == thrash[j] then
  96.                     turtle.select(i)
  97.                     turtle.drop()
  98.                 end
  99.             end
  100.         end
  101.     end
  102. end
  103.  
  104. stackItems()
  105. dropThrash()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement