- have fun with programming and game
Minecraft coordinates is different than what we learn from geometry. you need keep below picture in mind when you do the minecraft coding.
For basic python syntax, pleas check Python syntax for details.
Below mission will use print
and command from minecraft api mcpi
import mcpi_e.minecraft as minecraft
import mcpi_e.block as block
from math import *
address="127.0.0.1" # change to address of your minecraft server
name ="change to your user name"
mc = minecraft.Minecraft.create(address,4711,name)
pos=mc.player.getTilePos()
Use mcpi module to find the position (x,y,z) of the block your player stand on.
Use Python print
command to display your location:
pos= #get your position
print("pos: x:{},y:{},z:{}".format(pos.x,pos.y,pos.z))
hint:
#return position with intiger number like (0,1,-10)
pos=mc.player.getTilePos()
# return posoition with float number like (1.02,1.23,-10.1)
pos=mc.player.getPos()
Use this link to check the name of the block type id:
Use getBlock
command to find the block type:
x=100
y=10
z=-10
id=mc.getBlock(x,y,z)
print("blockId:",id)
Let me know how you die after teleport to a position :)
Code example:
#move you to a given location
x=100
y=100
z=-10
print("teleport me to: x:{},y:{},z:{}".format(x,y,z))
mc.player.setTilePos(x,y,z)
Find out how to move yourselfe to east 100, then north, then west, then top etc.
use key F3
to check your location after transport.
Try place a watermelon beside you.
# place a block
(x,y,z)=pos=mc.player.getTilePos()
mc.setBlock(x,y,z,103)
Use python code to place color block like below
mc=Minecraft.create(serverAddress,pythonApiPort,playerName)
pos=mc.player.getTilePos()
(x,y,z)=pos=mc.player.getPos()
mc.setBlock(x+1,y,z,block.WOOL_GREEN)
mc.setBlock(x+2,y,z,block.WOOL_RED)
mc.setBlock(x+3,y,z,block.WOOL_BLUE)