Created
June 14, 2019 23:46
-
-
Save Adrodoc/b4904b234f57edfae1fda26c828a7ab5 to your computer and use it in GitHub Desktop.
proof of concept for simulating nested function calls with command blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# @e[limit=2] | |
tag @e[limit=2] add todo | |
tag @e[tag=todo,limit=1] add current | |
tag @e[tag=current] remove todo | |
execute as @e[tag=current] run say 1 | |
execute as @e[tag=current] run say 2 | |
tag @e[tag=current] remove current | |
# single layer | |
scoreboard objectives add mcfd_stackframe dummy | |
# set up new stackframe | |
execute as @e[type=pig] run function mcfd:new_stackframe_part | |
scoreboard players add @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# loop | |
# tag current stackframe part | |
tag @e[type=area_effect_cloud,tag=mcfd_stackframe_part,scores={mcfd_stackframe=1},limit=1] add mcfd_current_stackframe_part | |
# invert: break loop | |
# tag current entity | |
function mcfd:tag_current_entity | |
# run function content as current entity | |
execute as @e[tag=mcfd_current_entity] run say 1 | |
execute as @e[tag=mcfd_current_entity] run say 2 | |
# remove current stackframe part | |
kill @e[type=area_effect_cloud,tag=mcfd_current_stackframe_part,scores={mcfd_stackframe=1}] | |
# goto loop | |
# restore previous stackframe | |
scoreboard players remove @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# restore current entity of previous stackframe | |
function mcfd:tag_current_entity | |
# nested layer | |
scoreboard objectives add mcfd_stackframe dummy | |
# set up new stackframe | |
execute as @e[type=pig] run function mcfd:new_stackframe_part | |
scoreboard players add @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# outer_loop | |
# tag current stackframe part | |
tag @e[type=area_effect_cloud,tag=mcfd_stackframe_part,scores={mcfd_stackframe=1},limit=1] add mcfd_current_stackframe_part | |
# invert: break outer_loop | |
# tag current entity | |
function mcfd:tag_current_entity | |
# run function content as current entity | |
execute as @e[tag=mcfd_current_entity] run say 1 | |
execute as @e[tag=mcfd_current_entity] run say 2 | |
# set up new stackframe | |
execute as @e[type=sheep] run function mcfd:new_stackframe_part | |
scoreboard players add @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# inner_loop | |
# tag current stackframe part | |
tag @e[type=area_effect_cloud,tag=mcfd_stackframe_part,scores={mcfd_stackframe=1},limit=1] add mcfd_current_stackframe_part | |
# invert: break inner_loop | |
# tag current entity | |
function mcfd:tag_current_entity | |
# run function content as current entity | |
execute as @e[tag=mcfd_current_entity] run say 1 | |
execute as @e[tag=mcfd_current_entity] run say 2 | |
# remove current stackframe part | |
kill @e[type=area_effect_cloud,tag=mcfd_current_stackframe_part,scores={mcfd_stackframe=1}] | |
# goto inner_loop | |
# restore previous stackframe | |
scoreboard players remove @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# restore current entity of previous stackframe | |
function mcfd:tag_current_entity | |
# remove current stackframe part | |
kill @e[type=area_effect_cloud,tag=mcfd_current_stackframe_part,scores={mcfd_stackframe=1}] | |
# goto outer_loop | |
# restore previous stackframe | |
scoreboard players remove @e[type=area_effect_cloud,tag=mcfd_stackframe_part] mcfd_stackframe 1 | |
# restore current entity of previous stackframe | |
function mcfd:tag_current_entity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment