Skip to content

Commit

Permalink
Merge branch 'development' into stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Aeldrion committed Feb 18, 2025
2 parents 9aed6cf + 81fbe36 commit b142752
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 47 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build/__pycache__

data/iris/function/get_hitbox/block.mcfunction
data/iris/**/tree
data/iris/**/shape_groups
53 changes: 30 additions & 23 deletions build/gen_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@

ONLINE = True
PARTITION_SUBSETS = 5

# Entities with variable sizes, for which not to override functions
SPECIAL_ENTITIES = [
"minecraft:armor_stand",
"minecraft:magma_cube",
"minecraft:phantom",
"minecraft:player",
"minecraft:pufferfish",
"minecraft:slime",
]

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


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 +69,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 +120,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 Expand Up @@ -162,7 +169,9 @@ def generate_entity_hitboxes(filename: str) -> None:
entity_data = {
key: entity_data[key]
for key in entity_data
if entity_data[key]["width"] > 0 and entity_data[key]["height"] > 0
if key not in SPECIAL_ENTITIES
and entity_data[key]["width"] > 0
and entity_data[key]["height"] > 0
}

# Group entities with identical hitboxes together
Expand All @@ -179,8 +188,6 @@ def generate_entity_hitboxes(filename: str) -> None:

# Generate function files for every hitbox group
for group in tqdm(entity_hitbox_groups, "Generating entity functions"):
if any([id_ in SPECIAL_ENTITIES for id_ in group]):
continue
width = entity_data[group[0]]["width"]
height = entity_data[group[0]]["height"]
commands = [
Expand Down
1 change: 1 addition & 0 deletions data/iris/function/get_hitbox/block/offset.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Computes seeded block offset for e.g. flowers, assuming the shape comprises a single box
#
# @within iris:get_hitbox/block
# @writes
# storage iris:data Shape: compound[]
# A list of cuboids given by two corners in the format {min: [x, y, z], max: [x, y z]}
Expand Down
1 change: 0 additions & 1 deletion data/iris/function/get_hitbox/block/xor.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Compute bitwise XOR (^) on two scores
#
# @private
# @within iris:get_hitbox/block/offset
# @reads
# score $a iris
Expand Down
6 changes: 3 additions & 3 deletions data/iris/function/get_hitbox/entity.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ execute if score $entity_found iris matches 0 if entity @s[type=#iris:tree/1] ru
execute if score $entity_found iris matches 0 if entity @s[type=#iris:tree/2] run function iris:get_hitbox/entity/tree/2
execute if score $entity_found iris matches 0 if entity @s[type=#iris:tree/3] run function iris:get_hitbox/entity/tree/3
execute if score $entity_found iris matches 0 if entity @s[type=#iris:tree/4] run function iris:get_hitbox/entity/tree/4
execute if score $entity_found iris matches 0 if entity @s[type=#iris:tree/5] run function iris:get_hitbox/entity/tree/5

# Scale
function iris:get_hitbox/entity/scale
Expand All @@ -29,6 +28,7 @@ scoreboard players operation $entity_{x} iris = ${x} iris
scoreboard players operation $entity_{y} iris = ${y} iris
scoreboard players operation $entity_{z} iris = ${z} iris
execute at @s summon minecraft:marker run function iris:get_position/get_coordinates
kill @e[type=minecraft:marker, tag=iris.coordinate_getter]
scoreboard players operation $entity_[x] iris >< $[x] iris
scoreboard players operation $entity_[y] iris >< $[y] iris
scoreboard players operation $entity_[z] iris >< $[z] iris
Expand Down Expand Up @@ -81,8 +81,8 @@ execute store result storage iris:data Shape[-1].max[1] double 0.000001 run scor
execute store result storage iris:data Shape[-1].max[2] double 0.000001 run scoreboard players get $entity_z1 iris

# Special case for item frames and paintings which are annoying
execute if score $entity_found iris matches 0 store success score $entity_found iris store success score $entity.is_item_frame iris if entity @s[type=#iris:item_frames]
execute if score $entity.is_item_frame iris matches 1 run function iris:get_hitbox/entity/item_frame
#execute if score $entity_found iris matches 0 store success score $entity_found iris store success score $entity.is_item_frame iris if entity @s[type=#iris:item_frames]
#execute if score $entity.is_item_frame iris matches 1 run function iris:get_hitbox/entity/item_frame

# Give this entity a tag and an ID, and store the ID in the hitbox
tag @s add iris.possible_target
Expand Down
4 changes: 2 additions & 2 deletions data/iris/function/get_hitbox/entity/scale.mcfunction
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#> iris:get_hitbox/entity/scale
#
# Scales a living entity according to its generic.scale attribute
# Scales a living entity according to its scale attribute
#
# @within iris:get_hitbox/entity

execute store result score $attribute_scale iris run attribute @s generic.scale get 1000
execute store result score $attribute_scale iris run attribute @s minecraft:scale get 1000
execute if score $attribute_scale iris matches 0 run return fail
execute if score $attribute_scale iris matches 1000 run return 0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scoreboard players set $entity_width iris 600000
scoreboard players set $entity_height iris 1800000
execute if predicate iris:swimming run return run scoreboard players set $entity_height iris 600000
execute if predicate iris:sneaking run return run scoreboard players set $entity_height iris 1500000
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
execute store result score $pufferfish_puffstate iris run data get entity @s PuffState
execute if score $pufferfish_puffstate iris matches 0 run scoreboard players set $entity_width iris 350000
execute if score $pufferfish_puffstate iris matches 1 run scoreboard players set $entity_width iris 500000
execute if score $pufferfish_puffstate iris matches 1 run scoreboard players set $entity_width iris 490000
execute if score $pufferfish_puffstate iris matches 2 run scoreboard players set $entity_width iris 700000
scoreboard players operation $entity_height iris = $entity_width iris

3 changes: 2 additions & 1 deletion data/iris/function/get_position/get_coordinates.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
# @within iris:get_position/main
# @within iris:get_hitbox/entity

tag @s add iris.coordinate_getter

# Get integer coordinates
data modify storage iris:data Pos set from entity @s Pos
execute store result score $[x] iris store result storage iris:args x int -1 run data get storage iris:data Pos[0]
Expand All @@ -21,4 +23,3 @@ execute store result score ${z} iris run data get storage iris:data Pos[2] 10000

# Clean up
data remove storage iris:data Pos
kill @s
2 changes: 1 addition & 1 deletion data/iris/function/get_position/get_rotation.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# Returns the context rotation as a vector
#
# @within iris:get_position/main
# @context A marker and a rotation
# @within iris:get_position/main

execute positioned 0.0 0.0 0.0 run teleport @s ^ ^ ^1000000
data modify storage iris:data Pos set from entity @s Pos
Expand Down
1 change: 1 addition & 0 deletions data/iris/function/get_position/main.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@

function iris:get_position/get_coordinates
function iris:get_position/get_rotation
kill @s
9 changes: 9 additions & 0 deletions data/iris/function/get_position/teleport.mcfunction
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
#> iris:get_position/teleport
#
# Teleports the executing entity to the current position plus a vector
#
# @context any entity
# @within iris:get_position/get_coordinates
# @input
# x, y, z: Target position relative to the current position

$teleport @s ~$(x) ~$(y) ~$(z)
2 changes: 1 addition & 1 deletion data/iris/function/get_target.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

# Reset tags, scores and storage
tag @e remove iris.targeted_entity
tag @e remove iris.potential_target
tag @e remove iris.possible_target
kill @e[type=minecraft:marker, tag=iris.targeted_block]
scoreboard players reset * iris.id

Expand Down
7 changes: 3 additions & 4 deletions data/iris/function/raycast/check_intersection/loop.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
#
# Tests for ray-box intersections with all axis-aligned bounding boxes of a hitbox
#
# @within iris:raycast/test_for_block
# @within iris:raycast/test_for_entity
# @within iris:raycast/check_intersection/loop
# @reads
# storage iris:data Shape
# A list of axis-aligned bounding boxes of the form {min: [x, y, z], max: [x, y, z]}
# @output
# Success: 1 if a box is hit, 0 otherwise
# Result: the distance to the first box that is hit
# @private
# @within iris:raycast/test_for_block
# @within iris:raycast/test_for_entity
# @within iris:raycast/check_intersection/loop

# Test for intersection with a single bounding box
data modify storage iris:data Box set from storage iris:data Shape[-1]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Converts an axis-aligned bounding box into three faces (the other tree faces are occluded) and tests for ray-plane intersections with any of them
#
# @within iris:raycast/check_intersection/loop
# @reads
# storage iris:data Box
# min: float[]
Expand All @@ -11,8 +12,6 @@
# @output
# Success: 1 if any face of the box is hit, 0 otherwise
# Result: the distance, in mm, before the first face that is hit
# @private
# @within iris:raycast/check_intersection/loop

# Decompose the box as three faces
data modify storage iris:data Faces set value [{Direction: "WEST_EAST"}, {Direction: "UP_DOWN"}, {Direction: "NORTH_SOUTH"}]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Tests for ray-plane intersections with a face
#
# @within iris:raycast/check_intersection/ray_box
# @reads
# storage iris:data Face: compound
# Direction: string
Expand All @@ -12,8 +13,6 @@
# @output
# Success: 1 if the face is hit, 0 otherwise
# Result: the distance, in mm, before the face is hit
# @private
# @within iris:raycast/check_intersection/ray_box

# Save face coordinates
execute store result score $x0 iris run data get storage iris:data Face.min[0] 1000000
Expand Down
1 change: 0 additions & 1 deletion data/iris/function/raycast/find_next_block.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Find the coordinates of the next tile that should be traversed by the ray
#
# @private
# @within iris:raycast/loop
# @writes
# scores $[x] $[y] $[z] iris
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#> iris:raycast/macro_functions/block_id_test
#
# @within iris:raycast/test_for_block
# @input
# id: A block ID or block tag ID
# @output
# Success/Result: 1 if the current block is the provided ID, 0 otherwise
# @within iris:raycast/test_for_block

$return run execute if block ~ ~ ~ $(id)
$return run execute if block ~ ~ ~ $(id)
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#
# Calls the provided function
#
# @within iris:raycast/on_hit
# @input
# function: a function name or function tag name
# @within iris:raycast/on_hit

$function $(function)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Auxiliary command for running macros from find_next_block
# Note: because there are only three possible input value combinations, they should all be cached and so the overhead from runtime compilation of macro lines should be minimal
#
# @within iris:raycast/find_next_block
# @input
# a: The axis along which we are moving (for example, if the ray moves one tile up, this is 'y'). One of 'x', 'y', or 'z'.
# b: Another axis. One of 'x', 'y', or 'z'.
Expand Down
1 change: 0 additions & 1 deletion data/iris/function/raycast/on_hit.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
# Writes all available information about the encountered block or entity
# See iris:get_target for full documentation
#
# @private
# @within iris:raycast/loop

# Write target type (one of BLOCK, ENTITY)
Expand Down
1 change: 1 addition & 0 deletions data/iris/function/raycast/test_for_block.mcfunction
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#> iris:raycast/test_for_block
#
# @within iris:raycast/loop
# @output
# Result: 0
# Success: 1 if a block was hit, 0 otherwise
Expand Down
1 change: 1 addition & 0 deletions data/iris/function/raycast/test_for_entity.mcfunction
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#> iris:raycast/test_for_entity
#
# @within iris:raycast/loop
# @output
# Result: 0
# Success: 1 if an entity was hit, 0 otherwise
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Rationale: for ${x} less than 100000, using the input as is in the fractional part of the corresponding relative coordinate in the teleport command sends the entity too far away (for example for ${x} = 3, we want to teleport to ~0.000003, not ~0.3)
# To avoid this issue, we pad the input value with six leading zeros, and we then cut the last six digits: 3 -> 0000003 -> tp @s ~0.000003 ...
#
# @within iris:set_coordinates/main
# @input
# value
# A numeric value between 0 and 999999
Expand Down
10 changes: 10 additions & 0 deletions data/iris/function/set_coordinates/teleport.mcfunction
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
#> iris:get_position/teleport
#
# Teleports the executing entity to a position given by integer and fractional coordinates
#
# @context any entity
# @within iris:get_position/get_coordinates
# @input
# x, y, z: The integer part (rounding near -inf) of the target coordinates
# dx, dy, dz: The fractional part of the target coordinates, in millionths of a block (must include leading zeros, e.g. 027319 or 463205 or 000000)

$teleport @s $(x).0 $(y).0 $(z).0
$execute at @s run teleport @s ~0.$(dx) ~0.$(dy) ~0.$(dz)
2 changes: 1 addition & 1 deletion pack.mcmeta
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"pack": {
"pack_format": 48,
"pack_format": 56,
"description": "A utility data pack to determine what block or entity a player is looking at"
}
}

0 comments on commit b142752

Please sign in to comment.