Add Commands
This commit is contained in:
1 parent
5714c1b786
commit
c54ab006ae
14 files changed
+209
-18
No files matched your search
@@ -1,4 +1,4 @@
|
||||
use crate::{bytebuf::ByteBuffer, text::Text, BitSet, ClientPacket, Property, VarInt};
|
||||
use crate::{bytebuf::ByteBuffer, text::TextComponent, BitSet, ClientPacket, Property, VarInt};
|
||||
|
||||
pub struct SetHeldItem {
|
||||
slot: i8,
|
||||
@@ -106,11 +106,11 @@ impl ClientPacket for CPlayerAbilities {
|
||||
}
|
||||
|
||||
pub struct CPlayDisconnect {
|
||||
reason: Text,
|
||||
reason: TextComponent,
|
||||
}
|
||||
|
||||
impl CPlayDisconnect {
|
||||
pub fn new(reason: Text) -> Self {
|
||||
pub fn new(reason: TextComponent) -> Self {
|
||||
Self { reason }
|
||||
}
|
||||
}
|
||||
@@ -123,6 +123,26 @@ impl ClientPacket for CPlayDisconnect {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CSystemChatMessge {
|
||||
content: TextComponent,
|
||||
overlay: bool,
|
||||
}
|
||||
|
||||
impl CSystemChatMessge {
|
||||
pub fn new(content: TextComponent, overlay: bool) -> Self {
|
||||
Self { content, overlay }
|
||||
}
|
||||
}
|
||||
|
||||
impl ClientPacket for CSystemChatMessge {
|
||||
const PACKET_ID: VarInt = 0x6C;
|
||||
|
||||
fn write(&self, bytebuf: &mut ByteBuffer) {
|
||||
bytebuf.put_slice(&self.content.encode());
|
||||
bytebuf.put_bool(self.overlay);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct CChangeDifficulty {
|
||||
difficulty: u8,
|
||||
locked: bool,
|
||||
|
||||
@@ -13,6 +13,8 @@ pub mod text;
|
||||
pub mod packet_decoder;
|
||||
pub mod packet_encoder;
|
||||
|
||||
pub const CURRENT_MC_PROTOCOL: u32 = 767;
|
||||
|
||||
pub const MAX_PACKET_SIZE: i32 = 2097152;
|
||||
|
||||
/// usally uses a namespace like "minecraft:thing"
|
||||
|
||||
@@ -14,6 +14,20 @@ impl ServerPacket for SConfirmTeleport {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SChatCommand {
|
||||
pub command: String,
|
||||
}
|
||||
|
||||
impl ServerPacket for SChatCommand {
|
||||
const PACKET_ID: VarInt = 0x04;
|
||||
|
||||
fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Self {
|
||||
Self {
|
||||
command: bytebuf.get_string().unwrap(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SPlayerPosition {
|
||||
pub x: f64,
|
||||
pub feet_y: f64,
|
||||
|
||||
@@ -6,12 +6,59 @@ use serde::{Deserialize, Serialize};
|
||||
// represents a text component
|
||||
// Reference: https://wiki.vg/Text_formatting#Text_components
|
||||
#[derive(Clone, PartialEq, Default, Debug, Serialize, Deserialize)]
|
||||
pub struct Text {
|
||||
pub struct TextComponent {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
impl Text {
|
||||
impl TextComponent {
|
||||
pub fn encode(&self) -> Vec<u8> {
|
||||
fastnbt::to_bytes_with_opts(&self, SerOpts::network_nbt()).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for TextComponent {
|
||||
fn from(value: String) -> Self {
|
||||
Self { text: value }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for TextComponent {
|
||||
fn from(value: &str) -> Self {
|
||||
Self {
|
||||
text: value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Text color
|
||||
#[derive(Default, Debug, Clone, Copy)]
|
||||
pub enum Color {
|
||||
/// The default color for the text will be used, which varies by context
|
||||
/// (in some cases, it's white; in others, it's black; in still others, it
|
||||
/// is a shade of gray that isn't normally used on text).
|
||||
#[default]
|
||||
Reset,
|
||||
/// One of the 16 named Minecraft colors
|
||||
Named(NamedColor),
|
||||
}
|
||||
|
||||
/// Named Minecraft color
|
||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
pub enum NamedColor {
|
||||
Black = 0,
|
||||
DarkBlue,
|
||||
DarkGreen,
|
||||
DarkCyan,
|
||||
DarkRed,
|
||||
Purple,
|
||||
Gold,
|
||||
Gray,
|
||||
DarkGray,
|
||||
Blue,
|
||||
BrightGreen,
|
||||
Cyan,
|
||||
Red,
|
||||
Pink,
|
||||
Yellow,
|
||||
White,
|
||||
}
|
||||
Reference in new issue
Block a user