Advertisement
Guest User

MinecraftCastleBuilder

a guest
Jul 29th, 2015
529
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.03 KB | None | 0 0
  1. #!/usr/bin/python
  2. #--------------------------------------
  3. #
  4. #     Minecraft Python API
  5. #        Castle Builder
  6. #
  7. # This script creates a castle complete
  8. # with moat and perimeter walls.
  9. #
  10. # Author : Matt Hawkins
  11. # Date   : 07/06/2014
  12. #
  13. # http://www.raspberrypi-spy.co.uk/
  14. #
  15. #--------------------------------------
  16.  
  17. # Import Minecraft libraries
  18. import mcpi.minecraft as minecraft
  19. import mcpi.block as block
  20.  
  21. mc = minecraft.Minecraft.create()
  22.  
  23. mc.postToChat("Let's build a castle!")
  24.  
  25. #--------------------------------------
  26. # Define Functions
  27. #--------------------------------------
  28.  
  29. def CreateWalls(size,baseheight,height,material,battlements,walkway):
  30.   # Create 4 walls with a specified width, height and material.
  31.   # Battlements and walkways can also be added to the top edges.
  32.  
  33.   mc.setBlocks(-size,baseheight+1,-size,size,baseheight+height,-size,material)
  34.   mc.setBlocks(-size,baseheight+1,-size,-size,baseheight+height,size,material)
  35.   mc.setBlocks(size,baseheight+1,size,-size,baseheight+height,size,material)
  36.   mc.setBlocks(size,baseheight+1,size,size,baseheight+height,-size,material)
  37.  
  38.   # Add battlements to top edge
  39.   if battlements==True:
  40.     for x in range(0,(2*size)+1,2):
  41.       mc.setBlock(size,baseheight+height+1,(x-size),material)
  42.       mc.setBlock(-size,baseheight+height+1,(x-size),material)
  43.       mc.setBlock((x-size),baseheight+height+1,size,material)
  44.       mc.setBlock((x-size),baseheight+height+1,-size,material)
  45.  
  46.   # Add wooden walkways
  47.   if walkway==True:
  48.     mc.setBlocks(-size+1,baseheight+height-1,size-1,size-1,baseheight+height-1,size-1,block.WOOD_PLANKS)
  49.     mc.setBlocks(-size+1,baseheight+height-1,-size+1,size-1,baseheight+height-1,-size+1,block.WOOD_PLANKS)
  50.     mc.setBlocks(-size+1,baseheight+height-1,-size+1,-size+1,baseheight+height-1,size-1,block.WOOD_PLANKS)
  51.     mc.setBlocks(size-1,baseheight+height-1,-size+1,size-1,baseheight+height-1,size-1,block.WOOD_PLANKS)  
  52.  
  53. def CreateLandscape(moatwidth,moatdepth,islandwidth):
  54.   # Set upper half to air
  55.   mc.setBlocks(-128,1,-128,128,128,128,block.AIR)
  56.   # Set lower half of world to dirt with a layer of grass
  57.   mc.setBlocks(-128,-1,-128,128,-128,128,block.DIRT)
  58.   mc.setBlocks(-128,0,-128,128,0,128,block.GRASS)
  59.   # Create water moat
  60.   mc.setBlocks(-moatwidth,0,-moatwidth,moatwidth,-moatdepth,moatwidth,block.WATER)
  61.   # Create island inside moat
  62.   mc.setBlocks(-islandwidth,0,-islandwidth,islandwidth,1,islandwidth,block.GRASS)  
  63.  
  64. def CreateKeep(size,baseheight,levels):
  65.   # Create a keep with a specified number
  66.   # of floors levels and a roof
  67.   height=(levels*5)+5
  68.  
  69.   CreateWalls(size,baseheight,height,block.STONE_BRICK,True,True)
  70.  
  71.   # Floors & Windows
  72.   for level in range(1,levels+1):
  73.     mc.setBlocks(-size+1,(level*5)+baseheight,-size+1,size-1,(level*5)+baseheight,size-1,block.WOOD_PLANKS)
  74.  
  75.   # Windows
  76.   for level in range(1,levels+1):
  77.     CreateWindows(0,(level*5)+baseheight+2,size,"N")
  78.     CreateWindows(0,(level*5)+baseheight+2,-size,"S")
  79.     CreateWindows(-size,(level*5)+baseheight+2,0,"W")
  80.     CreateWindows(size,(level*5)+baseheight+2,0,"E")
  81.  
  82.   # Door
  83.   mc.setBlocks(0,baseheight+1,size,0,baseheight+2,size,block.AIR)
  84.  
  85. def CreateWindows(x,y,z,dir):
  86.  
  87.   if dir=="N" or dir=="S":
  88.     z1=z
  89.     z2=z
  90.     x1=x-2
  91.     x2=x+2
  92.  
  93.   if dir=="E" or dir=="W":
  94.     z1=z-2
  95.     z2=z+2
  96.     x1=x
  97.     x2=x
  98.  
  99.   mc.setBlocks(x1,y,z1,x1,y+1,z1,block.AIR)
  100.   mc.setBlocks(x2,y,z2,x2,y+1,z2,block.AIR)
  101.  
  102.   if dir=="N":
  103.     a=3
  104.   if dir=="S":
  105.     a=2
  106.   if dir=="W":
  107.     a=0
  108.   if dir=="E":
  109.     a=1
  110.  
  111.   mc.setBlock(x1,y-1,z1,109,a)
  112.   mc.setBlock(x2,y-1,z2,109,a)
  113.  
  114. #--------------------------------------
  115. #
  116. # Main Script
  117. #
  118. #--------------------------------------
  119.  
  120. print "Create ground and moat"
  121. CreateLandscape(33,10,23)  
  122.  
  123. print "Create outer walls"
  124. CreateWalls(21,1,5,block.STONE_BRICK,True,True)
  125.  
  126. print "Create inner walls"
  127. CreateWalls(13,1,6,block.STONE_BRICK,True,True)
  128.  
  129. print "Create Keep with 4 levels"
  130. CreateKeep(5,1,4)
  131.  
  132. print "Position player on Keep's walkway"
  133. mc.player.setPos(0,30,4)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement