Posted 03 November 2013 - 02:14 PM
Have you ever wanted to use Python in ComputerCraft? Well now's your chance! With CCPy v1.0, you can do just that, with access to the key APIs that make ComputerCraft work, for example the Term API, OS API etc.
Coming very soon
Here's the list of features coming very soon:
Edit: 2014 here's the source code (probs no one reading this now anyway, but I need to delete old files eventually): http://www.mediafire.com/download/stp5bh6oq8kris5/Source.zip
Installation
Download the zip file containing all the necessary files here: http://www.mediafire...h4klsy6ppr84b6l
With the latest forge version installed for your 1.6.x version of Minecraft, drag both jython-standalone-2.5.4-rc1.jar and CCPy.zip to your mods folder, in .minecraft. Finally, drag CCPy_Resource_Pack_v1.0.zip to the resourcepacks folder in .minecraft.
Basics (need to know)
To craft the Python Module block, needed to run Python programs, put some green dye, string, stone and redstone into the crafting bench in any order. Then shift-click it onto the side of your computer.
To start programming in Python, simply type "editpy <program name>", to use the editor, but with syntax highlighting for Python. I recommend appending ".py" to all your Python programs, so that people can differentiate between Python and Lua programs. To run your programs, type "runpy <program name> <arguments>", and it'll start right up. You will need a Python Module attached to your computer for this to work. There is a pause while the Jython Interpreter starts up, but your program will start running after ~1 second.
Programming with the APIs
The equivalent of "rednet.open("right")" in a Python program will be "cc.rednet_open("right")". This pattern applies for all API calls. This is to avoid conflicting names of APIs. For example, Python already has an os module ready for import, which would conflict with the ComputerCraft OS API. The equivalent of "keys.enter" is just "cc.keys["enter"]" in Python. When there are an arbitrary number of paraments, the known ones are normal, but the arbitrary number is stored in a list. For example, peripheral.call in lua always has a side as the first argument, and the function name to call on the peripheral as the second, and then an unknown number of extra arguments. In Python, the first two are the same, and then the extra arguments of unknown length are in a list. However, when there is an optional argument in Lua, for example the timeout on rednet.receive, this is also optional in Python. EXCEPTION: cc.peripheral_call still needs an empty array as the third argument, when there aren't any extra arguments. When there are multiple return values, for example "os.pullEvent()" in Lua, the values are returned in a list aswell. For example, "cc.os_pullEvent()" returns a list with the first element as the event type, and the rest as values from the event.
The full list of the implemented APIs is:
Output
Just use the print keyword in Python, like usual. This is the equivalent of the print() function in Lua. You can also use "cc.term_write".
Warning (IMPORTANT!)
This should be able to run on a server, however it isn't at all sandboxed. This means that I haven't prevented the Python programs from doing everything the programmer wants. For example, if you run this on your server on your own computer, then everyone can read and delete your files, run commands, etc. Therefore, only let people you trust on your server, or don't run a server at all.
Don't use input() for input, use cc.read(). If you use input(), your ComputerCraft computer will "crash", and you'll have to restart it, or exit the world and re-enter it.
Bugs
Please post any bugs not already posted below, with the title of "Bug". Include as much info as you can, including output logs, what you did to cause the bug, program code, etc. so I can sort it out ASAP.
Screenshots
Coming very soon
Here's the list of features coming very soon:
- Sandboxing (it's not very good if viruses could propagate through this mod, when people download other people's scripts)
- Turtle support (hopefully, haven't investigated whether it's possible or not yet)
Edit: 2014 here's the source code (probs no one reading this now anyway, but I need to delete old files eventually): http://www.mediafire.com/download/stp5bh6oq8kris5/Source.zip
Installation
Download the zip file containing all the necessary files here: http://www.mediafire...h4klsy6ppr84b6l
With the latest forge version installed for your 1.6.x version of Minecraft, drag both jython-standalone-2.5.4-rc1.jar and CCPy.zip to your mods folder, in .minecraft. Finally, drag CCPy_Resource_Pack_v1.0.zip to the resourcepacks folder in .minecraft.
Basics (need to know)
To craft the Python Module block, needed to run Python programs, put some green dye, string, stone and redstone into the crafting bench in any order. Then shift-click it onto the side of your computer.
To start programming in Python, simply type "editpy <program name>", to use the editor, but with syntax highlighting for Python. I recommend appending ".py" to all your Python programs, so that people can differentiate between Python and Lua programs. To run your programs, type "runpy <program name> <arguments>", and it'll start right up. You will need a Python Module attached to your computer for this to work. There is a pause while the Jython Interpreter starts up, but your program will start running after ~1 second.
Programming with the APIs
The equivalent of "rednet.open("right")" in a Python program will be "cc.rednet_open("right")". This pattern applies for all API calls. This is to avoid conflicting names of APIs. For example, Python already has an os module ready for import, which would conflict with the ComputerCraft OS API. The equivalent of "keys.enter" is just "cc.keys["enter"]" in Python. When there are an arbitrary number of paraments, the known ones are normal, but the arbitrary number is stored in a list. For example, peripheral.call in lua always has a side as the first argument, and the function name to call on the peripheral as the second, and then an unknown number of extra arguments. In Python, the first two are the same, and then the extra arguments of unknown length are in a list. However, when there is an optional argument in Lua, for example the timeout on rednet.receive, this is also optional in Python. EXCEPTION: cc.peripheral_call still needs an empty array as the third argument, when there aren't any extra arguments. When there are multiple return values, for example "os.pullEvent()" in Lua, the values are returned in a list aswell. For example, "cc.os_pullEvent()" returns a list with the first element as the event type, and the rest as values from the event.
The full list of the implemented APIs is:
- Term (without redirect/restore, due to my Java implementation of printing, and would require a lot of rewriten code)
- Rednet
- Key
- Colo(u)r
- OS
- Peripheral
- Redstone
- Disk
- And a miscellaneous function, read ("cc.read()") for input.
Output
Just use the print keyword in Python, like usual. This is the equivalent of the print() function in Lua. You can also use "cc.term_write".
Warning (IMPORTANT!)
This should be able to run on a server, however it isn't at all sandboxed. This means that I haven't prevented the Python programs from doing everything the programmer wants. For example, if you run this on your server on your own computer, then everyone can read and delete your files, run commands, etc. Therefore, only let people you trust on your server, or don't run a server at all.
Don't use input() for input, use cc.read(). If you use input(), your ComputerCraft computer will "crash", and you'll have to restart it, or exit the world and re-enter it.
Bugs
Please post any bugs not already posted below, with the title of "Bug". Include as much info as you can, including output logs, what you did to cause the bug, program code, etc. so I can sort it out ASAP.
Screenshots
Edited on 17 December 2014 - 05:56 PM