Skip to main content

An extension of the Minecraft Pi API.

Project description

MCPI Addons

A Minecraft Pi Edition: Reborn mod to add more features to the API.

Note: requires Reborn v2.4.8 or later.

Installing

First you will need to install the frontend from pip, to do that you can use pip3 install mcpi-addons. If you don't want to (or can't) compile the backend then you can grab the newest version from the releases page.

Compiling

Just run ./build.sh to create the binary and run mv libextrapi.so ~/.minecraft-pi/mods to install the mod, this is needed because MCPI doesn't support any of these extensions that this api adds, so a C++ mod is loaded to intercept CommandServer::parse.

How to use

Here is a simple "Hello World" example:

# Import the api
from mcpi_addons.minecraft import Minecraft
# Initialize the api (MCPI must be open and in a world at this time)
mc = Minecraft.create()

# Post to chat
mc.postToChat("Hello world!")

For a tutorial see the 'Using the API' section of stuffaboutcode.com.

What does it do?

It adds these:

  • custom.log
    • custom.log.debug (mc.logging.debug(msg)) Logs a message in debug mode.
    • custom.log.info (mc.logging.info(msg)) Logs a message.
    • custom.warn (mc.logging.warn(msg)) Logs a warning.
    • custom.log.error (mc.logging.error(msg)) Logs an error.
  • custom.inventory
    • custom.inventory.getSlot (mc.inventory.getHeldItem()) Gets the id, auxiliary, and count of the current slot.
    • custom.inventory.unsafeGive (mc.inventory.unsafeGive(id=-2, auxiliary=-2, count=-2)) give the player the item without safety checking (-2 means don't change)
    • custom.inventory.give (mc.inventory.give(id=-2, auxiliary=-2, count=-2)) give the player the item without safety checking (-2 means don't change)
  • custom.override
    • custom.override.reset (mc.resetOverrides()) resets all tile and item overrides.
    • custom.override (mc.override(before, after)) overrides the id before with the id of after.
  • world.getBlocks
    • world.getBlocks (mc.getBlocks(x, y, z, x2, y2, z2)) Gets a flat list of the blocks between (x, y, z) and (x2, y2, z2).
    • world.getBlocks.3D (mc.getBlocks3D(x, y, z, x2, y2, z2)) Gets a 3D list of the blocks between (x, y, z) and (x2, y2, z2).
  • custom.post
    • custom.post.client (mc.postToClient(msg)) Posts the message to the chat client side.
    • custom.post.noPrefix (mc.postWithoutPrefix(msg)) Posts the message without the username prefix.
  • custom.key
    • custom.key.press (mc.player.press(key)) Presses a key.
    • custom.key.release (mc.player.release(key)) Releases a key.
  • world.getPlayerId (mc.getPlayerEntityId(name)) Gets the id of a player from the name.
  • custom.username
    • custom.username (mc.player.getUsername()) Gets the local players username.
    • custom.username.all (mc.getUsernames()) Gets a list of player usernames.
  • custom.world
    • custom.world.particle (mc.particle(x, y, z, particle)) Spawns the particle at (x,y,z).
    • custom.world.dir (mc.world.dir()) Get the world folder.
    • custom.world.name (mc.world.name()) Get the world name.
  • custom.player
    • custom.player.getHealth (mc.player.getHealth()) Returns the players health.
    • custom.player.setHealth (mc.player.setHealth(health)) Sets the players health.
    • custom.player.closeGUI (mc.player.closeGUI()) Closes the current screen.
    • custom.player.getGamemode (mc.player.getGamemode()) Returns the players gamemode.
  • custom.entity
    • custom.entity.spawn (mc.entity.spawn(id, x, y, z, health = -1, dir = (0, 0), data = 0)) spawns an entity of type id at x, y, z, with health health (or fuse/lifetime) pointing in dir direction with data data.
  • custom.reborn
    • custom.reborn.getFeature (mc.reborn.getFeature(feature: string) -> bool) Gets the status of a reborn feature
    • custom.reborn.getVersion (mc.reborn.getVersion() -> string) Gets the reborn version
  • events.chat
    • events.chat.post (mc.events.pollChatPosts() -> [string]) return a list of messages shown in client side chat
    • events.chat.size (mc.events.setChatSize(size = 64)) clears the chat list and resets the size

I want to add more so please give me suggestions.

Todo list

I am going to add theses features someday, but they aren't here now. Feel free to create a PR that adds them or other features!

  • player.setGamemode(gamemode: int) Sets the players gamemode.
  • player.getOxygen() -> int Gets the player oxygen.
  • player.setOxygen(oxygen: int) Sets the players oxygen.
  • player.getInventory() -> int[] Gets the player inventory.
  • player.setInventory(inventory: int[]) Sets the player inventory.
  • entity.getArmor(id: int) -> int[4] Gets the players armor.
  • entity.setArmor(helmet: int, chestplate: int, leggings: int, boots: int) Sets the players armor.
  • camera.getCameraState() -> int Gets the camera state.
  • camera.setCameraState(state: int) Sets the camera state.
  • minecraft.getVersion() -> str 0.1.0 or 0.1.1, will be determined at compile time and will require Legacy support.
  • world.seed() -> string Gets the worlds seed.

Known bugs

  • Using the particle iconcrack with mc.particle crashes the game, but using an invalid particle name is fine.
  • postToClient really doesn't like it when you use \n. When posted they might also post a lot of garbage to server side chat.

Extras

Raspberry Juice compatibility

One day all of these will be supported.

  • getBlocks
  • getPlayerEntityId
  • events.pollChatPosts
  • player/entity.getRotation
  • player/entity.getPitch
  • player/entity.getDirection

Particles

Particles are client side and only shown if the player is within 16 blocks. Here is a particle list I found at 0x107511 in minecraft-pi

  • bubble (only works in water)
  • crit
  • flame
  • lava
  • smoke
  • largesmoke
  • reddust
  • ironcrack (crashes the game)
  • snowballpoof
  • explode

Tiles/Items

A list of tiles can be found here and a list of items here.

Entities

A list of entities can be found here.

Changelog

  • 1.2.0

    • Add reborn.getVersion, reborn.getFeature, events.chat.posts, and events.chat.size, by Red-exe-Engineer
  • 1.1.1

    • Add basic entity spawning.
  • 1.1.0

    • Fixed bug with causing args to be cut off at the first left parenthesis.
    • Fixed bug in world.getBlocks and custom.getBlocks3D causing them to target the wrong position.
    • Added tests.
    • Improved docs.
    • Many breaking API changes.
    • Many internal changes.
    • Added custom.player.getHealth, custom.player.setHealth, custom.player.closeGUI, and custom.player.getGamemode.
  • 1.0.3

    • Added world.getBlocks, custom.getBlocks3D.
    • Improved custom.particle.
    • Removed getOffset from minecraft.py.
  • 1.0.2

    • Added custom.overrideTile, custom.overrideItem, and custom.resetOverrides.
  • 1.0.1

    • Added functionality to world.getPlayerId.
    • Added custom.getUsernames.
  • 1.0.0

    • Stopped getSlot from crashing the game with invalid ids.
    • Added press, unpress, worldName, worldDir, particle, getOffset, and logging (debug, info, warn, err).
    • Uploaded to pypi and github.
  • Beta

    • Added getSlot and give.
  • Alpha

    • Had getUsername, postWithoutPrefix, and postClient.

Screenshots

Here is a screenshot of using overrides and particles:

Here is a screenshot of using entity spawning with arrows and direction:

Here is a screenshot of using TNT entities and falling bedrock entities to make a cannon:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MCPI-Addons-1.2.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

MCPI_Addons-1.2.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file MCPI-Addons-1.2.0.tar.gz.

File metadata

  • Download URL: MCPI-Addons-1.2.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.31.1 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for MCPI-Addons-1.2.0.tar.gz
Algorithm Hash digest
SHA256 f84e06e14df89f4ef3a423025b0eb255a2a090209c8c7812774204fa4459418b
MD5 db7e0d1111b083bce8ae60d29b2e90b2
BLAKE2b-256 d369acf58e780c8df98dce6686a2023c72bf7d4fe974256cb56450bd84cfccc4

See more details on using hashes here.

File details

Details for the file MCPI_Addons-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: MCPI_Addons-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.31.1 importlib-metadata/4.11.0 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.2

File hashes

Hashes for MCPI_Addons-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1176e94c9a6e0a7ec5c8b85b84a1e7c0289ea1b834beba8b23918a8f2311df56
MD5 97680f98a1a07fb7f3ba39788466c0b8
BLAKE2b-256 5dce79f36494143257022edd4c062b574d2cdf5d1d0c5ee59afafde8a7ede88d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page