largeNumberGoeshere

getFuelValue.lua

Apr 27th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None | 0 0
  1.  
  2.  
  3. ---- finds out which item it is and what fuel
  4. function getFuelFromTable(tab,value)
  5.     for i,v in pairs(tab) do
  6.         local a = v[1]  -- name of item
  7.         local b = v[2]  -- heating value
  8.        
  9.         local valueClipped = ""
  10.        
  11.         local char1 = string.sub(a,1,1)
  12.         if char1 == "*" then
  13.                 a = string.sub(a,2,-1)
  14.                 --crazy work around that allows wildcard-like functionality
  15.                 --> if the last characters of 'a' are the same as the last characters of 'value' then true
  16.                 local aLen = string.len(a)
  17.                 valueClipped = string.sub(value,-aLen,-1)
  18.                 --print(a)
  19.         else
  20.                 valueClipped = value
  21.         end
  22.        
  23.        
  24.         if a == valueClipped then
  25.             return b
  26.         end
  27.     end
  28.    
  29.     --not found
  30.     return false
  31.  
  32. end
  33.  
  34.  
  35.  
  36. function getFuelValue(fuelSlot)
  37.             local stdFuelValues = {
  38.                     {"minecraft:charcoal",80},
  39.                     {"minecraft:coal",80},
  40.                     {"minecraft:stick",5},
  41.                     {"minecraft:lava_bucket",1000},
  42.                     {"*_log",15},
  43.                     {"*_planks",15},
  44.                     {"*_plank",15},
  45.                     {"*_planks_slab",15},
  46.                     {"*_chest",15},
  47.                     {"*_wool",5}
  48.                    
  49.             }
  50.  
  51.             local prevSlot = turtle.getSelectedSlot()
  52.            
  53.             --change slots, if neccesary
  54.             if prevSlot ~= fuelSlot then
  55.                     turtle.select(fuelSlot)
  56.             end
  57.            
  58.             --get the name of the item in fuel slot
  59.             local a,b = turtle.getItemDetail()
  60.             if a ~= nil then
  61.                 local name = a.name
  62.                 a=nil; b=nil
  63.                
  64.                 local fuelValue = getFuelFromTable(stdFuelValues,name)
  65.                 return fuelValue
  66.             else
  67.                
  68.             end
  69.  
  70.             --change slots back, if neccesary          
  71.             if fuelSlot ~= prevSlot then
  72.                     turtle.select(prevSlot)
  73.             end
  74.            
  75.             return nil
  76.            
  77.            
  78.            
  79. end
  80.  
  81. --local fslot = 1
  82. --getFuelValue(fslot)
  83.  
  84. return getFuelValue
  85.  
  86.  
Add Comment
Please, Sign In to add comment