Table of Contents

Class BlockEntityBehavior

Namespace
Vintagestory.API.Common
Assembly
VintagestoryAPI.dll

Basic class for block entities - a data structures to hold custom information for blocks, e.g. for chests to hold it's contents Open in GitHub

public abstract class BlockEntityBehavior
Inheritance
BlockEntityBehavior
Inherited Members
Extension Methods

Constructors

BlockEntityBehavior(BlockEntity)

public BlockEntityBehavior(BlockEntity blockentity)

Parameters

blockentity BlockEntity

Fields

Api

public ICoreAPI Api

Field Value

ICoreAPI

Blockentity

The block for this behavior instance.

public BlockEntity Blockentity

Field Value

BlockEntity

properties

The properties of this block behavior.

public JsonObject? properties

Field Value

JsonObject

Properties

Block

Alias of BlockEntity.Block

public Block Block { get; }

Property Value

Block

Pos

Alias of Blockentity.Pos

public BlockPos Pos { get; }

Property Value

BlockPos

Methods

FromTreeAttributes(ITreeAttribute, IWorldAccessor)

public virtual void FromTreeAttributes(ITreeAttribute tree, IWorldAccessor worldAccessForResolve)

Parameters

tree ITreeAttribute
worldAccessForResolve IWorldAccessor

GetBlockInfo(IPlayer, StringBuilder)

public virtual void GetBlockInfo(IPlayer forPlayer, StringBuilder dsc)

Parameters

forPlayer IPlayer
dsc StringBuilder

Initialize(ICoreAPI, JsonObject)

Called right after the block behavior was created

public virtual void Initialize(ICoreAPI api, JsonObject properties)

Parameters

api ICoreAPI
properties JsonObject

OnBlockBroken(IPlayer?)

public virtual void OnBlockBroken(IPlayer? byPlayer = null)

Parameters

byPlayer IPlayer

OnBlockPlaced(ItemStack?)

public virtual void OnBlockPlaced(ItemStack? byItemStack = null)

Parameters

byItemStack ItemStack

OnBlockRemoved()

public virtual void OnBlockRemoved()

OnBlockUnloaded()

public virtual void OnBlockUnloaded()

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

[Obsolete("Use the variant with resolveImports parameter")]
public virtual void OnLoadCollectibleMappings(IWorldAccessor worldForNewMappings, Dictionary<int, AssetLocation> oldBlockIdMapping, Dictionary<int, AssetLocation> oldItemIdMapping, int schematicSeed)

Parameters

worldForNewMappings IWorldAccessor
oldBlockIdMapping Dictionary<int, AssetLocation>
oldItemIdMapping Dictionary<int, AssetLocation>
schematicSeed int

OnLoadCollectibleMappings(IWorldAccessor, Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>, int, bool)

public virtual void OnLoadCollectibleMappings(IWorldAccessor worldForNewMappings, Dictionary<int, AssetLocation> oldBlockIdMapping, Dictionary<int, AssetLocation> oldItemIdMapping, int schematicSeed, bool resolveImports)

Parameters

worldForNewMappings IWorldAccessor
oldBlockIdMapping Dictionary<int, AssetLocation>
oldItemIdMapping Dictionary<int, AssetLocation>
schematicSeed int
resolveImports bool

OnPlacementBySchematic(ICoreServerAPI, IBlockAccessor, BlockPos, Dictionary<int, Dictionary<int, int>>, int, Block, bool)

public virtual void OnPlacementBySchematic(ICoreServerAPI api, IBlockAccessor blockAccessor, BlockPos pos, Dictionary<int, Dictionary<int, int>> replaceBlocks, int centerrockblockid, Block layerBlock, bool resolveImports)

Parameters

api ICoreServerAPI
blockAccessor IBlockAccessor
pos BlockPos
replaceBlocks Dictionary<int, Dictionary<int, int>>
centerrockblockid int
layerBlock Block
resolveImports bool

OnReceivedClientPacket(IPlayer, int, byte[])

public virtual void OnReceivedClientPacket(IPlayer fromPlayer, int packetid, byte[] data)

Parameters

fromPlayer IPlayer
packetid int
data byte[]

OnReceivedServerPacket(int, byte[])

public virtual void OnReceivedServerPacket(int packetid, byte[] data)

Parameters

packetid int
data byte[]

OnStoreCollectibleMappings(Dictionary<int, AssetLocation>, Dictionary<int, AssetLocation>)

public virtual void OnStoreCollectibleMappings(Dictionary<int, AssetLocation> blockIdMapping, Dictionary<int, AssetLocation> itemIdMapping)

Parameters

blockIdMapping Dictionary<int, AssetLocation>
itemIdMapping Dictionary<int, AssetLocation>

OnTesselation(ITerrainMeshPool, ITesselatorAPI)

Let's you add your own meshes to a chunk. Don't reuse the meshdata instance anywhere in your code. Return true to skip the default mesh. WARNING! The Tesselator runs in a seperate thread, so you have to make sure the fields and methods you access inside this method are thread safe.

public virtual bool OnTesselation(ITerrainMeshPool mesher, ITesselatorAPI tessThreadTesselator)

Parameters

mesher ITerrainMeshPool

The chunk mesh, add your stuff here

tessThreadTesselator ITesselatorAPI

If you need to tesselate something, you should use this tesselator, since using the main thread tesselator can cause race conditions and crash the game

Returns

bool

True to skip default mesh, false to also add the default mesh

ToTreeAttributes(ITreeAttribute)

public virtual void ToTreeAttributes(ITreeAttribute tree)

Parameters

tree ITreeAttribute