mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
feat: extend plugin api
This commit is contained in:
22
crates/pumpkin-plugin-api/src/events/dialog/dialog_clear.rs
Normal file
22
crates/pumpkin-plugin-api/src/events/dialog/dialog_clear.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use crate::wit::pumpkin::plugin::event::{DialogClearEventData, Event, EventType};
|
||||
|
||||
use super::super::FromIntoEvent;
|
||||
|
||||
/// An event that occurs when a player's dialog is cleared.
|
||||
pub struct DialogClearEvent;
|
||||
|
||||
impl FromIntoEvent for DialogClearEvent {
|
||||
const EVENT_TYPE: EventType = EventType::DialogClearEvent;
|
||||
type Data = DialogClearEventData;
|
||||
|
||||
fn data_from_event(event: Event) -> Self::Data {
|
||||
match event {
|
||||
Event::DialogClearEvent(data) => data,
|
||||
_ => panic!("unexpected event"),
|
||||
}
|
||||
}
|
||||
|
||||
fn data_into_event(data: Self::Data) -> Event {
|
||||
Event::DialogClearEvent(data)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
use crate::wit::pumpkin::plugin::event::{DialogClickActionEventData, Event, EventType};
|
||||
|
||||
use super::super::FromIntoEvent;
|
||||
|
||||
/// An event that occurs when a player clicks a custom dialog button.
|
||||
pub struct DialogClickActionEvent;
|
||||
|
||||
impl FromIntoEvent for DialogClickActionEvent {
|
||||
const EVENT_TYPE: EventType = EventType::DialogClickActionEvent;
|
||||
type Data = DialogClickActionEventData;
|
||||
|
||||
fn data_from_event(event: Event) -> Self::Data {
|
||||
match event {
|
||||
Event::DialogClickActionEvent(data) => data,
|
||||
_ => panic!("unexpected event"),
|
||||
}
|
||||
}
|
||||
|
||||
fn data_into_event(data: Self::Data) -> Event {
|
||||
Event::DialogClickActionEvent(data)
|
||||
}
|
||||
}
|
||||
22
crates/pumpkin-plugin-api/src/events/dialog/dialog_show.rs
Normal file
22
crates/pumpkin-plugin-api/src/events/dialog/dialog_show.rs
Normal file
@@ -0,0 +1,22 @@
|
||||
use crate::wit::pumpkin::plugin::event::{DialogShowEventData, Event, EventType};
|
||||
|
||||
use super::super::FromIntoEvent;
|
||||
|
||||
/// An event that occurs when a dialog is shown to a player.
|
||||
pub struct DialogShowEvent;
|
||||
|
||||
impl FromIntoEvent for DialogShowEvent {
|
||||
const EVENT_TYPE: EventType = EventType::DialogShowEvent;
|
||||
type Data = DialogShowEventData;
|
||||
|
||||
fn data_from_event(event: Event) -> Self::Data {
|
||||
match event {
|
||||
Event::DialogShowEvent(data) => data,
|
||||
_ => panic!("unexpected event"),
|
||||
}
|
||||
}
|
||||
|
||||
fn data_into_event(data: Self::Data) -> Event {
|
||||
Event::DialogShowEvent(data)
|
||||
}
|
||||
}
|
||||
10
crates/pumpkin-plugin-api/src/events/dialog/mod.rs
Normal file
10
crates/pumpkin-plugin-api/src/events/dialog/mod.rs
Normal file
@@ -0,0 +1,10 @@
|
||||
/// Dialog clear event.
|
||||
pub mod dialog_clear;
|
||||
/// Dialog click action event.
|
||||
pub mod dialog_click_action;
|
||||
/// Dialog show event.
|
||||
pub mod dialog_show;
|
||||
|
||||
pub use dialog_clear::*;
|
||||
pub use dialog_click_action::*;
|
||||
pub use dialog_show::*;
|
||||
@@ -18,6 +18,8 @@ use crate::{Context, Result, Server, wit::pumpkin::plugin::event::EventType};
|
||||
|
||||
/// Block events.
|
||||
pub mod block;
|
||||
/// Dialog events.
|
||||
pub mod dialog;
|
||||
/// Enchantment events.
|
||||
pub mod enchantment;
|
||||
/// Entity events.
|
||||
@@ -40,6 +42,7 @@ pub mod vehicle;
|
||||
pub mod world;
|
||||
|
||||
pub use block::*;
|
||||
pub use dialog::*;
|
||||
pub use enchantment::*;
|
||||
pub use entity::*;
|
||||
pub use hanging::*;
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
use crate::wit::pumpkin::plugin::event::{CustomClickActionEventData, Event, EventType};
|
||||
|
||||
use super::super::FromIntoEvent;
|
||||
|
||||
/// An event that occurs when a player clicks a custom dialog button.
|
||||
pub struct CustomClickActionEvent;
|
||||
|
||||
impl FromIntoEvent for CustomClickActionEvent {
|
||||
const EVENT_TYPE: EventType = EventType::CustomClickActionEvent;
|
||||
type Data = CustomClickActionEventData;
|
||||
|
||||
fn data_from_event(event: Event) -> Self::Data {
|
||||
match event {
|
||||
Event::CustomClickActionEvent(data) => data,
|
||||
_ => panic!("unexpected event"),
|
||||
}
|
||||
}
|
||||
|
||||
fn data_into_event(data: Self::Data) -> Event {
|
||||
Event::CustomClickActionEvent(data)
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,6 @@ pub mod async_player_pre_login;
|
||||
pub mod bedrock_form_response;
|
||||
/// Player main hand change event.
|
||||
pub mod changed_main_hand;
|
||||
/// Custom inventory click action event.
|
||||
pub mod custom_click_action;
|
||||
/// Egg throw event.
|
||||
pub mod egg_throw;
|
||||
/// Experience change event.
|
||||
@@ -155,7 +153,6 @@ pub use async_player_chat::*;
|
||||
pub use async_player_pre_login::*;
|
||||
pub use bedrock_form_response::*;
|
||||
pub use changed_main_hand::*;
|
||||
pub use custom_click_action::*;
|
||||
pub use egg_throw::*;
|
||||
pub use exp_change::*;
|
||||
pub use fish::*;
|
||||
|
||||
107
crates/pumpkin-plugin-api/src/ext/block.rs
Normal file
107
crates/pumpkin-plugin-api/src/ext/block.rs
Normal file
@@ -0,0 +1,107 @@
|
||||
use crate::wit::pumpkin::plugin::world::{
|
||||
Block, BlockState, get_all_block_names, get_all_blocks, get_block_by_id, get_block_by_name,
|
||||
get_block_count, get_block_from_state, get_block_from_state_id, get_block_properties,
|
||||
get_block_state_by_id, get_block_state_count, get_default_state_from_block,
|
||||
get_default_state_from_block_id, get_state_ids_for_block_id, get_states_for_block,
|
||||
get_states_for_block_id,
|
||||
};
|
||||
|
||||
impl Block {
|
||||
/// Returns all registered blocks in the registry.
|
||||
#[must_use]
|
||||
pub fn all() -> Vec<Self> {
|
||||
get_all_blocks()
|
||||
}
|
||||
|
||||
/// Returns the names of all registered blocks.
|
||||
#[must_use]
|
||||
pub fn all_names() -> Vec<String> {
|
||||
get_all_block_names()
|
||||
}
|
||||
|
||||
/// Returns the total number of registered block types.
|
||||
#[must_use]
|
||||
pub fn count() -> u32 {
|
||||
get_block_count()
|
||||
}
|
||||
|
||||
/// Returns the total number of registered block states.
|
||||
#[must_use]
|
||||
pub fn total_state_count() -> u32 {
|
||||
get_block_state_count()
|
||||
}
|
||||
|
||||
/// Gets a block definition by its numerical block ID.
|
||||
#[must_use]
|
||||
pub fn from_id(id: u16) -> Option<Self> {
|
||||
get_block_by_id(id)
|
||||
}
|
||||
|
||||
/// Gets a block definition by its namespaced name (e.g., "minecraft:stone" or "stone").
|
||||
#[must_use]
|
||||
pub fn from_name(name: &str) -> Option<Self> {
|
||||
get_block_by_name(name)
|
||||
}
|
||||
|
||||
/// Gets the block definition for a given block state ID.
|
||||
#[must_use]
|
||||
pub fn from_state_id(state_id: u16) -> Option<Self> {
|
||||
get_block_from_state_id(state_id)
|
||||
}
|
||||
|
||||
/// Gets the block definition for a given block state.
|
||||
#[must_use]
|
||||
pub fn from_state(state: &BlockState) -> Self {
|
||||
get_block_from_state(state)
|
||||
}
|
||||
|
||||
/// Gets all valid block states for this block type.
|
||||
#[must_use]
|
||||
pub fn get_states(&self) -> Vec<BlockState> {
|
||||
get_states_for_block(self)
|
||||
}
|
||||
|
||||
/// Gets all valid block states for a given numerical block ID.
|
||||
#[must_use]
|
||||
pub fn get_states_for_id(block_id: u16) -> Vec<BlockState> {
|
||||
get_states_for_block_id(block_id)
|
||||
}
|
||||
|
||||
/// Gets all valid block state IDs for a given numerical block ID.
|
||||
#[must_use]
|
||||
pub fn get_state_ids_for_id(block_id: u16) -> Vec<u16> {
|
||||
get_state_ids_for_block_id(block_id)
|
||||
}
|
||||
|
||||
/// Gets the default block state for this block.
|
||||
#[must_use]
|
||||
pub fn get_default_state(&self) -> BlockState {
|
||||
get_default_state_from_block(self)
|
||||
}
|
||||
|
||||
/// Gets the default block state for a given numerical block ID.
|
||||
#[must_use]
|
||||
pub fn get_default_state_for_id(block_id: u16) -> Option<BlockState> {
|
||||
get_default_state_from_block_id(block_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockState {
|
||||
/// Gets the parent block definition for this block state.
|
||||
#[must_use]
|
||||
pub fn get_block(&self) -> Block {
|
||||
get_block_from_state(self)
|
||||
}
|
||||
|
||||
/// Gets a detailed block state by its numerical block state ID.
|
||||
#[must_use]
|
||||
pub fn from_id(state_id: u16) -> Option<Self> {
|
||||
get_block_state_by_id(state_id)
|
||||
}
|
||||
|
||||
/// Gets property key-value pairs for this block state.
|
||||
#[must_use]
|
||||
pub fn get_properties(&self) -> Vec<(String, String)> {
|
||||
get_block_properties(self.id)
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
mod advancement;
|
||||
mod attributes;
|
||||
mod block;
|
||||
mod game_rules;
|
||||
pub mod player;
|
||||
mod server_list_ping;
|
||||
|
||||
@@ -145,7 +145,10 @@ pub use wit::pumpkin::plugin::item_stack::ItemStack;
|
||||
pub use wit::pumpkin::plugin::player::Player;
|
||||
pub use wit::pumpkin::plugin::scoreboard::{CollisionRule, NametagVisibility, TeamSettings};
|
||||
pub use wit::pumpkin::plugin::server::Dimension;
|
||||
pub use wit::pumpkin::plugin::world::World;
|
||||
pub use wit::pumpkin::plugin::world::{
|
||||
Block, BlockDirection, BlockState, BlockStateInfo, Entity, Flammable, RayTraceBlockResult,
|
||||
RayTraceEntityResult, RaycastResult, World, WorldBorder,
|
||||
};
|
||||
pub use worldgen::{ChunkBuffer, ChunkGenerator, GenerationPhase, GeneratorManager};
|
||||
|
||||
/// Advancement WIT API re-exports.
|
||||
@@ -157,7 +160,11 @@ pub mod advancement {
|
||||
|
||||
/// Java dialog WIT API re-exports.
|
||||
pub mod java_dialog {
|
||||
pub use crate::wit::pumpkin::plugin::java_dialogs::{ActionButton, DialogBody, DialogType};
|
||||
pub use crate::wit::pumpkin::plugin::java_dialogs::{
|
||||
Action, ActionButton, AfterAction, CustomClickAction, Dialog, DialogBody, DialogInput,
|
||||
DialogInputBool, DialogInputNumberRange, DialogInputSingleOption, DialogInputText,
|
||||
DialogType, Link, LinkLabel, LinkType,
|
||||
};
|
||||
}
|
||||
|
||||
/// WIT-based logging subscriber.
|
||||
|
||||
Reference in New Issue
Block a user