Minecraft Python PDF
Minecraft Python PDF
Quick Reference
BC1
print(d)
else:
print("wrong")
Using elif/else for multiple choices Checking multiple conditions
with and, or
if a==1: if choice>0 and choice<=8:
else:
print("anything else")
Checking for different or same Checking for less with if
with if
if a!=1: if a<1:
if a==1: if a<=1:
print("finished") if a>=1:
myname() hello("Andrew")
myname() hello("Geraldine")
Returning values from functions Writing to global variables inside
functions
def smallest(a, b): treasure_x = 0
if a<b:
squareRoot = math.sqrt(number)
f.close() f.write("Amanda:10000\n")
print(t) f.close()
Getting a list of matching Stripping unwanted white space
filenames from strings
import glob a = "\n\n hello \n\n"
print(n)
display.write("up") display.clear()
display.pattern([1,1,0,1,1,0,1,0])
b = block.DIRT.id
Creating a connection to Minecraft Posting a message to the Minecraft
chat
mc = minecraft.Minecraft.create() mc.postToChat("Hello Minecraft")
Getting the player’s tile position Setting the player’s tile position
# what are the coordinates of tile x = 5
pos = mc.player.getTilePos() z = 7
x = pos.x mc.player.setTilePos(x, y, z)
y = pos.y
z = pos.z
Getting the player’s position Setting the player’s position
# get precise position of player # set precise position of player
x = pos.x z = 1.23
y = pos.y mc.setPos(x, y, z)
z = pos.z
Getting the height of the world Getting the block type at a position
# y position of first non-AIR block # id of block (e.g. block.DIRT.id)
for e in events:
pos = e.pos
print(pos.x)
minecraftstuff mcdrawing =
minecraftstuff.MinecraftDrawing(mc)
Drawing a line between two points Getting all the block positions of a
line, as a list
mcdrawing.drawLine(0, 0, 0, line = mcdrawing.getLine(
0,0,0,10,10,10)
10, 10, 10, block.DIRT.id)
pos1 = line[0]
print(pos1.x)
Drawing a sphere Drawing a circle
mcdrawing.drawSphere(0, 0, 0, mcdrawing.drawCircle(0, 0, 0,
filled = True
tri.append(minecraft.Vec3(0,0,0))
tri.append(minecraft.Vec3(10,0,0))
tri.append(minecraft.Vec3(5,10,0))
mcdrawing.drawFace(tri, filled,
block.DIRT.id)
blocks =
[minecraftstuff.ShapeBlock(0,0,0, shape.clear()
block.DIRT.id),
minecraftstuff.ShapeBlock(1,0,0,
block.DIRT.id)]
pos = Vec3(0,0,0)
shape =
minecraftstuff.MinecraftShape(mc,
pos, blocks)
Moving a shape to a position Moving a shape by a number of blocks
shape.move(10, 10, 10) ymove = 1
shape.moveBy(0, ymove, 0)