-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement player abilities packet #432
Implement player abilities packet #432
Conversation
This reverts commit 9b134d9.
[Flags] | ||
public enum PlayerAbility | ||
{ | ||
None = 0x00, | ||
Invulnerable = 0x01, | ||
Flying = 0x02, | ||
AllowFlying = 0x04, | ||
CreativeMode = 0x08 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in the API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
} | ||
} | ||
|
||
public PlayerAbility Abilities { get; internal set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be made accessible through the api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
public PlayerAbility Abilities { get; set; } = PlayerAbility.None; | ||
|
||
public float FlyingSpeed { get; set; } = 0.05F; | ||
|
||
public float FieldOfViewModifier { get; set; } = 0.1F; | ||
|
||
public int Id { get; } | ||
|
||
public PlayerAbilitiesPacket(bool toClient) | ||
{ | ||
Id = toClient ? 0x36 : 0x20; | ||
} | ||
|
||
public void Serialize(MinecraftStream stream) | ||
{ | ||
using var packetStream = new MinecraftStream(); | ||
packetStream.WriteByte((byte)Abilities); | ||
packetStream.WriteFloat(FlyingSpeed); | ||
packetStream.WriteFloat(FieldOfViewModifier); | ||
|
||
stream.Lock.Wait(); | ||
stream.WriteVarInt(Id.GetVarIntLength() + (int)packetStream.Length); | ||
stream.WriteVarInt(Id); | ||
packetStream.Position = 0; | ||
packetStream.CopyTo(stream); | ||
stream.Lock.Release(); | ||
} | ||
|
||
public void Populate(MinecraftStream stream) | ||
{ | ||
Abilities = (PlayerAbility) stream.ReadByte(); | ||
} | ||
|
||
public void Populate(byte[] data) | ||
{ | ||
using var stream = new MinecraftStream(data); | ||
Populate(stream); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the Field attribute on the packet properties so the source generators can write Serialize and Populate methods for you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently the SG does not like it because it does not have a parameter-less constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Packet SG doesn't use/look at constructors 🤨
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to make sure the class is set to partial ^ ^
…erAbilitiesPacket # Conflicts: # Obsidian/Entities/Player.cs # Obsidian/Net/Packets/Play/Clientbound/PlayerAbilitiesPacket.cs
I will close this PR to fix the weird Git issues I am having (to not spam this PR), then re-open it again later. |
No description provided.