"""
Tutorial 1: a paved square with a small tower and a gateway.

Run it with::

    mciwb run first_build.py
"""

from mciwb.imports import (
    Direction,
    Item,
    Vec3,
    Volume,
    get_client,
    get_world,
    polygon,
)

# the north west corner of the build, one block above the ground
ORIGIN = Vec3(632, 73, -1658)

world = get_world()
client = get_client()

# -- clear --
# everything is placed relative to ORIGIN: the site is 11 blocks from west
# to east, 13 from north to south and 8 high
site = Volume.from_corners(ORIGIN, ORIGIN + Vec3(10, 7, 12))
site.fill(client, Item.AIR)

# -- floor --
# one fill command paves the whole site
paving = Volume.from_corners(ORIGIN, ORIGIN + Vec3(10, 0, 12))
paving.fill(client, Item.STONE_BRICKS)

# -- block --
# a single block, standing on the paving
centre = ORIGIN + Vec3(5, 1, 5)
world.set_block(centre, Item.GOLD_BLOCK)

# -- tower --
# a hollow tower around it, 5 blocks high. With 12 sides it is nearly
# round, and 9 blocks across
polygon(client, centre, height=5, diameter=3, sides=12, item=Item.STONE_BRICKS)
# a door in the south side of the tower, facing out
door = centre + Direction.SOUTH * 4
world.place_door(door, Item.OAK_DOOR, Direction.SOUTH)

# -- gateway --
# two posts and a lintel on the south edge of the site, a block at a time
post = ORIGIN + Vec3(3, 1, 12)
for y in range(4):
    world.set_block(post + Direction.UP * y, Item.OBSIDIAN)
    world.set_block(post + Direction.EAST * 4 + Direction.UP * y, Item.OBSIDIAN)
for x in range(5):
    world.set_block(post + Direction.EAST * x + Direction.UP * 4, Item.OBSIDIAN)
# a block state: a lantern hanging from the middle of the lintel
lantern = post + Direction.EAST * 2 + Direction.UP * 3
world.set_block(lantern, Item.LANTERN, nbt=["hanging=true"])

# -- check --
print(f"built from {tuple(site.start)} to {tuple(site.end)}")
print(f"the centre is {world.get_block(centre)}")
print(f"the door is {world.get_block(door)}")
