diff --git a/level/component/blockentitydata.go b/level/component/blockentitydata.go new file mode 100644 index 00000000..f93cc2b9 --- /dev/null +++ b/level/component/blockentitydata.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 = (*BlockEntityData)(nil) + +type BlockEntityData struct { + dynbt.Value +} + +// ID implements DataComponent. +func (BlockEntityData) ID() string { + return "minecraft:block_entity_data" +} + +// ReadFrom implements DataComponent. +func (b *BlockEntityData) ReadFrom(r io.Reader) (n int64, err error) { + return pk.NBT(&b.Value).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (b *BlockEntityData) WriteTo(w io.Writer) (n int64, err error) { + return pk.NBT(&b.Value).WriteTo(w) +} diff --git a/level/component/bucketentitydata.go b/level/component/bucketentitydata.go new file mode 100644 index 00000000..8cd43dfb --- /dev/null +++ b/level/component/bucketentitydata.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 = (*BucketEntityData)(nil) + +type BucketEntityData struct { + dynbt.Value +} + +// ID implements DataComponent. +func (BucketEntityData) ID() string { + return "minecraft:bucket_entity_data" +} + +// ReadFrom implements DataComponent. +func (b *BucketEntityData) ReadFrom(r io.Reader) (n int64, err error) { + return pk.NBT(&b.Value).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (b *BucketEntityData) WriteTo(w io.Writer) (n int64, err error) { + return pk.NBT(&b.Value).WriteTo(w) +} diff --git a/level/component/bundlecontents.go b/level/component/bundlecontents.go new file mode 100644 index 00000000..95742e84 --- /dev/null +++ b/level/component/bundlecontents.go @@ -0,0 +1,24 @@ +package component + +import "io" + +var _ DataComponent = (*BundleContents)(nil) + +type BundleContents struct { + // TODO +} + +// ID implements DataComponent. +func (BundleContents) ID() string { + return "minecraft:bundle_contents" +} + +// ReadFrom implements DataComponent. +func (b *BundleContents) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (b *BundleContents) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +} diff --git a/level/component/chargedprojectiles.go b/level/component/chargedprojectiles.go new file mode 100644 index 00000000..b6802790 --- /dev/null +++ b/level/component/chargedprojectiles.go @@ -0,0 +1,24 @@ +package component + +import "io" + +var _ DataComponent = (*ChargedProjectiles)(nil) + +type ChargedProjectiles struct { + // TODO +} + +// ID implements DataComponent. +func (ChargedProjectiles) ID() string { + return "minecraft:charged_projectiles" +} + +// ReadFrom implements DataComponent. +func (c *ChargedProjectiles) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (c *ChargedProjectiles) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +} diff --git a/level/component/debugstickstate.go b/level/component/debugstickstate.go new file mode 100644 index 00000000..d716a731 --- /dev/null +++ b/level/component/debugstickstate.go @@ -0,0 +1,29 @@ +package component + +import ( + "io" + + "github.com/Tnze/go-mc/level/block" + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*DebugStickState)(nil) + +type DebugStickState struct { + Data block.State +} + +// ID implements DataComponent. +func (DebugStickState) ID() string { + return "minecraft:debug_stick_state" +} + +// ReadFrom implements DataComponent. +func (d *DebugStickState) ReadFrom(r io.Reader) (n int64, err error) { + return pk.NBT(&d.Data).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (d *DebugStickState) WriteTo(w io.Writer) (n int64, err error) { + return pk.NBT(&d.Data).WriteTo(w) +} diff --git a/level/component/entitydata.go b/level/component/entitydata.go new file mode 100644 index 00000000..9250a164 --- /dev/null +++ b/level/component/entitydata.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 = (*EntityData)(nil) + +type EntityData struct { + dynbt.Value +} + +// ID implements DataComponent. +func (EntityData) ID() string { + return "minecraft:entity_data" +} + +// ReadFrom implements DataComponent. +func (e *EntityData) ReadFrom(r io.Reader) (n int64, err error) { + return pk.NBT(&e.Value).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (e *EntityData) WriteTo(w io.Writer) (n int64, err error) { + return pk.NBT(&e.Value).WriteTo(w) +} diff --git a/level/component/instrument.go b/level/component/instrument.go new file mode 100644 index 00000000..ddd68d2d --- /dev/null +++ b/level/component/instrument.go @@ -0,0 +1,85 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*Instrument)(nil) + +// TODO +type Instrument struct { + Type pk.VarInt + SoundEvent SoundEvent + UseDuration pk.Float + Range pk.Float +} + +// ID implements DataComponent. +func (Instrument) ID() string { + return "minecraft:instrument" +} + +// ReadFrom implements DataComponent. +func (i *Instrument) ReadFrom(r io.Reader) (n int64, err error) { + return pk.Tuple{ + &i.Type, + pk.Opt{ + Has: func() bool { return i.Type == 0 }, + Field: pk.Tuple{ + &i.SoundEvent, + &i.UseDuration, + &i.Range, + }, + }, + }.ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (i *Instrument) WriteTo(w io.Writer) (n int64, err error) { + return pk.Tuple{ + &i.Type, + pk.Opt{ + Has: func() bool { return i.Type == 0 }, + Field: pk.Tuple{ + &i.SoundEvent, + &i.UseDuration, + &i.Range, + }, + }, + }.WriteTo(w) +} + +// TODO +type SoundEvent struct { + Type pk.VarInt + SoundName pk.Identifier + FixedRange pk.Option[pk.Float, *pk.Float] +} + +func (s *SoundEvent) ReadFrom(r io.Reader) (int64, error) { + return pk.Tuple{ + &s.Type, + pk.Opt{ + Has: func() bool { return s.Type == 0 }, + Field: pk.Tuple{ + &s.SoundName, + &s.FixedRange, + }, + }, + }.ReadFrom(r) +} + +func (s SoundEvent) WriteTo(w io.Writer) (int64, error) { + return pk.Tuple{ + &s.Type, + pk.Opt{ + Has: func() bool { return s.Type == 0 }, + Field: pk.Tuple{ + &s.SoundName, + &s.FixedRange, + }, + }, + }.WriteTo(w) +} diff --git a/level/component/mappostprogressing.go b/level/component/mappostprogressing.go new file mode 100644 index 00000000..1df19346 --- /dev/null +++ b/level/component/mappostprogressing.go @@ -0,0 +1,31 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*MapPostProcessing)(nil) + +type MapPostProcessing int32 + +const ( + Lock MapPostProcessing = iota + Scale +) + +// ID implements DataComponent. +func (MapPostProcessing) ID() string { + return "minecraft:map_post_processing" +} + +// ReadFrom implements DataComponent. +func (m *MapPostProcessing) ReadFrom(r io.Reader) (n int64, err error) { + return (*pk.VarInt)(m).ReadFrom(r) +} + +// WriteTo implements DataComponent. +func (m *MapPostProcessing) WriteTo(w io.Writer) (n int64, err error) { + return (*pk.VarInt)(m).WriteTo(w) +} diff --git a/level/component/potioncontents.go b/level/component/potioncontents.go new file mode 100644 index 00000000..5cb97e24 --- /dev/null +++ b/level/component/potioncontents.go @@ -0,0 +1,30 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*PotionContents)(nil) + +type PotionContents struct { + PotionID pk.Option[pk.VarInt, *pk.VarInt] + CustomColor pk.Option[pk.Int, *pk.Int] + PotionEffects []any +} + +// ID implements DataComponent. +func (PotionContents) ID() string { + return "minecraft:potion_contents" +} + +// ReadFrom implements DataComponent. +func (p *PotionContents) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (p *PotionContents) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +} diff --git a/level/component/suspicioussteweffects.go b/level/component/suspicioussteweffects.go new file mode 100644 index 00000000..e7b54fca --- /dev/null +++ b/level/component/suspicioussteweffects.go @@ -0,0 +1,26 @@ +package component + +import ( + "io" +) + +var _ DataComponent = (*SuspiciousStewEffects)(nil) + +type SuspiciousStewEffects struct { + Effects []any +} + +// ID implements DataComponent. +func (SuspiciousStewEffects) ID() string { + return "minecraft:suspicious_stew_effects" +} + +// ReadFrom implements DataComponent. +func (s *SuspiciousStewEffects) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (s *SuspiciousStewEffects) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +} diff --git a/level/component/trim.go b/level/component/trim.go new file mode 100644 index 00000000..0540bf1d --- /dev/null +++ b/level/component/trim.go @@ -0,0 +1,24 @@ +package component + +import "io" + +var _ DataComponent = (*Trim)(nil) + +type Trim struct { + +} + +// ID implements DataComponent. +func (Trim) ID() string { + return "minecraft:trim" +} + +// ReadFrom implements DataComponent. +func (t *Trim) ReadFrom(r io.Reader) (n int64, err error) { + panic("unimplemented") +} + +// WriteTo implements DataComponent. +func (t *Trim) WriteTo(w io.Writer) (n int64, err error) { + panic("unimplemented") +} diff --git a/level/component/writablebookcontent.go b/level/component/writablebookcontent.go new file mode 100644 index 00000000..0e7619b5 --- /dev/null +++ b/level/component/writablebookcontent.go @@ -0,0 +1,33 @@ +package component + +import ( + "io" + + pk "github.com/Tnze/go-mc/net/packet" +) + +var _ DataComponent = (*WritableBookContent)(nil) + +type WritableBookContent struct { + Pages []Page +} + +// ID implements DataComponent. +func (w *WritableBookContent) ID() string { + return "minecraft:writable_book_content" +} + +// ReadFrom implements DataComponent. +func (w *WritableBookContent) ReadFrom(reader io.Reader) (n int64, err error) { + return pk.Array(&w.Pages).ReadFrom(reader) +} + +// WriteTo implements DataComponent. +func (w *WritableBookContent) WriteTo(writer io.Writer) (n int64, err error) { + return pk.Array(&w.Pages).WriteTo(writer) +} + +type Page struct { + Raw pk.String + Filtered pk.Option[pk.String, *pk.String] +}