Pythonization of ComputerCraft Minecraft mod. Write Python instead Lua! Fork by TheKidThatCodes
Project description
Pythonized CC Tweaked (ComputerCraft) API
This fork uses restrictedpython to keep people from hacking you
-
IF YOU ARE HOSTING AS LOCALHOST (not a replit or external server)
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 = "127.0.0.0/8" action = "allow" # change here deny to allow
-
Install & start python language server
Choose one of the following:
Docker way:
docker run -it -p 8080:8080 neumond/python-computer-craft
Install & run manually:
pip install cc-secure python -m cc-secure.server
-
Start Minecraft, open up any computer and type:
wget http://127.0.0.1:8080/ py py
or, if you are running on a replit or an external server, you can change the adress that is being
wget
ed to the replit or external server's ip or adressex.
wget http://a_repl.somebody.repl.co py py
or
wget http://420.696.969.9 py py
(that ip is not real, instad, replace the ip with the one your server is on)
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.
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 Distribution
Built Distribution
File details
Details for the file cc-secure-0.1.1.tar.gz
.
File metadata
- Download URL: cc-secure-0.1.1.tar.gz
- Upload date:
- Size: 30.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f381f7c37baca15dd9dc0ba2039378bdf76318ade4099a6f03cd2c79aa5f2d38 |
|
MD5 | 1f3e33f0968189d2be880cfe5066e397 |
|
BLAKE2b-256 | 4501747cd1f0b766a5cb26c7f16e8618a17327503a21392494550ee8dbb5e670 |
File details
Details for the file cc_secure-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: cc_secure-0.1.1-py3-none-any.whl
- Upload date:
- Size: 38.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fa5bd451d2a735375a0bd6881bbdae959a720991d89066f78f28e0f9a2009dc |
|
MD5 | 20e65fb0d07403d67e68166a601f19fa |
|
BLAKE2b-256 | d01e751a37e2b7ad76d44627529e10924dc9462bb9f7af6297d457600fd102aa |