Table of Contents

Class CollectibleBehavior

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll
public abstract class CollectibleBehavior
Inheritance
CollectibleBehavior
Derived
Inherited Members

Constructors

CollectibleBehavior(CollectibleObject)

public CollectibleBehavior(CollectibleObject collObj)

Parameters

collObj CollectibleObject

Fields

collObj

The collectible object (item or block) for this behavior instance.

public CollectibleObject collObj

Field Value

CollectibleObject

propertiesAtString

The properties of this block behavior.

public string propertiesAtString

Field Value

string

Properties

ClientSideOptional

If true, this behavior is not required on the client. This is here because copygirl doesn't stop asking for it. Probably breaks things. If it breaks things, complain to copygirl please :p

public virtual bool ClientSideOptional { get; }

Property Value

bool

Methods

GetHeldInteractionHelp(ItemSlot, ref EnumHandling)

Interaction help that is shown when selecting the item in the hotbar slot

public virtual WorldInteraction[] GetHeldInteractionHelp(ItemSlot inSlot, ref EnumHandling handling)

Parameters

inSlot ItemSlot
handling EnumHandling

Returns

WorldInteraction[]

GetHeldItemInfo(ItemSlot, StringBuilder, IWorldAccessor, bool)

public virtual void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)

Parameters

inSlot ItemSlot
dsc StringBuilder
world IWorldAccessor
withDebugInfo bool

GetHeldItemName(StringBuilder, ItemStack)

public virtual void GetHeldItemName(StringBuilder sb, ItemStack itemStack)

Parameters

sb StringBuilder
itemStack ItemStack

GetHeldReadyAnimation(ItemSlot, Entity, EnumHand, ref EnumHandling)

public virtual string GetHeldReadyAnimation(ItemSlot activeHotbarSlot, Entity forEntity, EnumHand hand, ref EnumHandling bhHandling)

Parameters

activeHotbarSlot ItemSlot
forEntity Entity
hand EnumHand
bhHandling EnumHandling

Returns

string

GetHeldTpHitAnimation(ItemSlot, Entity, ref EnumHandling)

public virtual string GetHeldTpHitAnimation(ItemSlot slot, Entity byEntity, ref EnumHandling bhHandling)

Parameters

slot ItemSlot
byEntity Entity
bhHandling EnumHandling

Returns

string

GetHeldTpIdleAnimation(ItemSlot, Entity, EnumHand, ref EnumHandling)

public virtual string GetHeldTpIdleAnimation(ItemSlot activeHotbarSlot, Entity forEntity, EnumHand hand, ref EnumHandling bhHandling)

Parameters

activeHotbarSlot ItemSlot
forEntity Entity
hand EnumHand
bhHandling EnumHandling

Returns

string

GetHeldTpUseAnimation(ItemSlot, Entity, ref EnumHandling)

public virtual string GetHeldTpUseAnimation(ItemSlot activeHotbarSlot, Entity forEntity, ref EnumHandling bhHandling)

Parameters

activeHotbarSlot ItemSlot
forEntity Entity
bhHandling EnumHandling

Returns

string

GetStorageFlags(ItemStack, ref EnumHandling)

public virtual EnumItemStorageFlags GetStorageFlags(ItemStack itemstack, ref EnumHandling handling)

Parameters

itemstack ItemStack
handling EnumHandling

Returns

EnumItemStorageFlags

GetToolMode(ItemSlot, IPlayer, BlockSelection)

Should return the current items tool mode.

public virtual int GetToolMode(ItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection)

Parameters

slot ItemSlot
byPlayer IPlayer
blockSelection BlockSelection

Returns

int

GetToolModes(ItemSlot, IClientPlayer, BlockSelection)

Called when the tool mode (F) key is pressed to generate the GUI

public virtual SkillItem[] GetToolModes(ItemSlot slot, IClientPlayer forPlayer, BlockSelection blockSel)

Parameters

slot ItemSlot
forPlayer IClientPlayer
blockSel BlockSelection

Returns

SkillItem[]

Initialize(JsonObject)

Called right after the block behavior was created, must call base method

public virtual void Initialize(JsonObject properties)

Parameters

properties JsonObject

OnBeforeRender(ICoreClientAPI, ItemStack, EnumItemRenderTarget, ref ItemRenderInfo)

Called when the collectible is rendered in hands, inventory or on the ground

public virtual void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)

Parameters

capi ICoreClientAPI
itemstack ItemStack
target EnumItemRenderTarget
renderinfo ItemRenderInfo

OnBlockBreaking(IPlayer, BlockSelection, ItemSlot, float, float, int, ref EnumHandling)

Player is holding this collectible and breaks the targeted block

public virtual float OnBlockBreaking(IPlayer player, BlockSelection blockSel, ItemSlot itemslot, float remainingResistance, float dt, int counter, ref EnumHandling handled)

Parameters

player IPlayer
blockSel BlockSelection
itemslot ItemSlot
remainingResistance float
dt float
counter int
handled EnumHandling

Returns

float

OnBlockBrokenWith(IWorldAccessor, Entity, ItemSlot, BlockSelection, float, ref EnumHandling)

Player has broken a block while holding this collectible. Return false if you want to cancel the block break event.

public virtual bool OnBlockBrokenWith(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, BlockSelection blockSel, float dropQuantityMultiplier, ref EnumHandling bhHandling)

Parameters

world IWorldAccessor
byEntity Entity
itemslot ItemSlot
blockSel BlockSelection
dropQuantityMultiplier float
bhHandling EnumHandling

Returns

bool

OnHeldAttackCancel(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, EnumItemUseCancelReason, ref EnumHandling)

When the player has canceled a custom attack action. Return false to deny action cancellation.

public virtual bool OnHeldAttackCancel(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, EnumItemUseCancelReason cancelReason, ref EnumHandling handling)

Parameters

secondsPassed float
slot ItemSlot
byEntity EntityAgent
blockSelection BlockSelection
entitySel EntitySelection
cancelReason EnumItemUseCancelReason
handling EnumHandling

Returns

bool

OnHeldAttackStart(ItemSlot, EntityAgent, BlockSelection, EntitySelection, ref EnumHandHandling, ref EnumHandling)

When the player has begun using this item for attacking (left mouse click). Return true to play a custom action.

public virtual void OnHeldAttackStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandHandling handHandling, ref EnumHandling handling)

Parameters

slot ItemSlot
byEntity EntityAgent
blockSel BlockSelection
entitySel EntitySelection
handHandling EnumHandHandling
handling EnumHandling

OnHeldAttackStep(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, ref EnumHandling)

Called continously when a custom attack action is playing. Return false to stop the action.

public virtual bool OnHeldAttackStep(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, ref EnumHandling handling)

Parameters

secondsPassed float
slot ItemSlot
byEntity EntityAgent
blockSelection BlockSelection
entitySel EntitySelection
handling EnumHandling

Returns

bool

OnHeldAttackStop(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, ref EnumHandling)

Called when a custom attack action is finished

public virtual void OnHeldAttackStop(float secondsPassed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSelection, EntitySelection entitySel, ref EnumHandling handling)

Parameters

secondsPassed float
slot ItemSlot
byEntity EntityAgent
blockSelection BlockSelection
entitySel EntitySelection
handling EnumHandling

OnHeldInteractCancel(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, EnumItemUseCancelReason, ref EnumHandling)

When the player released the right mouse button. Return false to deny the cancellation (= will keep using the item until OnHeldInteractStep returns false).

public virtual bool OnHeldInteractCancel(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, EnumItemUseCancelReason cancelReason, ref EnumHandling handled)

Parameters

secondsUsed float
slot ItemSlot
byEntity EntityAgent
blockSel BlockSelection
entitySel EntitySelection
cancelReason EnumItemUseCancelReason
handled EnumHandling

Returns

bool

OnHeldInteractStart(ItemSlot, EntityAgent, BlockSelection, EntitySelection, bool, ref EnumHandHandling, ref EnumHandling)

Called when the player right clicks while holding this block/item in his hands

public virtual void OnHeldInteractStart(ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, bool firstEvent, ref EnumHandHandling handHandling, ref EnumHandling handling)

Parameters

slot ItemSlot
byEntity EntityAgent
blockSel BlockSelection
entitySel EntitySelection
firstEvent bool
handHandling EnumHandHandling

Whether or not to do any subsequent actions. If not set or set to NotHandled, the action will not called on the server.

handling EnumHandling

Set to PreventDefault to not try eating the item, set to PreventSubsequent to ignore any subsequent calls to OnHeldInteractStart() of other behaviors

OnHeldInteractStep(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, ref EnumHandling)

Called every frame while the player is using this collectible

public virtual bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)

Parameters

secondsUsed float
slot ItemSlot
byEntity EntityAgent
blockSel BlockSelection
entitySel EntitySelection
handling EnumHandling

Returns

bool

OnHeldInteractStop(float, ItemSlot, EntityAgent, BlockSelection, EntitySelection, ref EnumHandling)

Called when the player successfully completed the using action, not called when successfully cancelled

public virtual void OnHeldInteractStop(float secondsUsed, ItemSlot slot, EntityAgent byEntity, BlockSelection blockSel, EntitySelection entitySel, ref EnumHandling handling)

Parameters

secondsUsed float
slot ItemSlot
byEntity EntityAgent
blockSel BlockSelection
entitySel EntitySelection
handling EnumHandling

OnLoaded(ICoreAPI)

Server Side: Called once the collectible has been registered Client Side: Called once the collectible has been loaded from server packet

public virtual void OnLoaded(ICoreAPI api)

Parameters

api ICoreAPI

OnUnloaded(ICoreAPI)

public virtual void OnUnloaded(ICoreAPI api)

Parameters

api ICoreAPI

SetToolMode(ItemSlot, IPlayer, BlockSelection, int)

Should set given toolmode

public virtual void SetToolMode(ItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection, int toolMode)

Parameters

slot ItemSlot
byPlayer IPlayer
blockSelection BlockSelection
toolMode int