2024-09-11 20:58:24 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using MinecraftClient.Inventory;
|
|
|
|
|
using MinecraftClient.Inventory.ItemPalettes;
|
|
|
|
|
using MinecraftClient.Protocol.Handlers.StructuredComponents.Core;
|
|
|
|
|
using MinecraftClient.Protocol.Message;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Protocol.Handlers.StructuredComponents.Components._1_20_6;
|
|
|
|
|
|
2024-10-05 13:37:52 +02:00
|
|
|
public class WrittenBlookContentComponent(DataTypes dataTypes, ItemPalette itemPalette, SubComponentRegistry subComponentRegistry) : StructuredComponent(dataTypes, itemPalette, subComponentRegistry)
|
2024-09-11 20:58:24 +02:00
|
|
|
{
|
|
|
|
|
public string RawTitle { get; set; } = null!;
|
|
|
|
|
public bool HasFilteredTitle { get; set; }
|
|
|
|
|
public string? FilteredTitle { get; set; }
|
|
|
|
|
public string Author { get; set; } = null!;
|
|
|
|
|
public int Generation { get; set; }
|
|
|
|
|
public int NumberOfPages { get; set; }
|
|
|
|
|
public List<BookPage> Pages { get; set; } = [];
|
|
|
|
|
public bool Resolved { get; set; }
|
|
|
|
|
|
|
|
|
|
public override void Parse(Queue<byte> data)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
RawTitle = DataTypes.ReadNextString(data);
|
|
|
|
|
HasFilteredTitle = DataTypes.ReadNextBool(data);
|
2024-09-11 20:58:24 +02:00
|
|
|
|
|
|
|
|
if (HasFilteredTitle)
|
2026-03-24 01:16:05 +00:00
|
|
|
FilteredTitle = DataTypes.ReadNextString(data);
|
2024-09-11 20:58:24 +02:00
|
|
|
|
2026-03-24 01:16:05 +00:00
|
|
|
Author = DataTypes.ReadNextString(data);
|
|
|
|
|
Generation = DataTypes.ReadNextVarInt(data);
|
|
|
|
|
NumberOfPages = DataTypes.ReadNextVarInt(data);
|
2024-09-11 20:58:24 +02:00
|
|
|
|
|
|
|
|
for (var i = 0; i < NumberOfPages; i++)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
var rawContentNbt = DataTypes.ReadNextNbt(data);
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
var rawContent = ChatParser.ParseText(rawContentNbt);
|
2026-03-24 01:16:05 +00:00
|
|
|
var hasFilteredContent = DataTypes.ReadNextBool(data);
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
Dictionary<string, object>? filteredContentNbt = null;
|
|
|
|
|
string? filteredContent = null;
|
2024-09-11 20:58:24 +02:00
|
|
|
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
if (hasFilteredContent)
|
|
|
|
|
{
|
2026-03-24 01:16:05 +00:00
|
|
|
filteredContentNbt = DataTypes.ReadNextNbt(data);
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
filteredContent = ChatParser.ParseText(filteredContentNbt);
|
|
|
|
|
}
|
2024-09-11 20:58:24 +02:00
|
|
|
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
Pages.Add(new BookPage(rawContent, hasFilteredContent, filteredContent, rawContentNbt, filteredContentNbt));
|
2024-09-11 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
|
2026-03-24 01:16:05 +00:00
|
|
|
Resolved = DataTypes.ReadNextBool(data);
|
2024-09-11 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Queue<byte> Serialize()
|
|
|
|
|
{
|
|
|
|
|
var data = new List<byte>();
|
|
|
|
|
|
|
|
|
|
data.AddRange(DataTypes.GetString(RawTitle));
|
|
|
|
|
data.AddRange(DataTypes.GetBool(HasFilteredTitle));
|
|
|
|
|
|
|
|
|
|
if (HasFilteredTitle)
|
|
|
|
|
{
|
|
|
|
|
if(FilteredTitle is null)
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
throw new InvalidOperationException("Can not serialize WrittenBookContentComponent because HasFilteredTitle is true but FilteredTitle is null!");
|
2024-09-11 20:58:24 +02:00
|
|
|
|
|
|
|
|
data.AddRange(DataTypes.GetString(FilteredTitle));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.AddRange(DataTypes.GetString(Author));
|
|
|
|
|
data.AddRange(DataTypes.GetVarInt(Generation));
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
data.AddRange(DataTypes.GetVarInt(Pages.Count));
|
2024-09-11 20:58:24 +02:00
|
|
|
|
|
|
|
|
foreach (var page in Pages)
|
|
|
|
|
{
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
data.AddRange(DataTypes.GetNbt(page.RawContentNbt));
|
2024-09-11 20:58:24 +02:00
|
|
|
data.AddRange(DataTypes.GetBool(page.HasFilteredContent));
|
|
|
|
|
|
|
|
|
|
if (page.HasFilteredContent)
|
fix: StructuredComponents batch 1 audit — TrimComponent, ProfileComponent, WrittenBookContent, and NBT serialization
Audited all 8 high-complexity structured components against official 1.20.6
decompiled STREAM_CODEC definitions. Found and fixed bugs in 3 components
plus a systemic NBT serialization issue:
TrimComponent (ID 35):
- Serialize had TrimPatternType and ShowInTooltip incorrectly nested inside
the TrimMaterialType==0 branch; moved them outside to match Parse logic
- Description fields (TrimMaterial.description, TrimPattern.description) were
read/written as String but official codec uses ComponentSerialization
(NBT Tag format); changed to ReadNextNbt/GetNbt
ProfileComponent (ID 46):
- Serialize was missing the HasUniqueId Bool prefix before UUID
- Serialize only wrote properties when count > 0 but omitted the VarInt count
prefix entirely when empty; now always writes VarInt count
WrittenBookContentComponent (ID 34):
- Page content uses Filterable<Component> where Component is NBT-encoded via
ComponentSerialization.STREAM_CODEC, not plain String; changed Parse to use
ReadNextNbt and Serialize to use GetNbt
- Added RawContentNbt/FilteredContentNbt fields to BookPage record for
round-trip NBT preservation
- Removed unnecessary ChatParser.ParseText on title (it's a plain string)
DataTypes.GetNbt:
- Added TAG_String root support for 1.20.4+ (chat components like "Page 1"
are encoded as TAG_String, not TAG_Compound)
- Fixed root name handling: versions >= 1.20.2 omit the root compound name,
but GetNbt was unconditionally writing it
Components confirmed correct (no changes needed):
- FoodComponentComponent (ID 20), ToolComponent (ID 22),
InstrumentComponent (ID 40), PotionContentsComponent (ID 31),
AttributeModifiersComponent (ID 12)
Made-with: Cursor
2026-03-20 00:09:05 +08:00
|
|
|
data.AddRange(DataTypes.GetNbt(page.FilteredContentNbt));
|
2024-09-11 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
data.AddRange(DataTypes.GetBool(Resolved));
|
|
|
|
|
return new Queue<byte>(data);
|
|
|
|
|
}
|
|
|
|
|
}
|