Something

This commit is contained in:
Bruno Rybársky 2024-12-23 08:46:49 +01:00
parent a6a7a94c20
commit 9e86b56442
Signed by: BRNSystems
GPG Key ID: 6C9206A821C70598
2 changed files with 33 additions and 2 deletions

@ -380,7 +380,7 @@ func handleRequest(conn net.Conn) {
break
}
// Handle block entity query logic here
player.queryBlockEntityTag(transactionID, position)
//player.queryBlockEntityTag(transactionID, position)
case 0x02: // Change Difficulty
difficulty, err := packetData.ReadByte()
@ -403,7 +403,8 @@ func handleRequest(conn net.Conn) {
break
}
// Acknowledge message logic here
player.acknowledgeMessage(messageCount)
messageCount = messageCount
//player.acknowledgeMessage(messageCount)
case 0x04, 0x05: // Chat Command & Signed Chat Command
command, err := receiveString(packetData)

@ -503,6 +503,36 @@ type ItemStack struct {
MaxCount int32
}
// WriteToBuffer serializes the ItemStack to a bytes.Buffer
func (i *ItemStack) WriteToBuffer(buf *bytes.Buffer) error {
// Add Item Count as VarInt
addVarint(buf, i.Count)
// Add optional fields only if Count > 0
if i.Count > 0 {
// Add ItemID as VarInt
addVarint(buf, i.ItemID)
// Add Number of components to add as VarInt
addVarint(buf, int32(len(i.ComponentsToAdd)))
for k, v := range i.ComponentsToAdd {
addVarint(buf, k)
// Customize based on an actual type of 'v'
if strVal, ok := v.(string); ok {
addVarint(buf, int32(len(strVal)))
addString(buf, strVal)
}
}
// Add Number of components to remove as VarInt
addVarint(buf, int32(len(i.ComponentsToRemove)))
for _, v := range i.ComponentsToRemove {
addVarint(buf, v)
}
}
return nil
}
func (slot *ItemStack) IsEmpty() bool {
return slot.Count == 0
}