pub mod response;
pub use response::Response;
pub use response::ResponseQueue;
use crate::recipes::RecipeId;
use basalt_types::{TextComponent, Uuid};
use crate::broadcast::BroadcastMessage;
use crate::gamemode::Gamemode;
use crate::logger::PluginLogger;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum UnlockReason {
AutoDiscovered,
Manual,
InitialJoin,
}
pub trait PlayerContext {
fn uuid(&self) -> Uuid;
fn entity_id(&self) -> i32;
fn username(&self) -> &str;
fn yaw(&self) -> f32;
fn pitch(&self) -> f32;
fn position(&self) -> (f64, f64, f64);
fn teleport(&self, x: f64, y: f64, z: f64, yaw: f32, pitch: f32);
fn set_gamemode(&self, mode: Gamemode);
fn registered_commands(&self) -> Vec<(String, String)>;
}
pub trait ChatContext {
fn send(&self, text: &str);
fn send_component(&self, component: &TextComponent);
fn action_bar(&self, text: &str);
fn broadcast(&self, text: &str);
fn broadcast_component(&self, component: &TextComponent);
}
pub trait WorldContext: crate::world::handle::WorldHandle {
fn send_block_ack(&self, sequence: i32);
fn stream_chunks(&self, cx: i32, cz: i32);
fn queue_persist_chunk(&self, cx: i32, cz: i32);
fn destroy_block_entity(&self, x: i32, y: i32, z: i32);
}
pub trait EntityContext {
fn spawn_dropped_item(&self, x: i32, y: i32, z: i32, item_id: i32, count: i32);
fn broadcast_block_change(&self, x: i32, y: i32, z: i32, block_state: i32);
#[allow(clippy::too_many_arguments)]
fn broadcast_entity_moved(
&self,
entity_id: i32,
x: f64,
y: f64,
z: f64,
yaw: f32,
pitch: f32,
on_ground: bool,
);
fn broadcast_player_joined(&self);
fn broadcast_player_left(&self);
fn broadcast_raw(&self, msg: BroadcastMessage);
fn broadcast_block_action(
&self,
x: i32,
y: i32,
z: i32,
action_id: u8,
action_param: u8,
block_id: i32,
);
}
pub trait ContainerContext {
fn open_chest(&self, x: i32, y: i32, z: i32);
fn open_crafting_table(&self, x: i32, y: i32, z: i32);
fn open(&self, container: &crate::container::Container);
fn notify_viewers(&self, x: i32, y: i32, z: i32, slot_index: i16, item: basalt_types::Slot);
}
pub trait RecipeContext {
fn unlock(&self, id: &RecipeId, reason: UnlockReason);
fn lock(&self, id: &RecipeId);
fn has(&self, id: &RecipeId) -> bool;
fn unlocked(&self) -> Vec<RecipeId>;
}
pub trait Context:
PlayerContext + ChatContext + WorldContext + EntityContext + ContainerContext + RecipeContext
{
fn logger(&self) -> PluginLogger;
fn player(&self) -> &dyn PlayerContext;
fn chat(&self) -> &dyn ChatContext;
fn world_ctx(&self) -> &dyn WorldContext;
fn entities(&self) -> &dyn EntityContext;
fn containers(&self) -> &dyn ContainerContext;
fn recipes(&self) -> &dyn RecipeContext;
}