diff --git a/level/chunk.go b/level/chunk.go index c9edef5..a684fe6 100644 --- a/level/chunk.go +++ b/level/chunk.go @@ -13,14 +13,14 @@ import ( "github.com/Tnze/go-mc/save" ) -type ChunkPos struct{ X, Z int } +type ChunkPos [2]int32 func (c ChunkPos) WriteTo(w io.Writer) (n int64, err error) { - n, err = pk.Int(c.X).WriteTo(w) + n, err = pk.Int(c[0]).WriteTo(w) if err != nil { return } - n1, err := pk.Int(c.Z).WriteTo(w) + n1, err := pk.Int(c[1]).WriteTo(w) return n + n1, err } @@ -33,7 +33,7 @@ func (c *ChunkPos) ReadFrom(r io.Reader) (n int64, err error) { if n1, err = z.ReadFrom(r); err != nil { return n + n1, err } - *c = ChunkPos{int(x), int(z)} + *c = ChunkPos{int32(x), int32(z)} return n + n1, nil } @@ -41,6 +41,7 @@ type Chunk struct { Sections []Section HeightMaps HeightMaps BlockEntity []BlockEntity + Status ChunkStatus } func EmptyChunk(secs int) *Chunk { @@ -57,6 +58,7 @@ func EmptyChunk(secs int) *Chunk { HeightMaps: HeightMaps{ MotionBlocking: NewBitStorage(bits.Len(uint(secs)*16), 16*16, nil), }, + Status: StatusEmpty, } } @@ -220,6 +222,7 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) { OceanFloor: NewBitStorage(bitsForHeight, 16*16, oceanFloor), WorldSurface: NewBitStorage(bitsForHeight, 16*16, worldSurface), }, + Status: ChunkStatus(c.Status), }, nil } @@ -278,7 +281,8 @@ func ChunkToSave(c *Chunk, dst *save.Chunk) (err error) { s.BlockLight = v.BlockLight } dst.Sections = sections - //dst.Heightmaps.MotionBlocking = c.HeightMaps.MotionBlocking.Raw() + dst.Heightmaps.MotionBlocking = c.HeightMaps.MotionBlocking.Raw() + dst.Status = string(c.Status) return } diff --git a/level/chunkstatus.go b/level/chunkstatus.go new file mode 100644 index 0000000..c8a1c96 --- /dev/null +++ b/level/chunkstatus.go @@ -0,0 +1,19 @@ +package level + +type ChunkStatus string + +const ( + StatusEmpty ChunkStatus = "empty" + StatusStructureStarts ChunkStatus = "structure_starts" + StatusStructureReferences ChunkStatus = "structure_references" + StatusBiomes ChunkStatus = "biomes" + StatusNoise ChunkStatus = "noise" + StatusSurface ChunkStatus = "surface" + StatusCarvers ChunkStatus = "carvers" + StatusLiquidCarvers ChunkStatus = "liquid_carvers" + StatusFeatures ChunkStatus = "features" + StatusLight ChunkStatus = "light" + StatusSpawn ChunkStatus = "spawn" + StatusHeightmaps ChunkStatus = "heightmaps" + StatusFull ChunkStatus = "full" +) diff --git a/save/region/mca.go b/save/region/mca.go index 9ded58c..4a5a6d1 100644 --- a/save/region/mca.go +++ b/save/region/mca.go @@ -28,6 +28,12 @@ func In(cx, cz int) (int, int) { return cx & 31, cz & 31 } +// At calculate the region's coordinates where the chunk in +// 计算chunk在哪一个region中 +func At(cx, cz int) (int, int) { + return cx >> 5, cz >> 5 +} + // Open a .mca file and read the head. // Close the Region after used. func Open(name string) (r *Region, err error) { diff --git a/server/clientinfo/clientinfo.go b/server/clientinfo/clientinfo.go deleted file mode 100644 index cb497b9..0000000 --- a/server/clientinfo/clientinfo.go +++ /dev/null @@ -1,89 +0,0 @@ -package clientinfo - -import ( - "context" - "github.com/Tnze/go-mc/server/ecs" - - "github.com/Tnze/go-mc/data/packetid" - pk "github.com/Tnze/go-mc/net/packet" - "github.com/Tnze/go-mc/server" -) - -type ClientInformation struct{} - -type Info struct { - Locale string - ViewDistance int - ChatMode byte - ChatColors bool - DisplayedSkinParts byte - MainHand byte // 0: Left, 1: Right. - EnableTextFiltering bool - AllowServerListings bool -} - -func (c *ClientInformation) Init(g *server.Game) { - infos := ecs.GetComponent[Info](g.World) - type updateData struct { - eid ecs.Index - info Info - } - updateChan := make(chan updateData) - g.Add(ecs.FuncSystem(func() { - for { - select { - case info := <-updateChan: - infos.SetValue(info.eid, info.info) - default: - return - } - } - }), "go-mc:ClientInfoSystem", nil) - g.AddHandler(&server.PacketHandler{ - ID: packetid.ServerboundClientInformation, - F: func(client *server.Client, player *server.Player, p server.Packet758) error { - var ( - Locale pk.String - ViewDistance pk.Byte - ChatMode pk.VarInt - ChatColors pk.Boolean - DisplayedSkinParts pk.UnsignedByte - MainHand pk.VarInt - EnableTextFiltering pk.Boolean - AllowServerListings pk.Boolean - ) - err := pk.Packet(p).Scan( - &Locale, - &ViewDistance, - &ChatMode, - &ChatColors, - &DisplayedSkinParts, - &MainHand, - &EnableTextFiltering, - &AllowServerListings, - ) - if err != nil { - return err - } - - updateChan <- updateData{ - eid: client.Index, - info: Info{ - Locale: string(Locale), - ViewDistance: int(ViewDistance), - ChatMode: byte(ChatMode), - ChatColors: bool(ChatColors), - DisplayedSkinParts: byte(DisplayedSkinParts), - MainHand: byte(MainHand), - EnableTextFiltering: bool(EnableTextFiltering), - AllowServerListings: bool(AllowServerListings), - }, - } - return nil - }, - }) -} - -func (c *ClientInformation) Run(ctx context.Context) {} -func (c *ClientInformation) ClientJoin(client *server.Client, player *server.Player) {} -func (c *ClientInformation) ClientLeft(client *server.Client, player *server.Player, reason error) {}