Check chunk data index and no longer panic
This commit is contained in:
@ -143,6 +143,9 @@ func ChunkFromSave(c *save.Chunk) (*Chunk, error) {
|
|||||||
sections := make([]Section, secs)
|
sections := make([]Section, secs)
|
||||||
for _, v := range c.Sections {
|
for _, v := range c.Sections {
|
||||||
i := int32(v.Y) - c.YPos
|
i := int32(v.Y) - c.YPos
|
||||||
|
if i < 0 || i >= int32(secs) {
|
||||||
|
return nil, fmt.Errorf("section Y value %d out of bounds", v.Y)
|
||||||
|
}
|
||||||
var err error
|
var err error
|
||||||
sections[i].BlockCount, sections[i].States, err = readStatesPalette(v.BlockStates.Palette, v.BlockStates.Data)
|
sections[i].BlockCount, sections[i].States, err = readStatesPalette(v.BlockStates.Palette, v.BlockStates.Data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,11 +13,11 @@ import (
|
|||||||
// Chunk is 16* chunk
|
// Chunk is 16* chunk
|
||||||
type Chunk struct {
|
type Chunk struct {
|
||||||
DataVersion int32
|
DataVersion int32
|
||||||
XPos int32 `nbt:"xPos"`
|
XPos int32 `nbt:"xPos"`
|
||||||
YPos int32 `nbt:"yPos"`
|
YPos int32 `nbt:"yPos"`
|
||||||
ZPos int32 `nbt:"zPos"`
|
ZPos int32 `nbt:"zPos"`
|
||||||
BlockEntities nbt.RawMessage `nbt:"block_entities"`
|
BlockEntities []nbt.RawMessage `nbt:"block_entities"`
|
||||||
Structures nbt.RawMessage `nbt:"structures"`
|
Structures nbt.RawMessage `nbt:"structures"`
|
||||||
Heightmaps struct {
|
Heightmaps struct {
|
||||||
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
|
MotionBlocking []uint64 `nbt:"MOTION_BLOCKING"`
|
||||||
MotionBlockingNoLeaves []uint64 `nbt:"MOTION_BLOCKING_NO_LEAVES"`
|
MotionBlockingNoLeaves []uint64 `nbt:"MOTION_BLOCKING_NO_LEAVES"`
|
||||||
|
Reference in New Issue
Block a user