This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Farrk's profile picture

Farrk's somewhat useful programs/utilities![OpenPeripherals]

Started by Farrk, 18 December 2013 - 05:18 PM
Farrk #1
Posted 18 December 2013 - 06:18 PM
Greetings, I've been playing with computercraft for quite a while, which is in my opinion top tier mod, and so useful that I wouldn't be able to accomplish half of stuff I've done while playing minecraft… In the past I didn't really care about saving what I made, since I could reproduce it from top of my head, but I now I felt like someone can actually spare some time on research and explosions by using some of the stuff I wrote in the past :)/>/> It will be also an opportunity for people that are quite new to computercraft to see how things can be done, so enjoy!

I will be updating this topic whenever I come up with something new, or when someone in this topic point out some mistake or just propose a better way to achieve same effect. Every program/utility will have short description so you can figure out what is this program/utility for.(1.6.4 packs are not out for too long, currently my programs are witten for FTB Unleashed 1.5.2 modpack, but I'm already getting around rewriting them to work on 1.6.4, soon enough I will have all my programs updated for 1.6.4 as well, unless I come across some issue with new OpenPeripherals that will require waiting on mod update).

Let's get to the point:
(Listed versions along with pastebins are just versions of modpacks that I have successfully tested programs I made, however they should work with any other modpack that has ComputerCraft and OpenPeripherals in them. Also bear in mind that while 1.5.2 tests were done with ComputerCraft and OpenPeripherals versions supplied in 1.1.7 version of the modpack by default, I strongly suggest to use latest OpenPeripherals version in 1.6.4 version of minecraft, which you can find at http://openmods.info:8080/job/OpenPeripheralCore/ ).

AS OF NOW PROGRAMS ARE SEPARATE FOR MC 1.5.2 AND 1.6.4 BUT I WILL SHORTLY UPDATE THEM WITH SINGLE PASTEBIN LINKS WHICH WILL PROVIDE COMPATIBILITY FOR BOTH VERSIONS OF MINECRAFT.

*getLiquidAmount(side,tankSide) function:
Spoiler[indent=1]This function will let you check amount of liquid stored in tank on "side" of turtle, by getting info from specified tank side "tankSide". If given no arguments function will use default arguments which are “top” for tank position in relation to turtle and “unknown” as side of tank to get information from.[/indent]
[indent=1]-1.5.2 and 1.6.4 compatible function by theoriginalbit:http://pastebin.com/3bzUZkdc[/indent]
*MFR automatic books/items enchanter program:
Spoiler[indent=1][/indent]
[indent=1]This program will let you enchant specific amount of items/books at once certain amount of times. It supports up to 16 items/stacks of books(full turtle, continuous items/books input possible to exceed 16 items/stacks limit) and will deposit enchanted items into any valid inventory north(default) of Auto-Enchanter. Side to which enchanted items will be sent to is configurable in line 1 of the program. Basic setup goes as follows: Any turtle facing MFR Auto-Enchanter and any valid inventory(Hopper,ME interface, anything) next to Auto-Enchanter in direction you specified in the program(default is north, therefore turtle needs to be in different spot. Valid sides to output items to are:”up”,”down”,”north”,”south”,”east”,”west”)[/indent]
[indent=1]-1.5.2&1.6.4: http://pastebin.com/yh9X22KU[/indent]
[indent=1]In 1.6.4 version Auto-Enchanter no longer let you enchant multiple books at once with same enchant, therefore you can no longer input amount of books to enchant at once.[/indent]
*DartCraft Spoils Bags processing program:
Spoiler[indent=1][/indent]
[indent=1]
Ever ran into situation where your fancy MFR spawner with monsters killed by Extra Utilities Iron Spikes gives you ton of Spoils Bags that just can’t be simply imported into turtle and opened by it without having first “initializing” them by taking them into player inventory ? This program with small help of AE will let you automatically open any amount of non-initialized Spoils bags! Basic setup goes as follows: PIM from OpenPeripherals with Fuzzy Export Bus attached with Spoils bag inside(Match Any setting), a turtle below PIM with this program with any valid inventory(preferably ME interface to import Spoils bag contents directly into the network) in front of it. After that all player has to do is to stand on PIM until turtle open all the bags![/indent]
[indent=1]-1.5.2(FTB Unleashed): http://pastebin.com/ZZHKvr8W[/indent]
[indent=1]-1.6.4(FTB Direwolf20 with DartCraft installed): (Not updated yet)[/indent]

*Program to display current ticks/second:
Spoiler[indent=1][/indent]
[indent=1]This program will let you see current t/s of server/single player world. During first run it adjusts sleep time to match 19-20 t/s and saves as computer/turtle name for later usage. As of now I am unsure how exact it is going to be at lower t/s, it will require further testing. It doesn't use any peripherals so OpenPeripherals doesn't need to be installed.Default website it gets timestamps from may get you blocked for too many requests(happened on test subject server), so I recommend hosting PHP script which returns the timestamps on your own hosting. Requires http api to be enabled![/indent]
[indent=1]-Any ComputerCraft: http://pastebin.com/y2AG6MXJ[/indent]
[indent=1]-PHP script, which return unix timestamp with microseconds: http://pastebin.com/pm1ejZMR[/indent]
*Program which empties your entire inventory while maintaining layout of items:
Spoiler

This program empties all your inventory slots(hotbar, inventory and armor) into enderchests while keeping track of amount of items that you had in your inventory, works like this : You go through pressure plate, then stand on PIM, it will check if your inventory is totally empty(as if you just used it) and then will proceed to restore all items into their places, otherwise it will store everything in enderchests to be later restored to player, after that just step on pressure plate on the other side(A potential usage for this explained below). Basic setup requires 2 sets of enderchests, 1 set for turtle/computer and 1 set for PIM, a turtle/computer, and 2 pressure plates. You can configure sides on which chests are in first 2 lines of the program, valid sides for PIM are ”north”,”south”,”east”,”west”(default west and east),turtle/computer just needs enderchests to be at left/right sides it.

I felt like writing this program because I saw decent way to use this along with mod called Sync(made by ichun for modjam) which lets you travel to your clones in overworld and nether almost instantly, however clones do not share inventory with each other, therefore i wrote this to overcome that problem.

-1.6.4:http://pastebin.com/kuExyAYD
*Program which is sorting items based on pattern in chest:
Spoiler
Long story short, this program will push items from input chest down(into trash can for example) if they match set up filter, or send it to other direction if they dont. It loads the filter once per startup, so be sure to restart the program after you change contents of the filter chest.
Basically if you want something to match the filter you just have to keep at least 1 piece of that item/block in filter chest(default:left), and after you start the program it will print out names of items that are added to filter. After that every now and then the program will iterate through input chest(default: right) and will send items matching the filter into certain direction(default:down), or if they dont match the filter into other certain direction(default:south). Default set up is shown is shown on screenshot.
The reason I did it this way is because names of items are not always obvious as they should be(tile.block.marble.0.name yo). Any block with valid inventory and getStackInSlot() method available can be either filter chest or input chest(ender chest, diamond chest etc). Things that you may want to change are declared and commented in the beginning of the program.

-1.6.4:http://pastebin.com/g4Yhyn8X

That is all for now, feel free to provide feedback, or report any issues. :)/>
Edited on 25 January 2014 - 08:36 PM
theoriginalbit #2
Posted 18 December 2013 - 06:36 PM
There are a few things throughout that you could improve on.

As an example, here is your getLiquidAmount function redone. The main changes:
  • Variables are localised
  • Works for both 1.5.2 and 1.6.4 versions of OpenPeripheral
  • Default tank is "unknown" instead of "down"… using "unknown" well get a tank no matter where it is.

local function getLiquidAmount(side, tankSide)
  local p = peripheral.wrap(side or "top")
  local getTankInfo = p.getTanks or p.getTankInfo
  local tankInfo = getTankInfo(tankSide or "unknown")
  local _,tank = next(tankInfo)
  return type(tank) == "table" and tank.amount or nil
end
Edited on 18 December 2013 - 05:36 PM
Farrk #3
Posted 18 December 2013 - 07:09 PM
There are a few things throughout that you could improve on.

As an example, here is your getLiquidAmount function redone. The main changes:
  • Variables are localised
  • Works for both 1.5.2 and 1.6.4 versions of OpenPeripheral
  • Default tank is "unknown" instead of "down"… using "unknown" well get a tank no matter where it is.

local function getLiquidAmount(side, tankSide)
  local p = peripheral.wrap(side or "top")
  local getTankInfo = p.getTanks or p.getTankInfo
  local tankInfo = getTankInfo(tankSide or "unknown")
  local _,tank = next(tankInfo)
  return type(tank) == "table" and tank.amount or nil
end

Quite valid point, I haven't thought of actually making programs being compatible with both versions! Time to sit and edit those things to work with either 1.5.2 or 1.6.4. Thank you for such useful input !(And I will start to use localised variables too!) I hope you don't mind me changing pastebin to add this function in place of mine(with credits added). About considering "down" a default it was just first side that came to my mind :)/>
Edited on 18 December 2013 - 06:10 PM
theoriginalbit #4
Posted 18 December 2013 - 07:12 PM
Thank you for such useful input !(And I will start to use localised variables too!) I hope you don't mind me changing pastebin to add this function in place of mine(with credits added).
Not at all, if I didn't want you to use it I wouldn't have made it, or I would have used a different example, not your one. Credits are not required, but are appreciated, thanks :)/>

About considering "down" a default it was just first side that came to my mind:)
Haha yeh, I assumed that you were unaware of "unknown".
dendimon #5
Posted 21 December 2013 - 03:11 PM
Thank you for such useful input !(And I will start to use localised variables too!) I hope you don't mind me changing pastebin to add this function in place of mine(with credits added).
Not at all, if I didn't want you to use it I wouldn't have made it, or I would have used a different example, not your one. Credits are not required, but are appreciated, thanks :)/>/>

About considering "down" a default it was just first side that came to my mind:)
Haha yeh, I assumed that you were unaware of "unknown".
Farrk,are you that Farrk who played on the server nukepowered and who knew famous person:vanyserezkhin?
Farrk #6
Posted 22 December 2013 - 04:54 AM
Well, yes. Why ?
MazeusXenon #7
Posted 23 December 2013 - 10:51 AM
So I tried your "getLiquidAmount" function using a computer and a single tank block from openblocks… and I always get nil. So, I had it just spit back "type(tank)" and it says its a string, which is why I always get a nil…. or I assume as much in that I can't get "tank.amount" because the type is a string and not an array or function!

Oh, and if I "print(tank)" I get "net.minecraftforge.fluids.fluidTankInfo@[hexcode]"
And "print(tank.amount)" returns an empty string

ANY help with this would be appreciated as we have a small city we are building on our server and want to be able to display to everyone liquid levels for our lava, oil, milk, UU matter, and any other liquids we are piling up from everyone's input! We're seriously geeking out with the idea of a public information system so I am hoping we can just Uber-geek it out and make everyone happy!

OP Version:0.21.1-100
Forge: 9.11.1.953
OpenBlocks: 1.2.2
Farrk #8
Posted 23 December 2013 - 01:55 PM
So I tried your "getLiquidAmount" function using a computer and a single tank block from openblocks… and I always get nil. So, I had it just spit back "type(tank)" and it says its a string, which is why I always get a nil…. or I assume as much in that I can't get "tank.amount" because the type is a string and not an array or function!

Oh, and if I "print(tank)" I get "net.minecraftforge.fluids.fluidTankInfo@[hexcode]"
And "print(tank.amount)" returns an empty string

ANY help with this would be appreciated as we have a small city we are building on our server and want to be able to display to everyone liquid levels for our lava, oil, milk, UU matter, and any other liquids we are piling up from everyone's input! We're seriously geeking out with the idea of a public information system so I am hoping we can just Uber-geek it out and make everyone happy!

OP Version:0.21.1-100
Forge: 9.11.1.953
OpenBlocks: 1.2.2

If it spits data you don't expect to see, it means you probably run not recent enough OpenPeripherals. Ask your server admin or update them to newest version yourself: http://openmods.info:8080/job/OpenPeripheral/
It should fix it.(I take that you are using OP supplied with FTB packs, which is kind of old-ish)
MazeusXenon #9
Posted 23 December 2013 - 02:42 PM
So I tried your "getLiquidAmount" function using a computer and a single tank block from openblocks… and I always get nil. So, I had it just spit back "type(tank)" and it says its a string, which is why I always get a nil…. or I assume as much in that I can't get "tank.amount" because the type is a string and not an array or function!

Oh, and if I "print(tank)" I get "net.minecraftforge.fluids.fluidTankInfo@[hexcode]"
And "print(tank.amount)" returns an empty string

ANY help with this would be appreciated as we have a small city we are building on our server and want to be able to display to everyone liquid levels for our lava, oil, milk, UU matter, and any other liquids we are piling up from everyone's input! We're seriously geeking out with the idea of a public information system so I am hoping we can just Uber-geek it out and make everyone happy!

OP Version:0.21.1-100
Forge: 9.11.1.953
OpenBlocks: 1.2.2

If it spits data you don't expect to see, it means you probably run not recent enough OpenPeripherals. Ask your server admin or update them to newest version yourself: http://openmods.info...OpenPeripheral/
It should fix it.(I take that you are using OP supplied with FTB packs, which is kind of old-ish)

Actually, its our own pack and I am one of the admins! So yeah - conference time to decide what we are going to update! Yay!
Farrk #10
Posted 25 January 2014 - 09:34 PM
Small update with "sorting/trashing" program!