Class CollectibleBehavior
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
A behavior object which can be added to any collectible. See the derived types for a list of documented collectible behaviors. Open in GitHub
[DocumentAsJson]
public abstract class CollectibleBehavior
- Inheritance
-
CollectibleBehavior
- Derived
- Inherited Members
- Extension Methods
Constructors
CollectibleBehavior(CollectibleObject)
public CollectibleBehavior(CollectibleObject collObj)
Parameters
collObjCollectibleObject
Fields
collObj
The collectible object (item or block) for this behavior instance.
public CollectibleObject collObj
Field Value
propertiesAtString
The properties of this block behavior.
public string propertiesAtString
Field Value
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
Methods
AfterGetTemperature(IWorldAccessor, ItemStack, float, ref EnumHandling)
public virtual void AfterGetTemperature(IWorldAccessor world, ItemStack itemstack, float temperature, ref EnumHandling handling)
Parameters
worldIWorldAccessoritemstackItemStacktemperaturefloathandlingEnumHandling
ConsumeCraftingIngredients(ItemSlot[], ItemSlot, GridRecipe, ref EnumHandling)
public virtual bool ConsumeCraftingIngredients(ItemSlot[] slots, ItemSlot outputSlot, GridRecipe matchingRecipe, ref EnumHandling handling)
Parameters
slotsItemSlot[]outputSlotItemSlotmatchingRecipeGridRecipehandlingEnumHandling
Returns
GetAttackPower(ItemStack, float, ref EnumHandling)
public virtual float GetAttackPower(ItemStack itemstack, float attackPower, ref EnumHandling bhHandling)
Parameters
itemstackItemStackattackPowerfloatbhHandlingEnumHandling
Returns
GetAttackRange(ItemStack, float, ref EnumHandling)
public virtual float GetAttackRange(ItemStack itemstack, float attackRange, ref EnumHandling bhHandling)
Parameters
itemstackItemStackattackRangefloatbhHandlingEnumHandling
Returns
GetDamageToEntity(float, Entity, ItemStack, ref bool, ref EnumHandling)
public virtual float GetDamageToEntity(float baseDamage, Entity entity, ItemStack itemStack, ref bool isCriticalHit, ref EnumHandling handling)
Parameters
baseDamagefloatentityEntityitemStackItemStackisCriticalHitboolhandlingEnumHandling
Returns
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
inSlotItemSlothandlingEnumHandling
Returns
GetHeldItemInfo(ItemSlot, StringBuilder, IWorldAccessor, bool)
public virtual void GetHeldItemInfo(ItemSlot inSlot, StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
Parameters
inSlotItemSlotdscStringBuilderworldIWorldAccessorwithDebugInfobool
GetHeldItemName(StringBuilder, ItemStack)
public virtual void GetHeldItemName(StringBuilder sb, ItemStack itemStack)
Parameters
sbStringBuilderitemStackItemStack
GetHeldReadyAnimation(ItemSlot, Entity, EnumHand, ref EnumHandling)
public virtual string GetHeldReadyAnimation(ItemSlot activeHotbarSlot, Entity forEntity, EnumHand hand, ref EnumHandling bhHandling)
Parameters
activeHotbarSlotItemSlotforEntityEntityhandEnumHandbhHandlingEnumHandling
Returns
GetHeldTpHitAnimation(ItemSlot, Entity, ref EnumHandling)
public virtual string GetHeldTpHitAnimation(ItemSlot slot, Entity byEntity, ref EnumHandling bhHandling)
Parameters
slotItemSlotbyEntityEntitybhHandlingEnumHandling
Returns
GetHeldTpIdleAnimation(ItemSlot, Entity, EnumHand, ref EnumHandling)
public virtual string GetHeldTpIdleAnimation(ItemSlot activeHotbarSlot, Entity forEntity, EnumHand hand, ref EnumHandling bhHandling)
Parameters
activeHotbarSlotItemSlotforEntityEntityhandEnumHandbhHandlingEnumHandling
Returns
GetHeldTpUseAnimation(ItemSlot, Entity, ref EnumHandling)
public virtual string GetHeldTpUseAnimation(ItemSlot activeHotbarSlot, Entity forEntity, ref EnumHandling bhHandling)
Parameters
activeHotbarSlotItemSlotforEntityEntitybhHandlingEnumHandling
Returns
GetMaxDurability(ItemStack, int, ref EnumHandling)
Define the max durability of this item
public virtual int GetMaxDurability(ItemStack itemstack, int durability, ref EnumHandling bhHandling)
Parameters
itemstackItemStackdurabilityintThe standard max durability of this item
bhHandlingEnumHandlingIf not set to PassThrough, the returned value is used
Returns
Exceptions
GetMergableQuantity(ItemStack, ItemStack, EnumMergePriority, ref EnumHandling)
public virtual int GetMergableQuantity(ItemStack sinkStack, ItemStack sourceStack, EnumMergePriority priority, ref EnumHandling handling)
Parameters
sinkStackItemStacksourceStackItemStackpriorityEnumMergePriorityhandlingEnumHandling
Returns
GetMiningSpeed(ItemStack, BlockSelection, Block, IPlayer, ref EnumHandling)
Multiplies resulted mining speed of the item by return value if 'bhHandling' is not equal to 'PassThrough'. If 'bhHandling' is not set to 'PreventDefault', the mining speed will be multiplied by standard item mining speed.
public virtual float GetMiningSpeed(ItemStack itemstack, BlockSelection blockSel, Block block, IPlayer forPlayer, ref EnumHandling bhHandling)
Parameters
itemstackItemStackblockSelBlockSelectionblockBlockforPlayerIPlayerbhHandlingEnumHandling
Returns
- float
Mining speed multiplier
GetMiningSpeeds(ItemSlot, ref EnumHandling)
Sets return value to mining speeds for all materials of the item if 'bhHandling' is not equal to 'PassThrough'.
public virtual Dictionary<EnumBlockMaterial, float> GetMiningSpeeds(ItemSlot slot, ref EnumHandling bhHandling)
Parameters
slotItemSlotbhHandlingEnumHandling
Returns
- Dictionary<EnumBlockMaterial, float>
Mining speeds
GetRemainingDurability(ItemStack, int, ref EnumHandling)
Sets return value to remaining durability if 'bhHandling' is not equal to 'PassThrough'. If 'bhHandling' is not set to 'PreventDefault', standard item durability will be added to result.
public virtual int GetRemainingDurability(ItemStack itemstack, int remainingDurability, ref EnumHandling bhHandling)
Parameters
itemstackItemStackremainingDurabilityintCurrent remaining durability
bhHandlingEnumHandling
Returns
- int
Remaining durability
GetStorageFlags(ItemStack, ref EnumHandling)
public virtual EnumItemStorageFlags GetStorageFlags(ItemStack itemstack, ref EnumHandling handling)
Parameters
itemstackItemStackhandlingEnumHandling
Returns
GetTemperature(IWorldAccessor, ItemStack, ref EnumHandling)
public virtual float GetTemperature(IWorldAccessor world, ItemStack itemstack, ref EnumHandling handling)
Parameters
worldIWorldAccessoritemstackItemStackhandlingEnumHandling
Returns
GetToolMode(ItemSlot, IPlayer, BlockSelection)
Should return the current items tool mode.
public virtual int GetToolMode(ItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection)
Parameters
slotItemSlotbyPlayerIPlayerblockSelectionBlockSelection
Returns
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
slotItemSlotforPlayerIClientPlayerblockSelBlockSelection
Returns
Initialize(JsonObject)
Called right after the block behavior was created, must call base method
public virtual void Initialize(JsonObject properties)
Parameters
propertiesJsonObject
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
capiICoreClientAPIitemstackItemStacktargetEnumItemRenderTargetrenderinfoItemRenderInfo
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
playerIPlayerblockSelBlockSelectionitemslotItemSlotremainingResistancefloatdtfloatcounterinthandledEnumHandling
Returns
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
worldIWorldAccessorbyEntityEntityitemslotItemSlotblockSelBlockSelectiondropQuantityMultiplierfloatbhHandlingEnumHandling
Returns
OnCreatedByCrafting(ItemSlot[], ItemSlot, ref EnumHandling)
[Obsolete("Use OnCreatedByCrafting(ItemSlot[] allInputSlots, ItemSlot outputSlot, IRecipeBase byRecipe, ref EnumHandling bhHandling) instead")]
public virtual void OnCreatedByCrafting(ItemSlot[] allInputslots, ItemSlot outputSlot, ref EnumHandling bhHandling)
Parameters
allInputslotsItemSlot[]outputSlotItemSlotbhHandlingEnumHandling
OnCreatedByCrafting(ItemSlot[], ItemSlot, GridRecipe, ref EnumHandling)
[Obsolete("Use OnCreatedByCrafting(ItemSlot[] allInputSlots, ItemSlot outputSlot, IRecipeBase byRecipe, ref EnumHandling bhHandling) instead")]
public virtual void OnCreatedByCrafting(ItemSlot[] allInputslots, ItemSlot outputSlot, GridRecipe byRecipe, ref EnumHandling bhHandling)
Parameters
allInputslotsItemSlot[]outputSlotItemSlotbyRecipeGridRecipebhHandlingEnumHandling
OnCreatedByCrafting(ItemSlot[], ItemSlot, IRecipeBase, ref EnumHandling)
public virtual void OnCreatedByCrafting(ItemSlot[] allInputSlots, ItemSlot outputSlot, IRecipeBase byRecipe, ref EnumHandling bhHandling)
Parameters
allInputSlotsItemSlot[]outputSlotItemSlotbyRecipeIRecipeBasebhHandlingEnumHandling
OnDamageItem(IWorldAccessor, Entity, ItemSlot, ref int, ref EnumHandling)
Called when item is damaged via 'CollectibleObject.DamageItem'
public virtual void OnDamageItem(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, ref int amount, ref EnumHandling bhHandling)
Parameters
worldIWorldAccessorbyEntityEntityitemslotItemSlotamountintbhHandlingEnumHandling
OnDestroyItem(IWorldAccessor, Entity, ItemSlot, ref EnumHandling)
Called when item is destroyed via 'CollectibleObject.OnDestroyItem'
public virtual void OnDestroyItem(IWorldAccessor world, Entity byEntity, ItemSlot itemSlot, ref EnumHandling bhHandling)
Parameters
worldIWorldAccessorbyEntityEntityitemSlotItemSlotbhHandlingEnumHandling
OnGetMaxDurability(ItemStack, ref EnumHandling)
Adds return value to resulted durability if 'bhHandling' is not equal to 'PassThrough'. If 'bhHandling' is not set to 'PreventDefault', standard item durability will be added to result.
[Obsolete("Use GetMaxDurability() instead, there do not return additional durability but the total durability")]
public virtual int OnGetMaxDurability(ItemStack itemstack, ref EnumHandling bhHandling)
Parameters
itemstackItemStackbhHandlingEnumHandling
Returns
- int
Additional durability
OnGetMiningSpeed(IItemStack, BlockSelection, Block, IPlayer, ref EnumHandling)
[Obsolete("Use GetMiningSpeed instead")]
public virtual float OnGetMiningSpeed(IItemStack itemstack, BlockSelection blockSel, Block block, IPlayer forPlayer, ref EnumHandling bhHandling)
Parameters
itemstackIItemStackblockSelBlockSelectionblockBlockforPlayerIPlayerbhHandlingEnumHandling
Returns
OnHandbookRecipeRender(ICoreClientAPI, GridRecipe, ItemSlot, double, double, double, double, ref EnumHandling)
public virtual void OnHandbookRecipeRender(ICoreClientAPI capi, GridRecipe recipe, ItemSlot slot, double x, double y, double z, double size, ref EnumHandling handling)
Parameters
capiICoreClientAPIrecipeGridRecipeslotItemSlotxdoubleydoublezdoublesizedoublehandlingEnumHandling
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
secondsPassedfloatslotItemSlotbyEntityEntityAgentblockSelectionBlockSelectionentitySelEntitySelectioncancelReasonEnumItemUseCancelReasonhandlingEnumHandling
Returns
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
slotItemSlotbyEntityEntityAgentblockSelBlockSelectionentitySelEntitySelectionhandHandlingEnumHandHandlinghandlingEnumHandling
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
secondsPassedfloatslotItemSlotbyEntityEntityAgentblockSelectionBlockSelectionentitySelEntitySelectionhandlingEnumHandling
Returns
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
secondsPassedfloatslotItemSlotbyEntityEntityAgentblockSelectionBlockSelectionentitySelEntitySelectionhandlingEnumHandling
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
secondsUsedfloatslotItemSlotbyEntityEntityAgentblockSelBlockSelectionentitySelEntitySelectioncancelReasonEnumItemUseCancelReasonhandledEnumHandling
Returns
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
slotItemSlotbyEntityEntityAgentblockSelBlockSelectionentitySelEntitySelectionfirstEventboolhandHandlingEnumHandHandlingWhether or not to do any subsequent actions. If not set or set to NotHandled, the action will not called on the server.
handlingEnumHandlingSet 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
secondsUsedfloatslotItemSlotbyEntityEntityAgentblockSelBlockSelectionentitySelEntitySelectionhandlingEnumHandling
Returns
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
secondsUsedfloatslotItemSlotbyEntityEntityAgentblockSelBlockSelectionentitySelEntitySelectionhandlingEnumHandling
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
apiICoreAPI
OnSetDurability(ItemStack, ref int, ref EnumHandling)
Called when item durability is set via 'CollectibleObject.SetDurability'
public virtual void OnSetDurability(ItemStack itemstack, ref int amount, ref EnumHandling bhHandling)
Parameters
itemstackItemStackamountintbhHandlingEnumHandling
OnTransitionNow(ItemSlot, TransitionableProperties, ref EnumHandling)
Called when any of its TransitionableProperties causes the stack to transition to another stack. Default behavior is to return props.TransitionedStack.ResolvedItemstack and set the stack size according to the transition rtio
public virtual ItemStack OnTransitionNow(ItemSlot slot, TransitionableProperties props, ref EnumHandling handling)
Parameters
slotItemSlotpropsTransitionablePropertieshandlingEnumHandling
Returns
- ItemStack
The stack it should transition into
OnUnloaded(ICoreAPI)
public virtual void OnUnloaded(ICoreAPI api)
Parameters
apiICoreAPI
RequiresTransitionableTicking(IWorldAccessor, ItemStack, ref EnumHandling)
public virtual bool RequiresTransitionableTicking(IWorldAccessor world, ItemStack itemstack, ref EnumHandling handling)
Parameters
worldIWorldAccessoritemstackItemStackhandlingEnumHandling
Returns
SetTemperature(IWorldAccessor, ItemStack, float, bool, ref EnumHandling)
public virtual void SetTemperature(IWorldAccessor world, ItemStack itemstack, float temperature, bool delayCooldown, ref EnumHandling handling)
Parameters
worldIWorldAccessoritemstackItemStacktemperaturefloatdelayCooldownboolhandlingEnumHandling
SetToolMode(ItemSlot, IPlayer, BlockSelection, int)
Should set given toolmode
public virtual void SetToolMode(ItemSlot slot, IPlayer byPlayer, BlockSelection blockSelection, int toolMode)
Parameters
slotItemSlotbyPlayerIPlayerblockSelectionBlockSelectiontoolModeint
TryMergeStacks(ItemStackMergeOperation, ref EnumHandling)
public virtual void TryMergeStacks(ItemStackMergeOperation op, ref EnumHandling handling)
Parameters
opItemStackMergeOperationhandlingEnumHandling
UpdateAndGetTransitionState(IWorldAccessor, ItemSlot, EnumTransitionType, ref EnumHandling)
public virtual TransitionState UpdateAndGetTransitionState(IWorldAccessor world, ItemSlot inslot, EnumTransitionType type, ref EnumHandling handling)
Parameters
worldIWorldAccessorinslotItemSlottypeEnumTransitionTypehandlingEnumHandling
Returns
UpdateAndGetTransitionStates(IWorldAccessor, ItemSlot, ref EnumHandling)
public virtual TransitionState[] UpdateAndGetTransitionStates(IWorldAccessor world, ItemSlot inslot, ref EnumHandling handling)
Parameters
worldIWorldAccessorinslotItemSlothandlingEnumHandling