當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Compound.Set方法代碼示例

本文整理匯總了Golang中nbt.Compound.Set方法的典型用法代碼示例。如果您正苦於以下問題:Golang Compound.Set方法的具體用法?Golang Compound.Set怎麽用?Golang Compound.Set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在nbt.Compound的用法示例。


在下文中一共展示了Compound.Set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: MarshalNbt

func (inv *Inventory) MarshalNbt(tag *nbt.Compound) (err error) {
	occupiedSlots := 0
	for i := range inv.slots {
		if inv.slots[i].Count > 0 {
			occupiedSlots++
		}
	}

	itemList := &nbt.List{nbt.TagCompound, make([]nbt.ITag, 0, occupiedSlots)}
	for i := range inv.slots {
		slot := &inv.slots[i]
		if slot.Count > 0 {
			slotTag := nbt.NewCompound()
			slotTag.Set("Slot", &nbt.Byte{int8(i)})
			if err = slot.MarshalNbt(slotTag); err != nil {
				return
			}
			itemList.Value = append(itemList.Value, slotTag)
		}
	}

	tag.Set("Items", itemList)

	return nil
}
開發者ID:compbrain,項目名稱:chunkymonkey,代碼行數:25,代碼來源:inventory.go

示例2: MarshalNbt

func (music *musicTileEntity) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	if err = music.tileEntity.MarshalNbt(tag); err != nil {
		return
	}

	tag.Set("id", &nbt.String{"Music"})
	tag.Set("note", &nbt.Byte{int8(music.note)})

	return nil
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:10,代碼來源:block_music.go

示例3: MarshalNbt

func (recordPlayer *recordPlayerTileEntity) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	if err = recordPlayer.tileEntity.MarshalNbt(tag); err != nil {
		return
	}

	tag.Set("id", &nbt.String{"RecordPlayer"})
	tag.Set("Record", &nbt.Int{recordPlayer.record})

	return nil
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:10,代碼來源:block_recordplayer.go

示例4: MarshalNbt

func (object *Object) MarshalNbt(tag nbt.Compound) (err error) {
	objTypeName, ok := ObjNameByType[object.ObjTypeId]
	if !ok {
		return errors.New("unknown object type")
	}
	if err = object.PointObject.MarshalNbt(tag); err != nil {
		return
	}
	tag.Set("id", &nbt.String{objTypeName})
	// TODO unknown fields
	return
}
開發者ID:b1naryth1ef,項目名稱:chunkymonkey,代碼行數:12,代碼來源:object.go

示例5: MarshalNbt

func (item *Item) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	if err = item.PointObject.MarshalNbt(tag); err != nil {
		return
	}
	tag.Set("id", &nbt.String{"Item"})
	tag.Set("Item", &nbt.Compound{map[string]nbt.ITag{
		"id":     &nbt.Short{int16(item.ItemTypeId)},
		"Count":  &nbt.Byte{int8(item.Count)},
		"Damage": &nbt.Short{int16(item.Data)},
	}})
	return nil
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:12,代碼來源:item.go

示例6: MarshalNbt

func (w *PlayerInventory) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	slots := make([]nbt.ITag, 0, 0)

	// Add the holding inventory
	for i := 0; i < int(w.holding.NumSlots()); i++ {
		slot := w.holding.Slot(SlotId(i))
		if !slot.IsEmpty() {
			slotTag := nbt.NewCompound()
			slotTag.Set("Slot", &nbt.Byte{int8(i)})
			if err = slot.MarshalNbt(slotTag); err != nil {
				return
			}
			slots = append(slots, slotTag)
		}
	}

	// Add the main inventory
	for i := 0; i < int(w.main.NumSlots()); i++ {
		slot := w.main.Slot(SlotId(i))
		if !slot.IsEmpty() {
			slotTag := nbt.NewCompound()
			slotTag.Set("Slot", &nbt.Byte{int8(i + playerInvHoldingNum)})
			if err = slot.MarshalNbt(slotTag); err != nil {
				return
			}
			slots = append(slots, slotTag)
		}
	}

	// Add the armor inventory
	for i := 0; i < int(w.armor.NumSlots()); i++ {
		slot := w.armor.Slot(SlotId(i))
		if !slot.IsEmpty() {
			slotTag := nbt.NewCompound()
			slotTag.Set("Slot", &nbt.Byte{int8(i + 100)})
			if err = slot.MarshalNbt(slotTag); err != nil {
				return
			}
			slots = append(slots, slotTag)
		}
	}

	tag.Set("Inventory", &nbt.List{nbt.TagCompound, slots})

	return nil
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:46,代碼來源:player_inventory.go

示例7: MarshalNbt

func (mobSpawner *mobSpawnerTileEntity) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	if err = mobSpawner.tileEntity.MarshalNbt(tag); err != nil {
		return
	}

	tag.Set("id", &nbt.String{"MobSpawner"})
	tag.Set("EntityId", &nbt.String{mobSpawner.entityMobType})
	tag.Set("Delay", &nbt.Short{int16(mobSpawner.delay)})

	return nil
}
開發者ID:valtyr,項目名稱:chunkymonkey,代碼行數:11,代碼來源:block_mobspawner.go

示例8: MarshalNbt

func (sign *signTileEntity) MarshalNbt(tag *nbt.Compound) (err error) {
	if err = sign.tileEntity.MarshalNbt(tag); err != nil {
		return
	}

	tag.Set("id", &nbt.String{"Sign"})
	tag.Set("Text1", &nbt.String{sign.text[0]})
	tag.Set("Text2", &nbt.String{sign.text[1]})
	tag.Set("Text3", &nbt.String{sign.text[2]})
	tag.Set("Text4", &nbt.String{sign.text[3]})

	return nil
}
開發者ID:compbrain,項目名稱:chunkymonkey,代碼行數:13,代碼來源:block_sign.go

示例9: MarshalNbt

func (inv *DispenserInventory) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	tag.Set("id", &nbt.String{"Trap"})
	return inv.Inventory.MarshalNbt(tag)
}
開發者ID:huwenshu,項目名稱:chunkymonkey,代碼行數:4,代碼來源:inv_dispenser.go

示例10: MarshalNbt

func (inv *FurnaceInventory) MarshalNbt(tag *nbt.Compound) (err os.Error) {
	tag.Set("id", &nbt.String{"Furnace"})
	tag.Set("BurnTime", &nbt.Short{int16(inv.burnTime)})
	tag.Set("CookTime", &nbt.Short{int16(inv.cookTime)})
	return inv.Inventory.MarshalNbt(tag)
}
開發者ID:valtyr,項目名稱:chunkymonkey,代碼行數:6,代碼來源:inv_furnace.go

示例11: MarshalNbt

func (s *Slot) MarshalNbt(tag nbt.Compound) (err error) {
	tag.Set("id", &nbt.Short{int16(s.ItemTypeId)})
	tag.Set("Count", &nbt.Byte{int8(s.Count)})
	tag.Set("Damage", &nbt.Short{int16(s.Data)})
	return nil
}
開發者ID:b1naryth1ef,項目名稱:chunkymonkey,代碼行數:6,代碼來源:slot.go

示例12: MarshalNbt

func (mob *Mob) MarshalNbt(tag nbt.Compound) (err error) {
	mobTypeName, ok := MobNameByType[mob.mobType]
	if !ok {
		return errors.New("unknown mob type")
	}
	if err = mob.PointObject.MarshalNbt(tag); err != nil {
		return
	}
	tag.Set("id", &nbt.String{mobTypeName})
	tag.Set("Rotation", &nbt.List{nbt.TagFloat, []nbt.ITag{
		&nbt.Float{float32(mob.look.Yaw)},
		&nbt.Float{float32(mob.look.Pitch)},
	}})
	// TODO
	tag.Set("Air", &nbt.Short{0})
	tag.Set("AttackTime", &nbt.Short{0})
	tag.Set("DeathTime", &nbt.Short{0})
	tag.Set("FallDistance", &nbt.Float{0})
	tag.Set("Fire", &nbt.Short{0})
	tag.Set("Health", &nbt.Short{0})
	tag.Set("HurtTime", &nbt.Short{0})
	return nil
}
開發者ID:b1naryth1ef,項目名稱:chunkymonkey,代碼行數:23,代碼來源:mob.go

示例13: MarshalNbt

// MarshalNbt packs the player data into a nbt.Compound so it can be written to
// persistant storage.
func (player *Player) MarshalNbt(tag *nbt.Compound) (err error) {
	if err = player.inventory.MarshalNbt(tag); err != nil {
		return
	}

	tag.Set("OnGround", &nbt.Byte{player.onGround})
	tag.Set("Dimension", &nbt.Int{player.dimension})
	tag.Set("Sleeping", &nbt.Byte{player.sleeping})
	tag.Set("FallDistance", &nbt.Float{player.fallDistance})
	tag.Set("SleepTimer", &nbt.Short{player.sleepTimer})
	tag.Set("AttackTime", &nbt.Short{player.attackTime})
	tag.Set("DeathTime", &nbt.Short{player.deathTime})
	tag.Set("Motion", &nbt.List{nbt.TagDouble, []nbt.ITag{
		&nbt.Double{float64(player.motion.X)},
		&nbt.Double{float64(player.motion.Y)},
		&nbt.Double{float64(player.motion.Z)},
	}})
	tag.Set("HurtTime", &nbt.Short{player.hurtTime})
	tag.Set("Air", &nbt.Short{player.air})
	tag.Set("Rotation", &nbt.List{nbt.TagFloat, []nbt.ITag{
		&nbt.Float{float32(player.look.Yaw)},
		&nbt.Float{float32(player.look.Pitch)},
	}})
	tag.Set("Pos", &nbt.List{nbt.TagDouble, []nbt.ITag{
		&nbt.Double{float64(player.position.X)},
		&nbt.Double{float64(player.position.Y)},
		&nbt.Double{float64(player.position.Z)},
	}})
	tag.Set("Fire", &nbt.Short{player.fire})
	tag.Set("Health", &nbt.Short{int16(player.health)})

	return nil
}
開發者ID:compbrain,項目名稱:chunkymonkey,代碼行數:35,代碼來源:player.go

示例14: MarshalNbt

func (inv *ChestInventory) MarshalNbt(tag *nbt.Compound) (err error) {
	tag.Set("id", &nbt.String{"Furnace"})
	return inv.Inventory.MarshalNbt(tag)
}
開發者ID:compbrain,項目名稱:chunkymonkey,代碼行數:4,代碼來源:inv_chest.go

示例15: MarshalNbt

func (inv *CraftingInventory) MarshalNbt(tag nbt.Compound) (err error) {
	tag.Set("id", &nbt.String{"Workbench"})
	return inv.Inventory.MarshalNbt(tag)
}
開發者ID:b1naryth1ef,項目名稱:chunkymonkey,代碼行數:4,代碼來源:inv_crafting.go


注:本文中的nbt.Compound.Set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。