🧱 custom_blocks#

Sets up the custom blocks of the definitions in the datapack.

beet_default(ctx: Context)[source]#

Main entry point for the custom blocks plugin. This plugin sets up custom blocks in the datapack based of the given definitions configuration.

Parameters:

ctx – The beet context.

write_block_features(
ns: str,
blocks: list[Block],
) → None[source]#

The functions of the features some blocks use, written only when one does.

warn_unplaceable_blocks() → None[source]#

Warn about the blocks without a vanilla block, which nothing can place.

write_shared_functions(ns: str) → None[source]#

The facing and light predicates, and the rotation and brightness functions every custom block uses.

write_stats_totals(ns: str, has_growing_seed: bool) → None[source]#

The stats lines counting every custom block, and every growing seed when there are any.

aiming#

Where the placer clicked a block being placed, found by stepping along their look, for the hosts of VanillaBlock.half.

write_aim(ns: str) → None[source]#

{ns}:custom_blocks/_aim/main, run as a marker summoned at the center of a block being placed, which it kills.

#upper ends at 1 when the look of the {ns}.placer player leaves the block through its upper half, which is how vanilla picks a top slab, and #floor at 1 when it leaves through the bottom face, the player having clicked the top of the block below.

destroying#

VANILLA_BLOCKS_TAG: str = 'used_vanilla_blocks'[source]#

The block tag listing every vanilla block a custom block stands in.

vanilla_block_of(
vanilla_block: JsonDict,
) → str | None[source]#

The vanilla block a custom block stands in, without its states or data, CUSTOM_BLOCK_ALTERNATIVE for an item frame block.

>>> vanilla_block_of({"id": "minecraft:furnace[lit=false]"}), vanilla_block_of({"contents": True}), vanilla_block_of({})
('minecraft:furnace', 'minecraft:item_frame', None)
write_destroy_dispatch(
ns: str,
unique_blocks: list[str],
) → None[source]#

Send a custom block whose vanilla block went missing to the group of blocks sharing that vanilla block.

write_groups(ns: str, unique_blocks: list[str]) → None[source]#

Per vanilla block, its stats line and the group function destroying whichever custom block it was.

write_block_destroys(ns: str) → None[source]#

Per custom block, the destroy function and the one turning the vanilla drop into the custom item.

write_block_destroy(
ns: str,
item: str,
data: Item,
block_id: str,
) → None[source]#

Write the destroy function of one custom block standing in block_id, and its replace_item function.

no_silk_touch_content(
ns: str,
item: str,
data: Item,
obj_block: Block,
item_nbt: str,
) → str[source]#

The replace_item commands of a block dropping something else unless mined with silk touch.

An ore relies on common_signals for the silk touch and the count, any other block checks the player’s tool itself.

loot_table_drop_lines(
ns: str,
obj_block: Block,
loot_table: LootTable | str,
) → str[source]#

The commands dropping loot_table rolled with the breaker’s tool instead of the vanilla drop, when no silk touch was used.

no_silk_touch_drop_lines(
ns: str,
drop: str | JsonDict | NoSilkTouchDrop,
) → str[source]#

The commands turning the vanilla drop into drop, an item id or a count of one, when no silk touch was used.

experience_lines(
ns: str,
experience: dict[str, int] | float,
) → str[source]#

The commands summoning, at the block, the experience points a drop gives when no silk touch was used.

>>> print(experience_lines("ns", {"min": 3, "max": 6}).strip())
execute if score #is_silk_touch ns.data matches 0 summon minecraft:experience_orb store result entity @s Value short 1 run random value 3..6
>>> print(experience_lines("ns", 2.25).strip())
execute if score #is_silk_touch ns.data matches 0 run summon minecraft:experience_orb ~ ~ ~ {Value:2s}
execute if score #is_silk_touch ns.data matches 0 if predicate {"type": "minecraft:random_chance","chance": 0.25} run summon minecraft:experience_orb ~ ~ ~ {Value:1s}
>>> experience_lines("ns", 0.0)
''
write_vanilla_checks(
ns: str,
unique_blocks: list[str],
) → None[source]#

The block tag of every vanilla block in use, and the predicates telling whether an entity still stands in its own.

write_periodic_checks(
ns: str,
has_growing_seed: bool,
) → None[source]#

Look for broken blocks every 2 ticks, every second and every 5 seconds, and refresh the brightness of a sample.

write_signal_listeners(ns: str) → None[source]#

Destroy a block from common_signals: a custom ore’s drop, any custom block in place, and an item frame block’s drop.

energy#

Registers the custom blocks with energy settings in the energy library, and refuses cables on their blocked faces.

ENERGY_DIRECTIONS: tuple[str, ...] = ('up', 'down', 'north', 'south', 'east', 'west')[source]#

The directions in the order the energy library numbers them, each followed by its opposite.

HORIZONTAL_FACINGS: tuple[tuple[str, str], ...] = (('north', '-45..45'), ('east', '45..135'), ('south', '135..-135'), ('west', '-135..-45'))[source]#

Where a machine’s front points for each range of its y_rotation, clockwise, as the wrench turns it.

RELATIVE_FACES: dict[str, int] = {'back': 2, 'front': 0, 'left': 1, 'right': 3}[source]#

How many clockwise steps each side face is from the front, left and right as seen by a player facing the front.

write_energy(ns: str) → None[source]#

Register every placeable custom block whose custom_data has energy, and refuse cables on its blocked_faces.

write_energy_calls(
funcs: BlockFunctions,
energy: JsonDict,
ns: str,
) → None[source]#

Register one custom block with the energy library, as a cable, a machine or a battery.

cable_refusals(tag: str, face: str) → list[str][source]#

The commands refusing a cable on one face of the machines with tag, for each way the machine can face.

Parameters:

face – top, bottom, or a key of RELATIVE_FACES.

>>> cable_refusals("a.solar", "top")
['execute if entity @s[tag=a.solar] if score #cable.in energy.data matches 1 run scoreboard players set #cable.out energy.data 0']
>>> [line.split(" matches ")[1][0] for line in cable_refusals("a.generator", "front")]
['3', '5', '2', '4']

host_states#

Displays following a host state that changes after placement, as the corner a stairs host makes or a furnace burning.

write_host_state(
block: Block,
) → None[source]#

Keep the custom_model_data string of the block’s display on the state of VanillaBlock.host_states its host is in.

It is set on placement and checked every second, the items definition showing the model copy of that state, and only for a block whose resource pack has such a copy.

interactions#

Blocks standing in an invisible host with an interaction entity: broken by hitting it, a seat when used.

CONVENTION_TAGS: tuple[str, ...] = ('global.ignore', 'global.ignore.kill', 'smithed.entity')[source]#

Tags keeping other packs from killing or moving the entities of a block.

interaction_of(
block: Block,
) → Interaction[source]#

The interaction of a block standing in an invisible host.

interaction_summon(
block: Block,
) → str[source]#

The commands summoning the block’s interaction on its bottom, run at the center of the block.

interaction_destroy(
block: Block,
) → str[source]#

The commands ending the block’s destroy function: feedback, its item unless #no_drop is 1, and its entities gone.

Only a creative player or a weak tool sets #no_drop, so anything else breaking the block, such as a quarry, gets the item. An item id as no_silk_touch_drop drops that item instead, as a lit lamp drops an unlit one.

feedback(
block: Block,
sound: str,
) → str[source]#

The particles of the block’s item and its hit or break sound, at the center of the block.

write_interactions(
blocks: list[Block],
) → None[source]#

The advancements noticing a player hitting or using an interaction, and what each block does then.

write_block_hit(
block: Block,
) → None[source]#

What hitting the block’s interaction does, run as it at the center of the block.

It counts the hit, then breaks the block once enough came.

inline_predicate(
predicate: JsonDict,
) → str[source]#

An entity_properties condition on the executing entity, written inline for execute if predicate.

write_seats(
seats: list[Block],
) → None[source]#

Using a seat mounts the player on an invisible display at its height, killed once empty.

machines#

Furnaces and brewing stands working VanillaBlock.machine_speed times faster, pushed one tick at a time while they work.

write_machine(
block: Block,
speed: float,
) → None[source]#

Push the progress of the block’s host by speed - 1 ticks every tick, the fractional part as a chance of one more.

A furnace’s own speed_multiplier resets whenever it lights up, which is why the progress is written by hand.

mining#

The tool a block needs to drop its item: enforced by vanilla through a host of the right level, or checked by StewBeet.

resolve_mining_hosts(
blocks: list[Block],
) → None[source]#

Give a block with mining and no host the default host of its level, and refuse a host that would not enforce it.

An ore keeps VANILLA_BLOCK_FOR_ORES, and an interaction host checks the tool itself, so both may need any tool.

Raises:

ValueError – When no vanilla host enforces the tool, or the host given is not one of Mining.hosts.

write_mining(
blocks: list[Block],
) → None[source]#

The item tag of the tools each Mining allows, and the check making an ore’s item vanish when mined with a weaker one.

An ore’s host breaks with any pickaxe, so its drop is checked against the tool of the nearest survival player within 8 blocks.

placing#

FACING: tuple[str, ...] = ('north', 'east', 'south', 'west')[source]#

The horizontal directions, in the order the #rotation score numbers them from 1, a block facing the placer.

LOOK_FACING_HOSTS: tuple[str, ...] = ('_stairs', '_fence_gate')[source]#

Hosts vanilla turns the way the placer looks rather than towards them.

write_placement(
obj_block: Block,
item: str,
data: Item,
) → tuple[str, str] | None[source]#

Write a custom block’s stats line and the functions placing it.

Returns:

The vanilla block it stands in and the entity showing it, None when its vanilla block has neither an id nor contents.

Write the advancement noticing an item frame block placed, and the function finding the frame it became.

write_display_placement(
obj_block: Block,
item: str,
data: Item,
custom_name: str,
) → str[source]#

Write the place functions of a block shown by an item display inside a vanilla block.

Returns:

The vanilla block’s id, without its states or data.

setblock_lines(
block: VanillaBlock,
custom_name: str,
) → str[source]#

The commands putting the vanilla block in place, facing as vanilla turns it when block_facing asks for it, and on the half the placer clicked when half asks for it.

A block opening an interface is placed with the custom name, which the interface then shows.

placed_variants(
block: VanillaBlock,
states: list[str],
) → list[tuple[str, list[str]]][source]#

The states the host can be placed with, each after the condition picking it from the placer’s rotation and clicked half.

display_setup(
obj_block: Block,
item: str,
data: Item,
custom_name: str,
) → str[source]#

The commands turning a freshly summoned item display into the block, run as that display.

write_frame_placement(
obj_block: Block,
item: str,
data: Item,
custom_name: str,
) → None[source]#

Write the place functions of a block that is an invisible item frame holding its model.

Have smithed’s custom block library place the blocks whose item is CUSTOM_BLOCK_VANILLA, when there are any.

write_head_searches(ns: str) → None[source]#

For each block placed as a player head, the advancement noticing it and the search finding where it went.

Search the cube around the player for the head just placed, one function per axis.

seeds#

GROWTH_TICKS: tuple[tuple[int, str], ...] = ((60, 'minute'), (5, 'second_5'), (1, 'second'))[source]#

Seconds added to the growth time per call, and the clock calling it, slowest first.

write_growing_seed(
obj_block: Block,
growing_seed: GrowingSeed,
item: str,
source_textures: dict[str, str],
) → None[source]#

Write what makes a seed grow through its stages, and what it drops once fully grown.

write_update_seed_model(
obj_block: Block,
num_stages: int,
growing_time: int,
) → None[source]#

Switch the seed’s model to the stage its growth time reached, the last stage being the grown plant.

write_growth_tick(
obj_block: Block,
item: str,
progress_stages: int,
growing_time: int,
) → None[source]#

Advance the growth time on the slowest clock that still reaches every stage on time.

seed_loot_table(
pools: list[GrowingSeedLoot],
) → JsonDict[source]#

The loot table a fully grown seed drops, one pool per loot.

A pool’s id is a vanilla item with minecraft:, one of this pack’s items when plain, and another loot table otherwise.

write_seed_functions(ns: str) → None[source]#

The function switching a seed’s stage and model, and the scores counting its growth.

write_seed_destroy(ns: str) → None[source]#

Break a seed whose block below is no longer the one it is planted on.

silent#