Hardware Reference
In-Depth Information
Start by creating a new program for the block friend:
1. Open IDLE, create click File New File to create a new program and save the file
as BlockFriend.py in the MyAdventures folder.
2. Import the minecraft , block , minecraftstuff , math and time modules:
import mcpi.minecraft as minecraft
import mcpi.block as block
import mcpi.minecraftstuff as minecraftstuff
import math
import time
3. The first thing you need to do is create a function to calculate the distance
between two points. This will be used to work out how far the block friend is
from your player:
def distanceBetweenPoints(point1, point2):
xd = point2.x - point1.x
yd = point2.y - point1.y
zd = point2.z - point1.z
return math.sqrt((xd*xd) + (yd*yd) + (zd*zd))
4. Now you need to decide how far away your player needs to be for the block friend
to stop following him. Create a constant to store the distance that you consider
to be “too far away”. I have chosen 15, meaning that when the block friend and
the player are 15 blocks apart, the block friend will stop following the player:
TOO_FAR_AWAY = 15
5. Create the Minecraft and MinecraftDrawing objects:
mc = minecraft.Minecraft.create()
mcdrawing = minecraftstuff.MinecraftDrawing(mc)
6. Create a variable to store the block's mood. For this adventure, the block will
either be happy or sad. Set it to "happy" :
blockMood = "happy"
7. Create the block friend, a few blocks away from the player, by getting the player's
position, adding 5 to the x position and using the getHeight() function to
find out the y position, so the block is sitting on top of the land:
friend = mc.player.getTilePos()
friend.x = friend.x + 5
friend.y = mc.getHeight(friend.x, friend.z)
mc.setBlock(friend.x, friend.y, friend.z,
block.DIAMOND_BLOCK.id)
mc.postToChat("<block> Hello friend")
 
Search WWH ::




Custom Search