Skip to content

Commit

Permalink
Make blocks locked behind experiments no longer required
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeldrion committed Oct 14, 2024
1 parent f38c6e8 commit e83003a
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions build/gen_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

ONLINE = True
PARTITION_SUBSETS = 5

# Entities with variable sizes, for which not to override functions
SPECIAL_ENTITIES = [
"minecraft:armor_stand",
"minecraft:magma_cube",
Expand All @@ -21,6 +23,12 @@
"minecraft:slime",
]

# Blocks locked behind experimental features; only needs to contain blocks that are unique in their own shape groups
EXPERIMENTAL_BLOCKS = [
"minecraft:pale_moss_carpet",
"minecraft:pale_hanging_moss"
]


def remove_useless_properties(block: dict) -> dict:
"""Remove block state properties that do not affect the shape of a block, e.g. waterlogged"""
Expand Down Expand Up @@ -63,19 +71,25 @@ def generate_block_hitboxes(filename: str) -> None:
)
block_data = {group[0]: block_data[group[0]] for group in block_shape_groups}

def get_group_id(group: list[str]):
representative = group[0]
name = unnamespace(representative)
if len(group) > 1:
return f"#iris:shape_groups/{name}"
if representative in EXPERIMENTAL_BLOCKS:
return f"#iris:experiments/{name}"
return representative

# Generate block tag files for every shape group with at least two blocks
for group in block_shape_groups:
if len(group) > 1:
make_tag(group, f"{BLOCK_TAG_PATH}/shape_groups")
elif group[0] in EXPERIMENTAL_BLOCKS:
make_tag(group, f"{BLOCK_TAG_PATH}/experiments")

# Generate function files for every shape group
for group in tqdm(block_shape_groups, "Generating block functions"):
representative = group[0]
block_id = (
("#iris:shape_groups/" + unnamespace(representative))
if len(group) > 1
else representative
)
block_id = get_group_id(group)

commands = []
for state in block_data[group[0]]["states"]:
Expand Down Expand Up @@ -108,28 +122,23 @@ def generate_block_hitboxes(filename: str) -> None:
commands.append(command)

make_function(
commands, f"{FUNCTION_PATH}/block/shape_groups", unnamespace(representative)
commands, f"{FUNCTION_PATH}/block/shape_groups", unnamespace(group[0])
)

# Generate block tags and functions for faster shape group lookup
groups_per_tag = -(-len(block_shape_groups) // PARTITION_SUBSETS)
for i in range(PARTITION_SUBSETS):
values = []
commands = []

for group in block_shape_groups[i * groups_per_tag : (i + 1) * groups_per_tag]:
if len(group) > 1:
representative = unnamespace(group[0])
values.append(f"#iris:shape_groups/{representative}")
commands.append(
f"execute if block ~ ~ ~ #iris:shape_groups/{representative} "
f"run function iris:get_hitbox/block/shape_groups/{representative}"
)
else:
values.append(group[0])
commands.append(
f"execute if block ~ ~ ~ {group[0]} run "
f"function iris:get_hitbox/block/shape_groups/{unnamespace(group[0])}"
)
block_id = get_group_id(group)
values.append(block_id)
commands.append(
f"execute if block ~ ~ ~ {block_id} "
f"run function iris:get_hitbox/block/shape_groups/{unnamespace(group[0])}"
)

make_tag(values, f"{BLOCK_TAG_PATH}/tree", name=str(i), required=False)
make_function(commands, f"{FUNCTION_PATH}/block/tree", str(i))

Expand Down

0 comments on commit e83003a

Please sign in to comment.