Custom blocks

Makes every Block of your definitions placeable. A vanilla block holds its place in the world, and an item display draws your model over it.

It runs in the basic and extensive templates as stewbeet.plugins.datapack.custom_blocks, and reads the blocks you declared with no configuration. Source

Every file one block gets

The Life Crystal Block of Stardust Fragment, declared once, ends up as 14 files:

FilesWritten by
4 functions in custom_blocks/life_crystal_block/this plugin
The crafting recipe, for Smithed CrafterRecipes
loot_table/i/life_crystal_block.jsonLoot tables
The manual page, and the block and recipe drawn for itIn-game manual
The item model, its definition, the texture and its .mcmetaItem models
The name in lang/en_us.jsonLang file

What this plugin writes

For each block, in function/custom_blocks/<id>/:

  • place_main sets the vanilla block and summons the item display.
  • place_secondary names the display and gives it the block's model.
  • destroy runs once the vanilla block is gone, and removes the display.
  • replace_item turns the dropped vanilla item into yours.

Once per pack, in function/custom_blocks/:

  • place and on_place find which of your blocks the Smithed Custom Block library just placed.
  • destroy and _groups/<vanilla block> send a display whose vanilla block is gone to that block's destroy.
  • get_rotation, check_light and compute_brightness turn the display and match its light to the world.

/function <namespace>:_stats_custom_blocks counts the blocks placed in the world, per block and per vanilla block:

Options

Set on the block's vanilla_block=VanillaBlock(...), or on the Block itself for the last two.

OptionDefaultWhat it does
idrequiredThe vanilla block that holds the place, such as "minecraft:iron_block"
block_facingFalse"player" turns the vanilla block the way vanilla turns it, towards the player for a furnace
visual_facing"none""player" turns the model towards the player, "item_frame" as the frame holding it
halfNone"click" places a slab, stairs or trapdoor on the half the player clicked
interactionNoneAn Interaction for an invisible host such as a barrier: hits to break, sounds, particles, a seat
uvlockFalseTurns copies of the model instead of the display, so textures stay on the world grid
margin1.002Scale of the model about the block's centre, so it is drawn in front of the host
machine_speedNoneHow many times faster a furnace, smoker, blast furnace or brewing stand host works
contentsFalseAn item frame instead of a vanilla block
Block.miningNoneThe tool level needed to get the item back
Block.no_silk_touch_dropNoneWhat an ore drops without Silk Touch, with optional experience

Limits

  • A block with no vanilla_block cannot be placed. The build says which ones.
  • A broken block's display goes within 2 ticks, and an ore's as soon as it drops its item. A check every 5 seconds catches anything missed.
  • The display is an entity: thousands of placed blocks cost what thousands of entities cost. The Performance guide covers the ticking ones.

Next steps

  • Definitions: every VanillaBlock option in detail.
  • Recipes: how the recipe of a block becomes a Smithed Crafter recipe.