Example #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
}
Example #2
0
// MergeBlockItems creates default item types from a defined list of block
// types. It does not override any pre-existing items types.
func (btl *BlockTypeList) CreateBlockItemTypes(itemTypes ItemTypeMap) {
	for id := range *btl {
		blockType := &(*btl)[id]
		if !blockType.defined {
			continue
		}
		if itemType, exists := itemTypes[types.ItemTypeId(id)]; exists {
			if len(itemType.Name) == 0 {
				itemType.Name = blockType.Name
			}
			if itemType.MaxStack == 0 {
				itemType.MaxStack = MaxStackDefault
			}
			continue
		}

		itemTypes[types.ItemTypeId(id)] = &ItemType{
			Id:       types.ItemTypeId(id),
			Name:     blockType.Name,
			MaxStack: MaxStackDefault,
		}
	}
}