Add: Basic Combat
This commit is contained in:
1 parent
c2bde2f73e
commit
9fc86e260b
15 files changed
+163
-55
No files matched your search
@@ -27,8 +27,8 @@ use pumpkin_protocol::{
|
||||
handshake::SHandShake,
|
||||
login::{SEncryptionResponse, SLoginAcknowledged, SLoginPluginResponse, SLoginStart},
|
||||
play::{
|
||||
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SPlayerCommand,
|
||||
SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
|
||||
SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||
},
|
||||
status::{SPingRequest, SStatusRequest},
|
||||
},
|
||||
@@ -159,6 +159,8 @@ impl Client {
|
||||
}
|
||||
|
||||
pub fn set_gamemode(&mut self, gamemode: GameMode) {
|
||||
let player = self.player.as_mut().unwrap();
|
||||
player.gamemode = gamemode;
|
||||
self.send_packet(&CGameEvent::new(3, gamemode.to_f32().unwrap()));
|
||||
}
|
||||
|
||||
@@ -282,6 +284,9 @@ impl Client {
|
||||
server,
|
||||
SClientInformationPlay::read(bytebuf).unwrap(),
|
||||
),
|
||||
SInteract::PACKET_ID => {
|
||||
self.handle_interact(server, SInteract::read(bytebuf).unwrap());
|
||||
}
|
||||
_ => log::error!("Failed to handle player packet id {}", packet.id.0),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
use num_traits::FromPrimitive;
|
||||
use pumpkin_entity::EntityId;
|
||||
use pumpkin_inventory::WindowType;
|
||||
use pumpkin_protocol::{
|
||||
client::play::{
|
||||
Animation, CEntityAnimation, CHeadRot, COpenScreen, CUpdateEntityPos, CUpdateEntityPosRot,
|
||||
CUpdateEntityRot,
|
||||
Animation, CEntityAnimation, CHeadRot, CHurtAnimation, COpenScreen, CUpdateEntityPos,
|
||||
CUpdateEntityPosRot, CUpdateEntityRot,
|
||||
},
|
||||
server::play::{
|
||||
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SPlayerCommand,
|
||||
SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||
SChatCommand, SChatMessage, SClientInformationPlay, SConfirmTeleport, SInteract,
|
||||
SPlayerCommand, SPlayerPosition, SPlayerPositionRotation, SPlayerRotation, SSwingArm,
|
||||
},
|
||||
VarInt,
|
||||
};
|
||||
@@ -15,7 +16,7 @@ use pumpkin_text::TextComponent;
|
||||
|
||||
use crate::{
|
||||
commands::{handle_command, CommandSender},
|
||||
entity::player::{ChatMode, Hand},
|
||||
entity::player::{ChatMode, GameMode, Hand},
|
||||
server::Server,
|
||||
util::math::wrap_degrees,
|
||||
};
|
||||
@@ -256,4 +257,24 @@ impl Client {
|
||||
server_listing: client_information.server_listing,
|
||||
});
|
||||
}
|
||||
|
||||
pub fn handle_interact(&mut self, server: &mut Server, interact: SInteract) {
|
||||
// TODO: do validation and stuff
|
||||
let config = &server.advanced_config.pvp;
|
||||
if config.enabled {
|
||||
let attacked_client = server.get_by_entityid(self, interact.entity_id.0 as EntityId);
|
||||
if let Some(client) = attacked_client {
|
||||
if config.protect_creative
|
||||
&& client.player.as_ref().unwrap().gamemode == GameMode::Creative
|
||||
{
|
||||
return;
|
||||
}
|
||||
drop(client);
|
||||
if config.hurt_animation {
|
||||
// todo
|
||||
server.broadcast_packet(self, &CHurtAnimation::new(interact.entity_id, 10.0))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user