Ejemplo n.º 1
0
func (item *Item) ReadNbt(tag nbt.ITag) (err os.Error) {
	if err = item.PointObject.ReadNbt(tag); err != nil {
		return
	}

	itemInfo, ok := tag.Lookup("Item").(*nbt.Compound)
	if !ok {
		return os.NewError("bad item data")
	}

	// Grab the basic item data
	id, idOk := itemInfo.Lookup("id").(*nbt.Short)
	count, countOk := itemInfo.Lookup("Count").(*nbt.Byte)
	data, dataOk := itemInfo.Lookup("Damage").(*nbt.Short)
	if !idOk || !countOk || !dataOk {
		return os.NewError("bad item data")
	}

	item.Slot = Slot{
		ItemTypeId: ItemTypeId(id.Value),
		Count:      ItemCount(count.Value),
		Data:       ItemData(data.Value),
	}

	return nil
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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
}
Ejemplo n.º 4
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
}
Ejemplo n.º 5
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
}
Ejemplo n.º 6
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
}
Ejemplo n.º 7
0
// Given the NamedTag for a level.dat, returns an appropriate
// IChunkStoreForeground.
func ChunkStoreForLevel(worldPath string, levelData nbt.ITag, dimension DimensionId) (store IChunkStoreForeground, err os.Error) {
	versionTag, ok := levelData.Lookup("Data/version").(*nbt.Int)

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

	return
}
Ejemplo n.º 8
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
}
Ejemplo n.º 9
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 {
		log.Fatalln("Invalid world format! (Is it pre-anvil?)")
	} else {
		switch version := versionTag.Value; version {
		case 19132:
			log.Fatalln("Chunky Monkey only supports the Anvil world format!")
		case 19133:
			store, err = newChunkStoreAnvil(worldPath, dimension)
		default:
			err = UnknownLevelVersion(version)
		}
	}

	return
}
Ejemplo n.º 10
0
func (obj *PointObject) ReadNbt(tag nbt.ITag) (err os.Error) {
	// Position within the chunk
	if obj.position, err = nbtutil.ReadAbsXyz(tag, "Pos"); err != nil {
		return
	}
	obj.LastSentPosition = *obj.position.ToAbsIntXyz()

	// Motion
	if obj.velocity, err = nbtutil.ReadAbsVelocity(tag, "Motion"); err != nil {
		return
	}
	obj.LastSentVelocity = *obj.velocity.ToVelocity()

	if onGround, ok := tag.Lookup("OnGround").(*nbt.Byte); ok {
		obj.onGround = onGround.Value != 0
	}

	return nil
}
Ejemplo n.º 11
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
}
Ejemplo n.º 12
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
}
Ejemplo n.º 13
0
func (mob *Mob) ReadNbt(tag nbt.ITag) (err os.Error) {
	if err = mob.PointObject.ReadNbt(tag); err != nil {
		return
	}

	if mob.look, err = nbtutil.ReadLookDegrees(tag, "Rotation"); err != nil {
		return
	}

	// TODO
	_ = tag.Lookup("FallDistance").(*nbt.Float).Value
	_ = tag.Lookup("Air").(*nbt.Short).Value
	_ = tag.Lookup("Fire").(*nbt.Short).Value

	return nil
}
Ejemplo n.º 14
0
func (s *Slot) ReadNbt(tag nbt.ITag) (err os.Error) {
	var ok bool
	var idTag, damageTag *nbt.Short
	var countTag *nbt.Byte

	if idTag, ok = tag.Lookup("id").(*nbt.Short); !ok {
		return os.NewError("id tag not Short")
	}
	if countTag, ok = tag.Lookup("Count").(*nbt.Byte); !ok {
		return os.NewError("Count tag not Byte")
	}
	if damageTag, ok = tag.Lookup("Damage").(*nbt.Short); !ok {
		return os.NewError("Damage tag not Short")
	}

	s.ItemTypeId = ItemTypeId(idTag.Value)
	s.Count = ItemCount(countTag.Value)
	s.Data = ItemData(damageTag.Value)

	return
}
Ejemplo n.º 15
0
// ReadNbt reads the player data from their persistently stored NBT data. It
// must only be called before Player.Start().
func (player *Player) ReadNbt(playerData nbt.ITag) (err os.Error) {
	if player.position, err = nbtutil.ReadAbsXyz(playerData, "Pos"); err != nil {
		return
	}

	if player.look, err = nbtutil.ReadLookDegrees(playerData, "Rotation"); err != nil {
		return
	}

	health, err := nbtutil.ReadShort(playerData, "Health")
	if err != nil {
		return
	}
	player.health = Health(health)

	if err = player.inventory.ReadNbt(playerData.Lookup("Inventory")); err != nil {
		return
	}

	if player.onGround, err = nbtutil.ReadByte(playerData, "OnGround"); err != nil {
		return
	}

	if player.dimension, err = nbtutil.ReadInt(playerData, "Dimension"); err != nil {
		return
	}

	if player.sleeping, err = nbtutil.ReadByte(playerData, "Sleeping"); err != nil {
		return
	}

	if player.fallDistance, err = nbtutil.ReadFloat(playerData, "FallDistance"); err != nil {
		return
	}

	if player.sleepTimer, err = nbtutil.ReadShort(playerData, "SleepTimer"); err != nil {
		return
	}

	if player.attackTime, err = nbtutil.ReadShort(playerData, "AttackTime"); err != nil {
		return
	}

	if player.deathTime, err = nbtutil.ReadShort(playerData, "DeathTime"); err != nil {
		return
	}

	if player.motion, err = nbtutil.ReadAbsVelocity(playerData, "Motion"); err != nil {
		return
	}

	if player.hurtTime, err = nbtutil.ReadShort(playerData, "HurtTime"); err != nil {
		return
	}

	if player.air, err = nbtutil.ReadShort(playerData, "Air"); err != nil {
		return
	}

	if player.fire, err = nbtutil.ReadShort(playerData, "Fire"); err != nil {
		return
	}

	return
}