SHOW:
|
|
- or go back to the newest paste.
| 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. |
| 7 | + | -- Buildcraft pipe. This allows you to fill the chest up with crap, but only send out |
| 8 | -- what needs to be charged! | |
| 9 | --The return trip is handled by an Autarchic AND Gate that is set to extract the item | |
| 10 | -- from the charge station once it is full. Set 1 setting to energy pulse when an item is | |
| 11 | -- in inventory, and the other setting set to energy pulse when charging a fully charged | |
| 12 | -- item. Easy Peasy! | |
| 13 | ||
| 14 | --Redux Update: Added the ability to test if an item sent to charge was returned, therefor allowing | |
| 15 | - | print("Usage: <name of program> <side sorter is attached to>");
|
| 15 | + | -- multiple users to use the same ender chest at the same time. The test is handled by a gate on the |
| 16 | -- return pipe that emits a redstone signal if an item is traversing. The redstone signal is picked up | |
| 17 | -- by the computer to let it know that the item is charged. | |
| 18 | --If you're confused at all by this explanation (and I know you are, cause I am too), please refer to | |
| 19 | -- this picture: http://imgur.com/ejP2juQ . This is my current setup that works without issue (knock on wood). | |
| 20 | ||
| 21 | - | --This is the ID of the Advanced Jetpack. |
| 21 | + | |
| 22 | - | --Theoretically, you could change it to whatever you need to have charged. |
| 22 | + | |
| 23 | - | local jetpackID = 30481; |
| 23 | + | print("Usage: <name of this program> <side sorter is attached to>");
|
| 24 | return; | |
| 25 | end | |
| 26 | ||
| 27 | local sorter = peripheral.wrap(tArgs[1]); | |
| 28 | ||
| 29 | --Redux Update: The programs scans the ender chest using ids from this table. | |
| 30 | --Feel free to add more ids for more chargeable items! | |
| 31 | local items = | |
| 32 | {
| |
| 33 | jetpack = 30209, | |
| 34 | A_jetpack = 30481, | |
| 35 | chest = 30177, | |
| 36 | pants = 30176, | |
| 37 | helm = 30178, | |
| 38 | boots = 30175, | |
| 39 | Q_Pants = 30172 | |
| 40 | }; | |
| 41 | ||
| 42 | --Small helper table to make working with cardinal directions easier. | |
| 43 | --5/29/13 | |
| 44 | --East and West values have been swapped from what the interactive sorter's wiki says. | |
| 45 | -- Unsure what is causing the values to be incorrect, as the same issues with East and | |
| 46 | -- West is present when using Factorization's Routers. | |
| 47 | local direction = | |
| 48 | {
| |
| 49 | down = 0, | |
| 50 | up = 1, | |
| 51 | north = 2, | |
| 52 | south = 3, | |
| 53 | west = 4, | |
| 54 | east = 5 | |
| 55 | } | |
| 56 | ||
| 57 | --Helper function to find the actual item ID and | |
| 58 | -- meta value from a UUID. | |
| 59 | local function getID(uuid) | |
| 60 | id = 0; | |
| 61 | meta = 0; | |
| 62 | ||
| 63 | if uuid > 32768 then | |
| 64 | id = uuid % 32768; | |
| 65 | meta = (uuid - id) / 32768; | |
| 66 | else | |
| 67 | id = uuid; | |
| 68 | meta = 0; | |
| 69 | end | |
| 70 | ||
| 71 | return id, meta; | |
| 72 | end | |
| 73 | ||
| 74 | --Simple helper function. Returns true, uuid and meta of item if found, | |
| 75 | -- false otherwise. | |
| 76 | local function findJetpack(direction) | |
| 77 | local inventory = sorter.list(direction); | |
| 78 | - | --Helper function to find a charged item. |
| 78 | + | |
| 79 | - | local function findChargedItem(direction, itemID) |
| 79 | + | |
| 80 | for name, itemID in pairs(items) do | |
| 81 | if (id == itemID) and (meta ~= 1) then | |
| 82 | return true, uuid, meta, name; | |
| 83 | - | if (itemID == id) and (meta == 1) then |
| 83 | + | |
| 84 | - | return true |
| 84 | + | |
| 85 | end | |
| 86 | return false; | |
| 87 | end | |
| 88 | ||
| 89 | --Helper function to find a charged item. Gets the redstone output from a | |
| 90 | -- gate on the return pipe coming from the MFE/MFSU | |
| 91 | - | --Make sure to fill in the required parameters before using! |
| 91 | + | --*Make sure to fill in the required parameter before using!* |
| 92 | -- change EDITME!!! to the side the redstone signal will enter the computer. | |
| 93 | -- Make sure to use quotation marks as well | |
| 94 | - | --Find the 'from' and 'to' direction values from the table provided |
| 94 | + | -- eg: rs.getInput("back") or rs.getInput("left")
|
| 95 | - | -- at the beginning of this script. |
| 95 | + | local function isItemCharged() |
| 96 | return rs.getInput(EDITME!!!); | |
| 97 | end | |
| 98 | ||
| 99 | - | local jetpackFound, uuid, meta, name = findJetpack(direction.up); |
| 99 | + | |
| 100 | --*Make sure to fill in the required parameters before using!* | |
| 101 | - | local itemID,_ = getID(uuid); |
| 101 | + | |
| 102 | - | |
| 102 | + | |
| 103 | - | sorter.extract(direction.up, uuid, direction.south, 1); |
| 103 | + | --Replace 'from' and 'to' with the correct directions, ideally using |
| 104 | -- the table provided at the top of this script. | |
| 105 | -- eg: sorter.extract(direction.north, uuid, direction.down, 1) | |
| 106 | ||
| 107 | - | if findChargedItem(direction.up, itemID) then |
| 107 | + | |
| 108 | while true do | |
| 109 | local jetpackFound, uuid, meta, name = findJetpack(CHANGEME!!!); | |
| 110 | ||
| 111 | if jetpackFound then | |
| 112 | sorter.extract(CHANGEME!!!, uuid, CHANGEME!!!, 1); | |
| 113 | print("Day: "..os.day().." Time: "..os.time());
| |
| 114 | print(name.." sent to charge"); | |
| 115 | while true do | |
| 116 | if isItemCharged() then | |
| 117 | print(name.." charged"); | |
| 118 | break; | |
| 119 | else | |
| 120 | sleep(0.5); | |
| 121 | end | |
| 122 | end | |
| 123 | end | |
| 124 | ||
| 125 | sleep(10); | |
| 126 | end |