use bytes::{BufMut, Bytes, BytesMut};
use ghast_protocol::RawPacket;
#[cfg(feature = "v1_8")]
pub(crate) fn v1_8(x: i32, z: i32) -> RawPacket {
let mut d = BytesMut::with_capacity(12_544);
for i in 0..4096 {
d.put_u16_le(if i >> 8 == 15 { 1 << 4 } else { 0 });
}
d.put_bytes(0, 2048); d.put_bytes(0xff, 2048); d.put_bytes(1, 256); RawPacket::from_packet(&ghast_protocol::v1_8::play::clientbound::MapChunk {
x,
z,
ground_up: true,
bit_map: 1 << 3,
chunk_data: d.freeze(),
})
.unwrap()
}
#[cfg(feature = "v1_12_2")]
pub(crate) fn v1_12_2(x: i32, z: i32) -> RawPacket {
let mut d = BytesMut::new();
d.put_u8(4); d.put_u8(2); d.put_u8(0); d.put_u8(1 << 4); d.put_u8(0x80); d.put_u8(0x02);
for w in 0..256 {
d.put_u64(if w >= 240 { 0x1111_1111_1111_1111 } else { 0 });
}
d.put_bytes(0, 2048); d.put_bytes(0xff, 2048); d.put_bytes(1, 256); RawPacket::from_packet(&ghast_protocol::v1_12_2::play::clientbound::MapChunk {
x,
z,
ground_up: true,
bit_map: 1 << 3,
chunk_data: d.freeze(),
block_entities: Vec::new(),
})
.unwrap()
}
#[cfg(feature = "v26_1")]
pub(crate) fn v26_1(x: i32, z: i32) -> RawPacket {
v26_1_sections(x, z, 24, 7)
}
#[cfg(feature = "v26_1")]
pub(crate) fn v26_1_sections(x: i32, z: i32, sections: usize, stone_at: usize) -> RawPacket {
use ghast_protocol::McWrite;
let stone = ghast_data::v26_1::BlockState::parse("stone").unwrap().id();
let mut d = BytesMut::new();
for section in 0..sections {
if section == stone_at {
d.put_i16(256);
d.put_i16(0);
d.put_u8(4);
d.put_varint(2);
d.put_varint(0);
d.put_varint(i32::from(stone));
for w in 0..256 {
d.put_u64(if w >= 240 { 0x1111_1111_1111_1111 } else { 0 });
}
} else {
d.put_i16(0);
d.put_i16(0);
d.put_u8(0);
d.put_varint(0);
}
d.put_u8(0);
d.put_varint(0);
}
RawPacket::from_packet(&ghast_protocol::v26_1::play::clientbound::MapChunk {
x,
z,
heightmaps: Vec::new(),
chunk_data: d.freeze(),
block_entities: Vec::new(),
sky_light_mask: Vec::new(),
block_light_mask: Vec::new(),
empty_sky_light_mask: Vec::new(),
empty_block_light_mask: Vec::new(),
sky_light: Vec::new(),
block_light: Vec::new(),
})
.unwrap()
}
#[cfg(feature = "v26_2")]
pub(crate) fn v26_2(x: i32, z: i32) -> RawPacket {
v26_2_sections(x, z, 24, 7)
}
#[cfg(feature = "v26_2")]
pub(crate) fn v26_2_sections(x: i32, z: i32, sections: usize, stone_at: usize) -> RawPacket {
use ghast_protocol::McWrite;
let stone = ghast_data::v26_2::BlockState::parse("stone").unwrap().id();
let mut d = BytesMut::new();
for section in 0..sections {
if section == stone_at {
d.put_i16(256);
d.put_i16(0);
d.put_u8(4);
d.put_varint(2);
d.put_varint(0);
d.put_varint(i32::from(stone));
for w in 0..256 {
d.put_u64(if w >= 240 { 0x1111_1111_1111_1111 } else { 0 });
}
} else {
d.put_i16(0);
d.put_i16(0);
d.put_u8(0);
d.put_varint(0);
}
d.put_u8(0);
d.put_varint(0);
}
RawPacket::from_packet(&ghast_protocol::v26_2::play::clientbound::MapChunk {
x,
z,
heightmaps: Vec::new(),
chunk_data: d.freeze(),
block_entities: Vec::new(),
sky_light_mask: Vec::new(),
block_light_mask: Vec::new(),
empty_sky_light_mask: Vec::new(),
empty_block_light_mask: Vec::new(),
sky_light: Vec::new(),
block_light: Vec::new(),
})
.unwrap()
}
#[cfg(feature = "v26_3")]
pub(crate) fn v26_3(x: i32, z: i32) -> RawPacket {
v26_3_sections(x, z, 24, 7)
}
#[cfg(feature = "v26_3")]
pub(crate) fn v26_3_sections(x: i32, z: i32, sections: usize, stone_at: usize) -> RawPacket {
use ghast_protocol::McWrite;
let stone = ghast_data::v26_3::BlockState::parse("stone").unwrap().id();
let mut d = BytesMut::new();
for section in 0..sections {
if section == stone_at {
d.put_i16(256);
d.put_i16(0);
d.put_u8(4);
d.put_varint(2);
d.put_varint(0);
d.put_varint(i32::from(stone));
for w in 0..256 {
d.put_u64(if w >= 240 { 0x1111_1111_1111_1111 } else { 0 });
}
} else {
d.put_i16(0);
d.put_i16(0);
d.put_u8(0);
d.put_varint(0);
}
d.put_u8(0);
d.put_varint(0);
}
RawPacket::from_packet(&ghast_protocol::v26_3::play::clientbound::MapChunk {
x,
z,
heightmaps: Vec::new(),
chunk_data: d.freeze(),
block_entities: Vec::new(),
sky_light_mask: Default::default(),
block_light_mask: Default::default(),
empty_sky_light_mask: Default::default(),
empty_block_light_mask: Default::default(),
sky_light: Vec::new(),
block_light: Vec::new(),
})
.unwrap()
}
#[cfg(feature = "v1_16_5")]
pub(crate) fn v1_16_5(x: i32, z: i32) -> RawPacket {
RawPacket::from_packet(&ghast_protocol::v1_16_5::play::clientbound::MapChunk {
x,
z,
ground_up: true,
bit_map: 0,
heightmaps: ghast_protocol::nbt::RawNbt::from_bytes(Bytes::from_static(&[10, 0, 0, 0]))
.unwrap(),
biomes: Some(vec![1; 1024]),
chunk_data: Bytes::new(),
block_entities: Vec::new(),
})
.unwrap()
}