Advertisement
Ichabod2032

Minecraft - Item Recharger Using Interactive Sorter

Apr 10th, 2013
431
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.50 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. --03/26/13
  26. --Found that wiki page was incorrect on east and west values. Switched them.
  27. --Tested on SSP and SMP worlds with CraftOS 1.5, unsure of the
  28. -- interactive sorter's mod version.
  29. local direction =
  30. {
  31.   down  = 0,
  32.   up    = 1,
  33.   north = 2,
  34.   south = 3,
  35.   west  = 4,
  36.   east  = 5
  37. }
  38.  
  39. --Helper function to find the actual item ID and
  40. -- meta value from a UUID.
  41. local function getID(uuid)
  42.   id = 0;
  43.   meta = 0;
  44.  
  45.   if uuid > 32768 then
  46.     id = uuid % 32768;
  47.     meta = (uuid - id) / 32768;
  48.   else
  49.     id = uuid;
  50.     meta = 0;
  51.   end
  52.  
  53.   return id, meta;
  54. end
  55.  
  56. --Simple helper function. Returns true and uuid of item if found,
  57. -- false otherwise.
  58. local function findJetpack(direction)
  59.   local inventory = sorter.list(direction);
  60.   for uuid, count in pairs(inventory) do
  61.     local id, meta = getID(uuid);
  62.     if (id == jetpackID) and (meta ~= 1) then
  63.       return true, uuid;
  64.     end
  65.   end
  66.   return false;
  67. end
  68.  
  69. --Make sure to fill in the required parameters before using!
  70. --The sorter's 'extract' function has the following parameters:
  71. -- sorter.extract(from, uuid, to, amount)
  72. --Find the 'from' and 'to' direction values from the table provided
  73. -- at the beginning of this script.
  74.  
  75. --Main loop start! WOO!
  76. while true do
  77.   local jetpackFound, uuid = findJetpack("Fill Me In!");
  78.   if jetpackFound then
  79.     sorter.extract("Fill me in!", uuid, "Fill me in!", 1);
  80.     print("Day: "..os.day().." Time: "..os.time());
  81.     print("Item sent to charge");
  82.   end
  83.   sleep(10);
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement