From c51313a9cc464f24ee487c62c36f85416d84935c Mon Sep 17 00:00:00 2001 From: Tnze Date: Sun, 28 Jul 2024 22:45:40 +0800 Subject: [PATCH] Add item DataComponent implements (part 2) --- level/component/components.go | 10 +++++ level/component/creativeslotlock.go | 4 +- level/component/damage.go | 18 +------- level/component/dyedcolor.go | 29 +++++++++++++ level/component/enchantmentglintoverride.go | 28 ++++++++++++ level/component/fireresistant.go | 22 ++++++++++ level/component/food.go | 47 +++++++++++++++++++++ level/component/hideadditionaltooltio.go | 4 +- level/component/hidetooltip.go | 4 +- level/component/intangibleprojectile.go | 22 ++++++++++ level/component/mapcolor.go | 15 +++++++ level/component/mapdecorations.go | 29 +++++++++++++ level/component/mapid.go | 14 ++++++ level/component/maxdamage.go | 18 +------- level/component/maxstacksize.go | 18 +------- level/component/repaircost.go | 18 +------- level/component/storedenchantments.go | 38 +++++++++++++++++ level/component/tool.go | 22 ++++++++++ 18 files changed, 287 insertions(+), 73 deletions(-) create mode 100644 level/component/dyedcolor.go create mode 100644 level/component/enchantmentglintoverride.go create mode 100644 level/component/fireresistant.go create mode 100644 level/component/food.go create mode 100644 level/component/intangibleprojectile.go create mode 100644 level/component/mapcolor.go create mode 100644 level/component/mapdecorations.go create mode 100644 level/component/mapid.go create mode 100644 level/component/storedenchantments.go create mode 100644 level/component/tool.go diff --git a/level/component/components.go b/level/component/components.go index 6fd93ed5..11eb6d5e 100644 --- a/level/component/components.go +++ b/level/component/components.go @@ -46,15 +46,25 @@ func NewComponent(id int32) DataComponent { case 17: return new(CreativeSlotLock) case 18: + return new(EnchantmentGlintOverride) case 19: + return new(IntangibleProjectile) case 20: + return new(Food) case 21: + return new(FireResistant) case 22: + return new(Tool) case 23: + return new(StoredEnchantments) case 24: + return new(DyedColor) case 25: + return new(MapColor) case 26: + return new(MapID) case 27: + return new(MapDecorations) case 28: case 29: case 30: diff --git a/level/component/creativeslotlock.go b/level/component/creativeslotlock.go index 67bd2e97..334f8289 100644 --- a/level/component/creativeslotlock.go +++ b/level/component/creativeslotlock.go @@ -1,8 +1,6 @@ package component -import ( - "io" -) +import "io" var _ DataComponent = (*CreativeSlotLock)(nil) diff --git a/level/component/damage.go b/level/component/damage.go index 9817821f..cbeed52b 100644 --- a/level/component/damage.go +++ b/level/component/damage.go @@ -1,28 +1,14 @@ package component -import ( - "io" - - pk "github.com/Tnze/go-mc/net/packet" -) +import pk "github.com/Tnze/go-mc/net/packet" var _ DataComponent = (*Damage)(nil) type Damage struct { - Damage pk.VarInt + pk.VarInt } // ID implements DataComponent. func (Damage) ID() string { return "minecraft:damage" } - -// ReadFrom implements DataComponent. -func (d *Damage) ReadFrom(r io.Reader) (n int64, err error) { - return d.Damage.ReadFrom(r) -} - -// WriteTo implements DataComponent. -func (d *Damage) WriteTo(w io.Writer) (n int64, err error) { - return d.Damage.WriteTo(w) -} diff --git a/level/component/dyedcolor.go b/level/component/dyedcolor.go new file mode 100644 index 00000000..7320f378 --- /dev/null +++ b/level/component/dyedcolor.go @@ -0,0 +1,29 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*DyedColor)(nil) + +type DyedColor struct { + RGB pk.Int + ShowInTooltip pk.Boolean +} + +// ID implements DataComponent. +func (DyedColor) ID() string { + return "minecraft:dyed_color" +} + +// ReadFrom implements DataComponent. +func (d *DyedColor) ReadFrom(r io.Reader) (n int64, err error) { + return pk.Tuple{&d.RGB, &d.ShowInTooltip}.ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (d *DyedColor) WriteTo(w io.Writer) (n int64, err error) { + return pk.Tuple{&d.RGB, &d.ShowInTooltip}.WriteTo(w) +} diff --git a/level/component/enchantmentglintoverride.go b/level/component/enchantmentglintoverride.go new file mode 100644 index 00000000..7f08dc28 --- /dev/null +++ b/level/component/enchantmentglintoverride.go @@ -0,0 +1,28 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*EnchantmentGlintOverride)(nil) + +type EnchantmentGlintOverride struct { + HasGlint pk.Boolean +} + +// ID implements DataComponent. +func (EnchantmentGlintOverride) ID() string { + return "minecraft:enchantment_glint_override" +} + +// ReadFrom implements DataComponent. +func (e *EnchantmentGlintOverride) ReadFrom(r io.Reader) (n int64, err error) { + return e.HasGlint.ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (e *EnchantmentGlintOverride) WriteTo(w io.Writer) (n int64, err error) { + return e.HasGlint.WriteTo(w) +} diff --git a/level/component/fireresistant.go b/level/component/fireresistant.go new file mode 100644 index 00000000..5f7e3776 --- /dev/null +++ b/level/component/fireresistant.go @@ -0,0 +1,22 @@ +package component + +import "io" + +var _ DataComponent = (*FireResistant)(nil) + +type FireResistant struct{} + +// ID implements DataComponent. +func (FireResistant) ID() string { + return "minecraft:fire_resistant" +} + +// ReadFrom implements DataComponent. +func (f *FireResistant) ReadFrom(r io.Reader) (n int64, err error) { + return 0, nil +} + +// WriteTo implements DataComponent. +func (f *FireResistant) WriteTo(w io.Writer) (n int64, err error) { + return 0, nil +} diff --git a/level/component/food.go b/level/component/food.go new file mode 100644 index 00000000..9caaa9c5 --- /dev/null +++ b/level/component/food.go @@ -0,0 +1,47 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*Food)(nil) + +type Food struct { + Nutrition pk.VarInt + Saturation pk.Float + CanAlwaysEat pk.Boolean + EatSeconds pk.Float + // TODO: using_converts_to + // TODO: effects +} + +// ID implements DataComponent. +func (Food) ID() string { + return "minecraft:food" +} + +// ReadFrom implements DataComponent. +func (f *Food) ReadFrom(r io.Reader) (n int64, err error) { + pk.Tuple{ + &f.Nutrition, + &f.Saturation, + &f.CanAlwaysEat, + &f.EatSeconds, + // TODO + }.ReadFrom(r) + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (f *Food) WriteTo(w io.Writer) (n int64, err error) { + pk.Tuple{ + &f.Nutrition, + &f.Saturation, + &f.CanAlwaysEat, + &f.EatSeconds, + // TODO + }.WriteTo(w) + panic("unimplemented") +} diff --git a/level/component/hideadditionaltooltio.go b/level/component/hideadditionaltooltio.go index da9c4eaa..30cc4d81 100644 --- a/level/component/hideadditionaltooltio.go +++ b/level/component/hideadditionaltooltio.go @@ -1,8 +1,6 @@ package component -import ( - "io" -) +import "io" var _ DataComponent = (*HideAdditionalTooptip)(nil) diff --git a/level/component/hidetooltip.go b/level/component/hidetooltip.go index c953dc66..b56c72e4 100644 --- a/level/component/hidetooltip.go +++ b/level/component/hidetooltip.go @@ -1,8 +1,6 @@ package component -import ( - "io" -) +import "io" var _ DataComponent = (*HideTooptip)(nil) diff --git a/level/component/intangibleprojectile.go b/level/component/intangibleprojectile.go new file mode 100644 index 00000000..5ae8b7c6 --- /dev/null +++ b/level/component/intangibleprojectile.go @@ -0,0 +1,22 @@ +package component + +import "io" + +var _ DataComponent = (*IntangibleProjectile)(nil) + +type IntangibleProjectile struct{} + +// ID implements DataComponent. +func (IntangibleProjectile) ID() string { + return "minecraft:intangible_projectile" +} + +// ReadFrom implements DataComponent. +func (i *IntangibleProjectile) ReadFrom(r io.Reader) (n int64, err error) { + return 0, nil +} + +// WriteTo implements DataComponent. +func (i *IntangibleProjectile) WriteTo(w io.Writer) (n int64, err error) { + return 0, nil +} diff --git a/level/component/mapcolor.go b/level/component/mapcolor.go new file mode 100644 index 00000000..cf6a7b14 --- /dev/null +++ b/level/component/mapcolor.go @@ -0,0 +1,15 @@ +package component + +import pk "github.com/Tnze/go-mc/net/packet" + +var _ DataComponent = (*MapColor)(nil) + +type MapColor struct { + // The RGB components of the color, encoded as an integer. + pk.Int +} + +// ID implements DataComponent. +func (MapColor) ID() string { + return "minecraft:map_color" +} diff --git a/level/component/mapdecorations.go b/level/component/mapdecorations.go new file mode 100644 index 00000000..e3090616 --- /dev/null +++ b/level/component/mapdecorations.go @@ -0,0 +1,29 @@ +package component + +import ( + "io" + + "github.com/Tnze/go-mc/nbt/dynbt" + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*MapDecorations)(nil) + +type MapDecorations struct { + dynbt.Value +} + +// ID implements DataComponent. +func (MapDecorations) ID() string { + return "minecraft:map_decorations" +} + +// ReadFrom implements DataComponent. +func (m *MapDecorations) ReadFrom(r io.Reader) (n int64, err error) { + return pk.NBT(&m.Value).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (m *MapDecorations) WriteTo(w io.Writer) (n int64, err error) { + return pk.NBT(&m.Value).WriteTo(w) +} diff --git a/level/component/mapid.go b/level/component/mapid.go new file mode 100644 index 00000000..9f4fab52 --- /dev/null +++ b/level/component/mapid.go @@ -0,0 +1,14 @@ +package component + +import pk "github.com/Tnze/go-mc/net/packet" + +var _ DataComponent = (*MapID)(nil) + +type MapID struct { + pk.VarInt +} + +// ID implements DataComponent. +func (MapID) ID() string { + return "minecraft:map_id" +} diff --git a/level/component/maxdamage.go b/level/component/maxdamage.go index 957fe061..38170ac8 100644 --- a/level/component/maxdamage.go +++ b/level/component/maxdamage.go @@ -1,28 +1,14 @@ package component -import ( - "io" - - pk "github.com/Tnze/go-mc/net/packet" -) +import pk "github.com/Tnze/go-mc/net/packet" var _ DataComponent = (*MaxDamage)(nil) type MaxDamage struct { - MaxDamage pk.VarInt + pk.VarInt } // ID implements DataComponent. func (MaxDamage) ID() string { return "minecraft:max_damage" } - -// ReadFrom implements DataComponent. -func (m *MaxDamage) ReadFrom(r io.Reader) (n int64, err error) { - return m.MaxDamage.ReadFrom(r) -} - -// WriteTo implements DataComponent. -func (m *MaxDamage) WriteTo(w io.Writer) (n int64, err error) { - return m.MaxDamage.WriteTo(w) -} diff --git a/level/component/maxstacksize.go b/level/component/maxstacksize.go index 0df95419..7aa94fe5 100644 --- a/level/component/maxstacksize.go +++ b/level/component/maxstacksize.go @@ -1,28 +1,14 @@ package component -import ( - "io" - - pk "github.com/Tnze/go-mc/net/packet" -) +import pk "github.com/Tnze/go-mc/net/packet" var _ DataComponent = (*MaxStackSize)(nil) type MaxStackSize struct { - MaxStackSize pk.VarInt + pk.VarInt } // ID implements DataComponent. func (MaxStackSize) ID() string { return "minecraft:max_stack_size" } - -// ReadFrom implements DataComponent. -func (m *MaxStackSize) ReadFrom(r io.Reader) (n int64, err error) { - return m.MaxStackSize.ReadFrom(r) -} - -// WriteTo implements DataComponent. -func (m *MaxStackSize) WriteTo(w io.Writer) (n int64, err error) { - return m.MaxStackSize.WriteTo(w) -} diff --git a/level/component/repaircost.go b/level/component/repaircost.go index edb14901..6225f7dc 100644 --- a/level/component/repaircost.go +++ b/level/component/repaircost.go @@ -1,28 +1,14 @@ package component -import ( - "io" - - pk "github.com/Tnze/go-mc/net/packet" -) +import pk "github.com/Tnze/go-mc/net/packet" var _ DataComponent = (*RepairCost)(nil) type RepairCost struct { - Cost pk.VarInt + pk.VarInt } // ID implements DataComponent. func (RepairCost) ID() string { return "minecraft:repair_cost" } - -// ReadFrom implements DataComponent. -func (r *RepairCost) ReadFrom(reader io.Reader) (n int64, err error) { - return r.Cost.ReadFrom(reader) -} - -// WriteTo implements DataComponent. -func (r *RepairCost) WriteTo(writer io.Writer) (n int64, err error) { - return r.Cost.WriteTo(writer) -} diff --git a/level/component/storedenchantments.go b/level/component/storedenchantments.go new file mode 100644 index 00000000..563248d4 --- /dev/null +++ b/level/component/storedenchantments.go @@ -0,0 +1,38 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*StoredEnchantments)(nil) + +type StoredEnchantments struct { + Enchantments []struct { + Type pk.VarInt + Level pk.VarInt + } + ShowInTooltip pk.Boolean +} + +// ID implements DataComponent. +func (StoredEnchantments) ID() string { + return "minecraft:stored_enchantments" +} + +// ReadFrom implements DataComponent. +func (s *StoredEnchantments) ReadFrom(r io.Reader) (n int64, err error) { + return pk.Tuple{ + pk.Array(&s.Enchantments), + &s.ShowInTooltip, + }.ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (s *StoredEnchantments) WriteTo(w io.Writer) (n int64, err error) { + return pk.Tuple{ + pk.Array(&s.Enchantments), + &s.ShowInTooltip, + }.WriteTo(w) +} diff --git a/level/component/tool.go b/level/component/tool.go new file mode 100644 index 00000000..c6bb8fdb --- /dev/null +++ b/level/component/tool.go @@ -0,0 +1,22 @@ +package component + +import "io" + +var _ DataComponent = (*Tool)(nil) + +type Tool struct{} + +// ID implements DataComponent. +func (Tool) ID() string { + return "minecraft:tool" +} + +// ReadFrom implements DataComponent. +func (t *Tool) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (t *Tool) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +}