Skip to content

Add new block data #452

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions data/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,7 @@
},
{
"id": "#bs.hitbox:intangible",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/hitbox.html#entities",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/hitbox.html#blocks",
"authors": [
"Aksiome"
],
Expand All @@ -1022,13 +1022,13 @@
"minecraft_version": "1.21"
},
"updated": {
"date": "2024/09/28",
"minecraft_version": "1.21"
"date": "2025/03/10",
"minecraft_version": "1.21.4"
}
},
{
"id": "#bs.hitbox:intangible",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/hitbox.html#blocks",
"documentation": "https://docs.mcbookshelf.dev/en/latest/modules/hitbox.html#entities",
"authors": [
"Aksiome"
],
Expand All @@ -1037,8 +1037,8 @@
"minecraft_version": "1.21"
},
"updated": {
"date": "2025/03/10",
"minecraft_version": "1.21.4"
"date": "2024/09/28",
"minecraft_version": "1.21"
}
},
{
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog/v3.1.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@
### `🔬 bs.dump`

- <abbr title="Bug Fix">🐛</abbr> **[#441](https://github.com/mcbookshelf/bookshelf/issues/441)** - Fixed `#bs.dump:var` incorrectly appending `undefined` to output.

### `🧱 bs.block`

- <abbr title="Feature Improvement">✨</abbr> **[#450](https://github.com/mcbookshelf/bookshelf/issues/450)** - Added `blast_resistance`, `hardness`, `transparent`, `ignited_by_lava`, `stack_size`, and `map_color` to the block data. The return of `#bs.block:get_block` and `#bs.block:get_type` now includes these properties.
12 changes: 12 additions & 0 deletions docs/modules/block.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,12 @@ Get all data related to the block at the current location, including its state a
- {nbt}`string` **fall**: The sound played when a player falls on the block.
- {nbt}`string` **place**: The sound played when a player places the block.
- {nbt}`string` **step**: The sound played when a player steps on the block.
- {nbt}`float` **blast_resistance**: The blast resistance of the block.
- {nbt}`float` **hardness**: The hardness of the block.
- {nbt}`bool` **transparent**: Whether the block is transparent.
- {nbt}`bool` **ignited_by_lava**: Whether the block can be ignited by lava.
- {nbt}`int` **stack_size**: The stack size of the block.
- {nbt}`string` **map_color**: The map color of the block, in hexadecimal format.
:::
```

Expand Down Expand Up @@ -229,6 +235,12 @@ Get the block type at the current location. Although states, NBTs, and propertie
- {nbt}`string` **fall**: The sound played when a player falls on the block.
- {nbt}`string` **place**: The sound played when a player places the block.
- {nbt}`string` **step**: The sound played when a player steps on the block.
- {nbt}`float` **blast_resistance**: The blast resistance of the block.
- {nbt}`float` **hardness**: The hardness of the block.
- {nbt}`bool` **transparent**: Whether the block is transparent.
- {nbt}`bool` **ignited_by_lava**: Whether the block can be ignited by lava.
- {nbt}`int` **stack_size**: The stack size of the block.
- {nbt}`string` **map_color**: The map color of the block, in hexadecimal format.
:::
```

Expand Down
57 changes: 57 additions & 0 deletions modules/bs.block/gen_blast_resistance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from collections import defaultdict

from beet import Context, LootTable

from bookshelf.definitions import MC_VERSIONS
from bookshelf.helpers import (
download_and_parse_json,
gen_loot_table_tree,
render_snbt,
)

DATA_META = "https://raw.githubusercontent.com/mcbookshelf/mcdata/refs/tags/{}/blocks/data.min.json"


def beet_default(ctx: Context) -> None:
"""Generate files used by the bs.block module."""
namespace = ctx.directory.name
entries = get_blast_resistances(ctx, MC_VERSIONS[-1])

with ctx.override(generate_namespace=namespace):
ctx.generate(
"get/get_blast_resistance",
gen_get_blast_resistance_loot_table(entries),
)


def get_blast_resistances(ctx: Context, version: str) -> list[tuple[str, list[str]]]:
"""Retrieve block blast resistances for the given version."""
cache = ctx.cache[f"version/{version}"]
blocks = download_and_parse_json(cache, DATA_META.format(version))
entries = defaultdict(list)
for block, data in blocks.items():
entries[data["blast_resistance"]].append(block)
return list(entries.items())


def gen_get_blast_resistance_loot_table(entries: list) -> LootTable:
"""Generate a loot table to retrieve blast resistance."""
return LootTable(
gen_loot_table_tree(entries, lambda entry: {
"type": "item",
"name": "egg",
"functions": [{
"function": "set_custom_data",
"tag": render_snbt({
"blast_resistance": entry[0],
}),
}],
}, lambda entries: [{
"condition": "location_check",
"predicate": {"block": {"blocks": list({
item for sublist
in [b[10:] for _, b in entries]
for item in sublist
})}},
}]),
)
3 changes: 2 additions & 1 deletion modules/bs.block/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"tags": ["runtime"]
},
"pipeline": [
"gen_blocks"
"gen_blocks",
"gen_blast_resistance"
]
}
Loading