1.19.2 chat support

This commit is contained in:
Tnze
2022-11-30 18:50:10 +08:00
parent 0b7ef620d9
commit 55d79f791a
13 changed files with 431 additions and 244 deletions

View File

@ -3,16 +3,15 @@ package basic
import (
"unsafe"
"github.com/Tnze/go-mc/chat"
"github.com/Tnze/go-mc/registry"
"github.com/Tnze/go-mc/data/packetid"
"github.com/Tnze/go-mc/nbt"
pk "github.com/Tnze/go-mc/net/packet"
)
// WorldInfo content player info in server.
type WorldInfo struct {
RegistryCodec RegistryCodec
RegistryCodec registry.NetworkCodec
DimensionType string
DimensionNames []string // Identifiers for all worlds on the server.
DimensionName string // Name of the world being spawned into.
@ -26,70 +25,6 @@ type WorldInfo struct {
IsFlat bool // True if the world is a superflat world; flat worlds have different void fog and a horizon at y=0 instead of y=63.
}
type Dimension struct {
FixedTime int64 `nbt:"fixed_time,omitempty"`
HasSkylight bool `nbt:"has_skylight"`
HasCeiling bool `nbt:"has_ceiling"`
Ultrawarm bool `nbt:"ultrawarm"`
Natural bool `nbt:"natural"`
CoordinateScale float64 `nbt:"coordinate_scale"`
BedWorks bool `nbt:"bed_works"`
RespawnAnchorWorks byte `nbt:"respawn_anchor_works"`
MinY int32 `nbt:"min_y"`
Height int32 `nbt:"height"`
LogicalHeight int32 `nbt:"logical_height"`
InfiniteBurn string `nbt:"infiniburn"`
Effects string `nbt:"effects"`
AmbientLight float64 `nbt:"ambient_light"`
PiglinSafe byte `nbt:"piglin_safe"`
HasRaids byte `nbt:"has_raids"`
MonsterSpawnLightLevel nbt.RawMessage `nbt:"monster_spawn_light_level"` // Tag_Int or {type:"minecraft:uniform", value:{min_inclusive: Tag_Int, max_inclusive: Tag_Int}}
MonsterSpawnBlockLightLimit int32 `nbt:"monster_spawn_block_light_limit"`
}
type ChatType struct {
Chat chat.Decoration `nbt:"chat"`
Narration chat.Decoration `nbt:"narration"`
}
type RegistryCodec struct {
// What is Below? (wiki.vg)
ChatType Registry[ChatType] `nbt:"minecraft:chat_type"`
DimensionType Registry[Dimension] `nbt:"minecraft:dimension_type"`
WorldGenBiome Registry[nbt.RawMessage] `nbt:"minecraft:worldgen/biome"`
}
type Registry[E any] struct {
Type string `nbt:"type"`
Value []struct {
Name string `nbt:"name"`
ID int32 `nbt:"id"`
Element E `nbt:"element"`
} `nbt:"value"`
}
func (r *Registry[E]) Find(name string) *E {
for i := range r.Value {
if r.Value[i].Name == name {
return &r.Value[i].Element
}
}
return nil
}
func (r *Registry[E]) FindByID(id int32) *E {
if id >= 0 && id < int32(len(r.Value)) && r.Value[id].ID == id {
return &r.Value[id].Element
}
for i := range r.Value {
if r.Value[i].ID == id {
return &r.Value[i].Element
}
}
return nil
}
type PlayerInfo struct {
EID int32 // The player's Entity ID (EID).
Hardcore bool // Is hardcore