Added Player inventory (WIP)
This commit is contained in:
1 parent
d6fb4ed121
commit
391d5cbcfc
13 files changed
+79
-10
No files matched your search
@@ -29,7 +29,7 @@ use pumpkin_protocol::{
|
||||
play::{
|
||||
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
|
||||
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation,
|
||||
SPlayerRotation, SSwingArm, SUseItemOn,
|
||||
SPlayerRotation, SSetHeldItem, SSwingArm, SUseItemOn,
|
||||
},
|
||||
status::{SPingRequest, SStatusRequest},
|
||||
},
|
||||
@@ -301,6 +301,9 @@ impl Client {
|
||||
SUseItemOn::PACKET_ID => {
|
||||
self.handle_use_item_on(server, SUseItemOn::read(bytebuf).unwrap())
|
||||
}
|
||||
SSetHeldItem::PACKET_ID => {
|
||||
self.handle_set_held_item(server, SSetHeldItem::read(bytebuf).unwrap())
|
||||
}
|
||||
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ use pumpkin_protocol::{
|
||||
server::play::{
|
||||
Action, SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
|
||||
SPlayerAction, SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation,
|
||||
SSwingArm, SUseItemOn,
|
||||
SSetHeldItem, SSwingArm, SUseItemOn,
|
||||
},
|
||||
};
|
||||
use pumpkin_text::TextComponent;
|
||||
@@ -320,4 +320,13 @@ impl Client {
|
||||
location.y += 2;
|
||||
server.broadcast_packet(self, &CBlockUpdate::new(location, 11.into()));
|
||||
}
|
||||
|
||||
pub fn handle_set_held_item(&mut self, _server: &mut Server, held: SSetHeldItem) {
|
||||
let slot = held.slot;
|
||||
if !(0..=8).contains(&slot) {
|
||||
self.kick("Invalid held slot")
|
||||
}
|
||||
let player = self.player.as_mut().unwrap();
|
||||
player.inventory.set_selected(slot);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ use std::str::FromStr;
|
||||
|
||||
use num_derive::{FromPrimitive, ToPrimitive};
|
||||
use pumpkin_entity::{entity_type::EntityType, Entity, EntityId};
|
||||
use pumpkin_inventory::player::PlayerInventory;
|
||||
use pumpkin_protocol::VarInt;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -15,6 +16,7 @@ pub struct Player {
|
||||
pub health: f32,
|
||||
pub food: i32,
|
||||
pub food_saturation: f32,
|
||||
pub inventory: PlayerInventory,
|
||||
|
||||
// Client side value, Should be not trusted
|
||||
pub on_ground: bool,
|
||||
@@ -22,6 +24,7 @@ pub struct Player {
|
||||
pub sneaking: bool,
|
||||
pub sprinting: bool,
|
||||
|
||||
// TODO: prbly should put this into an Living Entitiy or something
|
||||
pub velocity: Vec3,
|
||||
|
||||
// Current awaiting teleport id, None if did not teleport
|
||||
@@ -41,6 +44,7 @@ impl Player {
|
||||
food: 20,
|
||||
food_saturation: 20.0,
|
||||
velocity: Vec3::new(0.0, 0.0, 0.0),
|
||||
inventory: PlayerInventory::new(),
|
||||
gamemode,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user