Skip to content

Commit

Permalink
Add item DataComponent implements (part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tnze committed Jul 28, 2024
1 parent 090493c commit c51313a
Show file tree
Hide file tree
Showing 18 changed files with 287 additions and 73 deletions.
10 changes: 10 additions & 0 deletions level/component/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions level/component/creativeslotlock.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package component

import (
"io"
)
import "io"

var _ DataComponent = (*CreativeSlotLock)(nil)

Expand Down
18 changes: 2 additions & 16 deletions level/component/damage.go
Original file line number Diff line number Diff line change
@@ -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)
}
29 changes: 29 additions & 0 deletions level/component/dyedcolor.go
Original file line number Diff line number Diff line change
@@ -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)
}
28 changes: 28 additions & 0 deletions level/component/enchantmentglintoverride.go
Original file line number Diff line number Diff line change
@@ -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)
}
22 changes: 22 additions & 0 deletions level/component/fireresistant.go
Original file line number Diff line number Diff line change
@@ -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
}
47 changes: 47 additions & 0 deletions level/component/food.go
Original file line number Diff line number Diff line change
@@ -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")
}
4 changes: 1 addition & 3 deletions level/component/hideadditionaltooltio.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package component

import (
"io"
)
import "io"

var _ DataComponent = (*HideAdditionalTooptip)(nil)

Expand Down
4 changes: 1 addition & 3 deletions level/component/hidetooltip.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package component

import (
"io"
)
import "io"

var _ DataComponent = (*HideTooptip)(nil)

Expand Down
22 changes: 22 additions & 0 deletions level/component/intangibleprojectile.go
Original file line number Diff line number Diff line change
@@ -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
}
15 changes: 15 additions & 0 deletions level/component/mapcolor.go
Original file line number Diff line number Diff line change
@@ -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"
}
29 changes: 29 additions & 0 deletions level/component/mapdecorations.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 = (*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)
}
14 changes: 14 additions & 0 deletions level/component/mapid.go
Original file line number Diff line number Diff line change
@@ -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"
}
18 changes: 2 additions & 16 deletions level/component/maxdamage.go
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 2 additions & 16 deletions level/component/maxstacksize.go
Original file line number Diff line number Diff line change
@@ -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)
}
18 changes: 2 additions & 16 deletions level/component/repaircost.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading

0 comments on commit c51313a

Please sign in to comment.