Skip to content

Commit

Permalink
wip!
Browse files Browse the repository at this point in the history
  • Loading branch information
DaPigGuy committed Jun 10, 2024
1 parent 6b07440 commit af7deca
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions server/session/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,31 +398,33 @@ func (s *Session) SendGameMode(mode world.GameMode) {

// sendAbilities sends the abilities of the Controllable entity of the session to the client.
func (s *Session) sendAbilities() {
mode, abilities := s.c.GameMode(), uint32(0)
abilities := uint32(0) | protocol.AbilityMayFly | protocol.AbilityFlying | protocol.AbilityNoClip | protocol.AbilityInvulnerable | protocol.AbilityInstantBuild | protocol.AbilityBuild | protocol.AbilityMine | protocol.AbilityDoorsAndSwitches | protocol.AbilityOpenContainers | protocol.AbilityAttackPlayers | protocol.AbilityAttackMobs
mode, abilitiesValues := s.c.GameMode(), uint32(0)

if mode.AllowsFlying() {
abilities |= protocol.AbilityMayFly
abilitiesValues |= protocol.AbilityMayFly
if s.c.Flying() {
abilities |= protocol.AbilityFlying
abilitiesValues |= protocol.AbilityFlying
}
}
if !mode.HasCollision() {
abilities |= protocol.AbilityNoClip
abilitiesValues |= protocol.AbilityNoClip
defer s.c.StartFlying()
// If the client is currently on the ground and turned to spectator mode, it will be unable to sprint during
// flight. In order to allow this, we force the client to be flying through a MovePlayer packet.
s.ViewEntityTeleport(s.c, s.c.Position())
}
if !mode.AllowsTakingDamage() {
abilities |= protocol.AbilityInvulnerable
abilitiesValues |= protocol.AbilityInvulnerable
}
if mode.CreativeInventory() {
abilities |= protocol.AbilityInstantBuild
abilitiesValues |= protocol.AbilityInstantBuild
}
if mode.AllowsEditing() {
abilities |= protocol.AbilityBuild | protocol.AbilityMine
abilitiesValues |= protocol.AbilityBuild | protocol.AbilityMine
}
if mode.AllowsInteraction() {
abilities |= protocol.AbilityDoorsAndSwitches | protocol.AbilityOpenContainers | protocol.AbilityAttackPlayers | protocol.AbilityAttackMobs
abilitiesValues |= protocol.AbilityDoorsAndSwitches | protocol.AbilityOpenContainers | protocol.AbilityAttackPlayers | protocol.AbilityAttackMobs
}
s.writePacket(&packet.UpdateAbilities{AbilityData: protocol.AbilityData{
EntityUniqueID: selfEntityRuntimeID,
Expand All @@ -431,8 +433,8 @@ func (s *Session) sendAbilities() {
Layers: []protocol.AbilityLayer{ // TODO: Support customization of fly and walk speeds.
{
Type: protocol.AbilityLayerTypeBase,
Abilities: protocol.AbilityCount - 1,
Values: abilities,
Abilities: abilities,
Values: abilitiesValues,
FlySpeed: protocol.AbilityBaseFlySpeed,
WalkSpeed: protocol.AbilityBaseWalkSpeed,
},
Expand Down

0 comments on commit af7deca

Please sign in to comment.