Python client for Evocraft
Project description
1. Set-up
python -m pip install test-evocraft-py
2. Starting the modded Minecraft server
Using python api
import test_evocraft_py
test_evocraft_py.start_server()
# shutdown
test_evocraft_py.shutdown_server()
Using cli
Usage: test-evocraft-py [OPTIONS]
Simple program that greets NAME for a total of COUNT times.
Options:
--start / --shutdown Start or shutdown server
--interactive Start server with interactive server console
--help Show this message and exit.
3. Spawn blocks on the Minecraft server with Python
There are three methods at the core of the API: spawnBlocks spawns a set of different blocks,
fillCube spawns a single type of block over a cubic volume and readCube which reads currently spawned blocks within a space.
If you aren't a seasoned Minecraft scholar, you can check information about different Minecraft blocks.
Here's example on how to spawn a flying machine with python (you'll need to have started the modded Minecraft server before):
import grpc
import minecraft_pb2_grpc
from minecraft_pb2 import *
channel = grpc.insecure_channel('localhost:5001')
client = minecraft_pb2_grpc.MinecraftServiceStub(channel)
client.fillCube(FillCubeRequest( # Clear a 20x10x20 working area
cube=Cube(
min=Point(x=-10, y=4, z=-10),
max=Point(x=10, y=14, z=10)
),
type=AIR
))
client.spawnBlocks(Blocks(blocks=[ # Spawn a flying machine
# Lower layer
Block(position=Point(x=1, y=5, z=1), type=PISTON, orientation=NORTH),
Block(position=Point(x=1, y=5, z=0), type=SLIME, orientation=NORTH),
Block(position=Point(x=1, y=5, z=-1), type=STICKY_PISTON, orientation=SOUTH),
Block(position=Point(x=1, y=5, z=-2), type=PISTON, orientation=NORTH),
Block(position=Point(x=1, y=5, z=-4), type=SLIME, orientation=NORTH),
# Upper layer
Block(position=Point(x=1, y=6, z=0), type=REDSTONE_BLOCK, orientation=NORTH),
Block(position=Point(x=1, y=6, z=-4), type=REDSTONE_BLOCK, orientation=NORTH),
# Activate
Block(position=Point(x=1, y=6, z=-1), type=QUARTZ_BLOCK, orientation=NORTH),
]))
To read the blocks present within a set of coordinates use readCube:
import grpc
import minecraft_pb2_grpc
from minecraft_pb2 import *
channel = grpc.insecure_channel('localhost:5001')
client = minecraft_pb2_grpc.MinecraftServiceStub(channel)
blocks = client.readCube(Cube(
min=Point(x=0, y=0, z=0),
max=Point(x=10, y=10, z=10)
))
print(blocks)
You can see the implemented Python methods at minecraft_pb2_grpc.py. For the general grpc definition please see minecraft-rpc.
If you'd like to interface with the server using other languages than Python, you can use the interface definition file you can generate clients for (almost) any programming language you like. See https://grpc.io/docs/languages/ and minecraft-rpc.
4. Rendering Minecraft
You can use the method client.readCube that allows to read which blocks are spawned, however, if you'd like to render Minecraft to see what your spawned creations look like or even interact with them, you'll need to buy and install Minecraft
- Install and launch Minecraft
- Create a compatible version:
InstallationsNew- Give it a name
- Select version 1.12.2
Create
- Launch it:
PlayMultiplayerDirect Connect- On
Server Addresswritelocalhost Join Server
On the server command line, you can use /tp @p x y z to teleport yourself to position {x,y,z} in the world.
5. Useful commands that you can type in the running server console
defaultgamemode creativeto set the default mode to creative;setworldspawn x y zto set the default player spawn point;time set dayto set time to day;gamerule doDaylightCycle falsestop the day/night cycle;gamemode creative <player name>set creative mode for a specific player (sometimes the default isn't working);teleport <player name> x y zteleport a player to x,y,z coordinates.
Et voilà:
Evolutionary algorithms implemented with the API
In this section we'll compile implementations of evolutionary algorithms using the API
- Interactive evolution: Evolve Minecraft entities interactively.
- Simple tower evolution in Python: Evolve tower that reach for a golden block in the sky.
Citation
If you use the code for academic or commecial use, please cite the associated paper:
@article{Grbic2020Dec,
author = {Djordje Grbic, Rasmus Berg Palm, Elias Najarro, Claire Glanois, Sebastian Risi},
title = {{EvoCraft: A New Challenge for Open-Endedness}},
journal = {arXiv},
year = {2020},
month = {Dec},
eprint = {2012.04751},
url = {https://arxiv.org/abs/2012.04751v1}
}
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
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 test_evocraft_py-0.1.7.tar.gz.
File metadata
- Download URL: test_evocraft_py-0.1.7.tar.gz
- Upload date:
- Size: 34.3 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c108d25aa5b20f7ae9c31b39e43a98fa6b1fdeba4a549d571fecda8979353c6e
|
|
| MD5 |
dba0b6f10d267c7bece5ab08ed44545b
|
|
| BLAKE2b-256 |
2f1ecf92bb1407f4942e3b433c09460389dc6486ea2898848a71d7a1ddae85d8
|
File details
Details for the file test_evocraft_py-0.1.7-py2.py3-none-any.whl.
File metadata
- Download URL: test_evocraft_py-0.1.7-py2.py3-none-any.whl
- Upload date:
- Size: 34.3 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0784ba442cb57ea5266226651ae4cf5e8e545b98e0efeb51a1f311e931c0a79
|
|
| MD5 |
7fd42b90d852c3fe3f8653a73276849b
|
|
| BLAKE2b-256 |
1cbc0e84e0da07c867cc37bbdb245e069c4e4b8b1f3772e9806459f47b8bd6c4
|