Advertisement
tjaccardi

ChestAPI

Mar 21st, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. function initialize()
  2.   transposer = require("transposer")
  3.   inventory_controller = require("inventory_controller")
  4.   sides = require("sides")
  5.   chestAccess = component.inventory_controler
  6.   transposer = component.transposer
  7.   end
  8.  
  9. function information()
  10.   print("StormWolf's Chest API for manipulating and checking inventories around it. Open source as long as I am creditted as the original author.")
  11.   print("REQUIRES A TRANSPOSER AND AN INVENTORY CONTROLLER")
  12.   print("All functions return 0 if there is no inventory unless otherwise documented.")
  13.   print("Available functions:")
  14.   print("inventoryScanner(side) - returns the inventory of inventory on given side.")
  15.   print("getMaxSize(side) - gives the maxiumum size of the inventory.")
  16.   print("transferItem(source, destination, sourceSlot, destinationSlot, quantity) - provide the written values and it will transfer an item.")
  17.   print("---------------------------------------------------------------------------------------------------------------------------------------------------")
  18.   print("Feel free to PM StormWolf with any functions you want added, they are mostly added on a per needed basis.")
  19.   end
  20.  
  21. local function isValid(side)
  22.     if not chestAccess.getInventorySize(side) then
  23.       return false
  24.     elseif chestAccess.getInventorySize(side) then
  25.       return true
  26.     end
  27.     return 0
  28.    end
  29.  
  30.  
  31. function inventoryScanner(side)
  32.   if not chestAccess.getInventorySize(side) then return 0 end
  33.   size = chestAccess.getInventorySize(side)
  34.   i = 1
  35.   while i<size do
  36.    item = chestAccess.getStackInSlot(side, i)
  37.    if isValid(side)==false then break end
  38.    inventory[i] = tostring(item.label)
  39.    i=i+1
  40.    end
  41.   return inventory
  42.   end
  43.  
  44. function getMaxSize(side)
  45.   if isValid(side)==false then return 0 end
  46.   size = chestAccess.getInventorySize(side)
  47.   return size
  48.   end
  49.  
  50. function transferItem(source, destination, sourceSlot, destinationSlot, quantity)
  51.   source = tonumber(source)
  52.   destination = tonumber(destination)
  53.   sourceSlot = tonumber(sourceSlot)
  54.   destinationSlot = tonumber(destinationSlot)
  55.   quantity = tonumber(quantity)
  56.   if not isValid(source) then return 0 end
  57.   if not isValid(destination) then return 0 end
  58.   invAccess.transferItem(source, destination, sourceSlot, location, quantity)
  59. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement