当前位置: 首页>>代码示例>>Golang>>正文


Golang nbt.ITag类代码示例

本文整理汇总了Golang中nbt.ITag的典型用法代码示例。如果您正苦于以下问题:Golang ITag类的具体用法?Golang ITag怎么用?Golang ITag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ITag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ReadNbt

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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:26,代码来源:item.go

示例2: ReadFloat

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:9,代码来源:nbtutil.go

示例3: ReadByte

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:9,代码来源:nbtutil.go

示例4: ReadInt

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:9,代码来源:nbtutil.go

示例5: ReadShort

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:9,代码来源:nbtutil.go

示例6: ReadBlockXyzCompound

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:12,代码来源:nbtutil.go

示例7: ChunkStoreForLevel

// 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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:18,代码来源:store.go

示例8: ReadFloat2

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:18,代码来源:nbtutil.go

示例9: ChunkStoreForLevel

// 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
}
开发者ID:b1naryth1ef,项目名称:chunkymonkey,代码行数:20,代码来源:store.go

示例10: ReadNbt

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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:19,代码来源:physics.go

示例11: ReadDouble3

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
}
开发者ID:compbrain,项目名称:chunkymonkey,代码行数:19,代码来源:nbtutil.go

示例12: absXyzFromNbt

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
}
开发者ID:b1naryth1ef,项目名称:chunkymonkey,代码行数:21,代码来源:worldstore.go

示例13: ReadNbt

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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:16,代码来源:mob.go

示例14: ReadNbt

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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:21,代码来源:slot.go

示例15: ReadNbt

// 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
}
开发者ID:nictuku,项目名称:chunkymonkey,代码行数:67,代码来源:player.go


注:本文中的nbt.ITag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。