Exercise 7

Modular Castle

A generated castle

So here is some code we build to generate a castle. We will adapt soon for it to ask size , height etc… We’ll also add more details to it.

import mcpi.minecraft as minecraft
import mcpi.block as block
import server
import sys
import time
mc = minecraft.Minecraft.create(server.address)
mc.postToChat("Kimi")
x,y,z = mc.player.getPos()
x = x+2
z = z+2
y=y-1
#Our tower targeted dimensions

ytower=16
xtower=20
ztower=15
#Ceiling heigh

yceiling=5
#Windows schee

Lwindows=3
lwindows=2
ywindows=2
#Tower Materials

m_wall=98
m_corner=49
m_windows=102
#Douves size

LDouves=1
#Douves offset

ODouves=3
#Profondeur douves

yDouves=10
#Fixing Size

LDouves=LDouves-1
ODouves=ODouves+1
yDouves=yDouves-1
#Calculating the real tower size

while xtower%Lwindows != 2:
    xtower = xtower+1
while ztower%Lwindows != 2:
    ztower = ztower+1
while ytower%yceiling != 0: 
    ytower = ytower+1
#adapting larger

xtower=xtower-1
ztower=ztower-1
ytower=ytower


#We build main volume

mc.setBlocks(x,y,z,x+xtower,y+ytower,z+ztower,m_wall)
#We draw the 4 borders

mc.setBlocks(x-ODouves-LDouves,y-yDouves,z-ODouves-LDouves,x-ODouves,y,z+ztower+ODouves+LDouves,326)
mc.setBlocks(x-ODouves-LDouves,y-yDouves,z-ODouves-LDouves,x++xtower+ODouves+LDouves,y,z-ODouves,326)
mc.setBlocks(x+xtower+ODouves,y-yDouves,z-ODouves-LDouves,x+xtower+ODouves+LDouves,y,z+ztower+ODouves+LDouves,326)
mc.setBlocks(x-ODouves-LDouves,y-yDouves,z+ztower+ODouves,x+xtower+ODouves+LDouves,y,z+ztower+ODouves+LDouves,326)
#We draw the 4 douves

mc.setBlocks(x,y,z,x,y+ytower,z,m_corner)
mc.setBlocks(x+xtower,y,z,x+xtower,y+ytower,z,m_corner)
mc.setBlocks(x,y,z+ztower,x,y+ytower,z+ztower,m_corner)
mc.setBlocks(x+xtower,y,z+ztower,x+xtower,y+ytower,z+ztower,m_corner)
#We fill with air

mc.setBlocks(x+1,y,z+1,x+xtower-1,y+ytower,z+ztower-1,0)
#We create a floor at level 5

for i in range(0, ytower+1):
    if i%yceiling == 0:
        mc.setBlocks(x+1,y+i,z+1,x+xtower-1,y+i,z+ztower-1,5,2)
#We place the windows

for i in range (0,xtower+1):
    for j in range (0,ztower+1):
        if ((i == 0 or i == xtower) and j%Lwindows == 2) or ((j == 0 or j == ztower) and i%Lwindows == 2):
            for k in range (0,ytower):
                if k %yceiling == 2:
                    mc.setBlocks(x+i,y+k,z+j,x+i,y+k+ywindows-1,z+j,m_windows)
                k=k+1
        j=j+1
    i = i+1

Castle Example 1 *Castle 1 - *

Castle Example 2 *Castle 2 - *