-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add item DataComponent implements (part 1)
- Loading branch information
Showing
26 changed files
with
860 additions
and
256 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
package basic | ||
|
||
import ( | ||
"github.com/Tnze/go-mc/data/packetid" | ||
pk "github.com/Tnze/go-mc/net/packet" | ||
) | ||
|
||
func (p *Player) handleCookieRequestPacket(packet pk.Packet) error { | ||
var key pk.Identifier | ||
err := packet.Scan(&key) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
cookieContent := p.c.Cookies[string(key)] | ||
err = p.c.Conn.WritePacket(pk.Marshal( | ||
packetid.ServerboundCookieResponse, | ||
key, pk.OptionEncoder[pk.ByteArray]{ | ||
Has: cookieContent != nil, | ||
Val: pk.ByteArray(cookieContent), | ||
}, | ||
)) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
return nil | ||
} | ||
|
||
func (p *Player) handleStoreCookiePacket(packet pk.Packet) error { | ||
var key pk.Identifier | ||
var payload pk.ByteArray | ||
err := packet.Scan(&key, &payload) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
p.c.Cookies[string(key)] = []byte(payload) | ||
return nil | ||
} | ||
package basic | ||
|
||
import ( | ||
"github.com/Tnze/go-mc/data/packetid" | ||
pk "github.com/Tnze/go-mc/net/packet" | ||
) | ||
|
||
func (p *Player) handleCookieRequestPacket(packet pk.Packet) error { | ||
var key pk.Identifier | ||
err := packet.Scan(&key) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
cookieContent := p.c.Cookies[string(key)] | ||
err = p.c.Conn.WritePacket(pk.Marshal( | ||
packetid.ServerboundCookieResponse, | ||
key, pk.OptionEncoder[pk.ByteArray]{ | ||
Has: cookieContent != nil, | ||
Val: pk.ByteArray(cookieContent), | ||
}, | ||
)) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
return nil | ||
} | ||
|
||
func (p *Player) handleStoreCookiePacket(packet pk.Packet) error { | ||
var key pk.Identifier | ||
var payload pk.ByteArray | ||
err := packet.Scan(&key, &payload) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
p.c.Cookies[string(key)] = []byte(payload) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
package basic | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
pk "github.com/Tnze/go-mc/net/packet" | ||
) | ||
|
||
func (p *Player) handleUpdateTags(packet pk.Packet) error { | ||
r := bytes.NewReader(packet.Data) | ||
|
||
var length pk.VarInt | ||
_, err := length.ReadFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
|
||
var registryID pk.Identifier | ||
for i := 0; i < int(length); i++ { | ||
_, err = registryID.ReadFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
|
||
registry := p.c.Registries.Registry(string(registryID)) | ||
if registry == nil { | ||
return Error{errors.New("unknown registry: " + string(registryID))} | ||
} | ||
|
||
_, err = registry.ReadTagsFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
} | ||
return nil | ||
} | ||
package basic | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
|
||
pk "github.com/Tnze/go-mc/net/packet" | ||
) | ||
|
||
func (p *Player) handleUpdateTags(packet pk.Packet) error { | ||
r := bytes.NewReader(packet.Data) | ||
|
||
var length pk.VarInt | ||
_, err := length.ReadFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
|
||
var registryID pk.Identifier | ||
for i := 0; i < int(length); i++ { | ||
_, err = registryID.ReadFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
|
||
registry := p.c.Registries.Registry(string(registryID)) | ||
if registry == nil { | ||
return Error{errors.New("unknown registry: " + string(registryID))} | ||
} | ||
|
||
_, err = registry.ReadTagsFrom(r) | ||
if err != nil { | ||
return Error{err} | ||
} | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Tnze/go-mc/data/registryid" | ||
"github.com/Tnze/go-mc/level/block" | ||
"github.com/Tnze/go-mc/registry" | ||
) | ||
|
||
func RegisterBlocks(reg *registry.Registry[block.Block]) { | ||
reg.Clear() | ||
for i, key := range registryid.Block { | ||
id, val := reg.Put(key, block.FromID[key]) | ||
if int32(i) != id || val == nil || *val == nil { | ||
panic("register blocks failed") | ||
} | ||
} | ||
} | ||
package bootstrap | ||
|
||
import ( | ||
"github.com/Tnze/go-mc/data/registryid" | ||
"github.com/Tnze/go-mc/level/block" | ||
"github.com/Tnze/go-mc/registry" | ||
) | ||
|
||
func RegisterBlocks(reg *registry.Registry[block.Block]) { | ||
reg.Clear() | ||
for i, key := range registryid.Block { | ||
id, val := reg.Put(key, block.FromID[key]) | ||
if int32(i) != id || val == nil || *val == nil { | ||
panic("register blocks failed") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package component | ||
|
||
import "io" | ||
|
||
var _ DataComponent = (*AttributeModifiers)(nil) | ||
|
||
type AttributeModifiers struct{} | ||
|
||
// ID implements DataComponent. | ||
func (AttributeModifiers) ID() string { | ||
return "minecraft:attribute_modifiers" | ||
} | ||
|
||
// ReadFrom implements DataComponent. | ||
func (a *AttributeModifiers) ReadFrom(r io.Reader) (n int64, err error) { | ||
panic("unimplemented") | ||
} | ||
|
||
// WriteTo implements DataComponent. | ||
func (a *AttributeModifiers) WriteTo(w io.Writer) (n int64, err error) { | ||
panic("unimplemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package component | ||
|
||
import "io" | ||
|
||
var _ DataComponent = (*CanBreak)(nil) | ||
|
||
type CanBreak struct{} | ||
|
||
// ID implements DataComponent. | ||
func (CanBreak) ID() string { | ||
return "minecraft:can_break" | ||
} | ||
|
||
// ReadFrom implements DataComponent. | ||
func (c *CanBreak) ReadFrom(r io.Reader) (n int64, err error) { | ||
panic("unimplemented") | ||
} | ||
|
||
// WriteTo implements DataComponent. | ||
func (c *CanBreak) WriteTo(w io.Writer) (n int64, err error) { | ||
panic("unimplemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package component | ||
|
||
import "io" | ||
|
||
var _ DataComponent = (*CanPlaceOn)(nil) | ||
|
||
type CanPlaceOn struct{} | ||
|
||
// ID implements DataComponent. | ||
func (CanPlaceOn) ID() string { | ||
return "minecraft:can_place_on" | ||
} | ||
|
||
// ReadFrom implements DataComponent. | ||
func (c *CanPlaceOn) ReadFrom(r io.Reader) (n int64, err error) { | ||
panic("unimplemented") | ||
} | ||
|
||
// WriteTo implements DataComponent. | ||
func (c *CanPlaceOn) WriteTo(w io.Writer) (n int64, err error) { | ||
panic("unimplemented") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package component | ||
|
||
import pk "github.com/Tnze/go-mc/net/packet" | ||
|
||
type DataComponent interface { | ||
pk.Field | ||
ID() string | ||
} | ||
|
||
func NewComponent(id int32) DataComponent { | ||
switch id { | ||
case 0: | ||
return new(CustomData) | ||
case 1: | ||
return new(MaxStackSize) | ||
case 2: | ||
return new(MaxDamage) | ||
case 3: | ||
return new(Damage) | ||
case 4: | ||
return new(Unbreakable) | ||
case 5: | ||
return new(CustomName) | ||
case 6: | ||
return new(ItemName) | ||
case 7: | ||
return new(Lore) | ||
case 8: | ||
return new(Rarity) | ||
case 9: | ||
return new(Enchantments) | ||
case 10: | ||
return new(CanPlaceOn) | ||
case 11: | ||
return new(CanBreak) | ||
case 12: | ||
return new(AttributeModifiers) | ||
case 13: | ||
return new(CustomModelData) | ||
case 14: | ||
return new(HideAdditionalTooptip) | ||
case 15: | ||
return new(HideTooptip) | ||
case 16: | ||
return new(RepairCost) | ||
case 17: | ||
return new(CreativeSlotLock) | ||
case 18: | ||
case 19: | ||
case 20: | ||
case 21: | ||
case 22: | ||
case 23: | ||
case 24: | ||
case 25: | ||
case 26: | ||
case 27: | ||
case 28: | ||
case 29: | ||
case 30: | ||
case 31: | ||
case 32: | ||
case 33: | ||
case 34: | ||
case 35: | ||
case 36: | ||
case 37: | ||
case 38: | ||
case 39: | ||
case 40: | ||
case 41: | ||
case 42: | ||
case 43: | ||
return new(Recipes) | ||
case 44: | ||
case 45: | ||
case 46: | ||
case 47: | ||
case 48: | ||
case 49: | ||
case 50: | ||
case 51: | ||
case 52: | ||
case 53: | ||
case 54: | ||
case 55: | ||
case 56: | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package component_test | ||
|
||
// func TestNewComponent(t *testing.T) { | ||
// for i, want := range registryid.DataComponentType { | ||
// comp := component.NewComponent(int32(i)) | ||
// if got := comp.ID(); got != want { | ||
// t.Errorf("DataComponent type mismatched: %s != %s", got, want) | ||
// } | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package component | ||
|
||
import ( | ||
"io" | ||
) | ||
|
||
var _ DataComponent = (*CreativeSlotLock)(nil) | ||
|
||
type CreativeSlotLock struct{} | ||
|
||
// ID implements DataComponent. | ||
func (c *CreativeSlotLock) ID() string { | ||
return "minecraft:creative_slot_lock" | ||
} | ||
|
||
// ReadFrom implements DataComponent. | ||
func (c *CreativeSlotLock) ReadFrom(r io.Reader) (n int64, err error) { | ||
return 0, nil | ||
} | ||
|
||
// WriteTo implements DataComponent. | ||
func (c *CreativeSlotLock) WriteTo(w io.Writer) (n int64, err error) { | ||
return 0, nil | ||
} |
Oops, something went wrong.