Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --2013 Ichabod_Clay (Ichabod2032)
- --Item charger script for Minecraft.
- --This script uses an Interactive Sorter to take an item (ideally from an ender chest)
- -- and send it off to charge in a charging station (batbox, MFE, MFSU).
- --The way I have it set up is the Sorter scans the chest every so often and, if the
- -- proper item is found, takes the item and sends it to a charge station through a
- -- Buildcraft pipe. This allows you to fill the chest up with crap, but only send out
- -- what needs to be charged!
- --The return trip is handled by an Autarchic AND Gate that is set to extract the item
- -- from the charge station once it is full. Set 1 setting to energy pulse when an item is
- -- in inventory, and the other setting set to energy pulse when charging a fully charged
- -- item. Easy Peasy!
- --Redux Update: Added the ability to test if an item sent to charge was returned, therefor allowing
- -- multiple users to use the same ender chest at the same time. The test is handled by a gate on the
- -- return pipe that emits a redstone signal if an item is traversing. The redstone signal is picked up
- -- by the computer to let it know that the item is charged.
- --If you're confused at all by this explanation (and I know you are, cause I am too), please refer to
- -- this picture: http://imgur.com/ejP2juQ . This is my current setup that works without issue (knock on wood).
- tArgs = {...};
- if #tArgs ~= 1 then
- print("Usage: <name of this program> <side sorter is attached to>");
- return;
- end
- local sorter = peripheral.wrap(tArgs[1]);
- --Redux Update: The programs scans the ender chest using ids from this table.
- --Feel free to add more ids for more chargeable items!
- local items =
- {
- jetpack = 30209,
- A_jetpack = 30481,
- chest = 30177,
- pants = 30176,
- helm = 30178,
- boots = 30175,
- Q_Pants = 30172
- };
- --Small helper table to make working with cardinal directions easier.
- --5/29/13
- --East and West values have been swapped from what the interactive sorter's wiki says.
- -- Unsure what is causing the values to be incorrect, as the same issues with East and
- -- West is present when using Factorization's Routers.
- local direction =
- {
- down = 0,
- up = 1,
- north = 2,
- south = 3,
- west = 4,
- east = 5
- }
- --Helper function to find the actual item ID and
- -- meta value from a UUID.
- local function getID(uuid)
- id = 0;
- meta = 0;
- if uuid > 32768 then
- id = uuid % 32768;
- meta = (uuid - id) / 32768;
- else
- id = uuid;
- meta = 0;
- end
- return id, meta;
- end
- --Simple helper function. Returns true, uuid and meta of item if found,
- -- false otherwise.
- local function findJetpack(direction)
- local inventory = sorter.list(direction);
- for uuid, count in pairs(inventory) do
- local id, meta = getID(uuid);
- for name, itemID in pairs(items) do
- if (id == itemID) and (meta ~= 1) then
- return true, uuid, meta, name;
- end
- end
- end
- return false;
- end
- --Helper function to find a charged item. Gets the redstone output from a
- -- gate on the return pipe coming from the MFE/MFSU
- --*Make sure to fill in the required parameter before using!*
- -- change EDITME!!! to the side the redstone signal will enter the computer.
- -- Make sure to use quotation marks as well
- -- eg: rs.getInput("back") or rs.getInput("left")
- local function isItemCharged()
- return rs.getInput(EDITME!!!);
- end
- --*Make sure to fill in the required parameters before using!*
- --The sorter's 'extract' function has the following parameters:
- -- sorter.extract(from, uuid, to, amount)
- --Replace 'from' and 'to' with the correct directions, ideally using
- -- the table provided at the top of this script.
- -- eg: sorter.extract(direction.north, uuid, direction.down, 1)
- --Main loop start! WOO!
- while true do
- local jetpackFound, uuid, meta, name = findJetpack(CHANGEME!!!);
- if jetpackFound then
- sorter.extract(CHANGEME!!!, uuid, CHANGEME!!!, 1);
- print("Day: "..os.day().." Time: "..os.time());
- print(name.." sent to charge");
- while true do
- if isItemCharged() then
- print(name.." charged");
- break;
- else
- sleep(0.5);
- end
- end
- end
- sleep(10);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement