Skip to content

Commit

Permalink
Add item DataComponent implements (part 3)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnze committed Jul 28, 2024
1 parent 085ef0e commit 76ff3a8
Show file tree
Hide file tree
Showing 12 changed files with 393 additions and 0 deletions.
29 changes: 29 additions & 0 deletions level/component/blockentitydata.go
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions level/component/bucketentitydata.go
Original file line number Diff line number Diff line change
@@ -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)
}
24 changes: 24 additions & 0 deletions level/component/bundlecontents.go
Original file line number Diff line number Diff line change
@@ -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")
}
24 changes: 24 additions & 0 deletions level/component/chargedprojectiles.go
Original file line number Diff line number Diff line change
@@ -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")
}
29 changes: 29 additions & 0 deletions level/component/debugstickstate.go
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions level/component/entitydata.go
Original file line number Diff line number Diff line change
@@ -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)
}
85 changes: 85 additions & 0 deletions level/component/instrument.go
Original file line number Diff line number Diff line change
@@ -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)
}
31 changes: 31 additions & 0 deletions level/component/mappostprogressing.go
Original file line number Diff line number Diff line change
@@ -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)
}
30 changes: 30 additions & 0 deletions level/component/potioncontents.go
Original file line number Diff line number Diff line change
@@ -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")
}
26 changes: 26 additions & 0 deletions level/component/suspicioussteweffects.go
Original file line number Diff line number Diff line change
@@ -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")
}
24 changes: 24 additions & 0 deletions level/component/trim.go
Original file line number Diff line number Diff line change
@@ -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")
}
Loading

0 comments on commit 76ff3a8

Please sign in to comment.