Advertisement
djst3rios

Mining Script part 2

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