Skip to main content

Pythonization of ComputerCraft Minecraft mod. Write Python instead Lua!

Project description

Pythonized CC Tweaked (ComputerCraft) API

Warning: CPython can't build safe sandboxes for arbitrary untrusted code (read more). Never use code in this repo if you don't trust your players!

  1. Download and install wheel from github releases

    pip install computercraft-*.whl
  2. Enable localhost in mod server config

    In case of singleplayer it's located inside your saves folder. In case of multiplayer check your server folder.

    Edit computercraft-server.toml

    	host = ""
    	action = "allow"  # change here deny to allow
  3. Start python server:

    python -m computercraft.server
  4. In minecraft, open up any computer and type:

    wget py

    Now you have python REPL in computercraft! To quit REPL type exit() and press enter.

py is short Lua program that interacts with the server. cc module contains almost everything as is in ComputerCraft documentation:

from cc import disk, os


Opening a file:

from cc import fs

with'filename', 'r') as f:
    for line in f:

Waiting for event (os.captureEvent instead os.pullEvent):

from cc import os

timer_id = os.startTimer(2)
for e in os.captureEvent('timer'):
    if e[0] == timer_id:
        print('Timer reached')

Using modems:

from cc import peripheral

modem = peripheral.wrap('back')
listen_channel = 5
# this automatically opens and closes modem on listen_channel
for msg in modem.receive(listen_channel):
    if msg.content == 'stop':
        modem.transmit(msg.reply_channel, listen_channel, msg.content)

Using parallel:

from cc import parallel, os

def fn():

parallel.waitForAll(fn, fn, fn)

Importing in-game files as modules:

from cc import import_file

p = import_file('/disk/')  # absolute
m = import_file('', __file__)  # relative to current file

More examples can be found in repository.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release. See tutorial on generating distribution archives.

Built Distribution

computercraft-0.3.0-py3-none-any.whl (29.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page