Demo Code#

Example code that uses the MCIWB library. These are the best worked examples of how to build with mciwb. The source is in src/mciwb/demo.

In mciwb shell import a demo with e.g. from mciwb.demo.pagoda import build_pagoda.

Example code that uses the mciwb library, as used in the tutorials.

Many of the demos build at coordinates in the seed 0 world created by mciwb start, around the default spawn point (632, 73, -1658).

mciwb.demo.pagoda#

Build a pagoda with polygon and fill commands.

Usage: build_pagoda(world.player.pos, width=20)

mciwb.demo.pagoda.build_pagoda(pos, width=4, floor_height=4, item: Item = Item.GOLD_BLOCK)[source]#

Create a pagoda out of blocks at the given position.

Each successive floor is narrower and each has a balcony at the top.

Parameters:
  • pos – position of the base of the pagoda

  • width – width of the base of the pagoda

  • floor_height – height of each floor

  • item – block to use for the base of the pagoda

mciwb.demo.shapes#

Functions to make some shapes in the world

mciwb.demo.shapes.box(start: Vec3, size: int, item=Item.ACACIA_FENCE)[source]#

makes a cube of blocks with SW bottom corner at start

Factored for easy understanding

mciwb.demo.shapes.pyramid(start: Vec3, size: int, item=Item.COBBLESTONE, **kwargs)[source]#

Build a pyramid with South West Corner at ‘start’

mciwb.demo.walls#

Build castle walls with crenellations using a Wall profile, plus a gate.

Usage: make_walls()

mciwb.demo.house#

Build houses with Wall profiles and command signs.

Usage: House() gives the player a “house” sign. Place it to build a house.

class mciwb.demo.house.House(height=1, width=3, depth=2, roof_item=Item.OAK_STAIRS)[source]#

A class for constructing a house in the Minecraft world.

Parameters:
  • width – The new width of the house in no. of windows

  • depth – The new depth of the house in no. of windows

  • height – The new height of the house in no. of floors

resize(width=None, depth=None, height=None)[source]#

Resize the house.

Parameters:
  • width – The new width of the house in no. of windows

  • depth – The new depth of the house in no. of windows

  • height – The new height of the house in no. of floors

build(position)[source]#

Build the house at the given position. The dimensions of the house are determined by the width, height, and depth attributes of the house class.

Parameters:

position – the location of the south-west bottom corner of the house.

mciwb.demo.gate#

Define a castle gateway with portcullis

mciwb.demo.gate.portcullis(position, close, width=4, height=6)[source]#

Open and close a portcullis

mciwb.demo.gate.make_gate(position=None)[source]#

Create a castle gate with working portcullis

mciwb.demo.gateway#

Define a castle gateway with portcullis and drawbridge

mciwb.demo.village#

Build a castle village with walls, a gate, houses and a pagoda.

This brings together most of the other demos, and builds near the spawn point of the seed 0 world created by mciwb start.

Usage: make_village()

mciwb.demo.clear#

Clear the area where mciwb.demo.village.make_village builds the village.

Usage: clear()

mciwb.demo.follow#

A pyramid of carved pumpkins that turns to face the player as they move.

Usage: SpookyPyramid(Vec3(0, 5, 0)).go() then .stop()

class mciwb.demo.follow.SpookyPyramid(pyramid_centre, size=11, player=None)[source]#

Spooky Pyramid Class: draws a pyramid centred at pyramid_centre, made of carved pumpkins that always turn to face the player

mciwb.demo.background#

Demonstrate the use of Monitor to set up a number of background threads to monitor the world and respond to player movement.

mciwb.demo.bat#

Make a pet bat follow you around floating over your head

mciwb.demo.arrows#

Implement exploding arrows.

mciwb.demo.snowball#

Implement exploding snowballs.

Note the snowball disappears when it hits something so we need to monitor all snowballs in flight and generate a BOOM at the last known position as they disappear.