Metadata-Version: 2.4
Name: computercraft
Version: 0.4.0
Summary: Pythonization of ComputerCraft Minecraft mod. Write Python instead Lua!
Author-email: Vitalik Verhovodov <knifeslaughter@gmail.com>
License: MIT License
        
        Copyright (c) 2020 neumond
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Repository, https://github.com/neumond/python-computer-craft
Keywords: computercraft,minecraft,cc:tweaked
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Education
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Games/Entertainment
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp
Requires-Dist: greenlet
Provides-Extra: dev
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# Pythonized CC Tweaked (ComputerCraft) API

**Warning**: CPython can't build safe sandboxes for arbitrary untrusted code
[(read more)](https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html).
Never use code in this repo if you don't trust your players!


1. 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`

    ```toml
    [[http.rules]]
		host = "$private"
		action = "allow"  # change here deny to allow
    ```

2. Install & start python language server

    ```sh
    python -m pip install computercraft
    python -m computercraft.server
    ```

3. Start Minecraft, open up any computer and type:

    ```sh
    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:

    ```sh
    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:

```python
from cc import disk, os

disk.eject('right')
print(os.getComputerLabel())
```

Opening a file:

```python
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`):

```python
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:

```python
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:

```python
from cc import parallel, os

def fn():
    os.sleep(2)
    print('done')

parallel.waitForAll(fn, fn, fn)
```

Importing in-game files as modules:

```python
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/`
