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

Add some client and serverbound packets #236

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Obsidian/Net/MinecraftStream.Writing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,4 +1194,28 @@ public void WriteParticleData(ParticleData value)
break;
}
}

[WriteMethod]
public void WriteMatchItem(MatchItem matchItem)
{
WriteString(matchItem.Match);
WriteBoolean(matchItem.HasTooltip);
if (matchItem.HasTooltip && matchItem.Tooltip is not null) WriteChat(matchItem.Tooltip);
}

[WriteMethod]
public async void WriteTrade(Trade trade)
{
await WriteSlotAsync(trade.InputItem1);
await WriteSlotAsync(trade.OutputItem);
WriteBoolean(trade.HasSecondItem);
if (trade.HasSecondItem && trade.InputItem2 is not null) await WriteSlotAsync(trade.InputItem2);
WriteBoolean(trade.TradeDisabled);
WriteInt(trade.NumberOfTradeUses);
WriteInt(trade.MaximumNumberOfTradeUses);
WriteInt(trade.Xp);
WriteInt(trade.SpecialPrice);
WriteFloat(trade.PriceMultiplier);
WriteInt(trade.Demand);
}
}
18 changes: 18 additions & 0 deletions Obsidian/Net/Packets/Login/LoginPluginRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Login;

public partial class LoginPluginRequest : IClientboundPacket
{
[Field(0), VarLength]
public int MessageId { get; set; }

[Field(1)]
public string Channel { get; set; }

[Field(2)]
public byte[] Data { get; set; }

public int Id => 0x04;

}
20 changes: 20 additions & 0 deletions Obsidian/Net/Packets/Login/LoginPluginResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Login;

public partial class LoginPluginResponse : IServerboundPacket
{
[Field(0), VarLength]
public int MessageId { get; set; }

[Field(1)]
public bool Successful { get; set; }

[Field(2)]
public byte[] Data { get; set; }

public int Id => 0x04;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
15 changes: 15 additions & 0 deletions Obsidian/Net/Packets/Play/Clientbound/MatchItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace Obsidian.Net.Packets.Play.Clientbound;

public class MatchItem
{
public MatchItem(string match, bool hasTooltip, ChatMessage? tooltip = null)
{
Match = match;
HasTooltip = hasTooltip;
Tooltip = tooltip;
}

public string Match { get; init; }
public bool HasTooltip { get; init; }
public ChatMessage? Tooltip { get; init; }
}
33 changes: 33 additions & 0 deletions Obsidian/Net/Packets/Play/Clientbound/TabCompleteResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Clientbound;

public partial class TabCompleteResponse : IClientboundPacket
{
public TabCompleteResponse(int transactionId, int start, int length, int count, List<MatchItem> matches)
{
TransactionId = transactionId;
Start = start;
Length = length;
Count = count;
Matches = matches;
}

[Field(0), VarLength]
public int TransactionId { get; init; }

[Field(1), VarLength]
public int Start { get; init; }

[Field(2), VarLength]
public int Length { get; init; }

[Field(3), VarLength]
public int Count { get; init; }

[Field(4)]
public List<MatchItem> Matches { get; init; }

public int Id => 0x11;

}
42 changes: 42 additions & 0 deletions Obsidian/Net/Packets/Play/Clientbound/Trade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
namespace Obsidian.Net.Packets.Play.Clientbound;

public class Trade
{
public Trade(ItemStack inputItem1, ItemStack outputItem, bool hasSecondItem, ItemStack inputItem2, bool tradeDisabled, int numberOfTradeUses, int maximumNumberOfTradeUses, int xp, int specialPrice, float priceMultiplier, int demand) : base()
{
InputItem1 = inputItem1;
OutputItem = outputItem;
HasSecondItem = hasSecondItem;
InputItem2 = inputItem2;
TradeDisabled = tradeDisabled;
NumberOfTradeUses = numberOfTradeUses;
MaximumNumberOfTradeUses = maximumNumberOfTradeUses;
Xp = xp;
SpecialPrice = specialPrice;
PriceMultiplier = priceMultiplier;
Demand = demand;
}

public ItemStack InputItem1 { get; init; }

public ItemStack OutputItem { get; init; }

public bool HasSecondItem { get; init; }

public ItemStack InputItem2 { get; init; }

public bool TradeDisabled { get; init; }

public int NumberOfTradeUses { get; init; }

public int MaximumNumberOfTradeUses { get; init; }

public int Xp { get; init; }

public int SpecialPrice { get; init; }

public float PriceMultiplier { get; init; }

public int Demand { get; init; }

}
42 changes: 42 additions & 0 deletions Obsidian/Net/Packets/Play/Clientbound/TradeList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Clientbound;

public partial class TradeList : IClientboundPacket
{
public TradeList(int windowId, sbyte size, List<Trade> trades, VillagerLevel villagerLevel, int experience, bool isRegularVillager, bool canRestock)
{
WindowId = windowId;
Size = size;
Trades = trades;
VillagerLevel = villagerLevel;
Experience = experience;
IsRegularVillager = isRegularVillager;
CanRestock = canRestock;
}

[Field(0), VarLength]
public int WindowId { get; init; }

[Field(1)]
public sbyte Size { get; init; }

[Field(2)]
public List<Trade> Trades { get; init; }

[Field(3), ActualType(typeof(int)), VarLength]
public VillagerLevel VillagerLevel { get; init; }

[Field(4), VarLength]
public int Experience { get; init; }

[Field(5)]
public bool IsRegularVillager { get; init; }

[Field(6)]
public bool CanRestock { get; init; }


public int Id => 0x28;

}
10 changes: 10 additions & 0 deletions Obsidian/Net/Packets/Play/Clientbound/VillagerLevel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Obsidian.Net.Packets.Play.Clientbound;

public enum VillagerLevel
{
Novice = 1,
Apprentice = 2,
Journeyman = 3,
Expert = 4,
Master = 5
}
26 changes: 26 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/EditBook.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class EditBook : IServerboundPacket
{
[Field(0), VarLength, ActualType(typeof(int))]
public Hand Hand { get; set; }

[Field(1), VarLength]
public int Count { get; set; }

[Field(2), ActualType(typeof(string))]
public List<string> Entries { get; set; }

[Field(3)]
public bool HasTitle { get; set; }

[Field(4)]
public string Title { get; set; }

public int Id => 0x15;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
20 changes: 20 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/GenerateStructure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class GenerateStructure : IServerboundPacket
{
[Field(0)]
public VectorF Position { get; set; }

[Field(1), VarLength]
public int Levels { get; set; }

[Field(2)]
public bool KeepJigsaws { get; set; }

public int Id => 0x0E;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
14 changes: 14 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/LockDifficulty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class LockDifficulty : IServerboundPacket
{
[Field(0)]
public bool Locked { get; set; }

public int Id => 0x10;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
14 changes: 14 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/PlayerMovement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class PlayerMovement : IServerboundPacket
{
[Field(0)]
public bool OnGround { get; set; }

public int Id => 0x14;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
17 changes: 17 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/QueryEntityNbt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class QueryEntityNbt : IServerboundPacket
{
[Field(0), VarLength]
public int TransactionId { get; set; }

[Field(1), VarLength]
public int EntityId { get; set; }

public int Id => 0x15;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
9 changes: 9 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/RecipeBookType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Obsidian.Net.Packets.Play.Serverbound;

public enum RecipeBookType
{
Crafting,
Furnace,
BlastFurnace,
Smoker
}
14 changes: 14 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/SelectTrade.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class SelectTrade : IServerboundPacket
{
[Field(0), VarLength]
public int SelectedSlot { get; set; }

public int Id => 0x23;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
17 changes: 17 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/SetBeaconEffect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class SetBeaconEffect : IServerboundPacket
{
[Field(0), VarLength]
public int PrimaryEffect { get; set; }

[Field(1), VarLength]
public int SecondaryEffect { get; set; }

public int Id => 0x24;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
21 changes: 21 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/SetRecipeBookState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class SetRecipeBookState : IServerboundPacket
{
[Field(0), VarLength, ActualType(typeof(int))]
public RecipeBookType BookId { get; private set; }

[Field(1)]
public bool BookOpen { get; private set; }

[Field(2)]
public bool FilterActive { get; private set; }

public int Id => 0x1E;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;

}
14 changes: 14 additions & 0 deletions Obsidian/Net/Packets/Play/Serverbound/Spectate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Obsidian.Entities;
using Obsidian.Serialization.Attributes;

namespace Obsidian.Net.Packets.Play.Serverbound;

public partial class Spectate : IServerboundPacket
{
[Field(0)]
public Guid TargetPlayer { get; set; }

public int Id => 0x2D;

public ValueTask HandleAsync(Server server, Player player) => ValueTask.CompletedTask;
}
Loading