Skip to content

Commit 65aeff0

Browse files
committed
Add emissive layer handling for hidden entities
- Added proper handling of hidden entities with emissive layers (Endermen, Spiders, Cave Spiders) by shrinking their scale and tracking their position to prevent enclosure breaches (closes #25) - Modified the attack predicate of the secondary dig-up requirements so that it disregards the Y-distance. This allows mobs to, for example, appear at the bottom of pillars, if a player decides to build up during the night - Added an activation distance recommendation message when using the vanilla activation mode - Fixed possibility for hidden falling mobs to lose their fall distance NBT when appearing - Updated CD workflow output formatting
1 parent 20de7bd commit 65aeff0

File tree

31 files changed

+272
-41
lines changed

31 files changed

+272
-41
lines changed

.github/workflows/cd.yml

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -358,42 +358,43 @@ jobs:
358358
run: |
359359
echo "Building summary..."
360360
if [ "${{ job.status }}" == "success" ]; then
361-
SUMMARY_CONTENT="<picture>
362-
<source media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/light-theme/success.svg\">
363-
<img alt=\"✅ Success\" src=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/dark-theme/success.svg\">
364-
</picture><br>
361+
SUMMARY_CONTENT="<picture>
362+
<source media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/light-theme/success.svg\">
363+
<img alt=\"✅ Success\" src=\"https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/dark-theme/success.svg\">
364+
</picture><br>
365365
366-
**${{ github.event.repository.name }} v${{ github.event.inputs.tag }}** for **Minecraft ${{ env.MC_HUMAN_VERSION_RANGE }}** published successfully!
366+
**${{ github.event.repository.name }} v${{ github.event.inputs.tag }}** for **Minecraft ${{ env.MC_HUMAN_VERSION_RANGE }}** published successfully!
367367
368-
[View Changelog](https://github.com/${{ github.repository }}/blob/v${{ github.event.inputs.tag }}/CHANGES.md)
368+
[View Changelog](https://github.com/${{ github.repository }}/blob/v${{ github.event.inputs.tag }}/CHANGES.md)
369369
370-
**Downloads:**
371-
"
370+
**Downloads:**
371+
"
372372
373-
if [ -n "${{ steps.upload_modrinth_dp.outputs.modrinth-url }}" ]; then
374-
SUMMARY_CONTENT+="- [Modrinth (Data Pack)](${{ steps.upload_modrinth_dp.outputs.modrinth-url }})
375-
"
376-
fi
377-
if [ -n "${{ steps.upload_modrinth_mod.outputs.modrinth-url }}" ]; then
378-
SUMMARY_CONTENT+="- [Modrinth (Mod)](${{ steps.upload_modrinth_mod.outputs.modrinth-url }})
379-
"
380-
fi
381-
if [ -n "${{ steps.upload_curseforge_dp.outputs.curseforge-url }}" ]; then
382-
SUMMARY_CONTENT+="- [CurseForge (Data Pack)](${{ steps.upload_curseforge_dp.outputs.curseforge-url }})
383-
"
384-
fi
385-
if [ -n "${{ steps.upload_curseforge_mod.outputs.curseforge-url }}" ]; then
386-
SUMMARY_CONTENT+="- [CurseForge (Mod)](${{ steps.upload_curseforge_mod.outputs.curseforge-url }})
387-
"
388-
fi
389-
if [ -n "${{ steps.upload_github.outputs.github-url }}" ]; then
390-
SUMMARY_CONTENT+="- [GitHub Releases](${{ steps.upload_github.outputs.github-url }})
391-
"
392-
fi
373+
if [ -n "${{ steps.upload_modrinth_dp.outputs.modrinth-url }}" ]; then
374+
SUMMARY_CONTENT+="- [Modrinth (Data Pack)](${{ steps.upload_modrinth_dp.outputs.modrinth-url }})
375+
"
376+
fi
377+
if [ -n "${{ steps.upload_modrinth_mod.outputs.modrinth-url }}" ]; then
378+
SUMMARY_CONTENT+="- [Modrinth (Mod)](${{ steps.upload_modrinth_mod.outputs.modrinth-url }})
379+
"
380+
fi
381+
if [ -n "${{ steps.upload_curseforge_dp.outputs.curseforge-url }}" ]; then
382+
SUMMARY_CONTENT+="- [CurseForge (Data Pack)](${{ steps.upload_curseforge_dp.outputs.curseforge-url }})
383+
"
384+
fi
385+
if [ -n "${{ steps.upload_curseforge_mod.outputs.curseforge-url }}" ]; then
386+
SUMMARY_CONTENT+="- [CurseForge (Mod)](${{ steps.upload_curseforge_mod.outputs.curseforge-url }})
387+
"
388+
fi
389+
if [ -n "${{ steps.upload_github.outputs.github-url }}" ]; then
390+
SUMMARY_CONTENT+="- [GitHub Releases](${{ steps.upload_github.outputs.github-url }})
391+
"
392+
fi
393+
394+
echo -e "$SUMMARY_CONTENT" >> $GITHUB_STEP_SUMMARY
393395
394-
echo -e "$SUMMARY_CONTENT" >> $GITHUB_STEP_SUMMARY
395396
else
396-
cat << EOF >> $GITHUB_STEP_SUMMARY
397+
cat << EOF >> $GITHUB_STEP_SUMMARY
397398
<picture>
398399
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/light-theme/error.svg">
399400
<img alt="❌ Error" src="https://raw.githubusercontent.com/Mqxx/GitHub-Markdown/main/blockquotes/badge/dark-theme/error.svg">

CHANGES.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
- Improved performance by refactoring entity activation distance calculations to bundle and cache position data retrieval calls, and updating batch activation logic (up to 1 ms faster per tick!)
1+
- **Entities with emissive layers are now properly hidden** (Endermen, Spiders, and Cave Spiders) (closes [#25](https://github.com/Tschipcraft/spawnanimations/issues/25))
2+
- Improved performance by refactoring entity activation distance calculations to bundle and cache position data retrieval calls, and updating batch activation logic (the whole data pack is now up to 1ms (~45%ish) faster per tick!)
3+
- Modified the attack predicate of the secondary dig-up requirements so that it disregards the Y-distance. This allows mobs to, for example, appear at the bottom of pillars, if a player decides to build up during the night
4+
- Added an activation distance recommendation message when using the vanilla activation mode
5+
- Fixed possibility for hidden falling mobs to lose their fall distance NBT when appearing
26
- Fixed v0 save format not correctly upgrading to v1 from 24w11a to 24w20a (affecting major releases 1.20.5 and 1.20.6)
37
- Improved armor save/resolve functions to include the vanishing curse enchantment in the root proxy chest item

assets/spawnanimations/lang/en_us.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
{
2+
"modmenu.summaryTranslation.spawnanimations": "Hostile mobs dig out of the ground or poof into existence when they spawn!",
3+
"modmenu.descriptionTranslation.spawnanimations": "Hostile mobs dig out of the ground or poof into existence when they spawn!\n§lWorks with:§r Zombies, Husks, Drowned, Skeletons, Strays, Bogged, Spiders, Cave Spiders, Creepers, Slimes, Magma Cubes, Wither Skeletons, Hoglins, Zombified Piglins, Striders, Enderman and Giants.\nThis data pack is designed to be as unintrusive as possible. Hidden entities including their worn armor and tools will only be invisible and silent.\nExecute the command §o/function §ospawnanimations:settings§r for a world-specific settings menu and/or install MidnightLib for global settings across all worlds.",
4+
"fml.menu.mods.info.description.spawnanimations": "Hostile mobs dig out of the ground or poof into existence when they spawn!\n\n§lWorks with:§r Zombies, Husks, Drowned, Skeletons, Strays, Bogged, Spiders, Cave Spiders, Creepers, Slimes, Magma Cubes, Wither Skeletons, Hoglins, Zombified Piglins, Striders, Enderman and Giants.\n\nThis data pack is designed to be as unintrusive as possible. Hidden entities including their worn armor and tools will only be invisible and silent.\n\nExecute the command §o/function §ospawnanimations:settings§r for a world-specific settings menu and/or install MidnightLib for global settings across all worlds.",
5+
26
"spawnanimations.midnightconfig.title": "Spawn Animations Configuration",
37
"spawnanimations.midnightconfig.empty": "",
48
"spawnanimations.midnightconfig.configure_ingame": "§dℹ Info:§r§f To configure this data pack on a world-to-world basis,",
@@ -13,7 +17,7 @@
1317
"spawnanimations.midnightconfig.activation_distance": "Activation Distance",
1418
"spawnanimations.midnightconfig.activation_distance.tooltip": "Default: §a20 blocks§f\nMobs closer to a player than this value will play the animation.\nSetting this to 0 will use the world-specific value.",
1519
"spawnanimations.midnightconfig.activation_mode": "Activation Mode",
16-
"spawnanimations.midnightconfig.activation_mode.tooltip": "Default: §aClassic§f\n§nClassic§r: Out of range mobs will stay hidden until a player is in range\n§nVanilla§r: Out of range mobs will spawn normally",
20+
"spawnanimations.midnightconfig.activation_mode.tooltip": "Default: §aClassic§f\n§nClassic§r: Out of range mobs will stay hidden until a player is in range\n§nVanilla§r: Out of range mobs will spawn normally\nWhen set to Vanilla, it is recommended to set the activation distance to at least 25 blocks to see the animation",
1721
"spawnanimations.midnightconfig.hide_worn_armor_and_tools": "Hide worn armor and tools",
1822
"spawnanimations.midnightconfig.hide_worn_armor_and_tools.tooltip": "Default: §aYes§f\nIf enabled, stores the worn armor and tools in the feet and in some versions leggings slot of a hidden entity.\n§6⚠ Note: This may impact worn armor and tool drop rates from farms when enabled.",
1923
"spawnanimations.midnightconfig.play_animation_on_unsupported_blocks": "Play block break animation on unsupported blocks",
@@ -26,7 +30,6 @@
2630
"spawnanimations.midnightconfig.enum.mode.CLASSIC": "§aClassic",
2731
"spawnanimations.midnightconfig.enum.mode.VANILLA": "§aVanilla",
2832

29-
"modmenu.summaryTranslation.spawnanimations": "Hostile mobs dig out of the ground or poof into existence when they spawn!",
3033
"modmenu.donate": "Donate",
3134
"modmenu.modrinth": "Modrinth",
3235
"modmenu.curseforge": "CurseForge",
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
##by Tschipcraft
2+
# Shrinks entities with an emissive layer to lowest possible scale (0.0625)
3+
# We do this using a negative scale modifier to not disturb the base scale value
4+
5+
attribute @s minecraft:scale modifier add spawnanimations.ehs.scale -1000000000000000000000000000000 add_value
6+
tag @s add ts.sa.ehs.shrunk
7+
8+
# Save initial position
9+
data modify storage spawnanimations:temp Pos set from entity @s Pos
10+
execute store result score @s ts.sa.prev_x run data get storage spawnanimations:temp Pos[0] 10
11+
execute store result score @s ts.sa.prev_y run data get storage spawnanimations:temp Pos[1] 10
12+
execute store result score @s ts.sa.prev_z run data get storage spawnanimations:temp Pos[2] 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
##by Tschipcraft
2+
# Shrunk entity @s is trying to escape an enclosure, when not to far away from its previous position we move it back
3+
4+
# Get current position
5+
data modify storage spawnanimations:temp Pos set from entity @s Pos
6+
execute store result score #current ts.sa.prev_x run data get storage spawnanimations:temp Pos[0] 10
7+
execute store result score #current ts.sa.prev_y run data get storage spawnanimations:temp Pos[1] 10
8+
execute store result score #current ts.sa.prev_z run data get storage spawnanimations:temp Pos[2] 10
9+
10+
scoreboard players operation #previous ts.sa.prev_x = @s ts.sa.prev_x
11+
scoreboard players operation #previous ts.sa.prev_y = @s ts.sa.prev_y
12+
scoreboard players operation #previous ts.sa.prev_z = @s ts.sa.prev_z
13+
14+
# Calculate diff
15+
scoreboard players operation #previous ts.sa.prev_x -= #current ts.sa.prev_x
16+
scoreboard players operation #previous ts.sa.prev_y -= #current ts.sa.prev_y
17+
scoreboard players operation #previous ts.sa.prev_z -= #current ts.sa.prev_z
18+
19+
# Make sure value is positive
20+
execute if score #previous ts.sa.prev_x matches ..0 run scoreboard players operation #previous ts.sa.prev_x *= #minus ts.sa.x
21+
execute if score #previous ts.sa.prev_y matches ..0 run scoreboard players operation #previous ts.sa.prev_y *= #minus ts.sa.x
22+
execute if score #previous ts.sa.prev_z matches ..0 run scoreboard players operation #previous ts.sa.prev_z *= #minus ts.sa.x
23+
24+
# Add distances together
25+
scoreboard players operation #previous ts.sa.prev_x += #previous ts.sa.prev_y
26+
scoreboard players operation #previous ts.sa.prev_x += #previous ts.sa.prev_z
27+
28+
# Move entity back to previous location if it moved not too far (distance times 10)
29+
execute if score #previous ts.sa.prev_x matches ..30 run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/move_back
30+
31+
# Trigger animation any way
32+
function spawnanimations:internal/animation/dig_up/start
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
##by Tschipcraft
2+
# Checks if shrunk entity @s is trying to escape a potential enclosure
3+
4+
# Inside block
5+
execute unless block ~ ~ ~ #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
6+
7+
# Model default enderman hitbox size
8+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^0.3 ^1.5 ^0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
9+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^0.3 ^1.5 ^-0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
10+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^-0.3 ^1.5 ^0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
11+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^-0.3 ^1.5 ^-0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
12+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^0.3 ^2.9 ^0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
13+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^0.3 ^2.9 ^-0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
14+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^-0.3 ^2.9 ^0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
15+
execute as @s[type=minecraft:enderman,tag=ts.sa.to_verify] unless block ^-0.3 ^2.9 ^-0.3 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
16+
17+
# Model default spider hitbox size
18+
execute as @s[type=minecraft:spider,tag=ts.sa.to_verify] unless block ~0.7 ~ ~0.7 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
19+
execute as @s[type=minecraft:spider,tag=ts.sa.to_verify] unless block ~0.7 ~ ~-0.7 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
20+
execute as @s[type=minecraft:spider,tag=ts.sa.to_verify] unless block ~-0.7 ~ ~-0.7 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
21+
execute as @s[type=minecraft:spider,tag=ts.sa.to_verify] unless block ~-0.7 ~ ~0.7 #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
22+
execute as @s[type=minecraft:spider,tag=ts.sa.to_verify] unless block ~ ~0.9 ~ #spawnanimations:nonsolid run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/prevent_enclosure_breach/check_distance
23+
24+
# Update position
25+
execute if entity @s[tag=ts.sa.to_verify] run data modify storage spawnanimations:temp Pos set from entity @s Pos
26+
execute if entity @s[tag=ts.sa.to_verify] store result score @s ts.sa.prev_x run data get storage spawnanimations:temp Pos[0] 10
27+
execute if entity @s[tag=ts.sa.to_verify] store result score @s ts.sa.prev_y run data get storage spawnanimations:temp Pos[1] 10
28+
execute if entity @s[tag=ts.sa.to_verify] store result score @s ts.sa.prev_z run data get storage spawnanimations:temp Pos[2] 10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
##by Tschipcraft
2+
3+
# Move back to previous position
4+
execute store result entity @s Pos[0] double 0.1 run scoreboard players get @s ts.sa.prev_x
5+
execute store result entity @s Pos[1] double 0.1 run scoreboard players get @s ts.sa.prev_y
6+
execute store result entity @s Pos[2] double 0.1 run scoreboard players get @s ts.sa.prev_z
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
##by Tschipcraft
2+
# Resets entities with an emissive layer that got their scale changed
3+
4+
attribute @s minecraft:scale modifier remove spawnanimations.ehs.scale
5+
tag @s remove ts.sa.ehs.shrunk

data/spawnanimations/function/internal/entity/ehs/hide_exec.mcfunction

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ execute if score $hide_armor ts.sa.settings matches 1..2 as @s[type=#spawnanimat
1010

1111
# Entity specific
1212
execute if entity @s[type=minecraft:creeper] run function spawnanimations:internal/entity/ehs/entity_specific/creeper/hide
13+
execute if entity @s[type=#spawnanimations:has_emissive_layer] run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/hide

data/spawnanimations/function/internal/entity/ehs/unhide.mcfunction

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ execute as @s[tag=ts.sa.ehs.saved] run function spawnanimations:internal/entity/
99

1010
# Entity specific
1111
execute if entity @s[type=minecraft:creeper] run function spawnanimations:internal/entity/ehs/entity_specific/creeper/unhide
12+
execute as @s[tag=ts.sa.ehs.shrunk] run function spawnanimations:internal/entity/ehs/entity_specific/emissive_layer/unhide
1213

1314
tag @s remove ts.sa.hidden

0 commit comments

Comments
 (0)