Esempio n. 1
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
}
Esempio n. 2
0
// UnmarshalNbt unpacks the player data from their persistantly stored NBT
// data. It must only be called before Player.Run().
func (player *Player) UnmarshalNbt(tag *nbt.Compound) (err error) {
	if player.position, err = nbtutil.ReadAbsXyz(tag, "Pos"); err != nil {
		return
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return nil
}