anvil chunk to real chunk conversion things
This commit is contained in:
+6
-1
@@ -99,7 +99,12 @@ func StateIdFromBlocKAndStateMap(version string, name string, stateMap map[strin
|
|||||||
err = BlockNotFoundErr
|
err = BlockNotFoundErr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
stateId, err = b.IdFromStateMap(stateMap)
|
if stateMap == nil {
|
||||||
|
stateId = b.DefaultState
|
||||||
|
} else {
|
||||||
|
stateId, err = b.IdFromStateMap(stateMap)
|
||||||
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+59
-3
@@ -1,5 +1,14 @@
|
|||||||
package anvil
|
package anvil
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/admin-else/strom/data"
|
||||||
|
"github.com/admin-else/strom/level"
|
||||||
|
"github.com/admin-else/strom/util"
|
||||||
|
)
|
||||||
|
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
DataVersion int32
|
DataVersion int32
|
||||||
Heightmaps map[string][]int64
|
Heightmaps map[string][]int64
|
||||||
@@ -8,17 +17,64 @@ type Chunk struct {
|
|||||||
Sections []Section
|
Sections []Section
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const McPrefix = "minecraft:"
|
||||||
|
|
||||||
|
func (c Chunk) ToStorage(version string) (toChunk *level.Chunk, err error) {
|
||||||
|
f := level.MakeBlockFormat(version)
|
||||||
|
toChunk = new(level.Chunk)
|
||||||
|
|
||||||
|
toChunk.Sections = make([]level.Section, len(c.Sections))
|
||||||
|
for i, s := range c.Sections {
|
||||||
|
pallete := make([]int32, len(s.BlockStates.Palette))
|
||||||
|
for j, p := range s.BlockStates.Palette {
|
||||||
|
pallete[j], err = data.StateIdFromBlocKAndStateMap(version, strings.TrimPrefix(p.Name, McPrefix), p.Properties)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// this is probably fine
|
||||||
|
uintSlice := unsafe.Slice((*uint64)(unsafe.Pointer(unsafe.SliceData(s.BlockStates.Data))), len(s.BlockStates.Data))
|
||||||
|
|
||||||
|
toChunk.Sections[i].Blocks, err = f.Import(uintSlice, util.BpeByNum(float64(len(s.BlockStates.Palette))), pallete)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
toChunk.Sections[i].BlockCount = int16(level.CountStorage(toChunk.Sections[i].Blocks, 0))
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, s := range c.Sections {
|
||||||
|
pallete := make([]int32, len(s.Biomes.Palette))
|
||||||
|
for j, p := range s.Biomes.Palette {
|
||||||
|
var b *data.Biome
|
||||||
|
b, ok := data.LookupBiomeByName(version, strings.TrimPrefix(p, McPrefix))
|
||||||
|
if !ok {
|
||||||
|
err = data.UnknownBiomeNameErr
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pallete[j] = b.Id
|
||||||
|
}
|
||||||
|
// this is probably fine
|
||||||
|
uintSlice := unsafe.Slice((*uint64)(unsafe.Pointer(unsafe.SliceData(s.Biomes.Data))), len(s.Biomes.Data))
|
||||||
|
|
||||||
|
toChunk.Sections[i].Biomes, err = f.Import(uintSlice, util.BpeByNum(float64(len(s.BlockStates.Palette))), pallete)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type Section struct {
|
type Section struct {
|
||||||
Y int8
|
Y int8
|
||||||
BlockStates struct {
|
BlockStates struct {
|
||||||
Data []int64
|
Data []int64 `nbt:"data,omitempty"`
|
||||||
Palette []struct {
|
Palette []struct {
|
||||||
Name string
|
Name string
|
||||||
Properties map[string]string `nbt:"properties,omitempty"`
|
Properties map[string]string `nbt:"properties,omitempty"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Biomes []struct {
|
Biomes struct {
|
||||||
Data []int64
|
Data []int64 `nbt:"data,omitempty"`
|
||||||
Palette []string
|
Palette []string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,3 +255,12 @@ func CompareStorage(a, b *Storage) bool {
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CountStorage(s *Storage, v int32) (a int) {
|
||||||
|
for i := range s.format.Len {
|
||||||
|
if w, _ := s.Get(i); w == v {
|
||||||
|
a++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user