use crate::components::BlockPosition;
#[derive(Debug, Clone)]
pub struct BlockBrokenEvent {
pub position: BlockPosition,
pub block_state: u16,
pub sequence: i32,
pub cancelled: bool,
}
crate::game_cancellable_event!(BlockBrokenEvent);
#[derive(Debug, Clone)]
pub struct BlockPlacedEvent {
pub position: BlockPosition,
pub block_state: u16,
pub sequence: i32,
pub cancelled: bool,
}
crate::game_cancellable_event!(BlockPlacedEvent);
#[derive(Debug, Clone)]
pub struct PlayerInteractEvent {
pub position: BlockPosition,
pub block_state: u16,
pub direction: i32,
pub sequence: i32,
pub cancelled: bool,
}
crate::game_cancellable_event!(PlayerInteractEvent);
#[cfg(test)]
mod tests {
use crate::events::Event;
use super::*;
#[test]
fn block_broken_cancellation() {
let mut event = BlockBrokenEvent {
position: BlockPosition { x: 0, y: 64, z: 0 },
block_state: 1,
sequence: 1,
cancelled: false,
};
assert!(!event.is_cancelled());
event.cancel();
assert!(event.is_cancelled());
}
#[test]
fn block_placed_downcast_roundtrip() {
let mut event = BlockPlacedEvent {
position: BlockPosition { x: 5, y: 64, z: 3 },
block_state: 1,
sequence: 42,
cancelled: false,
};
let any = event.as_any_mut();
let concrete = any.downcast_mut::<BlockPlacedEvent>().unwrap();
assert_eq!(concrete.block_state, 1);
}
#[test]
fn event_routing() {
use crate::events::{BusKind, EventRouting};
assert_eq!(BlockBrokenEvent::BUS, BusKind::Game);
assert_eq!(BlockPlacedEvent::BUS, BusKind::Game);
assert_eq!(PlayerInteractEvent::BUS, BusKind::Game);
}
}