|
| 1 | +# Adventure 3: buildHouse2.py |
| 2 | + |
| 3 | +# From the book: "Adventures in Minecraft" |
| 4 | +# written by David Whale and Martin O'Hanlon, Wiley, 2014 |
| 5 | +# http://eu.wiley.com/WileyCDA/WileyTitle/productCd-111894691X.html |
| 6 | +# |
| 7 | +# This program builds a house with a doorway, windows, a roof |
| 8 | +# and a carpet. It defines a house() function that you can easily |
| 9 | +# reuse in other programs. |
| 10 | + |
| 11 | +# Import necessary modules |
| 12 | +import mcpi.minecraft as minecraft |
| 13 | +import mcpi.block as block |
| 14 | + |
| 15 | +# Connect to Minecraft |
| 16 | +mc = minecraft.Minecraft.create() |
| 17 | + |
| 18 | +# A constant, that sets the size of your house |
| 19 | +SIZE = 20 |
| 20 | + |
| 21 | +# define a new function, that builds a house |
| 22 | +def house(): |
| 23 | + # Calculate the midpoints of the front face of the house |
| 24 | + midx = x+SIZE/2 |
| 25 | + midy = y+SIZE/2 |
| 26 | + |
| 27 | + # Build the outer shell of the house |
| 28 | + mc.setBlocks(x, y, z, x+SIZE, y+SIZE, z+SIZE, block.COBBLESTONE.id) |
| 29 | + |
| 30 | + # Carve the insides out with AIR |
| 31 | + mc.setBlocks(x+1, y, z+1, x+SIZE-2, y+SIZE-1, z+SIZE-2, block.AIR.id) |
| 32 | + |
| 33 | + # Carve out a space for the doorway |
| 34 | + mc.setBlocks(midx-1, y, z, midx+1, y+3, z, block.AIR.id) |
| 35 | + |
| 36 | + # Carve out the left hand window |
| 37 | + mc.setBlocks(x+3, y+SIZE-3, z, midx-3, midy+3, z, block.GLASS.id) |
| 38 | + |
| 39 | + # Carve out the right hand window |
| 40 | + mc.setBlocks(midx+3, y+SIZE-3, z, x+SIZE-3, midy+3, z, block.GLASS.id) |
| 41 | + |
| 42 | + # Add a wooden roof |
| 43 | + mc.setBlocks(x, y+SIZE, z, x+SIZE, y+SIZE, z+SIZE, block.WOOD.id) |
| 44 | + |
| 45 | + # Add a woolen carpet, the colour is 14, which is red. |
| 46 | + mc.setBlocks(x+1, y-1, z+1, x+SIZE-2, y-1, z+SIZE-2, block.WOOL.id, 14) |
| 47 | + |
| 48 | +# Get the players position |
| 49 | +pos = mc.player.getPos() |
| 50 | + |
| 51 | +# Decide where to start building the house, slightly away from player |
| 52 | +x = pos.x + 2 |
| 53 | +y = pos.y |
| 54 | +z = pos.z |
| 55 | + |
| 56 | +# run the house() function that was defined by def house(): |
| 57 | +# this will build a house at x,y,z |
| 58 | +house() |
| 59 | + |
| 60 | +# END |
| 61 | + |
| 62 | + |
0 commit comments