Table of Contents

Class ItemStack

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll
public class ItemStack : IItemStack
Inheritance
ItemStack
Implements
Inherited Members

Constructors

ItemStack()

Create a new empty itemstack

public ItemStack()

ItemStack(byte[])

Create a new itemstack from a byte serialized array(without resolving the block/item)

public ItemStack(byte[] data)

Parameters

data byte[]

ItemStack(BinaryReader)

Create a new itemstack from a byte serialized stream (without resolving the block/item)

public ItemStack(BinaryReader reader)

Parameters

reader BinaryReader

ItemStack(BinaryReader, IWorldAccessor)

Create a new itemstack from a byte serialized stream (with resolving the block/item)

public ItemStack(BinaryReader reader, IWorldAccessor resolver)

Parameters

reader BinaryReader
resolver IWorldAccessor

ItemStack(int, EnumItemClass, int, TreeAttribute, IWorldAccessor)

Create a new itemstack with given collectible id, itemclass, stacksize, attributes and a resolver to turn the collectibe + itemclass into an Item/Block

public ItemStack(int id, EnumItemClass itemClass, int stacksize, TreeAttribute stackAttributes, IWorldAccessor resolver)

Parameters

id int
itemClass EnumItemClass
stacksize int
stackAttributes TreeAttribute
resolver IWorldAccessor

ItemStack(Block, int)

Create a new itemstack from given block and given stack size

public ItemStack(Block block, int stacksize = 1)

Parameters

block Block
stacksize int

ItemStack(CollectibleObject, int)

Create a new itemstack from given block/item and given stack size

public ItemStack(CollectibleObject collectible, int stacksize = 1)

Parameters

collectible CollectibleObject
stacksize int

ItemStack(Item, int)

Create a new itemstack from given item and given stack size

public ItemStack(Item item, int stacksize = 1)

Parameters

item Item
stacksize int

Fields

Class

Wether its a block Block or Item

public EnumItemClass Class

Field Value

EnumItemClass

Id

The id of the block or item

public int Id

Field Value

int

block

protected Block block

Field Value

Block

item

protected Item item

Field Value

Item

stacksize

protected int stacksize

Field Value

int

Properties

Attributes

Attributes assigned to this particular itemstack which are saved and synchronized.

public ITreeAttribute Attributes { get; set; }

Property Value

ITreeAttribute

Block

If this is a stack of blocks, this is the type of block it's holding, otherwise null

public Block Block { get; }

Property Value

Block

Collectible

The item/block base class this stack is holding

public CollectibleObject Collectible { get; }

Property Value

CollectibleObject

Item

If this is a stack of items, this is the type of items it's holding, otherwise null

public Item Item { get; }

Property Value

Item

ItemAttributes

The Attributes assigned to the underlying block/item. Should not be modified, as it applies to globally.

public JsonObject ItemAttributes { get; }

Property Value

JsonObject

StackSize

The amount of items/blocks in this stack

public int StackSize { get; set; }

Property Value

int

TempAttributes

Temporary Attributes assigned to this particular itemstack, not synchronized, not saved! Modifiable.

public ITreeAttribute TempAttributes { get; set; }

Property Value

ITreeAttribute

Methods

Clone()

Creates a full copy of the item stack

public ItemStack Clone()

Returns

ItemStack

Equals(IWorldAccessor, ItemStack, params string[])

Returns true if both stacks exactly match

public bool Equals(IWorldAccessor worldForResolve, ItemStack sourceStack, params string[] ignoreAttributeSubTrees)

Parameters

worldForResolve IWorldAccessor
sourceStack ItemStack
ignoreAttributeSubTrees string[]

Returns

bool

FixMapping(Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>, IWorldAccessor)

This method should always be called when an itemstack got loaded from the savegame or when it got imported. When this method return false, you should discard the itemstack because it could not get resolved and a warning will be logged.

public bool FixMapping(Dictionary<int, AssetLocation> oldBlockMapping, Dictionary<int, AssetLocation> oldItemMapping, IWorldAccessor worldForNewMapping)

Parameters

oldBlockMapping Dictionary<int, AssetLocation>
oldItemMapping Dictionary<int, AssetLocation>
worldForNewMapping IWorldAccessor

Returns

bool

FromBytes(BinaryReader)

Reads all the itemstacks properties from a series of bytes, including its stack attributes

public void FromBytes(BinaryReader stream)

Parameters

stream BinaryReader

GetDescription(IWorldAccessor, ItemSlot, bool)

Returns a human readable description of the item/block

public string GetDescription(IWorldAccessor world, ItemSlot inSlot, bool debug = false)

Parameters

world IWorldAccessor
inSlot ItemSlot
debug bool

Returns

string

GetEmptyClone()

Creates a full copy of the item stack, except for its stack size.

public ItemStack GetEmptyClone()

Returns

ItemStack

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

GetHashCode(string[])

public int GetHashCode(string[] ignoredAttributes)

Parameters

ignoredAttributes string[]

Returns

int

GetName()

Returns a human readable name of the item/block

public string GetName()

Returns

string

MatchesSearchText(IWorldAccessor, string)

Returns true if searchText is found in the item/block name as supplied from GetName()

public bool MatchesSearchText(IWorldAccessor world, string searchText)

Parameters

world IWorldAccessor
searchText string

Returns

bool

ResolveBlockOrItem(IWorldAccessor)

Sets the item/block based on the currently set itemclass + id

public bool ResolveBlockOrItem(IWorldAccessor resolver)

Parameters

resolver IWorldAccessor

Returns

bool

Satisfies(ItemStack)

Returns true if this item stack is a satisfactory replacement for given itemstack. It's basically an Equals() test, but ignores additional attributes of the sourceStack

public bool Satisfies(ItemStack sourceStack)

Parameters

sourceStack ItemStack

Returns

bool

SetFrom(ItemStack)

Replace all the properties (id, class, attributes, stacksize, etc...) from this item stack by given stack

public void SetFrom(ItemStack stack)

Parameters

stack ItemStack

ToBytes()

Serializes the itemstack into a series of bytes, including its stack attributes

public byte[] ToBytes()

Returns

byte[]

ToBytes(BinaryWriter)

Serializes the itemstack into a series of bytes, including its stack attributes

public void ToBytes(BinaryWriter stream)

Parameters

stream BinaryWriter

ToString()

Turn the itemstack into a simple string representation

public override string ToString()

Returns

string