本文整理汇总了Golang中nbt.Compound类的典型用法代码示例。如果您正苦于以下问题:Golang Compound类的具体用法?Golang Compound怎么用?Golang Compound使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Compound类的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
}
示例2: UnmarshalNbt
func (item *Item) UnmarshalNbt(tag *nbt.Compound) (err os.Error) {
if err = item.PointObject.UnmarshalNbt(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
}
示例3: UnmarshalNbt
func (inv *Inventory) UnmarshalNbt(tag *nbt.Compound) (err error) {
itemList, ok := tag.Lookup("Items").(*nbt.List)
if !ok {
return errors.New("bad inventory - not a list")
}
for _, slotTagITag := range itemList.Value {
slotTag, ok := slotTagITag.(*nbt.Compound)
if !ok {
return errors.New("inventory slot not a compound")
}
var slotIdTag *nbt.Byte
if slotIdTag, ok = slotTag.Lookup("Slot").(*nbt.Byte); !ok {
return errors.New("Slot ID not a byte")
}
slotId := SlotId(slotIdTag.Value)
if err = inv.SlotUnmarshalNbt(slotTag, slotId); err != nil {
return
}
}
return nil
}
示例4: 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
}
示例5: 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
}
示例6: 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
}
示例7: 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
}
示例8: UnmarshalNbt
func (recordPlayer *recordPlayerTileEntity) UnmarshalNbt(tag *nbt.Compound) (err os.Error) {
if err = recordPlayer.tileEntity.UnmarshalNbt(tag); err != nil {
return
}
if recordTag, ok := tag.Lookup("Record").(*nbt.Int); !ok {
return os.NewError("missing or incorrect type for RecordPlayer Record")
} else {
recordPlayer.record = recordTag.Value
}
return nil
}
示例9: UnmarshalNbt
func (music *musicTileEntity) UnmarshalNbt(tag *nbt.Compound) (err os.Error) {
if err = music.tileEntity.UnmarshalNbt(tag); err != nil {
return
}
if noteTag, ok := tag.Lookup("note").(*nbt.Byte); !ok {
return os.NewError("missing or incorrect type for Music note")
} else {
music.note = NotePitch(noteTag.Value)
}
return nil
}
示例10: UnmarshalNbt
func (sign *signTileEntity) UnmarshalNbt(tag *nbt.Compound) (err error) {
if err = sign.tileEntity.UnmarshalNbt(tag); err != nil {
return
}
var textTags [4]*nbt.String
var ok bool
if textTags[0], ok = tag.Lookup("Text1").(*nbt.String); !ok {
return errors.New("tile entity sign missing or bad type Text1")
}
if textTags[1], ok = tag.Lookup("Text2").(*nbt.String); !ok {
return errors.New("tile entity sign missing or bad type Text2")
}
if textTags[2], ok = tag.Lookup("Text3").(*nbt.String); !ok {
return errors.New("tile entity sign missing or bad type Text3")
}
if textTags[3], ok = tag.Lookup("Text4").(*nbt.String); !ok {
return errors.New("tile entity sign missing or bad type Text4")
}
for i, textTag := range textTags {
sign.text[i] = textTag.Value
}
return nil
}
示例11: 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
}
示例12: UnmarshalNbt
func (obj *PointObject) UnmarshalNbt(tag *nbt.Compound) (err 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
}
示例13: UnmarshalNbt
func (mobSpawner *mobSpawnerTileEntity) UnmarshalNbt(tag *nbt.Compound) (err os.Error) {
if err = mobSpawner.tileEntity.UnmarshalNbt(tag); err != nil {
return
}
if entityIdTag, ok := tag.Lookup("EntityId").(*nbt.String); !ok {
return os.NewError("missing or incorrect type for MobSpawner EntityId")
} else {
mobSpawner.entityMobType = entityIdTag.Value
}
if delayTag, ok := tag.Lookup("Delay").(*nbt.Short); !ok {
return os.NewError("missing or incorrect type for MobSpawner Delay")
} else {
mobSpawner.delay = types.Ticks(delayTag.Value)
}
return nil
}
示例14: UnmarshalNbt
func (object *Object) UnmarshalNbt(tag nbt.Compound) (err error) {
if err = object.PointObject.UnmarshalNbt(tag); err != nil {
return
}
var typeName string
if entityObjectId, ok := tag.Lookup("id").(*nbt.String); !ok {
return errors.New("missing object type id")
} else {
typeName = entityObjectId.Value
}
var ok bool
if object.ObjTypeId, ok = ObjTypeByName[typeName]; !ok {
return errors.New("unknown object type id")
}
// TODO load orientation
return
}
示例15: UnmarshalNbt
func (inv *FurnaceInventory) UnmarshalNbt(tag *nbt.Compound) (err os.Error) {
if err = inv.Inventory.UnmarshalNbt(tag); err != nil {
return
}
if burnTimeTag, ok := tag.Lookup("BurnTime").(*nbt.Short); !ok {
return os.NewError("Bad or missing BurnTime tag in Furnace NBT")
} else {
inv.burnTime = types.Ticks(burnTimeTag.Value)
// We don't know what the burnTimeMax was, as it is not stored, so taking
// BurnTime for this value as well.
inv.burnTimeMax = inv.burnTime
}
if cookTimeTag, ok := tag.Lookup("CookTime").(*nbt.Short); !ok {
return os.NewError("Bad or missing CookTime tag in Furnace NBT")
} else {
inv.cookTime = types.Ticks(cookTimeTag.Value)
}
return nil
}