Пример #1
0
func (pc *preChunk) getLevelTag() (nbt.TagCompound, error) {
	r := bytes.NewReader(pc.data)

	var root nbt.Tag
	var err error
	switch pc.compression {
	case compressGZip:
		root, _, err = nbt.ReadGzipdNamedTag(r)
	case compressZlib:
		root, _, err = nbt.ReadZlibdNamedTag(r)
	default:
		err = UnknownCompression
	}

	if err != nil {
		return nil, err
	}

	if root.Type != nbt.TAG_Compound {
		return nil, errors.New("Root tag is not a TAG_Compound")
	}

	lvl, err := root.Payload.(nbt.TagCompound).GetCompound("Level")
	if err != nil {
		return nil, fmt.Errorf("Could not read Level tag: %s", err)
	}

	return lvl, nil
}
Пример #2
0
func getMapCenter(leveldat io.Reader) (int, int, error) {
	lvl, _, err := nbt.ReadGzipdNamedTag(leveldat)
	if err != nil {
		return 0, 0, err
	}

	if lvl.Type != nbt.TAG_Compound {
		return 0, 0, invalidLevelDat(errors.New("Root tag has wrong type"))
	}
	root := lvl.Payload.(nbt.TagCompound)

	data, err := root.GetCompound("Data")
	if err != nil {
		return 0, 0, invalidLevelDat(err)
	}

	x, err := data.GetInt("SpawnX")
	if err != nil {
		return 0, 0, invalidLevelDat(err)
	}

	z, err := data.GetInt("SpawnZ")
	if err != nil {
		return 0, 0, invalidLevelDat(err)
	}

	return int(x), int(z), nil
}