Skip to content

CustomBlock

Namespace Mc.Scripting.Content · Kind class (sealed)

public sealed class CustomBlock

A custom block: a state of a vanilla block that vanilla play seldom produces (and never turns a block into: the engine guards it), with its own hardness, drops and behaviour. The world stores a plain vanilla block state (so a server without the plugin shows a note block, never a corrupt chunk); a resource pack gives that state its own model (ResourcePackBuilder.AddCustomBlock).

Which state. Custom blocks live in the note block’s states with a mob head instrument (the ones nobody gets without a head above the block), 175 of them, handed out in registration order and remembered in the file named by content.state_file in Ramjet.toml, so the same id gets the same state after a restart. CustomBlock.BaseBlock names the family: only minecraft:note_block exists in this version. While a block is registered the vanilla note block behaviour (tuning, notes, the instrument following the block below) is suppressed for its state.

Mining. The server decides how long a block takes to break, from CustomBlock.HardnessValue; the client predicts it from the note block (hardness 0.8), so a block that takes much longer than that appears to break on the client and comes back (the server refuses to finish it early): keep custom hardness near 0.8 or lower for smooth mining.

Member Description
CustomBlock(string id, string baseBlock = "minecraft:note_block") Creates a definition.
public CustomBlock(string id, string baseBlock = "minecraft:note_block")

Creates a definition.

Parameters

Name Type Description
id string The id of the block, "myplugin:ruby_ore".
baseBlock string = "minecraft:note_block" The vanilla block whose state space hosts it (only minecraft:note_block).
Member Description
string BaseBlock { get; } The vanilla block whose states host it.
float HardnessValue { get; } How long it takes to mine (vanilla hardness; negative = unbreakable).
string Id { get; } The id.
string? ModelId { get; } The model id of the block in the resource pack (assets/myplugin/models/block/ruby_ore.json is "myplugin:block/ruby_ore"), or null.
BlockState State { get; } The block state that stands for the block in the world (valid after registration).
public string BaseBlock { get; }

The vanilla block whose states host it.

public float HardnessValue { get; }

How long it takes to mine (vanilla hardness; negative = unbreakable).

public string Id { get; }

The id.

public string? ModelId { get; }

The model id of the block in the resource pack (assets/myplugin/models/block/ruby_ore.json is "myplugin:block/ruby_ore"), or null.

public BlockState State { get; }

The block state that stands for the block in the world (valid after registration).

Member Description
CustomBlock Drops(Func<BlockBreakContext, IEnumerable<ItemStack>> drops) Sets what the block drops when a player breaks it (nothing drops in creative mode, and nothing by default).
CustomBlock DropsItem(CustomItem item, int count = 1) The block drops this item (a registered custom item or any stack) when broken.
CustomBlock Hardness(float hardness) Sets the hardness.
CustomBlock Model(string modelId) Sets the model the resource pack gives the block (used by ResourcePackBuilder.AddCustomBlock).
CustomBlock OnBreak(Action<BlockBreakContext> handler) Sets what happens when a player breaks the block (before the drops; cancel the context to keep the block).
CustomBlock OnInteract(Action<BlockInteractContext> handler) Sets what happens when a player right-clicks the block (sneaking with an item in hand skips it, like vanilla blocks).
CustomBlock OnPlace(Action<BlockPlaceContext> handler) Sets what happens when a player places the block with a custom item (CustomItem.Places); cancel the context to refuse.
bool Place(World world, BlockPos pos) Puts the block into the world (registered blocks only).
public CustomBlock Drops(Func<BlockBreakContext, IEnumerable<ItemStack>> drops)

Sets what the block drops when a player breaks it (nothing drops in creative mode, and nothing by default).

Parameters

Name Type Description
drops Func<BlockBreakContext, IEnumerable<ItemStack>> Gives the stacks to drop.

Returns CustomBlock: This definition.

public CustomBlock DropsItem(CustomItem item, int count = 1)

The block drops this item (a registered custom item or any stack) when broken.

Parameters

Name Type Description
item CustomItem The item.
count int = 1 How many.

Returns CustomBlock: This definition.

public CustomBlock Hardness(float hardness)

Sets the hardness.

Parameters

Name Type Description
hardness float The hardness (stone is 1.5; negative = unbreakable).

Returns CustomBlock: This definition.

public CustomBlock Model(string modelId)

Sets the model the resource pack gives the block (used by ResourcePackBuilder.AddCustomBlock).

Parameters

Name Type Description
modelId string The block model id, "myplugin:block/ruby_ore".

Returns CustomBlock: This definition.

public CustomBlock OnBreak(Action<BlockBreakContext> handler)

Sets what happens when a player breaks the block (before the drops; cancel the context to keep the block).

Parameters

Name Type Description
handler Action<BlockBreakContext> The handler.

Returns CustomBlock: This definition.

public CustomBlock OnInteract(Action<BlockInteractContext> handler)

Sets what happens when a player right-clicks the block (sneaking with an item in hand skips it, like vanilla blocks).

Parameters

Name Type Description
handler Action<BlockInteractContext> The handler.

Returns CustomBlock: This definition.

public CustomBlock OnPlace(Action<BlockPlaceContext> handler)

Sets what happens when a player places the block with a custom item (CustomItem.Places); cancel the context to refuse.

Parameters

Name Type Description
handler Action<BlockPlaceContext> The handler.

Returns CustomBlock: This definition.

public bool Place(World world, BlockPos pos)

Puts the block into the world (registered blocks only).

Parameters

Name Type Description
world World The dimension.
pos BlockPos The position.

Returns bool: True when the block was set.

BlockBreakContext · BlockInteractContext · BlockPlaceContext · BlockPos · BlockState · CustomItem · ItemStack · World