Exemple #1
0
func ReadFloat(tag nbt.ITag, path string) (v float32, err error) {
	vTag, ok := tag.Lookup(path).(*nbt.Float)
	if !ok {
		err = fmt.Errorf("ReadFloat %q: was not a Float", path)
		return
	}

	return vTag.Value, nil
}
Exemple #2
0
func ReadByte(tag nbt.ITag, path string) (v int8, err error) {
	vTag, ok := tag.Lookup(path).(*nbt.Byte)
	if !ok {
		err = fmt.Errorf("ReadByte %q: was not a Byte", path)
		return
	}

	return vTag.Value, nil
}
Exemple #3
0
func ReadInt(tag nbt.ITag, path string) (v int32, err error) {
	vTag, ok := tag.Lookup(path).(*nbt.Int)
	if !ok {
		err = fmt.Errorf("ReadInt %q: was not a Int", path)
		return
	}

	return vTag.Value, nil
}
Exemple #4
0
func ReadShort(tag nbt.ITag, path string) (v int16, err error) {
	vTag, ok := tag.Lookup(path).(*nbt.Short)
	if !ok {
		err = fmt.Errorf("ReadShort %q: was not a Short", path)
		return
	}

	return vTag.Value, nil
}
Exemple #5
0
func ReadBlockXyzCompound(tag nbt.ITag) (loc BlockXyz, err error) {
	x, xOk := tag.Lookup("x").(*nbt.Int)
	y, yOk := tag.Lookup("y").(*nbt.Int)
	z, zOk := tag.Lookup("z").(*nbt.Int)

	if !xOk || !yOk || !zOk {
		err = fmt.Errorf("ReadBlockXyzCompound: x, y or z was not present or not an Int in %#v", tag)
		return
	}

	return BlockXyz{BlockCoord(x.Value), BlockYCoord(y.Value), BlockCoord(z.Value)}, nil
}
Exemple #6
0
// Given the NamedTag for a level.dat, returns an appropriate
// IChunkStoreForeground.
func ChunkStoreForLevel(worldPath string, levelData nbt.ITag, dimension DimensionId) (store IChunkStoreForeground, err error) {
	versionTag, ok := levelData.Lookup("Data/version").(*nbt.Int)

	if !ok {
		store, err = newChunkStoreAlpha(worldPath, dimension)
	} else {
		switch version := versionTag.Value; version {
		case 19132:
			store, err = newChunkStoreBeta(worldPath, dimension)
		default:
			err = UnknownLevelVersion(version)
		}
	}

	return
}
Exemple #7
0
func ReadFloat2(tag nbt.ITag, path string) (x, y float32, err error) {
	list, ok := tag.Lookup(path).(*nbt.List)
	if !ok || len(list.Value) != 2 {
		err = fmt.Errorf("ReadFloat2 %q: not a list of 2", path)
		return
	}

	xv, xok := list.Value[0].(*nbt.Float)
	yv, yok := list.Value[1].(*nbt.Float)

	if ok = xok && yok; ok {
		x, y = xv.Value, yv.Value
	} else {
		err = fmt.Errorf("ReadFloat2 %q: X or Y was not a Float", path)
	}

	return
}
Exemple #8
0
func ReadDouble3(tag nbt.ITag, path string) (x, y, z float64, err error) {
	list, ok := tag.Lookup(path).(*nbt.List)
	if !ok || len(list.Value) != 3 {
		err = fmt.Errorf("ReadDouble3 %q: not a list of 3", path)
		return
	}

	xv, xok := list.Value[0].(*nbt.Double)
	yv, yok := list.Value[1].(*nbt.Double)
	zv, zok := list.Value[2].(*nbt.Double)

	if ok = xok && yok && zok; ok {
		x, y, z = xv.Value, yv.Value, zv.Value
	} else {
		err = fmt.Errorf("ReadDouble3 %q: X, Y or Z was not a Double", path)
	}

	return
}
Exemple #9
0
func absXyzFromNbt(tag nbt.ITag, path string) (pos AbsXyz, err error) {
	posList, posOk := tag.Lookup(path).(*nbt.List)
	if !posOk {
		err = BadType(path)
		return
	}
	x, xOk := posList.Value[0].(*nbt.Double)
	y, yOk := posList.Value[1].(*nbt.Double)
	z, zOk := posList.Value[2].(*nbt.Double)
	if !xOk || !yOk || !zOk {
		err = BadType(path)
		return
	}

	pos = AbsXyz{
		AbsCoord(x.Value),
		AbsCoord(y.Value),
		AbsCoord(z.Value),
	}
	return
}