Skip to content

Commit

Permalink
Minior Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Nov 3, 2024
1 parent 1842e8e commit 8db277f
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 154 deletions.
2 changes: 1 addition & 1 deletion extractor/src/main/kotlin/de/snowii/extractor/Extractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Extractor : ModInitializer {
Recipes(),
Particles(),
SyncedRegistries(),
Packet(),
Packets(),
Screens(),
Items(),
Blocks(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.minecraft.network.state.*
import net.minecraft.server.MinecraftServer


class Packet : Extractor.Extractor {
class Packets : Extractor.Extractor {
override fun fileName(): String {
return "packets.json"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Recipes : Extractor.Extractor {

recipeJson.addProperty("name", recipeRaw.id.value.toString())
val recipe: Recipe<*> = recipeRaw.value()
recipeJson.addProperty("category", recipe.group)
recipeJson.addProperty("group", recipe.group)
recipeJson.addProperty("type", recipe.type.toString())
val placementArray = JsonArray()
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-inventory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use open_container::OpenContainer;

/// https://wiki.vg/Inventory
#[derive(Debug, ToPrimitive, FromPrimitive, Clone, Copy, Eq, PartialEq)]
#[repr(u16)]
#[repr(u8)]
pub enum WindowType {
// not used
Generic9x1 = screen!("minecraft:generic_9x1"),
Expand Down
4 changes: 0 additions & 4 deletions pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ mod packet;
#[proc_macro_attribute]
pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();

let name = &ast.ident;

let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();

let input: proc_macro2::TokenStream = packet::packet_clientbound(input);
Expand All @@ -28,9 +26,7 @@ pub fn client_packet(input: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn server_packet(input: TokenStream, item: TokenStream) -> TokenStream {
let ast: syn::DeriveInput = syn::parse(item.clone()).unwrap();

let name = &ast.ident;

let (impl_generics, ty_generics, _) = ast.generics.split_for_impl();

let input: proc_macro2::TokenStream = packet::packet_serverbound(input);
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-macros/src/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ use serde::Deserialize;
#[derive(Deserialize)]
pub struct Screen {
name: String,
id: u16,
id: u8,
}

static SCREENS: LazyLock<HashMap<String, u16>> = LazyLock::new(|| {
static SCREENS: LazyLock<HashMap<String, u8>> = LazyLock::new(|| {
serde_json::from_str::<Vec<Screen>>(include_str!("../../assets/screens.json"))
.expect("Could not parse screens.json registry.")
.into_iter()
Expand Down
80 changes: 0 additions & 80 deletions pumpkin-protocol/README.md

This file was deleted.

5 changes: 0 additions & 5 deletions pumpkin-registry/README.md

This file was deleted.

17 changes: 0 additions & 17 deletions pumpkin-world/README.md

This file was deleted.

12 changes: 6 additions & 6 deletions pumpkin-world/src/cylindrical_chunk_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use pumpkin_core::math::vector2::Vector2;
#[derive(Debug, PartialEq)]
pub struct Cylindrical {
pub center: Vector2<i32>,
pub view_distance: i32,
pub view_distance: u8,
}

impl Cylindrical {
pub fn new(center: Vector2<i32>, view_distance: i32) -> Self {
pub fn new(center: Vector2<i32>, view_distance: u8) -> Self {
Self {
center,
view_distance,
Expand Down Expand Up @@ -45,19 +45,19 @@ impl Cylindrical {
}

fn left(&self) -> i32 {
self.center.x - self.view_distance - 1
self.center.x - self.view_distance as i32 - 1
}

fn bottom(&self) -> i32 {
self.center.z - self.view_distance - 1
self.center.z - self.view_distance as i32 - 1
}

fn right(&self) -> i32 {
self.center.x + self.view_distance + 1
self.center.x + self.view_distance as i32 + 1
}

fn top(&self) -> i32 {
self.center.z + self.view_distance + 1
self.center.z + self.view_distance as i32 + 1
}

fn is_within_distance(&self, x: i32, z: i32) -> bool {
Expand Down
36 changes: 16 additions & 20 deletions pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use pumpkin_protocol::{
status::CPingResponse,
},
server::{
config::{SAcknowledgeFinishConfig, SClientInformationConfig, SKnownPacks, SPluginMessage},
config::{SClientInformationConfig, SKnownPacks, SPluginMessage},
handshake::SHandShake,
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
status::{SStatusPingRequest, SStatusRequest},
login::{SEncryptionResponse, SLoginPluginResponse, SLoginStart},
status::SStatusPingRequest,
},
ConnectionState, KnownPack, CURRENT_MC_PROTOCOL,
};
Expand Down Expand Up @@ -55,14 +55,14 @@ impl Client {
}
}

pub async fn handle_status_request(&self, server: &Server, _status_request: SStatusRequest) {
log::debug!("Handling status request for id");
pub async fn handle_status_request(&self, server: &Server) {
log::debug!("Handling status request");
let status = server.get_status();
self.send_packet(&status.lock().await.get_status()).await;
}

pub async fn handle_ping_request(&self, ping_request: SStatusPingRequest) {
log::debug!("Handling ping request for id");
log::debug!("Handling ping request");
self.send_packet(&CPingResponse::new(ping_request.payload))
.await;
self.close();
Expand Down Expand Up @@ -147,7 +147,7 @@ impl Client {
server: &Server,
encryption_response: SEncryptionResponse,
) {
log::debug!("Handling encryption for id");
log::debug!("Handling encryption");
let shared_secret = server.decrypt(&encryption_response.shared_secret).unwrap();

if let Err(error) = self.set_encryption(Some(&shared_secret)).await {
Expand Down Expand Up @@ -254,7 +254,7 @@ impl Client {
}

pub async fn handle_plugin_response(&self, plugin_response: SLoginPluginResponse) {
log::debug!("Handling plugin for id");
log::debug!("Handling plugin");
let velocity_config = &ADVANCED_CONFIG.proxy.velocity;
if velocity_config.enabled {
let mut address = self.address.lock().await;
Expand All @@ -273,12 +273,8 @@ impl Client {
}
}

pub async fn handle_login_acknowledged(
&self,
server: &Server,
_login_acknowledged: SLoginAcknowledged,
) {
log::debug!("Handling login acknowledged for id");
pub async fn handle_login_acknowledged(&self, server: &Server) {
log::debug!("Handling login acknowledged");
self.connection_state.store(ConnectionState::Config);
self.send_packet(&server.get_branding()).await;

Expand Down Expand Up @@ -315,14 +311,14 @@ impl Client {
&self,
client_information: SClientInformationConfig,
) {
log::debug!("Handling client settings for id");
log::debug!("Handling client settings");
if let (Some(main_hand), Some(chat_mode)) = (
Hand::from_i32(client_information.main_hand.into()),
ChatMode::from_i32(client_information.chat_mode.into()),
) {
*self.config.lock().await = Some(PlayerConfig {
locale: client_information.locale,
view_distance: client_information.view_distance,
view_distance: client_information.view_distance as u8,
chat_mode,
chat_colors: client_information.chat_colors,
skin_parts: client_information.skin_parts,
Expand All @@ -336,7 +332,7 @@ impl Client {
}

pub async fn handle_plugin_message(&self, plugin_message: SPluginMessage) {
log::debug!("Handling plugin message for id");
log::debug!("Handling plugin message");
if plugin_message.channel.starts_with("minecraft:brand")
|| plugin_message.channel.starts_with("MC|Brand")
{
Expand All @@ -349,7 +345,7 @@ impl Client {
}

pub async fn handle_known_packs(&self, server: &Server, _config_acknowledged: SKnownPacks) {
log::debug!("Handling known packs for id");
log::debug!("Handling known packs");
for registry in &server.cached_registry {
self.send_packet(&CRegistryData::new(
&registry.registry_id,
Expand All @@ -363,8 +359,8 @@ impl Client {
self.send_packet(&CFinishConfig::new()).await;
}

pub fn handle_config_acknowledged(&self, _config_acknowledged: &SAcknowledgeFinishConfig) {
log::debug!("Handling config acknowledge for id");
pub fn handle_config_acknowledged(&self) {
log::debug!("Handling config acknowledge");
self.connection_state.store(ConnectionState::Play);
self.make_player
.store(true, std::sync::atomic::Ordering::Relaxed);
Expand Down
1 change: 1 addition & 0 deletions pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl Player {
}

let click = Click::new(
// TODO: This is very bad
packet
.mode
.0
Expand Down
10 changes: 4 additions & 6 deletions pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct PlayerConfig {
/// The player's preferred language.
pub locale: String, // 16
/// The maximum distance at which chunks are rendered.
pub view_distance: i8,
pub view_distance: u8,
/// The player's chat mode settings
pub chat_mode: ChatMode,
/// Whether chat colors are enabled.
Expand Down Expand Up @@ -392,8 +392,7 @@ impl Client {
let bytebuf = &mut packet.bytebuf;
match packet.id.0 {
SStatusRequest::PACKET_ID => {
self.handle_status_request(server, SStatusRequest::read(bytebuf)?)
.await;
self.handle_status_request(server).await;
}
SStatusPingRequest::PACKET_ID => {
self.handle_ping_request(SStatusPingRequest::read(bytebuf)?)
Expand Down Expand Up @@ -432,8 +431,7 @@ impl Client {
.await;
}
SLoginAcknowledged::PACKET_ID => {
self.handle_login_acknowledged(server, SLoginAcknowledged::read(bytebuf)?)
.await;
self.handle_login_acknowledged(server).await;
}
_ => {
log::error!(
Expand Down Expand Up @@ -463,7 +461,7 @@ impl Client {
.await;
}
SAcknowledgeFinishConfig::PACKET_ID => {
self.handle_config_acknowledged(&SAcknowledgeFinishConfig::read(bytebuf)?);
self.handle_config_acknowledged();
}
SKnownPacks::PACKET_ID => {
self.handle_known_packs(server, SKnownPacks::read(bytebuf)?)
Expand Down
5 changes: 3 additions & 2 deletions pumpkin/src/client/player_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ impl Player {
) {
*self.config.lock().await = PlayerConfig {
locale: client_information.locale,
view_distance: client_information.view_distance,
// A Negative view distance would be impossible and make no sense right ?, Mojang: Lets make is signed :D
view_distance: client_information.view_distance as u8,
chat_mode,
chat_colors: client_information.chat_colors,
skin_parts: client_information.skin_parts,
Expand All @@ -398,7 +399,7 @@ impl Player {
}
}

pub async fn handle_interact(&self, _: &Server, interact: SInteract) {
pub async fn handle_interact(&self, interact: SInteract) {
let sneaking = interact.sneaking;
let entity = &self.living_entity.entity;
if entity.sneaking.load(std::sync::atomic::Ordering::Relaxed) != sneaking {
Expand Down
Loading

0 comments on commit 8db277f

Please sign in to comment.