Class ItemStack
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
public class ItemStack : IItemStack
- Inheritance
-
ItemStack
- Implements
- Inherited Members
- Extension Methods
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
BinaryReaderresolver
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
intitemClass
EnumItemClassstacksize
intstackAttributes
TreeAttributeresolver
IWorldAccessor
ItemStack(Block, int)
Create a new itemstack from given block and given stack size
public ItemStack(Block block, int stacksize = 1)
Parameters
ItemStack(CollectibleObject, int)
Create a new itemstack from given block/item and given stack size
public ItemStack(CollectibleObject collectible, int stacksize = 1)
Parameters
collectible
CollectibleObjectstacksize
int
ItemStack(Item, int)
Create a new itemstack from given item and given stack size
public ItemStack(Item item, int stacksize = 1)
Parameters
Fields
Class
Wether its a block Block or Item
public EnumItemClass Class
Field Value
Id
The id of the block or item
public int Id
Field Value
block
protected Block block
Field Value
item
protected Item item
Field Value
stacksize
protected int stacksize
Field Value
Properties
Attributes
Attributes assigned to this particular itemstack which are saved and synchronized.
public ITreeAttribute Attributes { get; set; }
Property Value
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
Collectible
The item/block base class this stack is holding
public CollectibleObject Collectible { get; }
Property Value
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
ItemAttributes
The Attributes assigned to the underlying block/item. Should not be modified, as it applies to globally.
public JsonObject ItemAttributes { get; }
Property Value
StackSize
The amount of items/blocks in this stack
public int StackSize { get; set; }
Property Value
TempAttributes
Temporary Attributes assigned to this particular itemstack, not synchronized, not saved! Modifiable.
public ITreeAttribute TempAttributes { get; set; }
Property Value
Methods
Clone()
Creates a full copy of the item stack
public ItemStack Clone()
Returns
Equals(IWorldAccessor, ItemStack, params string[])
Returns true if both stacks exactly match
public bool Equals(IWorldAccessor worldForResolve, ItemStack sourceStack, params string[] ignoreAttributeSubTrees)
Parameters
worldForResolve
IWorldAccessorsourceStack
ItemStackignoreAttributeSubTrees
string[]
Returns
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
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
IWorldAccessorinSlot
ItemSlotdebug
bool
Returns
GetEmptyClone()
Creates a full copy of the item stack, except for its stack size.
public ItemStack GetEmptyClone()
Returns
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
GetName()
Returns a human readable name of the item/block
public string GetName()
Returns
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
IWorldAccessorsearchText
string
Returns
ResolveBlockOrItem(IWorldAccessor)
Sets the item/block based on the currently set itemclass + id
public bool ResolveBlockOrItem(IWorldAccessor resolver)
Parameters
resolver
IWorldAccessor
Returns
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
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()