Skip to content

Commit

Permalink
Some refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Dec 23, 2024
1 parent fd66790 commit 3dae300
Show file tree
Hide file tree
Showing 72 changed files with 333 additions and 284 deletions.
7 changes: 7 additions & 0 deletions pumpkin-protocol/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ name = "pumpkin-protocol"
version.workspace = true
edition.workspace = true

[features]
default = ["packets", "query"]
packets = ["serverbound", "clientbound"]
serverbound = []
clientbound = []
query = []

[dependencies]
pumpkin-nbt = { path = "../pumpkin-nbt" }
pumpkin-config = { path = "../pumpkin-config" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::slot::Slot;
use crate::codec::slot::Slot;
use crate::VarInt;

use pumpkin_macros::client_packet;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/client/play/c_set_container_slot.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::slot::Slot;
use crate::codec::slot::Slot;
use crate::VarInt;

use pumpkin_macros::client_packet;
Expand Down
1 change: 1 addition & 0 deletions pumpkin-protocol/src/codec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use thiserror::Error;

pub mod bit_set;
pub mod identifier;
pub mod slot;
pub mod var_int;
pub mod var_long;

Expand Down
File renamed without changes.
4 changes: 3 additions & 1 deletion pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ use pumpkin_core::text::{style::Style, TextComponent};
use serde::{Deserialize, Serialize};

pub mod bytebuf;
#[cfg(feature = "clientbound")]
pub mod client;
pub mod codec;
pub mod packet_decoder;
pub mod packet_encoder;
#[cfg(feature = "query")]
pub mod query;
#[cfg(feature = "serverbound")]
pub mod server;
pub mod slot;

/// To current Minecraft protocol
/// Don't forget to change this when porting
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/packet_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Cipher = cfb8::Decryptor<aes::Aes128>;
pub struct PacketDecoder {
buf: BytesMut,
decompress_buf: BytesMut,
compression: bool,
cipher: Option<Cipher>,
compression: bool,
decompressor: Decompressor,
}

Expand All @@ -28,8 +28,8 @@ impl Default for PacketDecoder {
Self {
buf: BytesMut::new(),
decompress_buf: BytesMut::new(),
compression: false,
cipher: None,
compression: false,
decompressor: Decompressor::new(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/packet_encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type Cipher = cfb8::Encryptor<aes::Aes128>;
pub struct PacketEncoder {
buf: BytesMut,
compress_buf: Vec<u8>,
compression_threshold: Option<u32>,
cipher: Option<Cipher>,
compression_threshold: Option<u32>,
compressor: Compressor, // Reuse the compressor for all packets
}

Expand All @@ -27,8 +27,8 @@ impl Default for PacketEncoder {
Self {
buf: BytesMut::with_capacity(1024),
compress_buf: Vec::with_capacity(1024),
compression_threshold: None,
cipher: None,
compression_threshold: None,
compressor: Compressor::new(CompressionLvl::fastest()), // init compressor with fastest compression level
}
}
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/server/config/s_cookie_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
#[server_packet("config:cookie_response")]
/// Response to a Cookie Request (configuration) from the server.
/// The Notchian (vanilla) server only accepts responses of up to 5 kiB in size.
pub struct SCookieResponse {
pub struct SConfigCookieResponse {
pub key: Identifier,
pub has_payload: bool,
pub payload_length: Option<VarInt>,
Expand All @@ -20,7 +20,7 @@ pub struct SCookieResponse {

const MAX_PAYLOAD_SIZE: i32 = 5120;

impl ServerPacket for SCookieResponse {
impl ServerPacket for SConfigCookieResponse {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
let key = bytebuf.try_get_identifer()?;
let has_payload = bytebuf.try_get_bool()?;
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/server/login/s_cookie_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use serde::de;
#[server_packet("login:cookie_response")]
/// Response to a Cookie Request (login) from the server.
/// The Notchian server only accepts responses of up to 5 kiB in size.
pub struct SCookieResponse {
pub struct SLoginCookieResponse {
pub key: Identifier,
pub has_payload: bool,
pub payload_length: Option<VarInt>,
Expand All @@ -19,7 +19,7 @@ pub struct SCookieResponse {

const MAX_PAYLOAD_SIZE: i32 = 5120;

impl ServerPacket for SCookieResponse {
impl ServerPacket for SLoginCookieResponse {
fn read(bytebuf: &mut impl Buf) -> Result<Self, ReadingError> {
let key = bytebuf.try_get_identifer()?;
let has_payload = bytebuf.try_get_bool()?;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/server/play/s_click_container.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::slot::Slot;
use crate::codec::slot::Slot;
use crate::VarInt;
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/server/play/s_set_creative_slot.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pumpkin_macros::server_packet;

use crate::slot::Slot;
use crate::codec::slot::Slot;

#[derive(serde::Deserialize, Debug)]
#[server_packet("play:set_creative_mode_slot")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ mod test {

use crate::{
block::BlockState,
world_gen::{
generation::{
chunk_noise::{
BlockStateSampler, ChunkNoiseDensityFunctions, ChunkNoiseGenerator,
ChunkNoiseState, LAVA_BLOCK, WATER_BLOCK,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ use pumpkin_macros::block_state;

use crate::{
block::BlockState,
match_ref_implementations,
world_gen::{
generation::{
noise::{density::basic::WrapperType, lerp3},
section_coords,
},
match_ref_implementations,
};

use super::{
Expand Down Expand Up @@ -1379,7 +1379,7 @@ impl ChunkNoiseGenerator {
mod test {
use pumpkin_core::math::vector2::Vector2;

use crate::world_gen::{
use crate::generation::{
aquifer_sampler::{FluidLevel, FluidLevelSampler},
generation_shapes::GenerationShape,
noise::{config::NoiseConfig, router::OVERWORLD_NOISE_ROUTER},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::biome::Biome;
use crate::block::block_state::BlockState;
use crate::chunk::{ChunkBlocks, ChunkData};
use crate::coordinates::{BlockCoordinates, ChunkRelativeBlockCoordinates, XZBlockCoordinates};
use crate::world_gen::Seed;
use crate::generation::Seed;

pub trait GeneratorInit {
fn new(seed: Seed) -> Self;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
biome::Biome,
chunk::ChunkBlocks,
coordinates::{BlockCoordinates, ChunkRelativeBlockCoordinates, XZBlockCoordinates},
world_gen::{
generation::{
generator::{BiomeGenerator, GeneratorInit, PerlinTerrainGenerator},
generic_generator::GenericGenerator,
Seed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{
biome::Biome,
block::block_state::BlockState,
coordinates::XZBlockCoordinates,
world_gen::{
generation::{
generator::{BiomeGenerator, GeneratorInit, TerrainGenerator},
generic_generator::GenericGenerator,
Seed,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
coordinates::{
ChunkRelativeBlockCoordinates, ChunkRelativeXZBlockCoordinates, XZBlockCoordinates,
},
world_gen::{
generation::{
generator::{BiomeGenerator, GeneratorInit, TerrainGenerator},
proto_chunk::ProtoChunk,
Seed, WorldGenerator,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ mod test {
};

use crate::{
read_data_from_file,
world_gen::noise::{
generation::noise::{
config::NoiseConfig,
density::{
built_in_density_function::{
Expand All @@ -165,6 +164,7 @@ mod test {
},
router::OVERWORLD_NOISE_ROUTER,
},
read_data_from_file,
};

use super::LegacyChunkNoiseVisitor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{hash::Hash, marker::PhantomData};

use crate::{match_ref_implementations, world_gen::noise::clamped_map};
use crate::{generation::noise::clamped_map, match_ref_implementations};

use super::{
component_functions::{
Expand Down Expand Up @@ -419,10 +419,10 @@ mod test {
use std::{fs, path::Path};

use crate::{
read_data_from_file,
world_gen::noise::density::{
generation::noise::density::{
component_functions::ImmutableComponentFunctionImpl, NoisePos, UnblendedNoisePos,
},
read_data_from_file,
};

use super::YClampedFunction;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::marker::PhantomData;

use crate::world_gen::blender::BlenderImpl;
use crate::generation::blender::BlenderImpl;

use super::{
component_functions::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -953,7 +953,7 @@ mod test {

use pumpkin_core::random::{legacy_rand::LegacyRand, RandomDeriver, RandomImpl};

use crate::world_gen::noise::{
use crate::generation::noise::{
built_in_noise_params,
density::{
noise::{InternalNoise, NoiseFunction},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use pumpkin_core::random::{legacy_rand::LegacyRand, RandomImpl};

use crate::world_gen::noise::simplex::SimplexNoiseSampler;
use crate::generation::noise::simplex::SimplexNoiseSampler;

use super::{
component_functions::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use component_functions::{
use enum_dispatch::enum_dispatch;
use noise::{InternalNoise, NoiseFunction};

use crate::world_gen::{blender::Blender, chunk_noise::ChunkNoisePos};
use crate::generation::{blender::Blender, chunk_noise::ChunkNoisePos};

use super::perlin::DoublePerlinNoiseParameters;

Expand Down Expand Up @@ -76,8 +76,8 @@ pub trait NoisePosImpl {
pub mod built_in_density_function {
use std::sync::{Arc, LazyLock};

use crate::world_gen::noise::built_in_noise_params::{self};
use crate::world_gen::positions::{MAX_COLUMN_HEIGHT, MIN_HEIGHT};
use crate::generation::noise::built_in_noise_params::{self};
use crate::generation::positions::{MAX_COLUMN_HEIGHT, MIN_HEIGHT};

use pumpkin_core::math::floor_div;

Expand Down Expand Up @@ -879,7 +879,7 @@ mod test {
legacy_rand::LegacyRand, RandomDeriver, RandomDeriverImpl, RandomImpl,
};

use crate::world_gen::noise::{
use crate::generation::noise::{
built_in_noise_params,
density::{built_in_density_function::*, NoisePos, UnblendedNoisePos},
perlin::DoublePerlinNoiseSampler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::{marker::PhantomData, sync::Arc};
use pumpkin_core::random::{xoroshiro128::Xoroshiro, RandomGenerator, RandomImpl};

use crate::{
match_ref_implementations,
world_gen::noise::{
generation::noise::{
clamped_lerp,
perlin::{DoublePerlinNoiseParameters, DoublePerlinNoiseSampler, OctavePerlinNoiseSampler},
},
match_ref_implementations,
};

use super::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{marker::PhantomData, sync::Arc};

use enum_dispatch::enum_dispatch;

use crate::world_gen::noise::lerp;
use crate::generation::noise::lerp;

use super::{
component_functions::{
Expand Down Expand Up @@ -744,7 +744,7 @@ mod test {

use pumpkin_core::random::{legacy_rand::LegacyRand, RandomDeriver, RandomImpl};

use crate::world_gen::noise::density::{
use crate::generation::noise::density::{
built_in_density_function::CONTINENTS_OVERWORLD,
component_functions::{ComponentReference, NoEnvironment, SharedComponentReference},
test::{FakeEnvironment, OwnedConverter, TestConverter},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// From da java

use crate::world_gen::noise::density::peaks_valleys_noise;
use crate::world_gen::noise::lerp;
use crate::generation::noise::density::peaks_valleys_noise;
use crate::generation::noise::lerp;

use super::component_functions::SharedComponentReference;
use super::spline::{FloatAmplifier, ImmutableSpline, ImmutableSplineRef, SplineBuilder};
Expand Down Expand Up @@ -523,7 +523,7 @@ pub fn create_jaggedness_spline(
mod test {
use pumpkin_core::random::{legacy_rand::LegacyRand, RandomDeriver, RandomImpl};

use crate::world_gen::noise::density::{
use crate::generation::noise::density::{
built_in_density_function::{
CONTINENTS_OVERWORLD, EROSION_OVERWORLD, RIDGES_FOLDED_OVERWORLD, RIDGES_OVERWORLD,
},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ mod double_perlin_noise_sampler_test {
legacy_rand::LegacyRand, xoroshiro128::Xoroshiro, RandomGenerator, RandomImpl,
};

use crate::world_gen::noise::perlin::{DoublePerlinNoiseParameters, DoublePerlinNoiseSampler};
use crate::generation::noise::perlin::{DoublePerlinNoiseParameters, DoublePerlinNoiseSampler};

#[test]
fn sample_legacy() {
Expand Down Expand Up @@ -760,7 +760,7 @@ mod perlin_noise_sampler_test {
random::{xoroshiro128::Xoroshiro, RandomDeriverImpl, RandomGenerator, RandomImpl},
};

use crate::{read_data_from_file, world_gen::noise::perlin::PerlinNoiseSampler};
use crate::{generation::noise::perlin::PerlinNoiseSampler, read_data_from_file};

use super::OctavePerlinNoiseSampler;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::sync::{Arc, LazyLock};

use crate::world_gen::{
use crate::generation::{
noise::density::{
apply_blend_density,
basic::RangeFunction,
Expand Down Expand Up @@ -476,8 +476,7 @@ mod test {
};

use crate::{
read_data_from_file,
world_gen::noise::{
generation::noise::{
config::LegacyChunkNoiseVisitor,
density::{
built_in_density_function::{EROSION_OVERWORLD, SLOPED_CHEESE_OVERWORLD},
Expand All @@ -491,6 +490,7 @@ mod test {
perlin::DoublePerlinNoiseSampler,
router::OVERWORLD_NOISE_ROUTER,
},
read_data_from_file,
};

use super::{apply_surface_slides, create_caves};
Expand Down
Loading

0 comments on commit 3dae300

Please sign in to comment.