Skip to content

Commit 684709f

Browse files
committed
chore: begin 1.21.6
1 parent d2aff00 commit 684709f

File tree

15 files changed

+651
-141
lines changed

15 files changed

+651
-141
lines changed

Cargo.lock

Lines changed: 320 additions & 90 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "2"
3-
members = [ "crawlspace-macro","crawlspace"]
3+
members = [ "crawlspace-macro","crawlspace", "crawlspace-slime"]
44

55
[profile.release-stripped]
66
inherits = "release"

crawlspace/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ tokio-util = "0.7.12"
4545
tracing = { version = "0.1.40", features = ["max_level_trace", "release_max_level_info"] }
4646
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
4747
uuid = "1.11.0"
48+
slimeball-lib = { git = "https://github.com/xoogware/slimeball.git" }
4849

4950
[features]
5051
default = []

crawlspace/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ async fn main() -> Result<()> {
7777
let state = Arc::new(state::State::new(VERSION, VERSION_NUM, args));
7878

7979
info!("Generating world chunk packets");
80-
let world_cache = WorldCache::from_anvil(state.clone(), &world);
80+
let world_cache = WorldCache::from_slime(state.clone(), world);
8181
info!("Done.");
8282

8383
#[cfg(feature = "lan")]

crawlspace/src/net/cache.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,81 @@ pub struct WorldCache {
4141
}
4242

4343
impl WorldCache {
44+
pub fn from_slime(state: CrawlState, world: slimeball_lib::SlimeWorld) -> Self {
45+
let mut chunks = world.chunks;
46+
chunks.sort_by(|a, b| {
47+
if (a.x + a.z) > (b.x + b.z) {
48+
Ordering::Greater
49+
} else {
50+
Ordering::Less
51+
}
52+
});
53+
54+
let block_states = Blocks::new();
55+
let containers = chunks
56+
.iter()
57+
.flat_map(|c|
58+
c.tile_entities
59+
.iter()
60+
.filter_map(|e| {
61+
let block_entity = BlockEntity::try_parse(e.clone()).map_or_else(
62+
|why| {
63+
warn!(
64+
"failed to parse block entity: {why}, ignoring in container cache for ({}, {})",
65+
c.x,
66+
c.z
67+
);
68+
None
69+
},
70+
|e| match e.keep_packed {
71+
true => None,
72+
false => Some(e),
73+
},
74+
);
75+
76+
let block_entity = block_entity?;
77+
78+
match block_entity.id.as_str() {
79+
"minecraft:chest" | "minecraft:trapped_chest" | "minecraft:barrel" => {
80+
Some(block_entity)
81+
}
82+
_ => None,
83+
}
84+
})
85+
.map(|container| {
86+
(
87+
(container.x, container.y, container.z),
88+
Container::try_from(container)
89+
.expect("Failed to convert container from block entity NBT"),
90+
)
91+
})
92+
.collect::<Vec<((i32, i32, i32), Container)>>()
93+
)
94+
.collect();
95+
96+
debug!("Containers: {:?}", containers);
97+
98+
let encoded = chunks
99+
.par_iter()
100+
.map(|chunk| {
101+
let mut encoder = Encoder::new();
102+
encoder
103+
.append_packet(&ChunkDataUpdateLightC::from_slime(
104+
state.clone(),
105+
chunk,
106+
&block_states,
107+
))
108+
.expect("Failed to append packet to encoder");
109+
encoder.take().to_vec()
110+
})
111+
.collect();
112+
113+
Self {
114+
encoded,
115+
containers,
116+
}
117+
}
118+
44119
pub fn from_anvil(crawlstate: CrawlState, world: &World) -> Self {
45120
let mut chunks = world.0.iter().collect::<Vec<_>>();
46121

crawlspace/src/protocol/datatypes/string.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a, const BOUND: usize> Encode for Rest<&'a str, BOUND> {
139139

140140
impl<'a, const BOUND: usize> Encode for Rest<Bytes<'a>, BOUND> {
141141
fn encode(&self, mut w: impl std::io::Write) -> Result<()> {
142-
let len = self.0.0.len();
142+
let len = self.0 .0.len();
143143

144144
ensure!(len <= BOUND, "length of bytes {len} exceeds bound {BOUND}");
145145

@@ -162,4 +162,4 @@ impl<'a, const BOUND: usize> Decode<'a> for Rest<Bytes<'a>, BOUND> {
162162

163163
Ok(Rest(content))
164164
}
165-
}
165+
}

crawlspace/src/protocol/packets/login/registry/biome.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct Effects {
4545
mood_sound: Option<MoodSound>,
4646
additions_sound: Option<AdditionsSound>,
4747
music: Option<Vec<Music>>,
48-
music_volume: Option<f32>
48+
music_volume: Option<f32>,
4949
}
5050

5151
#[derive(Clone, Debug, Serialize, Deserialize)]

crawlspace/src/protocol/packets/login/registry/dimension.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
use serde::{Deserialize, Serialize};
2121

22-
use super::{RegistryItem, deserialize_bool};
22+
use super::{deserialize_bool, RegistryItem};
2323

2424
#[derive(Clone, Debug, Serialize, Deserialize)]
2525
pub struct DimensionType {

crawlspace/src/protocol/packets/play/world.rs

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,140 @@ impl ChunkSection {
367367
},
368368
}
369369
}
370+
371+
pub fn slime_to_sec(
372+
crawlstate: CrawlState,
373+
value: &slimeball_lib::Section,
374+
block_states: &Blocks,
375+
) -> Self {
376+
let mut blocks = Vec::new();
377+
let bit_length = (64 - (value.block_states.palette.len() as u64).leading_zeros()).max(4);
378+
379+
let blocks_per_long = 64 / bit_length;
380+
381+
#[cfg(not(feature = "modern_art"))]
382+
let bit_mask = (1 << bit_length) - 1;
383+
384+
match value.block_states.data {
385+
None => blocks.fill(0),
386+
Some(ref data) => {
387+
trace!("data.len(): {}", data.len());
388+
trace!("blocks_per_long: {blocks_per_long}");
389+
blocks.resize(data.len() * blocks_per_long as usize, 0);
390+
let mut i = 0;
391+
for long in data.iter() {
392+
#[cfg(not(feature = "modern_art"))]
393+
{
394+
let long = *long as u64;
395+
for b in 0..blocks_per_long {
396+
blocks[i] = ((long >> (bit_length * b)) & bit_mask) as i16;
397+
i += 1;
398+
}
399+
}
400+
401+
#[cfg(feature = "modern_art")]
402+
{
403+
let mut long = *long as u64;
404+
while long != 0 {
405+
blocks[i] = (long & ((1 << bit_length) - 1)) as i16;
406+
long >>= bit_length;
407+
i += 1;
408+
}
409+
}
410+
}
411+
}
412+
}
413+
414+
let palette = value
415+
.block_states
416+
.palette
417+
.iter()
418+
.map(|b| BlockState::parse_state_slime(b, block_states).unwrap_or(BlockState::AIR))
419+
.collect::<Vec<_>>();
420+
421+
let blocks: Vec<u16> = blocks
422+
.iter()
423+
// todo: come up with a better way to do this(?)
424+
.map(|b| palette.get(*b as usize).unwrap_or(&BlockState::AIR).0)
425+
.collect();
426+
427+
let block_count = blocks.iter().filter(|b| **b != 0).collect::<Vec<_>>().len();
428+
429+
let bit_length = match palette.len() {
430+
1 => 0,
431+
l => (64 - l.leading_zeros()).max(4) as u8,
432+
};
433+
434+
trace!("bit_length: {bit_length}");
435+
436+
let palette = {
437+
if bit_length == 15 {
438+
Palette::Direct
439+
} else if bit_length >= 4 {
440+
Palette::Indirect(VarInt(palette.len() as i32), palette)
441+
} else {
442+
Palette::SingleValued(*palette.first().unwrap())
443+
}
444+
};
445+
446+
let blocks = match palette {
447+
Palette::Indirect(_, ref p) => blocks
448+
.iter()
449+
.map(|requested| p.iter().position(|pb| pb.0 == *requested).unwrap() as u16)
450+
.collect::<Vec<_>>(),
451+
_ => blocks,
452+
};
453+
454+
trace!("palette: {:?}", palette);
455+
trace!("blocks: {:?}", blocks);
456+
457+
let data = {
458+
let data = match palette {
459+
Palette::Direct | Palette::Indirect(..) => {
460+
let blocks_per_long = 64 / bit_length;
461+
let mut data = vec![0i64; blocks.len() / blocks_per_long as usize];
462+
let mut blocks_so_far = 0;
463+
let mut long_index = 0;
464+
465+
for block in blocks {
466+
if blocks_so_far == blocks_per_long {
467+
blocks_so_far = 0;
468+
long_index += 1;
469+
}
470+
471+
let block = block as i64;
472+
473+
data[long_index] |= block << (blocks_so_far * bit_length);
474+
blocks_so_far += 1;
475+
trace!("block: {} ({:b}), long (after appending): {:b}, blocks so far: {blocks_so_far}", block, block, data[long_index])
476+
}
477+
478+
data
479+
}
480+
Palette::SingleValued(_) => Vec::with_capacity(0),
481+
};
482+
483+
let data = fastnbt::LongArray::new(data.to_vec());
484+
trace!("data: {:?}", data);
485+
data
486+
};
487+
488+
Self {
489+
block_count: block_count as i16,
490+
block_states: PalettedContainer {
491+
bits_per_entry: bit_length,
492+
palette,
493+
data_array: data,
494+
},
495+
biomes: PalettedContainer {
496+
bits_per_entry: 0,
497+
palette: Palette::SingleValued(BlockState(
498+
crawlstate.registry_cache.the_end_biome_id,
499+
)),
500+
data_array: fastnbt::LongArray::new(vec![]),
501+
},
502+
}
503+
}
370504
}
371505

372506
impl ChunkDataUpdateLightC<'_> {
@@ -414,6 +548,55 @@ impl ChunkDataUpdateLightC<'_> {
414548
block_light_arrays: vec![],
415549
}
416550
}
551+
552+
pub fn from_slime(
553+
crawlstate: CrawlState,
554+
value: &slimeball_lib::Chunk,
555+
block_states: &Blocks,
556+
) -> Self {
557+
let data = value
558+
.sections
559+
.iter()
560+
.map(|sec| ChunkSection::slime_to_sec(crawlstate.clone(), sec, block_states))
561+
.collect::<Vec<_>>();
562+
563+
let block_entities = value
564+
.tile_entities
565+
.clone()
566+
.into_iter()
567+
.filter_map(|e| {
568+
world::BlockEntity::try_parse(e).map_or_else(
569+
|why| {
570+
warn!(
571+
"Failed to parse block entity: {why}, ignoring in final chunk packet for ({}, {})",
572+
value.x,
573+
value.z,
574+
);
575+
None
576+
},
577+
|e| match e.keep_packed {
578+
true => None,
579+
false => Some(e),
580+
},
581+
)
582+
})
583+
.map(Into::into)
584+
.collect::<Vec<self::BlockEntity>>();
585+
586+
Self {
587+
x: value.x,
588+
z: value.z,
589+
heightmaps: HeightMaps(HashMap::new()),
590+
data,
591+
entities: block_entities,
592+
sky_light_mask: BitVec::from_elem(18, false),
593+
block_light_mask: BitVec::from_elem(18, false),
594+
empty_sky_light_mask: BitVec::from_elem(18, true),
595+
empty_block_light_mask: BitVec::from_elem(18, true),
596+
sky_light_arrays: vec![],
597+
block_light_arrays: vec![],
598+
}
599+
}
417600
}
418601

419602
#[derive(Debug, Packet, Encode)]

crawlspace/src/state.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ use std::sync::{atomic::AtomicUsize, Arc};
2222
use tokio::sync::{mpsc, Mutex, RwLock, Semaphore};
2323
use tokio_util::sync::CancellationToken;
2424

25+
use crate::protocol::packets::login::registry::TAGS;
2526
use crate::{
2627
args::Args,
27-
net::{cache::{TagCache, RegistryCache}, player::SharedPlayer},
28+
net::{
29+
cache::{RegistryCache, TagCache},
30+
player::SharedPlayer,
31+
},
2832
protocol::packets::login::registry::ALL_REGISTRIES,
2933
server::Server,
3034
};
31-
use crate::protocol::packets::login::registry::TAGS;
3235

3336
#[derive(Debug)]
3437
pub struct State {

0 commit comments

Comments
 (0)