Minecraft-client networking library in Python
Go to file
joo 969419da3f Fix: non-monotonic protocol versions are not correctly handled
After 1.16.3, Mojang started publishing snapshot, pre-release and release
candidate versions of Minecraft with protocol version numbers of the form
`(1 << 30) | n' where 'n' is a small non-negative integer increasing with each
such version; the release versions continued to use the old format. For
example, these are the last 8 published Minecraft versions as of this commit:

release           1.16.3      uses protocol version 753
pre-release       1.16.4-pre1 uses protocol version 1073741825 == (1 << 30) | 1
pre-release       1.16.4-pre2 uses protocol version 1073741826 == (1 << 30) | 2
release candidate 1.16.4-rc1  uses protocol version 1073741827 == (1 << 30) | 3
release           1.16.4      uses protocol version 754
snapshot          20w45a      uses protocol version 1073741829 == (1 << 30) | 5
snapshot          20w46a      uses protocol version 1073741830 == (1 << 30) | 6
snapshot          20w48a      uses protocol version 1073741831 == (1 << 30) | 7

This means that protocol versions no longer increase monotonically with respect
to publication history, a property that was assumed to hold in much of
pyCraft's code relating to support of multiple protocol versions. This commit
rectifies the issue by replacing any comparison of protocol versions by their
numerical value with a comparison based on their publication time.

Newly defined is the dictionary `minecraft.PROTOCOL_VERSION_INDICES', which
maps each known protocol version to its index in the protocol chronology. As
such, the bound method `minecraft.PROTOCOL_VERSION_INDICES.get` can be used as
a key function for the built-in `sorted`, `min` and `max` functions to collate
protocol versions chronologically.

Two utility functions are provided for direct comparison of protocol versions:
    `minecraft.utility.protocol_earlier` and
    `minecraft.utility.protocol_earlier_eq`.

Additionally, four methods are added to the `ConnectionContext` type to ease
the most common cases where the protocol of a given context must be compared to
a given version number:
    `minecraft.connection.ConnectionContext.protocol_earlier`,
    `minecraft.connection.ConnectionContext.protocol_earlier_eq`,
    `minecraft.connection.ConnectionContext.protocol_later` and
    `minecraft.connection.ConnectionContext.protocol_later_eq`.
2020-12-02 15:11:39 +01:00
bin Update testing configuration: 2017-05-19 11:58:14 +01:00
docs Added listener decorator documentation (#161) 2020-08-17 17:49:25 +02:00
minecraft Fix: non-monotonic protocol versions are not correctly handled 2020-12-02 15:11:39 +01:00
tests Fix: non-monotonic protocol versions are not correctly handled 2020-12-02 15:11:39 +01:00
.gitignore Add .vscode to gitignore 2020-08-17 05:40:40 +02:00
.travis.yml Update travis distro to focal (#203) 2020-11-11 20:59:28 -05:00
LICENSE Licensed under Apache License, Version 2.0 2012-10-10 14:29:32 +05:00
MANIFEST.in Switched to using pylintrc file instead of command line options. 2015-04-06 15:47:22 +02:00
pylintrc Switched to using pylintrc file instead of command line options. 2015-04-06 15:47:22 +02:00
README.rst List support for Minecraft 1.16.4 in README.rst 2020-12-02 14:28:59 +01:00
requirements.txt Merge branch 'v1.16' into master 2020-08-19 20:27:11 +02:00
setup.py Merge branch 'v1.16' into master 2020-08-19 20:27:11 +02:00
start.py Remove support for Python 2.7 2020-08-17 07:10:10 +02:00
tox.ini Fix: non-monotonic protocol versions are not correctly handled 2020-12-02 15:11:39 +01:00

pyCraft
=======
.. image:: https://travis-ci.org/ammaraskar/pyCraft.svg?branch=master
    :target: https://travis-ci.org/ammaraskar/pyCraft
.. image:: https://readthedocs.org/projects/pycraft/badge/?version=latest
    :target: https://pycraft.readthedocs.org/en/latest
.. image:: https://coveralls.io/repos/ammaraskar/pyCraft/badge.svg?branch=master 
    :target: https://coveralls.io/r/ammaraskar/pyCraft?branch=master


Minecraft Python Client Library!

This projects aims to be a modern, Python3-compatible, well-documented library for
communication with a MineCraft server.

Detailed information for developers can be found here:
`<http://pycraft.readthedocs.org/en/latest/>`_.

``start.py`` is a basic example of a headless client using the library
Use ``start.py --help`` for the options.

Supported Minecraft versions
----------------------------
pyCraft is compatible with the following Minecraft releases:

* 1.8, 1.8.1, 1.8.2, 1.8.3, 1.8.4, 1.8.5, 1.8.6, 1.8.7, 1.8.8, 1.8.9
* 1.9, 1.9.1, 1.9.2, 1.9.3, 1.9.4
* 1.10, 1.10.1, 1.10.2
* 1.11, 1.11.1, 1.11.2
* 1.12, 1.12.1, 1.12.2
* 1.13, 1.13.1, 1.13.2
* 1.14, 1.14.1, 1.14.2, 1.14.3, 1.14.4
* 1.15, 1.15.1, 1.15.2
* 1.16, 1.16.1, 1.16.2, 1.16.3, 1.16.4

In addition, some development snapshots and pre-release versions are supported:
`<minecraft/__init__.py>`_ contains a full list of supported Minecraft versions
and corresponding protocol version numbers.

Supported functionality
-----------------------
Although pyCraft is compatible any supported server, only a subset of all
packets are currently decoded or encoded by the library: those necessary
to remain connected to the server, those used for chat, and some others.

Developers wishing to use other functionality with pyCraft can contribute by
implementing packet classes for the desired packets, adding them under
`<minecraft/networking/packets>`_, and sending a pull request.

Supported Python versions
-------------------------
pyCraft is compatible with (at least) the following Python implementations:

* Python 3.5
* Python 3.6
* Python 3.7
* Python 3.8
* PyPy

Requirements
------------
- `cryptography <https://github.com/pyca/cryptography#cryptography>`_
- `requests <http://docs.python-requests.org/en/latest/>`_
- `PyNBT <https://github.com/TkTech/PyNBT>`_

The requirements are also stored in ``setup.py``

See the installation instructions for the cryptography library here: `<https://cryptography.io/en/latest/installation/>`_
but essentially ``pip install -r requirements.txt`` should cover everything.

Contact
-------
This project currently has 2 main developers, *Ammar Askar* and *Jeppe Klitgaard*.

GitHub
^^^^^^
The preferred method of communication is via this GitHub page.

Mail
^^^^
We can be contacted by mail:

* Ammar Askar `ammar@ammaraskar.com <mailto:ammar@ammaraskar.com>`_
* Jeppe Klitgaard `jeppe@dapj.dk <mailto:jeppe@dapj.dk>`_

IRC
^^^
We can often be found on the ``minecraftdev`` IRC on
`irc.esper.net <https://www.esper.net/>`_

We go by the names of ``ammar2`` and ``dkkline``.