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!
-
Before you start Minecraft, 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[[http.rules]] host = "$private" action = "allow" # change here deny to allow
-
Install & start python language server
python -m pip install computercraft python -m computercraft.server
-
Start Minecraft, open up any computer and type:
wget http://127.0.0.1:8000 py py
Now you have python REPL in computercraft! To quit REPL type
exit()and press enter.To run any program:
py program.py # relative to current dir py /path/to/program.py
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
disk.eject('right')
print(os.getComputerLabel())
Opening a file:
from cc import fs
with fs.open('filename', 'r') as f:
for line in f:
print(line)
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')
break
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):
print(repr(msg))
if msg.content == 'stop':
break
else:
modem.transmit(msg.reply_channel, listen_channel, msg.content)
Using parallel:
from cc import parallel, os
def fn():
os.sleep(2)
print('done')
parallel.waitForAll(fn, fn, fn)
Importing in-game files as modules:
from cc import import_file
p = import_file('/disk/program.py') # absolute
m = import_file('lib.py', __file__) # relative to current file
More examples can be found in this repository: examples/ and tests/cc_programs/
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file computercraft-0.4.0-py3-none-any.whl.
File metadata
- Download URL: computercraft-0.4.0-py3-none-any.whl
- Upload date:
- Size: 46.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
661f116e361a6e5016f471b12b8e8a21e8e6512cd2c3e99ca85134ad5bf4aaf0
|
|
| MD5 |
8b330b85bd9c075fe92d50f940249daf
|
|
| BLAKE2b-256 |
57594d909e35d8ec56a7f9defd6f23c8e22630f26c99840d61b772534a6f76cc
|