Skip to content
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

Closed
wants to merge 16 commits into from
Closed

Implement player abilities packet #432

wants to merge 16 commits into from

Conversation

TheVeryStarlk
Copy link
Contributor

No description provided.

Comment on lines 5 to 13
[Flags]
public enum PlayerAbility
{
None = 0x00,
Invulnerable = 0x01,
Flying = 0x02,
AllowFlying = 0x04,
CreativeMode = 0x08
}
Copy link
Member

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

Copy link
Contributor Author

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; }
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +17 to +54
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);
}
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Member

@Tides Tides Feb 27, 2024

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 🤨

Copy link
Member

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
@TheVeryStarlk
Copy link
Contributor Author

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.
cc: @Tides

@TheVeryStarlk TheVeryStarlk deleted the playerAbilitiesPacket branch February 27, 2024 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants