Guest User

charge

a guest
May 29th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.09 KB | None | 0 0
  1. --2013 Ichabod_Clay (Ichabod2032)
  2. --Item charger script for Minecraft.
  3. --This script uses an Interactive Sorter to take an item (ideally from an ender chest)
  4. -- and send it off to charge in a charging station (batbox, MFE, MFSU).
  5. --The way I have it set up is the Sorter scans the chest every so often and, if the
  6. -- proper item is found, takes the item and sends it to a charge station through a
  7. -- Buildcraft pipe.
  8. --The return trip is handled by an Autarchic AND Gate that is set to extract the item
  9. -- from the charge station once it is full. Set 1 setting to energy pulse when an item is
  10. -- in inventory, and the other setting set to energy pulse when charging a fully charged
  11. -- item. Easy Peasy!
  12.  
  13. tArgs = {...};
  14. if #tArgs ~= 1 then
  15.   print("Usage: <name of program> <side sorter is attached to>");
  16.   return;
  17. end
  18.  
  19. local sorter = peripheral.wrap(tArgs[1]);
  20.  
  21. --This is the ID of the Advanced Jetpack.
  22. --Theoretically, you could change it to whatever you need to have charged.
  23. local jetpackID = 30481;
  24.  
  25. local items =
  26. {
  27.   jetpack   = 30209,
  28.   A_jetpack = 30481,
  29.   chest     = 30177,
  30.   pants     = 30176,
  31.   helm      = 30178,
  32.   boots     = 30175,
  33.   Q_Pants   = 30172
  34. };
  35.  
  36. local direction =
  37. {
  38.   down  = 0,
  39.   up    = 1,
  40.   north = 2,
  41.   south = 3,
  42.   west  = 4,
  43.   east  = 5
  44. }
  45.  
  46. --Helper function to find the actual item ID and
  47. -- meta value from a UUID.
  48. local function getID(uuid)
  49.   id = 0;
  50.   meta = 0;
  51.  
  52.   if uuid > 32768 then
  53.     id = uuid % 32768;
  54.     meta = (uuid - id) / 32768;
  55.   else
  56.     id = uuid;
  57.     meta = 0;
  58.   end
  59.  
  60.   return id, meta;
  61. end
  62.  
  63. --Simple helper function. Returns true, uuid and meta of item if found,
  64. -- false otherwise.
  65. local function findJetpack(direction)
  66.   local inventory = sorter.list(direction);
  67.   for uuid, count in pairs(inventory) do
  68.     local id, meta = getID(uuid);
  69.     for name, itemID in pairs(items) do
  70.       if (id == itemID) and (meta ~= 1) then
  71.         return true, uuid, meta, name;
  72.       end
  73.     end
  74.   end
  75.   return false;
  76. end
  77.  
  78. --Helper function to find a charged item.
  79. local function findChargedItem(direction, itemID)
  80.   local inventory = sorter.list(direction);
  81.   for uuid, count in pairs(inventory) do
  82.     local id, meta = getID(uuid);
  83.     if (itemID == id) and (meta == 1) then
  84.       return true
  85.     end
  86.   end
  87.   return false;
  88. end
  89.  
  90.  
  91. --Make sure to fill in the required parameters before using!
  92. --The sorter's 'extract' function has the following parameters:
  93. -- sorter.extract(from, uuid, to, amount)
  94. --Find the 'from' and 'to' direction values from the table provided
  95. -- at the beginning of this script.
  96.  
  97. --Main loop start! WOO!
  98. while true do
  99.   local jetpackFound, uuid, meta, name = findJetpack(direction.up);
  100.   if jetpackFound then
  101.     local itemID,_ = getID(uuid);
  102.    
  103.     sorter.extract(direction.up, uuid, direction.south, 1);
  104.     print("Day: "..os.day().." Time: "..os.time());
  105.     print(name.." sent to charge");
  106.     while true do
  107.       if findChargedItem(direction.up, itemID) then
  108.         print(name.." charged");
  109.         break;
  110.       else
  111.         sleep(0.5);
  112.       end
  113.     end
  114.   end
  115.   sleep(10);
  116. end
Advertisement
Add Comment
Please, Sign In to add comment