Advertisement
Guest User

ekran.lua

a guest
Apr 25th, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | None | 0 0
  1. local component = require "component"
  2. local transposer = component.transposer
  3. local sides = require "sides"
  4. local redstone = component.redstone
  5.  
  6. local inputChest = sides.up--Chest that has the input items
  7. local craftingChest = sides.north--Chest that has crafting items and ready to be extracted
  8.  
  9. local terrasteel = {"Manasteel Ingot", "Mana Pearl", "Mana Diamond"}
  10.  
  11. function getAmount(container, checkAmountOf)--container: side of the container ; item: label of the item
  12.   inventory = transposer.getAllStacks(container)
  13.   tmp = 0
  14.   for i = 1, inventory.count() do
  15.     if inventory[i].label == checkAmountOf then
  16.       tmp = tmp + 1
  17.     end
  18.   end
  19. return tmp
  20. end
  21.  
  22.  
  23. function amountIsValid(container, amount, item)--container: side of the inventory that we are checking the amount of ; item: label of the item
  24.  
  25.   return amount < getAmount(container, item)
  26.  
  27. end
  28.  
  29.  
  30. function moveItem(source, destination, amount, item)
  31.   sourceSlots = transposer.getAllStacks(source)
  32.  
  33.     if amountIsValid(source, amount, item) then
  34.       return true, -1
  35.     else
  36.       missing = amount - getAmount(source, item)
  37.       return false, missing
  38.     end
  39. end
  40.  
  41.  
  42. function startCrafting()
  43.  
  44.   input = transposer.getAllStacks(inputChest)
  45.  
  46.     for i=1, 3 do
  47.       if getAmount(input, terrasteel[i]) < 0  then
  48.           _, missing = moveItem(inputChest, craftingChest, 1, terrasteel[i])
  49.         print(missing .. "many "..terrasteel[i].." is missing")
  50.         return nil
  51.       end
  52.     end
  53.  
  54. redstone.setOutput(sides.north, 15)
  55. os.sleep(2)
  56. redstone.setOutput(sides.up, 15)
  57. print("The item is crafting...")
  58.  
  59. end
  60.  
  61. startCrafting()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement