Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryntet authored Aug 24, 2024
2 parents 52943f6 + c7f15de commit 67dd35e
Show file tree
Hide file tree
Showing 26 changed files with 497 additions and 356 deletions.
12 changes: 12 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# A whitelist of files that should be included into docker
# Put an exclaimation mark before everything to include

# Ignore everything
*

# Allow the source code folders
!/pumpkin*/

# Dependencies
!Cargo.lock
!Cargo.toml
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM rust:1-alpine3.19 AS builder
ENV RUSTFLAGS="-C target-feature=-crt-static -C target-cpu=native"
RUN apk add --no-cache musl-dev
WORKDIR /pumpkin
COPY . /pumpkin
RUN cargo build --release
RUN strip target/release/pumpkin

FROM alpine:3.19
WORKDIR /pumpkin
RUN apk add --no-cache libgcc
COPY --from=builder /pumpkin/target/release/pumpkin /pumpkin/pumpkin
ENTRYPOINT ["/pumpkin/pumpkin"]
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ Then run:
RUSTFLAGS="-C target-cpu=native" cargo run --release
```

### Docker

Experimental Docker support is available.
The image is currently not published anywhere, but you can use the following command to build it:

```shell
docker build . -t pumpkin
```

To run it use the following command:

```shell
docker run --rm -v "./world:/pumpkin/world" pumpkin
```

## Contributions

Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md)
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/play/c_entity_velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ use crate::VarInt;
#[derive(Serialize)]
#[packet(0x5A)]
pub struct CEntityVelocity<'a> {
entitiy_id: &'a VarInt,
entity_id: &'a VarInt,
velocity_x: i16,
velocity_y: i16,
velocity_z: i16,
}

impl<'a> CEntityVelocity<'a> {
pub fn new(entitiy_id: &'a VarInt, velocity_x: f32, velocity_y: f32, velocity_z: f32) -> Self {
pub fn new(entity_id: &'a VarInt, velocity_x: f32, velocity_y: f32, velocity_z: f32) -> Self {
Self {
entitiy_id,
entity_id,
velocity_x: (velocity_x.clamp(-3.9, 3.9) * 8000.0) as i16,
velocity_y: (velocity_y.clamp(-3.9, 3.9) * 8000.0) as i16,
velocity_z: (velocity_z.clamp(-3.9, 3.9) * 8000.0) as i16,
Expand Down
6 changes: 3 additions & 3 deletions pumpkin-protocol/src/client/play/c_hurt_animation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use crate::VarInt;
#[derive(Serialize)]
#[packet(0x24)]
pub struct CHurtAnimation<'a> {
entitiy_id: &'a VarInt,
entity_id: &'a VarInt,
yaw: f32,
}

impl<'a> CHurtAnimation<'a> {
pub fn new(entitiy_id: &'a VarInt, yaw: f32) -> Self {
Self { entitiy_id, yaw }
pub fn new(entity_id: &'a VarInt, yaw: f32) -> Self {
Self { entity_id, yaw }
}
}
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/client/play/c_remove_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::VarInt;
#[packet(0x42)]
pub struct CRemoveEntities<'a> {
count: VarInt,
entitiy_ids: &'a [VarInt],
entity_ids: &'a [VarInt],
}

impl<'a> CRemoveEntities<'a> {
pub fn new(entitiy_ids: &'a [VarInt]) -> Self {
pub fn new(entity_ids: &'a [VarInt]) -> Self {
Self {
count: VarInt(entitiy_ids.len() as i32),
entitiy_ids,
count: VarInt(entity_ids.len() as i32),
entity_ids,
}
}
}
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/client/play/c_sync_player_position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::VarInt;

#[derive(Serialize)]
#[packet(0x40)]
pub struct CSyncPlayerPostion {
pub struct CSyncPlayerPosition {
x: f64,
y: f64,
z: f64,
Expand All @@ -15,7 +15,7 @@ pub struct CSyncPlayerPostion {
teleport_id: VarInt,
}

impl CSyncPlayerPostion {
impl CSyncPlayerPosition {
pub fn new(
x: f64,
y: f64,
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/client/play/c_system_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ use serde::Serialize;

#[derive(Serialize)]
#[packet(0x6C)]
pub struct CSystemChatMessge<'a> {
pub struct CSystemChatMessage<'a> {
content: TextComponent<'a>,
overlay: bool,
}

impl<'a> CSystemChatMessge<'a> {
impl<'a> CSystemChatMessage<'a> {
pub fn new(content: TextComponent<'a>, overlay: bool) -> Self {
Self { content, overlay }
}
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/client/play/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ mod c_subtitle;
mod c_sync_player_position;
mod c_system_chat_message;
mod c_unload_chunk;
mod c_update_entitiy_pos_rot;
mod c_update_entity_pos;
mod c_update_entity_pos_rot;
mod c_update_entity_rot;
mod c_worldevent;
mod player_action;
Expand Down Expand Up @@ -74,8 +74,8 @@ pub use c_subtitle::*;
pub use c_sync_player_position::*;
pub use c_system_chat_message::*;
pub use c_unload_chunk::*;
pub use c_update_entitiy_pos_rot::*;
pub use c_update_entity_pos::*;
pub use c_update_entity_pos_rot::*;
pub use c_update_entity_rot::*;
pub use c_worldevent::*;
pub use player_action::*;
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ pub enum PacketError {
#[error("packet length is out of bounds")]
OutOfBounds,
#[error("malformed packet length VarInt")]
MailformedLength,
MalformedLength,
}

#[derive(Debug, PartialEq)]
Expand Down
2 changes: 1 addition & 1 deletion pumpkin-protocol/src/packet_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl PacketDecoder {
let packet_len = match VarInt::decode_partial(&mut r) {
Ok(len) => len,
Err(VarIntDecodeError::Incomplete) => return Ok(None),
Err(VarIntDecodeError::TooLarge) => Err(PacketError::MailformedLength)?,
Err(VarIntDecodeError::TooLarge) => Err(PacketError::MalformedLength)?,
};

if !(0..=MAX_PACKET_SIZE).contains(&packet_len) {
Expand Down
4 changes: 2 additions & 2 deletions pumpkin-protocol/src/server/play/s_chat_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct SChatMessage {
pub timestamp: i64,
pub salt: i64,
pub signature: Option<Bytes>,
pub messagee_count: VarInt,
pub message_count: VarInt,
pub acknowledged: FixedBitSet,
}

Expand All @@ -25,7 +25,7 @@ impl ServerPacket for SChatMessage {
timestamp: bytebuf.get_i64(),
salt: bytebuf.get_i64(),
signature: bytebuf.get_option(|v| v.copy_to_bytes(256)),
messagee_count: bytebuf.get_var_int(),
message_count: bytebuf.get_var_int(),
acknowledged: bytebuf.get_fixed_bitset(20),
})
}
Expand Down
8 changes: 4 additions & 4 deletions pumpkin-protocol/src/server/play/s_player_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{bytebuf::DeserializerError, ServerPacket, VarInt};

#[packet(0x25)]
pub struct SPlayerCommand {
pub entitiy_id: VarInt,
pub entity_id: VarInt,
pub action: VarInt,
pub jump_boost: VarInt,
}
Expand All @@ -16,16 +16,16 @@ pub enum Action {
LeaveBed,
StartSprinting,
StopSprinting,
StartHourseJump,
StopHourseJump,
StartHorseJump,
StopHorseJump,
OpenVehicleInventory,
StartFlyingElytra,
}

impl ServerPacket for SPlayerCommand {
fn read(bytebuf: &mut crate::bytebuf::ByteBuffer) -> Result<Self, DeserializerError> {
Ok(Self {
entitiy_id: bytebuf.get_var_int(),
entity_id: bytebuf.get_var_int(),
action: bytebuf.get_var_int(),
jump_boost: bytebuf.get_var_int(),
})
Expand Down
2 changes: 2 additions & 0 deletions pumpkin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ num-traits = "0.2"
num-derive = "0.4"
num-bigint = "0.4.6"

ctrlc = "3.4"

# encryption
rsa = "0.9.6"
rsa-der = "0.3.0"
Expand Down
5 changes: 2 additions & 3 deletions pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,11 @@ impl Client {

pub async fn handle_config_acknowledged(
&mut self,
server: &mut Server,
_server: &mut Server,
_config_acknowledged: SAcknowledgeFinishConfig,
) {
dbg!("config acknowledged");
self.connection_state = ConnectionState::Play;
// generate a player
server.spawn_player(self).await;
self.make_player = true;
}
}
16 changes: 8 additions & 8 deletions pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ use pumpkin_protocol::client::play::{
use pumpkin_protocol::slot::Slot;
use pumpkin_world::item::Item;

impl super::Client {
use crate::entity::player::Player;

impl Player {
pub fn open_container(
&mut self,
window_type: WindowType,
Expand All @@ -26,7 +28,7 @@ impl super::Client {
.unwrap())
.into();
let title = TextComponent::text(window_title.unwrap_or(window_type.default_title()));
self.send_packet(&COpenScreen::new(
self.client.send_packet(&COpenScreen::new(
(window_type.clone() as u8 + 1).into(),
menu_protocol_id,
title,
Expand All @@ -40,14 +42,12 @@ impl super::Client {
items: Option<Vec<Option<&'a Item>>>,
carried_item: Option<&'a Item>,
) {
let player = self.player.as_ref().unwrap();

let slots: Vec<Slot> = {
if let Some(mut items) = items {
items.extend(player.inventory.slots());
items.extend(self.inventory.slots());
items
} else {
player.inventory.slots()
self.inventory.slots()
}
.into_iter()
.map(|item| {
Expand All @@ -69,7 +69,7 @@ impl super::Client {
};
let packet =
CSetContainerContent::new(window_type as u8 + 1, 0.into(), &slots, &carried_item);
self.send_packet(&packet);
self.client.send_packet(&packet);
}

pub fn set_container_slot(
Expand All @@ -78,7 +78,7 @@ impl super::Client {
slot: usize,
item: Option<&Item>,
) {
self.send_packet(&CSetContainerSlot::new(
self.client.send_packet(&CSetContainerSlot::new(
window_type as i8,
0,
slot,
Expand Down
Loading

0 comments on commit 67dd35e

Please sign in to comment.