Snippets

Víctor Goñi Sanz basicAPI Minecraft python

Created by Víctor Goñi Sanz
###############################################
# API MCPI Minecraft using Python
# Name: basicAPI.py
# Author: vgoni
# License: LGPL
###############################################
# Import python modules
import mcpi.minecraft as minecraft
import mcpi.block as block
import server
import sys
import time

# Prepare API
mc = minecraft.Minecraft.create(server.address)

# Echo a message
mc.postToChat("This is the basic API")
mc.postToChat("")

# Part I, player data
###############################################
mc.postToChat("Part I: ")
mc.postToChat("---------------------")
playerDirection = mc.player.getDirection()
playerPos = mc.player.getPos()
playerFront = mc.player.getDirection() + mc.player.getPos()
playerRotation = mc.player.getRotation()

# Get the ID of next block in floor, "The id (or type) of block" 1 = Stone, 3 = Dirt... check API
blockType = mc.getBlock(playerFront.x, playerFront.y, playerFront.z)

mc.postToChat("Player direction: %f, %f, %f" % (playerDirection.x, playerDirection.y, playerDirection.z))
mc.postToChat("Player position: %f, %f, %f" % (playerPos.x, playerPos.y, playerPos.z))
mc.postToChat("In front of the player at: %f, %f, %f we have a block with: %d type" % (playerFront.x, playerFront.y, playerFront.z, blockType))
mc.postToChat("Player rotation: %f" % playerRotation)

# Change direction, is not possible right now
#playerRotation += 90
#mc.postToChat("Rotate 90, now will be: %f" % playerRotation)
#time.sleep(0.1)

#mc.player.setPos(0,0,0)            # Work
#mc.player.setDirection(1,0,0)      # No work, is not in the API
#mc.player.setRotation(0)           # No work, is not in the API
#mc.postToChat("Rotate 90")

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.