11. API - Events

The events module defines the Events class, which provides methods for querying events in the Minecraft world, and BlockHitEvent which is the only event type currently supported.

Note

All items in this module are available from the picraft namespace without having to import picraft.events directly.

The following items are defined in the module:

11.1. Events

class picraft.events.Events(connection)[source]

This class implements the events attribute.

clear()[source]

Forget all pending events that have not yet been retrieved with poll().

This method is used to clear the list of block-hit events that have occurred since the last call to poll() with retrieving them. This is useful for ensuring that events subsequently retrieved definitely occurred after the call to clear().

poll()[source]

Return a list of all events that have occurred since the last call to poll(). Currently the only type of event supported is the block-hit event represented by instances of BlockHitEvent.

For example:

>>> w = World()
>>> w.events.poll()
[<BlockHit pos=1,1,1 face="x+" player=1>,
 <BlockHit pos=1,1,1 face="x+" player=1>]

11.2. BlockHitEvent

class picraft.events.BlockHitEvent(pos, face, player)[source]

Event representing a block being hit by a player.

This tuple derivative represents the event resulting from a player striking a block with their sword in the Minecraft world. Users will not normally need to construct instances of this class, rather they are constructed and returned by calls to poll().

Note

Please note that the block hit event only registers when the player right clicks with the sword. For some reason, left clicks do not count.

pos

A Vector indicating the position of the block which was struck.

face

A string indicating which side of the block was struck. This can be one of six values: ‘x+’, ‘x-‘, ‘y+’, ‘y-‘, ‘z+’, or ‘z-‘. The value indicates the axis, and direction along that axis, that the side faces:

_images/block_faces.png
player

A Player instance representing the player that hit the block.