MinecraftShape API

The MinecraftShape API allows you create and manipulate shapes (collections of blocks) in Minecraft.

The shapes can be small or big and the API helps by efficiently moving them and only changing the blocks which have actually changed.

the ISS in minecraft

Example:

from mcpi.minecraft import Minecraft
from mcpi import block
from minecraftstuff import MinecraftShape

mc = minecraft.Minecraft.create()

pos = mc.player.getTilePos()

myShape = MinecraftShape(mc, pos)

# create a big cube
myShape.setBlocks(-5, -5, -5, 5, 5, 5, block.WOOL.id, 5)

#move it 10 blocks up
myshape.moveBy(0, 10, 0)

#rotate it 45 degrees
myshape.rotate(45, 0, 0)

MinecraftShape

class minecraftstuff.MinecraftShape(mc, position, shapeBlocks=None, visible=True)

MinecraftShape - the implementation of a ‘shape’ in Minecraft.

Each shape consists of one or many blocks with a position relative to each other.

Shapes can be transformed by movement and rotation.

When a shape is changed and redrawn in Minecraft only the blocks which have changed are updated.

Parameters:
  • mc (mcpi.minecraft.Minecraft) – A Minecraft object which is connected to a world.
  • position (mcpi.minecraft.Vec3) – The position where the shape should be created
  • shapeBlocks (list) – A list of ShapeBlocks which make up the shape. This defaults to None.
  • visible (bool) – Where the shape should be visible. This defaults to True.
clear()

clears the shape in Minecraft

draw()

draws the shape in Minecraft, taking into account where it was last drawn, only updating the blocks which have changed

getShapeBlock(x, y, z)

returns the ShapeBlock for an ‘actual position’

Parameters:
  • x (int) – The x position.
  • y (int) – The y position.
  • z (int) – The z position.
move(x, y, z)

moves the position of the shape to x,y,z

Parameters:
  • x (int) – The x position.
  • y (int) – The y position.
  • z (int) – The z position.
moveBy(x, y, z)

moves the position of the shape by x,y,z

Parameters:
  • x (int) – The number of blocks to move in x.
  • y (int) – The number of blocks to move in y.
  • z (int) – The number of blocks to move in z.
redraw()

redraws the shape in Minecraft, by clearing all the blocks and redrawing them

reset()

resets the shape back to its original position

rotate(yaw, pitch, roll)

sets the rotation of a shape by yaw, pitch and roll

Parameters:
  • yaw (float) – The yaw rotation in degrees.
  • pitch (float) – The pitch rotation in degrees.
  • roll (float) – The roll rotation in degrees.
rotateBy(yaw, pitch, roll)

increments the rotation of a shape by yaw, pitch and roll

Parameters:
  • yaw (float) – The yaw rotation in degrees.
  • pitch (float) – The pitch rotation in degrees.
  • roll (float) – The roll rotation in degrees.
setBlock(x, y, z, blockType, blockData=0, tag='')

sets one block in the shape and redraws it

draws a single point in Minecraft, i.e. 1 block

Parameters:
  • x (int) – The x position.
  • y (int) – The y position.
  • z (int) – The z position.
  • blockType (int) – The block id.
  • blockData (int) – The block data value, defaults to 0.
  • tag (string) – A tag for the block, this is useful for grouping blocks together and keeping track of them as the position of blocks can change, defaults to "".
setBlocks(x1, y1, z1, x2, y2, z2, blockType, blockData=0, tag='')

creates a cuboid of blocks in the shape and redraws it

Parameters:
  • x1 (int) – The x position of the first point.
  • y1 (int) – The y position of the first point.
  • z1 (int) – The z position of the first point.
  • x2 (int) – The x position of the second point.
  • y2 (int) – The y position of the second point.
  • z2 (int) – The z position of the second point.
  • blockType (int) – The block id.
  • blockData (int) – The block data value, defaults to 0.
  • tag (string) – A tag for the block, this is useful for grouping blocks together and keeping track of them as the position of blocks can change, defaults to "".

ShapeBlock

class minecraftstuff.ShapeBlock(x, y, z, blockType, blockData=0, tag='')

ShapeBlock - a class to hold one block within a shape

Parameters:
  • x (int) – The x position.
  • y (int) – The y position.
  • z (int) – The z position.
  • blockType (int) – The block id.
  • blockData (int) – The block data value, defaults to 0.
  • tag (string) – A tag for the block, this is useful for grouping blocks together and keeping track of them as the position of blocks can change, defaults to "".
resetRelativePos()

resets the relative position of the block back to its original position