Playing around with minecraft doing some python coding

We look at the posibility of coding python in order to change your minecraft world. Adding blocks with python and creating buildings and games in Minecraft.

Adventure in Minecraft:
https://ift.tt/2UpJuvQ

Castle code:

# Import necessary modules
import mcpi.minecraft as minecraft
import mcpi.block as block

# Connect to Minecraft
mc = minecraft.Minecraft.create()

# Get the players position
pos = mc.player.getTilePos()

# Decide where to start building the house, slightly away from player
x = pos.x
y = pos.y
z = pos.z

HEIGHT = 10
SIZE = 20

def tower(x, z):
    mc.setBlocks(x-5, y, z-5, x+5, y+HEIGHT+2, z+5, block.AIR.id)

    # Sides    
    mc.setBlocks(x-5, y, z-2, x-5, y+HEIGHT+1, z+2, block.COBBLESTONE.id)
    mc.setBlocks(x+5, y, z-2, x+5, y+HEIGHT+1, z+2, block.COBBLESTONE.id)
    mc.setBlocks(x-2, y, z-5, x+2, y+HEIGHT+1, z-5, block.COBBLESTONE.id)
    mc.setBlocks(x-2, y, z+5, x+2, y+HEIGHT+1, z+5, block.COBBLESTONE.id)
    mc.setBlocks(x-3, y, z-4, x-3, y+HEIGHT+1, z-4, block.COBBLESTONE.id)
    mc.setBlocks(x-4, y, z-3, x-4, y+HEIGHT+1, z-3, block.COBBLESTONE.id)
    mc.setBlocks(x+3, y, z-4, x+3, y+HEIGHT+1, z-4, block.COBBLESTONE.id)
    mc.setBlocks(x+4, y, z-3, x+4, y+HEIGHT+1, z-3, block.COBBLESTONE.id)
    mc.setBlocks(x-3, y, z+4, x-3, y+HEIGHT+1, z+4, block.COBBLESTONE.id)
    mc.setBlocks(x-4, y, z+3, x-4, y+HEIGHT+1, z+3, block.COBBLESTONE.id)
    mc.setBlocks(x+3, y, z+4, x+3, y+HEIGHT+1, z+4, block.COBBLESTONE.id)
    mc.setBlocks(x+4, y, z+3, x+4, y+HEIGHT+1, z+3, block.COBBLESTONE.id)

    for i in range(-2, 3):
        if i % 2 == 0:
            mc.setBlocks(x+i, y+HEIGHT+2, z+5, x+i, y+HEIGHT+2, z+5, block.COBBLESTONE.id)
            mc.setBlocks(x+i, y+HEIGHT+2, z-5, x+i, y+HEIGHT+2, z-5, block.COBBLESTONE.id)
            mc.setBlocks(x+5, y+HEIGHT+2, z+i, x+5, y+HEIGHT+2, z+i, block.COBBLESTONE.id)
            mc.setBlocks(x-5, y+HEIGHT+2, z+i, x-5, y+HEIGHT+2, z+i, block.COBBLESTONE.id)

    # Floor
    mc.setBlocks(x-3, y+HEIGHT, z-3, x+3, y+HEIGHT, z+3, block.COBBLESTONE.id)
    mc.setBlocks(x-4, y+HEIGHT, z-3, x+4, y+HEIGHT, z+3, block.COBBLESTONE.id)
    mc.setBlocks(x-3, y+HEIGHT, z-4, x+3, y+HEIGHT, z+4, block.COBBLESTONE.id)

def tower_stair(x, z, count, dir, side_count):
    if count > HEIGHT:
        return

    if side_count > 6:
        dir += 1
        side_count = 1
    if dir > 3:
        dir = 0

    if dir == 0:
        display_dir = 0
        x += 1
    if dir == 1:
        display_dir = 2
        z += 1
    if dir == 2:
        display_dir = 1
        x -= 1
    if dir == 3:
        display_dir = 3
        z -= 1

    mc.setBlocks(x, y+count-1, z, x, y+count-1, z, block.COBBLESTONE.id, display_dir)
    mc.setBlocks(x, y+count, z, x, y+count, z, block.STAIRS_COBBLESTONE.id, display_dir)
    mc.setBlocks(x, y+count+1, z, x, y+count+4, z, block.AIR.id, display_dir)

    tower_stair(x, z, count+1, dir, side_count+1)

#mc.setBlocks(x-100, y-1, z-100, x+100, y-1, z+100, block.COBBLESTONE.id)
#mc.setBlocks(x-100, y, z-100, x+100, y+HEIGHT+5 , z+100, block.AIR.id)

mc.setBlocks(x-SIZE, y-1, z-SIZE, x+SIZE, y-1, z+SIZE, block.COBBLESTONE.id)

mc.setBlocks(x-SIZE, y, z-SIZE, x-SIZE+4, y+HEIGHT, z+SIZE, block.COBBLESTONE.id)
mc.setBlocks(x+SIZE, y, z-SIZE, x+SIZE-4, y+HEIGHT, z+SIZE, block.COBBLESTONE.id)
mc.setBlocks(x-SIZE, y, z-SIZE, x+SIZE, y+HEIGHT, z-SIZE+4, block.COBBLESTONE.id)
mc.setBlocks(x-SIZE, y, z+SIZE, x+SIZE, y+HEIGHT, z+SIZE-4, block.COBBLESTONE.id)

mc.setBlocks(x-SIZE, y, z-SIZE, x-SIZE, y+HEIGHT+1, z+SIZE, block.COBBLESTONE.id)
mc.setBlocks(x-SIZE+4, y, z-SIZE, x-SIZE+4, y+HEIGHT+1, z+SIZE, block.COBBLESTONE.id)

mc.setBlocks(x+SIZE, y, z-SIZE, x+SIZE, y+HEIGHT+1, z+SIZE, block.COBBLESTONE.id)
mc.setBlocks(x+SIZE-4, y, z-SIZE, x+SIZE-4, y+HEIGHT+1, z+SIZE, block.COBBLESTONE.id)

mc.setBlocks(x-SIZE, y, z-SIZE, x+SIZE, y+HEIGHT+1, z-SIZE, block.COBBLESTONE.id)
mc.setBlocks(x-SIZE, y, z-SIZE+4, x+SIZE, y+HEIGHT+1, z-SIZE+4, block.COBBLESTONE.id)

mc.setBlocks(x-SIZE, y, z+SIZE-4, x+SIZE, y+HEIGHT+1, z+SIZE-4, block.COBBLESTONE.id)
mc.setBlocks(x-SIZE, y, z+SIZE, x+SIZE, y+HEIGHT+1, z+SIZE, block.COBBLESTONE.id)

for i in range(-SIZE, SIZE+1):
    if i % 2 == 0:
        mc.setBlocks(x+i, y+HEIGHT+2, z+SIZE, x+i, y+HEIGHT+2, z+SIZE, block.COBBLESTONE.id)
        mc.setBlocks(x+i, y+HEIGHT+2, z-SIZE, x+i, y+HEIGHT+2, z-SIZE, block.COBBLESTONE.id)
        mc.setBlocks(x+SIZE, y+HEIGHT+2, z+i, x+SIZE, y+HEIGHT+2, z+i, block.COBBLESTONE.id)
        mc.setBlocks(x-SIZE, y+HEIGHT+2, z+i, x-SIZE, y+HEIGHT+2, z+i, block.COBBLESTONE.id)

for i in range(-SIZE+4, SIZE-4):
    if i % 2 == 1:
        mc.setBlocks(x+i, y+HEIGHT+2, z+SIZE-4, x+i, y+HEIGHT+2, z+SIZE-4, block.COBBLESTONE.id)
        mc.setBlocks(x+i, y+HEIGHT+2, z-SIZE+4, x+i, y+HEIGHT+2, z-SIZE+4, block.COBBLESTONE.id)
        mc.setBlocks(x+SIZE-4, y+HEIGHT+2, z+i, x+SIZE-4, y+HEIGHT+2, z+i, block.COBBLESTONE.id)
        mc.setBlocks(x-SIZE+4, y+HEIGHT+2, z+i, x-SIZE+4, y+HEIGHT+2, z+i, block.COBBLESTONE.id)

tower(x-SIZE+2, z-SIZE+2)
tower(x+SIZE-2, z-SIZE+2)
tower(x-SIZE+2, z+SIZE-2)
tower(x+SIZE-2, z+SIZE-2)

tower_stair(x-SIZE+1, z-SIZE+5, 0, 2, 5)
tower_stair(x+SIZE-5, z-SIZE+1, 0, 3, 5)
tower_stair(x-SIZE+5, z+SIZE-1, 0, 1, 5)
tower_stair(x+SIZE-1, z+SIZE-5, 0, 0, 5)

# Doors
mc.setBlocks(x-SIZE+5, y, z-SIZE+5, x+SIZE-5, y+3, z+SIZE-5, block.AIR.id)

mc.setBlocks(x-SIZE+3, y+HEIGHT+1, z-SIZE+1, x-SIZE+1, y+HEIGHT+2, z-SIZE+8, block.AIR.id)
mc.setBlocks(x-SIZE+3, y+HEIGHT+1, z+SIZE-1, x-SIZE+1, y+HEIGHT+2, z+SIZE-8, block.AIR.id)
mc.setBlocks(x+SIZE-3, y+HEIGHT+1, z-SIZE+1, x+SIZE-1, y+HEIGHT+2, z-SIZE+8, block.AIR.id)
mc.setBlocks(x+SIZE-3, y+HEIGHT+1, z+SIZE-1, x+SIZE-1, y+HEIGHT+2, z+SIZE-8, block.AIR.id)

mc.setBlocks(x-SIZE+1, y+HEIGHT+1, z-SIZE+3, x-SIZE+8, y+HEIGHT+2, z-SIZE+1, block.AIR.id)
mc.setBlocks(x+SIZE-1, y+HEIGHT+1, z-SIZE+3, x+SIZE-8, y+HEIGHT+2, z-SIZE+1, block.AIR.id)
mc.setBlocks(x-SIZE+1, y+HEIGHT+1, z+SIZE-3, x-SIZE+8, y+HEIGHT+2, z+SIZE-1, block.AIR.id)
mc.setBlocks(x+SIZE-1, y+HEIGHT+1, z+SIZE-3, x+SIZE-8, y+HEIGHT+2, z+SIZE-1, block.AIR.id)

mc.setBlocks(x-3, y+4, z-3, x+3, y+4, z+3, block.WOOD_PLANKS.id)

mc.setBlocks(x-3, y, z-3, x-3, y+4, z+3, block.WOOD_PLANKS.id)
mc.setBlocks(x-3, y, z-3, x+3, y+4, z-3, block.WOOD_PLANKS.id)
mc.setBlocks(x-3, y, z+3, x+3, y+4, z+3, block.WOOD_PLANKS.id)
mc.setBlocks(x+3, y, z+3, x+3, y+4, z-3, block.WOOD_PLANKS.id)

mc.setBlocks(x+3, y, z, x+3, y+1, z, block.AIR.id)

mc.player.setTilePos(x+10, y, z);
mc.setBlocks(x-3, y+4, z+4, x+3, y+4, z+4, block.STAIRS_WOOD.id, 3)
mc.setBlocks(x-3, y+5, z+3, x+3, y+5, z+3, block.STAIRS_WOOD.id, 3)
mc.setBlocks(x-3, y+6, z+2, x+3, y+6, z+2, block.STAIRS_WOOD.id, 3)
mc.setBlocks(x-3, y+7, z+1, x+3, y+7, z+1, block.STAIRS_WOOD.id, 3)

mc.setBlocks(x-3, y+7, z, x+3, y+7, z, block.WOOD_PLANKS.id)
mc.setBlocks(x-3, y+6, z-1, x+3, y+6, z+1, block.WOOD_PLANKS.id)
mc.setBlocks(x-3, y+5, z-2, x+3, y+5, z+2, block.WOOD_PLANKS.id)

mc.setBlocks(x-3, y+4, z-4, x+3, y+4, z-4, block.STAIRS_WOOD.id, 2)
mc.setBlocks(x-3, y+5, z-3, x+3, y+5, z-3, block.STAIRS_WOOD.id, 2)
mc.setBlocks(x-3, y+6, z-2, x+3, y+6, z-2, block.STAIRS_WOOD.id, 2)
mc.setBlocks(x-3, y+7, z-1, x+3, y+7, z-1, block.STAIRS_WOOD.id, 2)

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.