Squashed below commits
Some checks failed
CodeQL / Analyze (go) (push) Has been cancelled
Go / Test (1.22) (push) Has been cancelled
Go / Test (^1.22) (push) Has been cancelled

nbt chat message

fixes some bug

chunk temp

relocate module

items id
This commit is contained in:
2025-08-26 02:37:53 +08:00
committed by 蒟蒻
parent f0bb92bdb9
commit 185020e31c
210 changed files with 3174 additions and 1749 deletions

View File

@ -5,7 +5,7 @@ import (
"io"
"math"
pk "github.com/Tnze/go-mc/net/packet"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
)
const (
@ -153,17 +153,7 @@ func (b *BitStorage) Raw() []uint64 {
return b.data
}
func (b *BitStorage) ReadFrom(r io.Reader) (int64, error) {
var Len pk.VarInt
n, err := Len.ReadFrom(r)
if err != nil {
return n, err
}
if cap(b.data) >= int(Len) {
b.data = b.data[:Len]
} else {
b.data = make([]uint64, Len)
}
func (b *BitStorage) ReadFrom(r io.Reader) (n int64, err error) {
var v pk.Long
for i := range b.data {
nn, err := v.ReadFrom(r)
@ -213,3 +203,19 @@ func (b *BitStorage) Fix(bits int) error {
}
return nil
}
func (b *BitStorage) Expand(bits int) error {
if bits == 0 {
b.mask = 0
b.bits = 0
b.valuesPerLong = 0
return nil
}
b.mask = 1<<bits - 1
b.bits = bits
b.valuesPerLong = 64 / bits
// check data length
dataLen := calcBitStorageSize(bits, b.length)
b.data = make([]uint64, dataLen)
return nil
}

View File

@ -5,7 +5,7 @@ import (
"reflect"
"testing"
pk "github.com/Tnze/go-mc/net/packet"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
)
var (

View File

@ -7,7 +7,7 @@ import (
"fmt"
"math/bits"
"github.com/Tnze/go-mc/nbt"
"git.konjactw.dev/falloutBot/go-mc/nbt"
)
type Block interface {

View File

@ -10,8 +10,8 @@ import (
"strings"
"text/template"
"github.com/Tnze/go-mc/internal/generateutils"
"github.com/Tnze/go-mc/nbt"
"git.konjactw.dev/falloutBot/go-mc/internal/generateutils"
"git.konjactw.dev/falloutBot/go-mc/nbt"
)
//go:embed blockentities.go.tmpl

View File

@ -9,8 +9,8 @@ import (
"os"
"text/template"
"github.com/Tnze/go-mc/internal/generateutils"
"github.com/Tnze/go-mc/nbt"
"git.konjactw.dev/falloutBot/go-mc/internal/generateutils"
"git.konjactw.dev/falloutBot/go-mc/nbt"
)
//go:embed blocks.go.tmpl

View File

@ -5,13 +5,12 @@ import (
"errors"
"fmt"
"io"
"math/bits"
"strconv"
"github.com/Tnze/go-mc/level/block"
"github.com/Tnze/go-mc/nbt"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/Tnze/go-mc/save"
"git.konjactw.dev/falloutBot/go-mc/level/block"
"git.konjactw.dev/falloutBot/go-mc/nbt"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
"git.konjactw.dev/falloutBot/go-mc/save"
)
type ChunkPos [2]int32
@ -55,16 +54,9 @@ func EmptyChunk(secs int) *Chunk {
}
}
return &Chunk{
Sections: sections,
HeightMaps: HeightMaps{
WorldSurfaceWG: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
WorldSurface: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
OceanFloorWG: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
OceanFloor: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
MotionBlocking: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
MotionBlockingNoLeaves: NewBitStorage(bits.Len(uint(secs)*16+1), 16*16, nil),
},
Status: StatusEmpty,
Sections: sections,
HeightMaps: HeightMaps{},
Status: StatusEmpty,
}
}
@ -110,17 +102,10 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) {
blockEntities[i].Type = block.EntityTypes[tmp.ID]
}
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs)*16 + 1)
// bitsForHeight := bits.Len( /* chunk height in blocks */ uint(secs)*16 + 1)
return &Chunk{
Sections: sections,
HeightMaps: HeightMaps{
WorldSurface: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE_WG"]),
WorldSurfaceWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["WORLD_SURFACE"]),
OceanFloorWG: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["OCEAN_FLOOR_WG"]),
OceanFloor: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["OCEAN_FLOOR"]),
MotionBlocking: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["MOTION_BLOCKING"]),
MotionBlockingNoLeaves: NewBitStorage(bitsForHeight, 16*16, c.Heightmaps["MOTION_BLOCKING_NO_LEAVES"]),
},
Sections: sections,
HeightMaps: HeightMaps{},
BlockEntity: blockEntities,
Status: ChunkStatus(c.Status),
}, nil
@ -193,12 +178,12 @@ func ChunkToSave(c *Chunk, dst *save.Chunk) (err error) {
if dst.Heightmaps == nil {
dst.Heightmaps = make(map[string][]uint64)
}
dst.Heightmaps["WORLD_SURFACE_WG"] = c.HeightMaps.WorldSurfaceWG.Raw()
dst.Heightmaps["WORLD_SURFACE"] = c.HeightMaps.WorldSurface.Raw()
dst.Heightmaps["OCEAN_FLOOR_WG"] = c.HeightMaps.OceanFloorWG.Raw()
dst.Heightmaps["OCEAN_FLOOR"] = c.HeightMaps.OceanFloor.Raw()
dst.Heightmaps["MOTION_BLOCKING"] = c.HeightMaps.MotionBlocking.Raw()
dst.Heightmaps["MOTION_BLOCKING_NO_LEAVES"] = c.HeightMaps.MotionBlockingNoLeaves.Raw()
// dst.Heightmaps["WORLD_SURFACE_WG"] = c.HeightMaps.WorldSurfaceWG.Raw()
// dst.Heightmaps["WORLD_SURFACE"] = c.HeightMaps.WorldSurface.Raw()
// dst.Heightmaps["OCEAN_FLOOR_WG"] = c.HeightMaps.OceanFloorWG.Raw()
// dst.Heightmaps["OCEAN_FLOOR"] = c.HeightMaps.OceanFloor.Raw()
// dst.Heightmaps["MOTION_BLOCKING"] = c.HeightMaps.MotionBlocking.Raw()
// dst.Heightmaps["MOTION_BLOCKING_NO_LEAVES"] = c.HeightMaps.MotionBlockingNoLeaves.Raw()
dst.Status = string(c.Status)
return
}
@ -269,46 +254,50 @@ func (c *Chunk) WriteTo(w io.Writer) (int64, error) {
}
return pk.Tuple{
// Heightmaps
pk.NBT(struct {
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
WorldSurface []uint64 `nbt:"WORLD_SURFACE"`
}{
MotionBlocking: c.HeightMaps.MotionBlocking.Raw(),
WorldSurface: c.HeightMaps.WorldSurface.Raw(),
}),
c.HeightMaps,
pk.ByteArray(data),
pk.Array(c.BlockEntity),
&light,
}.WriteTo(w)
}
func (c *Chunk) ReadFrom(r io.Reader) (int64, error) {
type HeightMap struct {
Type int32
Data []pk.Long
}
func (h *HeightMap) ReadFrom(r io.Reader) (int64, error) {
var (
heightmaps struct {
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
WorldSurface []uint64 `nbt:"WORLD_SURFACE"`
Type pk.VarInt
Data []pk.Long
}
data pk.ByteArray
)
n, err := pk.Tuple{
pk.NBT(&heightmaps),
&data,
pk.Array(&c.BlockEntity),
&LightData{
SkyLightMask: make(pk.BitSet, (16*16*16-1)>>6+1),
BlockLightMask: make(pk.BitSet, (16*16*16-1)>>6+1),
SkyLight: []pk.ByteArray{},
BlockLight: []pk.ByteArray{},
},
&heightmaps.Type,
pk.Array(&heightmaps.Data),
}.ReadFrom(r)
if err != nil {
return n, err
}
h.Type = int32(heightmaps.Type)
h.Data = heightmaps.Data
return n, nil
}
bitsForHeight := bits.Len( /* chunk height in blocks */ uint(len(c.Sections))*16 + 1)
c.HeightMaps.MotionBlocking = NewBitStorage(bitsForHeight, 16*16, heightmaps.MotionBlocking)
c.HeightMaps.WorldSurface = NewBitStorage(bitsForHeight, 16*16, heightmaps.WorldSurface)
func (c *Chunk) ReadFrom(r io.Reader) (int64, error) {
var (
heightmaps []HeightMap
data pk.ByteArray
)
n, err := pk.Tuple{
pk.Array(&heightmaps),
&data,
}.ReadFrom(r)
if err != nil {
return n, err
}
err = c.PutData(data)
return n, err
@ -340,13 +329,14 @@ func (c *Chunk) PutData(data []byte) error {
return nil
}
type HeightMaps struct {
WorldSurfaceWG *BitStorage // test = NOT_AIR
WorldSurface *BitStorage // test = NOT_AIR
OceanFloorWG *BitStorage // test = MATERIAL_MOTION_BLOCKING
OceanFloor *BitStorage // test = MATERIAL_MOTION_BLOCKING
MotionBlocking *BitStorage // test = BlocksMotion or isFluid
MotionBlockingNoLeaves *BitStorage // test = BlocksMotion or isFluid
type HeightMaps []HeightMap
func (h *HeightMaps) ReadFrom(r io.Reader) (int64, error) {
n, err := pk.Array(&h).ReadFrom(r)
if err != nil {
return n, err
}
return n, nil
}
type BlockEntity struct {

View File

@ -3,7 +3,7 @@
package item
import (
"github.com/Tnze/go-mc/level/block"
"git.konjactw.dev/falloutBot/go-mc/level/block"
)
type (
@ -13,7 +13,8 @@ type (
)
{{- range .}}
func ({{.Name | ToGoTypeName}}) ID() string { return {{.Name | printf "%q"}} }
func ({{.Name | ToGoTypeName}}) Name() string { return {{.Name | printf "%q"}} }
func ({{.Name | ToGoTypeName}}) ID() ID { return {{.Id | printf "%d"}} }
{{- end}}
{{- range .}}

View File

@ -9,8 +9,8 @@ import (
"os"
"text/template"
"github.com/Tnze/go-mc/internal/generateutils"
"github.com/Tnze/go-mc/nbt"
"git.konjactw.dev/falloutBot/go-mc/internal/generateutils"
"git.konjactw.dev/falloutBot/go-mc/nbt"
)
//go:embed items.go.tmpl

View File

@ -3,11 +3,12 @@ package item
import (
_ "embed"
"github.com/Tnze/go-mc/level/block"
"git.konjactw.dev/falloutBot/go-mc/level/block"
)
type Item interface {
ID() string
ID() ID
Name() string
}
type BlockItem interface {

File diff suppressed because it is too large Load Diff

View File

@ -4,9 +4,9 @@ import (
"io"
"strconv"
"github.com/Tnze/go-mc/level/biome"
"github.com/Tnze/go-mc/level/block"
pk "github.com/Tnze/go-mc/net/packet"
"git.konjactw.dev/falloutBot/go-mc/level/biome"
"git.konjactw.dev/falloutBot/go-mc/level/block"
pk "git.konjactw.dev/falloutBot/go-mc/net/packet"
)
type State interface {
@ -142,12 +142,14 @@ func (p *PaletteContainer[T]) ReadFrom(r io.Reader) (n int64, err error) {
return n, err
}
p.data = NewBitStorage(p.bits, p.data.length, nil)
nn, err = p.data.ReadFrom(r)
n += nn
if err != nil {
return n, err
}
return n, p.data.Fix(p.bits)
return n, nil
}
func (p *PaletteContainer[T]) WriteTo(w io.Writer) (n int64, err error) {

View File

@ -4,7 +4,7 @@ import (
"math/rand"
"testing"
"github.com/Tnze/go-mc/level/block"
"git.konjactw.dev/falloutBot/go-mc/level/block"
)
func TestPaletteContainer_seq(t *testing.T) {