Class BlockBehavior
- Namespace
- Vintagestory.API.Common
- Assembly
- VintagestoryAPI.dll
Allows for definitions of behaviors of a block that can be applied to any block See the derived types for a list of all documented block behaviors. Open in GitHub
[DocumentAsJson]
public abstract class BlockBehavior : CollectibleBehavior
- Inheritance
-
BlockBehavior
- Derived
- Inherited Members
- Extension Methods
Constructors
BlockBehavior(Block)
public BlockBehavior(Block block)
Parameters
blockBlock
Fields
block
The block for this behavior instance.
public Block block
Field Value
Methods
Activate(IWorldAccessor, Caller, BlockSelection, ITreeAttribute, ref EnumHandling)
public virtual void Activate(IWorldAccessor world, Caller caller, BlockSelection blockSel, ITreeAttribute activationArgs, ref EnumHandling handled)
Parameters
worldIWorldAccessorcallerCallerblockSelBlockSelectionactivationArgsITreeAttributehandledEnumHandling
CanAttachBlockAt(IBlockAccessor, Block, BlockPos, BlockFacing, ref EnumHandling, Cuboidi)
Used by torches and other blocks to check if it can attach itself to that block. The default behavior tests for SideSolid[blockFace.Index]
public virtual bool CanAttachBlockAt(IBlockAccessor world, Block block, BlockPos pos, BlockFacing blockFace, ref EnumHandling handling, Cuboidi attachmentArea = null)
Parameters
worldIBlockAccessorblockBlockposBlockPosblockFaceBlockFacinghandlingEnumHandlingattachmentAreaCuboidi
Returns
CanCreatureSpawnOn(IBlockAccessor, BlockPos, EntityProperties, BaseSpawnConditions, ref EnumHandling)
Should return if supplied entitytype is allowed to spawn on this block
public virtual bool CanCreatureSpawnOn(IBlockAccessor blockAccessor, BlockPos pos, EntityProperties type, BaseSpawnConditions sc, ref EnumHandling handling)
Parameters
blockAccessorIBlockAccessorposBlockPostypeEntityPropertiesscBaseSpawnConditionshandlingEnumHandling
Returns
CanPlaceBlock(IWorldAccessor, IPlayer, BlockSelection, ref EnumHandling, ref string)
Step 2: Test if the block can be placed
public virtual bool CanPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
Parameters
worldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionhandlingEnumHandlingfailureCodestring
Returns
DoPlaceBlock(IWorldAccessor, IPlayer, BlockSelection, ItemStack, ref EnumHandling)
Step 3: Place the block. Return false if it cannot be placed (but you should rather return false in CanPlaceBlock).
public virtual bool DoPlaceBlock(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ItemStack byItemStack, ref EnumHandling handling)
Parameters
worldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionbyItemStackItemStackhandlingEnumHandling
Returns
GetDrops(IWorldAccessor, BlockPos, IPlayer, ref float, ref EnumHandling)
Is called before a block is broken, should return what items this block should drop. Return null or empty array for no drops. The default behavior drops whatever block.Drops is set to.
public virtual ItemStack[] GetDrops(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref float dropChanceMultiplier, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPosbyPlayerIPlayerdropChanceMultiplierfloathandlingEnumHandling
Returns
GetHeatRetention(BlockPos, BlockFacing, ref EnumHandling)
[Obsolete("Use GetRetention() instead")]
public virtual int GetHeatRetention(BlockPos pos, BlockFacing facing, ref EnumHandling handled)
Parameters
posBlockPosfacingBlockFacinghandledEnumHandling
Returns
GetHeldBlockInfo(IWorldAccessor, ItemSlot)
public virtual string GetHeldBlockInfo(IWorldAccessor world, ItemSlot inSlot)
Parameters
worldIWorldAccessorinSlotItemSlot
Returns
GetHorizontallyFlippedBlockCode(EnumAxis, ref EnumHandling)
For any block that can be flipped vertically, this method should be implemented to return the correctly flipped block code. It is used by the world edit tool for allowing block data rotations
public virtual AssetLocation GetHorizontallyFlippedBlockCode(EnumAxis axis, ref EnumHandling handling)
Parameters
axisEnumAxishandlingEnumHandling
Returns
GetLiquidBarrierHeightOnSide(BlockFacing, BlockPos, ref EnumHandling)
public virtual float GetLiquidBarrierHeightOnSide(BlockFacing face, BlockPos pos, ref EnumHandling handled)
Parameters
faceBlockFacingposBlockPoshandledEnumHandling
Returns
GetMiningSpeedModifier(IWorldAccessor, BlockPos, IPlayer)
If this is less than 1.0, will slow down mining of the given block (e.g. used for reinforced blocks)
public virtual float GetMiningSpeedModifier(IWorldAccessor world, BlockPos pos, IPlayer byPlayer)
Parameters
worldIWorldAccessorposBlockPosbyPlayerIPlayer
Returns
GetPlacedBlockInfo(IWorldAccessor, BlockPos, IPlayer)
Called by the block info HUD for displaying additional information
public virtual string GetPlacedBlockInfo(IWorldAccessor world, BlockPos pos, IPlayer forPlayer)
Parameters
worldIWorldAccessorposBlockPosforPlayerIPlayer
Returns
GetPlacedBlockInteractionHelp(IWorldAccessor, BlockSelection, IPlayer, ref EnumHandling)
public virtual WorldInteraction[] GetPlacedBlockInteractionHelp(IWorldAccessor world, BlockSelection selection, IPlayer forPlayer, ref EnumHandling handling)
Parameters
worldIWorldAccessorselectionBlockSelectionforPlayerIPlayerhandlingEnumHandling
Returns
GetPlacedBlockName(StringBuilder, IWorldAccessor, BlockPos)
public virtual void GetPlacedBlockName(StringBuilder sb, IWorldAccessor world, BlockPos pos)
Parameters
sbStringBuilderworldIWorldAccessorposBlockPos
GetRetention(BlockPos, BlockFacing, EnumRetentionType, ref EnumHandling)
public virtual int GetRetention(BlockPos pos, BlockFacing facing, EnumRetentionType type, ref EnumHandling handled)
Parameters
posBlockPosfacingBlockFacingtypeEnumRetentionTypehandledEnumHandling
Returns
GetRotatedBlockCode(int, ref EnumHandling)
For any block that can be rotated, this method should be implemented to return the correct rotated block code. It is used by the world edit tool for allowing block data rotations
public virtual AssetLocation GetRotatedBlockCode(int angle, ref EnumHandling handling)
Parameters
angleinthandlingEnumHandling
Returns
GetSnowCoveredBlockCode(float)
public virtual AssetLocation GetSnowCoveredBlockCode(float snowLevel)
Parameters
snowLevelfloat
Returns
GetVerticallyFlippedBlockCode(ref EnumHandling)
For any block that can be flipped upside down, this method should be implemented to return the correctly flipped block code. It is used by the world edit tool for allowing block data rotations
public virtual AssetLocation GetVerticallyFlippedBlockCode(ref EnumHandling handling)
Parameters
handlingEnumHandling
Returns
IsReplacableBy(Block, ref EnumHandling)
Used to determine if a block should be treated like air when placing blocks. (e.g. used for tallgrass)
public virtual bool IsReplacableBy(Block block, ref EnumHandling handling)
Parameters
blockBlockhandlingEnumHandling
Returns
OnAsyncClientParticleTick(IAsyncParticleManager, BlockPos, float, float)
public virtual void OnAsyncClientParticleTick(IAsyncParticleManager manager, BlockPos pos, float windAffectednessAtPos, float secondsTicking)
Parameters
managerIAsyncParticleManagerposBlockPoswindAffectednessAtPosfloatsecondsTickingfloat
OnBlockBroken(IWorldAccessor, BlockPos, IPlayer, ref EnumHandling)
Called when a survival player has broken the block. The default behavior removes the block and spawns the block drops.
public virtual void OnBlockBroken(IWorldAccessor world, BlockPos pos, IPlayer byPlayer, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPosbyPlayerIPlayerhandlingEnumHandling
OnBlockExploded(IWorldAccessor, BlockPos, BlockPos, EnumBlastType, ref EnumHandling)
public virtual void OnBlockExploded(IWorldAccessor world, BlockPos pos, BlockPos explosionCenter, EnumBlastType blastType, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPosexplosionCenterBlockPosblastTypeEnumBlastTypehandlingEnumHandling
OnBlockInteractCancel(float, IWorldAccessor, IPlayer, BlockSelection, ref EnumHandling)
public virtual bool OnBlockInteractCancel(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
Parameters
secondsUsedfloatworldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionhandlingEnumHandling
Returns
OnBlockInteractStart(IWorldAccessor, IPlayer, BlockSelection, ref EnumHandling)
When a player does a right click while targeting this placed block. Should return true if the event is handled, so that other events can occur, e.g. eating a held item if the block is not interactable with.
public virtual bool OnBlockInteractStart(IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
Parameters
worldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionhandlingEnumHandling
Returns
OnBlockInteractStep(float, IWorldAccessor, IPlayer, BlockSelection, ref EnumHandling)
public virtual bool OnBlockInteractStep(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
Parameters
secondsUsedfloatworldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionhandlingEnumHandling
Returns
OnBlockInteractStop(float, IWorldAccessor, IPlayer, BlockSelection, ref EnumHandling)
public virtual void OnBlockInteractStop(float secondsUsed, IWorldAccessor world, IPlayer byPlayer, BlockSelection blockSel, ref EnumHandling handling)
Parameters
secondsUsedfloatworldIWorldAccessorbyPlayerIPlayerblockSelBlockSelectionhandlingEnumHandling
OnBlockPlaced(IWorldAccessor, BlockPos, ref EnumHandling)
Step 4: Block was placed. Always called when a block has been placed through whatever method, except during worldgen or via ExchangeBlock() Until 1.20: The BlockEntity (if the block has one) does not exist yet at this point and will not be generated if handling is not PassThrough 1.21+: The BlockEntity (if the block has one) exists at this point. Setting handling to PreventDefault or PreventSubsequent has no effect on BlockEntity creation, but may affect/prevent later behaviors
public virtual void OnBlockPlaced(IWorldAccessor world, BlockPos blockPos, ref EnumHandling handling)
Parameters
worldIWorldAccessorblockPosBlockPoshandlingEnumHandling
OnBlockRemoved(IWorldAccessor, BlockPos, ref EnumHandling)
Always called when a block has been removed through whatever method, except during worldgen or via ExchangeBlock() For Worldgen you might be able to use TryPlaceBlockForWorldGen() to attach custom behaviors during placement/removal
The default behavior is to delete the block entity, if this block has any
public virtual void OnBlockRemoved(IWorldAccessor world, BlockPos pos, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPoshandlingEnumHandling
OnCreatedByCrafting(ItemSlot[], ItemSlot, GridRecipe, ref EnumHandling)
public override void OnCreatedByCrafting(ItemSlot[] allInputslots, ItemSlot outputSlot, GridRecipe byRecipe, ref EnumHandling handled)
Parameters
allInputslotsItemSlot[]outputSlotItemSlotbyRecipeGridRecipehandledEnumHandling
OnNeighbourBlockChange(IWorldAccessor, BlockPos, BlockPos, ref EnumHandling)
Called when any of it's 6 neighbour blocks has been changed
public virtual void OnNeighbourBlockChange(IWorldAccessor world, BlockPos pos, BlockPos neibpos, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPosneibposBlockPoshandlingEnumHandling
OnPickBlock(IWorldAccessor, BlockPos, ref EnumHandling)
When the player has presed the middle mouse click on the block. The default behavior returns an itemstack with the block itself
public virtual ItemStack OnPickBlock(IWorldAccessor world, BlockPos pos, ref EnumHandling handling)
Parameters
worldIWorldAccessorposBlockPoshandlingEnumHandling
Returns
ShouldReceiveClientParticleTicks(IWorldAccessor, IPlayer, BlockPos, ref EnumHandling)
Everytime the player moves by 8 blocks (or rather leaves the current 8-grid), a scan of all blocks 32x32x32 blocks around the player is initiated and this method is called. If the method returns true, the block is registered to a client side game ticking for spawning particles and such. This method will be called everytime the player left his current 8-grid area.
The default behavior is to return true if block.ParticleProperties are set
public virtual bool ShouldReceiveClientParticleTicks(IWorldAccessor world, IPlayer byPlayer, BlockPos pos, ref EnumHandling handling)
Parameters
worldIWorldAccessorbyPlayerIPlayerposBlockPoshandlingEnumHandling
Returns
TryPlaceBlock(IWorldAccessor, IPlayer, ItemStack, BlockSelection, ref EnumHandling, ref string)
Step 1: Called when the player attempts to place this block. The default behavior calls Block.DoPlaceBlock(). If returned true and default behavior has not been prevented, the game will next call CanPlaceBlock(). If that method also returns true and default behavior has not been overriden, DoPlaceBlock() will get called.
public virtual bool TryPlaceBlock(IWorldAccessor world, IPlayer byPlayer, ItemStack itemstack, BlockSelection blockSel, ref EnumHandling handling, ref string failureCode)
Parameters
worldIWorldAccessorbyPlayerIPlayeritemstackItemStackblockSelBlockSelectionhandlingEnumHandlingfailureCodestring