Skip to content

Commit 8c5d6dc

Browse files
committed
fix: bedrock SActorEvent packet
1 parent 28e8187 commit 8c5d6dc

19 files changed

Lines changed: 101 additions & 104 deletions

File tree

pumpkin-protocol/src/bedrock/server/actor_event.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::serial::PacketWrite;
1+
use crate::{codec::var_long::VarLong, serial::PacketWrite};
22
use std::io::{Error, Write};
33

44
use pumpkin_macros::packet;
@@ -9,7 +9,7 @@ use crate::codec::var_int::VarInt;
99
#[derive(Debug, PacketWrite)]
1010
#[packet(27)]
1111
pub struct SActorEvent {
12-
pub entity_runtime_id: VarInt,
12+
pub entity_runtime_id: VarLong,
1313
pub event_type: ActorEventType,
1414
pub event_data: VarInt,
1515
pub fire_at_position: Option<Vector3<f32>>,

pumpkin-protocol/src/java/client/config/registry_data.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,26 @@ use crate::{
55
codec::var_int::VarInt,
66
ser::{NetworkWriteExt, WritingError},
77
};
8-
use pumpkin_data::packet::clientbound::CONFIG_REGISTRY_DATA;
8+
use pumpkin_data::{packet::clientbound::CONFIG_REGISTRY_DATA, registry::RegistryEntryData};
99
use pumpkin_macros::java_packet;
1010
use pumpkin_util::{resource_location::ResourceLocation, version::JavaMinecraftVersion};
1111

1212
#[java_packet(CONFIG_REGISTRY_DATA)]
1313
pub struct CRegistryData<'a> {
1414
pub registry_id: &'a ResourceLocation,
15-
pub entries: &'a [RegistryEntry],
15+
pub entries: &'a [RegistryEntryData],
1616
}
1717

1818
impl<'a> CRegistryData<'a> {
1919
#[must_use]
20-
pub const fn new(registry_id: &'a ResourceLocation, entries: &'a [RegistryEntry]) -> Self {
20+
pub const fn new(registry_id: &'a ResourceLocation, entries: &'a [RegistryEntryData]) -> Self {
2121
Self {
2222
registry_id,
2323
entries,
2424
}
2525
}
2626
}
2727

28-
pub struct RegistryEntry {
29-
pub entry_id: ResourceLocation,
30-
pub data: Option<Box<[u8]>>,
31-
}
32-
33-
impl RegistryEntry {
34-
#[must_use]
35-
pub const fn new(entry_id: ResourceLocation, data: Option<Box<[u8]>>) -> Self {
36-
Self { entry_id, data }
37-
}
38-
}
39-
4028
impl ClientPacket for CRegistryData<'_> {
4129
fn write_packet_data(
4230
&self,

pumpkin-util/src/math/pool.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,28 @@ impl Pool {
1515
///
1616
/// # Returns
1717
/// An `Option<E>` representing the selected element, or `None` if the distribution is empty.
18-
pub fn get<E: Clone>(distribution: &[Weighted<E>], random: &mut RandomGenerator) -> Option<E> {
18+
pub fn get<'a, E>(
19+
distribution: &'a [Weighted<E>],
20+
random: &mut RandomGenerator,
21+
) -> Option<&'a E> {
1922
let mut total_weight = 0;
2023
for dist in distribution {
2124
total_weight += dist.weight;
2225
}
26+
2327
let mut index = random.next_bounded_i32(total_weight);
28+
2429
if total_weight < 64 {
2530
return Some(FlattenedContent::get(index, distribution, total_weight));
2631
}
32+
2733
// WrappedContent
2834
for dist in distribution {
2935
index -= dist.weight;
3036
if index >= 0 {
3137
continue;
3238
}
33-
return Some(dist.data.clone());
39+
return Some(&dist.data);
3440
}
3541
None
3642
}
@@ -58,16 +64,17 @@ impl FlattenedContent {
5864
///
5965
/// # Returns
6066
/// The element corresponding to the given index.
61-
pub fn get<E: Clone>(index: i32, entries: &[Weighted<E>], total_weight: i32) -> E {
62-
let mut final_entries = Vec::with_capacity(total_weight as usize);
67+
pub fn get<E>(index: i32, entries: &[Weighted<E>], _total_weight: i32) -> &E {
6368
let mut cur_index = 0;
69+
6470
for entry in entries {
6571
let weight = entry.weight;
66-
for i in cur_index..cur_index + weight {
67-
final_entries.insert(i as usize, entry.data.clone());
72+
if index >= cur_index && index < cur_index + weight {
73+
return &entry.data;
6874
}
6975
cur_index += weight;
7076
}
71-
final_entries[index as usize].clone()
77+
78+
&entries[0].data
7279
}
7380
}

pumpkin-world/build.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ fn main() {
2121

2222
for (pool_id, elements) in pools {
2323
pool_code.push_str(&format!(
24-
" \"minecraft:{}\" | \"{}\" => Some(&[\n",
25-
pool_id, pool_id
24+
" \"minecraft:{pool_id}\" | \"{pool_id}\" => Some(&[\n"
2625
));
2726
for element in elements {
28-
pool_code.push_str(&format!(" \"{}\",\n", element));
27+
pool_code.push_str(&format!(" \"{element}\",\n"));
2928
}
3029
pool_code.push_str(" ]),\n");
3130
}
@@ -37,7 +36,7 @@ fn main() {
3736
pool_code.push_str(" _ => None,\n");
3837
pool_code.push_str(" }\n}\n");
3938

40-
fs::write(&dest_path, format!("{}\n{}", code, pool_code)).unwrap();
39+
fs::write(&dest_path, format!("{code}\n{pool_code}")).unwrap();
4140
println!("cargo:rerun-if-changed=assets/structures");
4241
}
4342

@@ -56,7 +55,7 @@ fn process_dir(
5655
let new_prefix = if prefix.is_empty() {
5756
name
5857
} else {
59-
format!("{}/{}", prefix, name)
58+
format!("{prefix}/{name}")
6059
};
6160
process_dir(&path, &new_prefix, code, pools);
6261
} else if name.ends_with(".nbt") {

pumpkin-world/src/block/state.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ impl RawBlockState {
1111

1212
#[inline]
1313
#[must_use]
14-
pub fn to_state(&self) -> &'static BlockState {
14+
pub const fn to_state(&self) -> &'static BlockState {
1515
BlockState::from_id(self.0)
1616
}
1717

1818
#[inline]
1919
#[must_use]
20-
pub fn to_block(&self) -> &'static Block {
20+
pub const fn to_block(&self) -> &'static Block {
2121
Block::from_state_id(self.0)
2222
}
2323

2424
#[inline]
2525
#[must_use]
26-
pub fn to_block_id(&self) -> u16 {
26+
pub const fn to_block_id(&self) -> u16 {
2727
Block::get_raw_id_from_state_id(self.0)
2828
}
2929
}

pumpkin-world/src/generation/noise/router/chunk_density_function.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct ChunkNoiseFunctionBuilderOptions {
161161
impl ChunkNoiseFunctionBuilderOptions {
162162
#[must_use]
163163
#[allow(clippy::too_many_arguments)]
164-
pub fn new(
164+
pub const fn new(
165165
horizontal_cell_block_count: usize,
166166
vertical_cell_block_count: usize,
167167
vertical_cell_count: usize,

pumpkin-world/src/generation/noise/router/density_function/beardifier.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub struct Beardifier {
114114
}
115115

116116
impl Beardifier {
117-
pub fn new(
117+
pub const fn new(
118118
structures: Vec<BeardifierStructure>,
119119
junctions: Vec<BeardifierJunction>,
120120
affected_box: Option<BlockBox>,

pumpkin-world/src/generation/noise/router/find_top_surface.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ impl FindTopSurface {
3434
}
3535

3636
#[must_use]
37-
pub fn density_index(&self) -> usize {
37+
pub const fn density_index(&self) -> usize {
3838
self.density_index
3939
}
4040

4141
#[must_use]
42-
pub fn upper_bound_index(&self) -> usize {
42+
pub const fn upper_bound_index(&self) -> usize {
4343
self.upper_bound_index
4444
}
4545

4646
#[must_use]
47-
pub fn cell_height(&self) -> i32 {
47+
pub const fn cell_height(&self) -> i32 {
4848
self.data.cell_height
4949
}
5050
}

pumpkin-world/src/generation/noise/router/proto_noise_router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ impl ProtoNoiseRouters {
458458
} => {
459459
let mut min_value = f64::INFINITY;
460460
let mut max_value = f64::NEG_INFINITY;
461-
for &idx in functions_indices.iter() {
461+
for &idx in *functions_indices {
462462
let min = stack[idx].min();
463463
let max = stack[idx].max();
464464
if min < min_value {

pumpkin-world/src/generation/proto_chunk.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ impl ProtoChunk {
348348
}
349349

350350
#[must_use]
351-
pub fn get_top_y(&self, heightmap: &HeightMap, x: i32, z: i32) -> i32 {
351+
pub const fn get_top_y(&self, heightmap: &HeightMap, x: i32, z: i32) -> i32 {
352352
match heightmap {
353353
HeightMap::WorldSurfaceWg => self.top_block_height_exclusive(x, z),
354354
HeightMap::WorldSurface => self.top_block_height_exclusive(x, z),
@@ -395,15 +395,15 @@ impl ProtoChunk {
395395
}
396396

397397
#[inline]
398-
fn local_pos_to_block_index(&self, x: i32, y: i32, z: i32) -> usize {
398+
const fn local_pos_to_block_index(&self, x: i32, y: i32, z: i32) -> usize {
399399
self.height() as usize * CHUNK_DIM as usize * x as usize
400400
+ CHUNK_DIM as usize * y as usize
401401
+ z as usize
402402
}
403403

404404
#[inline]
405405
#[must_use]
406-
pub fn local_biome_pos_to_biome_index(&self, x: i32, y: i32, z: i32) -> usize {
406+
pub const fn local_biome_pos_to_biome_index(&self, x: i32, y: i32, z: i32) -> usize {
407407
let biome_height = self.height() as usize >> 2;
408408
biome_height * biome_coords::from_block(CHUNK_DIM as i32) as usize * x as usize
409409
+ biome_coords::from_block(CHUNK_DIM as i32) as usize * y as usize

0 commit comments

Comments
 (0)