Advertisement
TheIncgi

Craft Blocks

Jul 10th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. --set to gui open event
  2. local args = {...}
  3. if args[1] ~= "event" or args[2] ~= "GUIOpened" then
  4.   log("&7Block crafting script should be set to the GUIOpened event")  
  5.   return
  6. end
  7. if args[4] ~= "crafting table" then
  8.   return
  9. end
  10.  
  11. local item = "minecraft:iron_ingot"
  12. local inv  = openInventory()
  13. local map  = inv.mapping[args[4]]
  14.  
  15. local function findItem( inv, map, itemName )
  16.   local matches = {}
  17.   local n = 1
  18.   for a,b in pairs( map.main ) do
  19.     local item = inv.getSlot(b)
  20.     if item and item.id==itemName then
  21.       matches[n] = b
  22.       n = n+1
  23.     end
  24.   end
  25.   for a,b in pairs( map.hotbar ) do
  26.     local item = inv.getSlot(b)
  27.     if item and item.id==itemName then
  28.       matches[n] = b
  29.       n = n+1
  30.     end
  31.   end
  32.   return matches
  33. end
  34.  
  35. --return true if at or before version
  36. local function versionCompare(v)
  37.   local check = v:gmatch("(%d+)%.?")
  38.   for now in _MOD_VERSION:gmatch("(%d+)%.?") do
  39.     if tonumber(check()) < tonumber(now) then
  40.       return false
  41.     end
  42.   end
  43.   return true
  44. end
  45.  
  46. local function craftBlocks( inv, map, itemName )
  47.   local matches = findItem( inv, map, itemName )
  48.   while #matches >= 9 and args[3].isOpen() do
  49.     local ready = true
  50.     repeat
  51.       ready = true
  52.       matches = findItem( inv, map, itemName )
  53.       for i = 1, 9 do
  54.         if not inv.getSlot(map.craftingIn[i]) then
  55.           ready = false
  56.           inv.click( table.remove(matches,1))
  57.           inv.click( map.craftingIn[i] )
  58.           waitTick()
  59.         end
  60.       end
  61.     until(ready)
  62.     waitTick()
  63.     inv.quick(map.craftOut + (versionCompare("7.7.6") and 1 or 0)   )  
  64.   end
  65. end
  66.  
  67. craftBlocks( inv, map, item )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement