Advertisement
Guest User

test

a guest
Jan 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. local A = {
  2.  [1] = {name="minecraft:coal", count=64},
  3.  [5] = {name="minecraft:wheat_seeds", count=54},
  4.  [7] = {name="minecraft:wheat_seeds", count=21}
  5. }
  6.  
  7. local total = 0
  8. for k,v in pairs(A) do
  9.  print(v.name .. " : " .. v.count)
  10. end
  11.  
  12. local non_full = 0
  13. for i=1,16 do
  14.  if A[i] ~= nil then
  15.   if A[i].name == "minecraft:wheat_seeds" and total < 64 then
  16.    total = total + A[i].count
  17.    --combine stacks
  18.    if non_full == 0 then
  19.     non_full = i
  20.    end
  21.    
  22.    if non_full ~= 0 then
  23.     A[non_full] = A[non_full] or {name="minecraft:wheat_seeds", count=0}
  24.     local slot_count = A[non_full].count
  25.     if slot_count < 64 then
  26.      local diff = math.abs(64 - slot_count)
  27.      printError(diff)
  28.      A[non_full].count = A[non_full].count + diff
  29.      A[i].count = A[i].count - diff    
  30.     end    
  31.    end
  32.   elseif A[i].name == "minecraft:wheat_seeds" and total >= 64 then
  33.    A[i].count = 0
  34.   end
  35.  else
  36.    if non_full == 0 then non_full = i end
  37.  end
  38. end
  39. print(non_full)
  40. print(total)
  41. for k,v in pairs(A) do
  42.  print(v.name .. " : " .. v.count)
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement