示例#1
0
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: types.ItemTypeId(id.Value),
		Count:      types.ItemCount(count.Value),
		Data:       types.ItemData(data.Value),
	}

	return nil
}
示例#2
0
func (bdi *blockDropItem) drop(chunk IChunkBlock, blockLoc types.BlockXyz, blockData byte) {
	var itemData types.ItemData
	if !bdi.CopyData {
		itemData = 0
	} else {
		itemData = types.ItemData(blockData)
	}

	spawnItemInBlock(chunk, blockLoc, bdi.DroppedItem, bdi.Count, itemData)
}