Skip to content

Commit

Permalink
Fixed bug with missing palette entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ReCore-sys committed Jan 30, 2025
1 parent d3f5bec commit f0da9e7
Show file tree
Hide file tree
Showing 10 changed files with 313 additions and 187 deletions.
1 change: 0 additions & 1 deletion scripts/new_packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ def to_camel_case(string) -> str:

packet_id = input(
"Packet ID (formatted as snake case, look on https://minecraft.wiki/w/Minecraft_Wiki:Projects/wiki.vg_merge/Protocol if you need to get the id): ")
packet_id = packet_id[:-2] + packet_id[-2:].upper()

with open(f"{packets_dir}/{packet_type}/{to_snake_case(packet_name)}.rs", "x") as f:
if packet_type == "incoming":
Expand Down
2 changes: 1 addition & 1 deletion src/bin/src/packet_handlers/login_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ async fn handle_ack_finish_configuration(
CollisionBounds {
x_offset_start: -0.3,
x_offset_end: 0.3,
y_offset_start: -0.5,
y_offset_start: 0.0,
y_offset_end: 1.5,
z_offset_start: -0.3,
z_offset_end: 0.3,
Expand Down
7 changes: 0 additions & 7 deletions src/bin/src/systems/chunk_sender.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,6 @@ impl System for ChunkSenderSystem {
trace!("Got chunk_recv 3 for sender");
for (key, chunk) in chunk_recv.needed_chunks.iter_mut() {
if let Some(chunk) = chunk {
chunk.sections.iter_mut().for_each(|section| {
// if random::<u8>() < 25 {
if let Err(e) = section.block_states.resize(8) {
error!("Error resizing block states: {:?}", e);
}
// }
});
to_drop.push(key.clone());
match ChunkAndLightData::from_chunk(&chunk.clone()) {
Ok(packet) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/chunk_batch_ack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl IncomingPacket for ChunkBatchAck {
let pos = state.universe.get_mut::<Position>(conn_id)?;
let head_block = state
.world
.get_block(pos.x as i32, pos.y as i32 - 1, pos.z as i32, "overworld")
.get_block_and_fetch(pos.x as i32, pos.y as i32 - 1, pos.z as i32, "overworld")
.await?;
if head_block.name == "minecraft:air" {
move_to_spawn = false;
Expand Down
23 changes: 18 additions & 5 deletions src/lib/net/src/packets/incoming/place_block.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use crate::connection::StreamWriter;
use crate::packets::outgoing::block_change_ack::BlockChangeAck;
use crate::packets::IncomingPacket;
use crate::NetResult;
use ferrumc_core::chunks::chunk_receiver::ChunkReceiver;
use ferrumc_core::collisions::bounds::CollisionBounds;
use ferrumc_core::transform::position::Position;
use ferrumc_macros::{packet, NetDecode};
use ferrumc_net_codec::encode::NetEncodeOpts;
use ferrumc_net_codec::net_types::network_position::NetworkPosition;
use ferrumc_net_codec::net_types::var_int::VarInt;
use ferrumc_state::ServerState;
Expand All @@ -25,14 +28,14 @@ pub struct PlaceBlock {
}

impl IncomingPacket for PlaceBlock {
async fn handle(self, _conn_id: usize, state: Arc<ServerState>) -> NetResult<()> {
async fn handle(self, conn_id: usize, state: Arc<ServerState>) -> NetResult<()> {
match self.hand.val {
0 => {
debug!("Placing block at {:?}", self.position);
let block_clicked = state
.clone()
.world
.get_block(
.get_block_and_fetch(
self.position.x,
self.position.y as i32,
self.position.z,
Expand Down Expand Up @@ -74,12 +77,22 @@ impl IncomingPacket for PlaceBlock {
})
};
if does_collide {
debug!("Block placement collided with entity");
trace!("Block placement collided with entity");
return Ok(());
}
{
if let Ok(mut conn) = state.universe.get_mut::<StreamWriter>(conn_id) {
let packet = BlockChangeAck {
sequence: self.sequence.clone(),
};
conn.send_packet(packet, &NetEncodeOpts::WithLength)?;
} else {
debug!("Could not get StreamWriter");
}
}
state
.world
.set_block(
.set_block_and_fetch(
x,
y as i32,
z,
Expand All @@ -96,7 +109,7 @@ impl IncomingPacket for PlaceBlock {
}
}
1 => {
debug!("Offhand block placement not implemented");
trace!("Offhand block placement not implemented");
}
_ => {
debug!("Invalid hand");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/net/src/packets/incoming/player_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl IncomingPacket for PlayerAction {
0 => {
state
.world
.set_block(
.set_block_and_fetch(
self.location.x,
self.location.y as i32,
self.location.z,
Expand Down
9 changes: 9 additions & 0 deletions src/lib/net/src/packets/outgoing/block_change_ack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use ferrumc_macros::{packet, NetEncode};
use ferrumc_net_codec::net_types::var_int::VarInt;
use std::io::Write;

#[derive(NetEncode)]
#[packet(packet_id = "block_changed_ack", state = "play")]
pub struct BlockChangeAck {
pub sequence: VarInt,
}
2 changes: 2 additions & 0 deletions src/lib/net/src/packets/outgoing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ pub mod update_entity_position;
pub mod update_entity_position_and_rotation;
pub mod update_entity_rotation;
// -----------------------------

pub mod block_change_ack;
Loading

0 comments on commit f0da9e7

Please sign in to comment.