Пример #1
0
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
0
func (w *nbtChunkWriter) SetTileEntities(tileEntities map[BlockIndex]gamerules.ITileEntity) {
	tileEntitiesNbt := make([]nbt.ITag, 0, len(tileEntities))
	for _, entity := range tileEntities {
		tag := nbt.NewCompound()

		if err := entity.MarshalNbt(tag); err != nil {
			log.Printf("%T.MarshalNbt failed: %v", entity, err)
			continue
		}

		tileEntitiesNbt = append(tileEntitiesNbt, tag)
	}
	w.chunkTag.Lookup("Level/TileEntities").(*nbt.List).Value = tileEntitiesNbt
}
Пример #3
0
func (w *nbtChunkWriter) SetEntities(entities map[EntityId]gamerules.INonPlayerEntity) {
	entitiesNbt := make([]nbt.ITag, 0, len(entities))
	for _, entity := range entities {
		tag := nbt.NewCompound()

		if err := entity.MarshalNbt(tag); err != nil {
			log.Printf("%T.MarshalNbt failed: %v", entity, err)
			continue
		}

		entitiesNbt = append(entitiesNbt, tag)
	}
	w.chunkTag.Lookup("Level/Entities").(*nbt.List).Value = entitiesNbt
}