Skip to content

Instantly share code, notes, and snippets.

@towerofnix
Created June 9, 2017 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save towerofnix/8c7447ee1b54b7987eb1b57fcd35e977 to your computer and use it in GitHub Desktop.
Save towerofnix/8c7447ee1b54b7987eb1b57fcd35e977 to your computer and use it in GitHub Desktop.
A basic entity loop demo using Minecraft 1.12's new mcfunction code — see http://minecraft.gamepedia.com/Functions
# Basic loop demo.
# The very first thing we need to do is all of our target entities as
# uncounted. Note that the loop iteration code will remove this tag as it
# runs.
scoreboard players tag @e[type=zombie] add zombie_loop_not_counted
# Now we'll start the iteration loop, but only if there's at least one
# uncounted entity. There's no sense in iterating over an empty list!
function test:zombie_loop/loop if @e[tag=zombie_loop_not_counted]
# First, grab one uncounted entity and mark it as the current entity.
# That means we'll be using it as our "current item", this iteration.
scoreboard players tag @e[tag=zombie_loop_not_counted,c=1] add zombie_loop_current
# Now that we've got an entity marked as the current entity, we can use it
# however we want:
execute @e[tag=zombie_loop_current] ~ ~ ~ particle cloud ~ ~0.5 ~ 1 1 1 0.1 100
execute @e[tag=zombie_loop_current] ~ ~ ~ say Hello!
# Now that we've gone and used this entity, we can remove it from the
# uncounted entity list by removing the relevant tag:
scoreboard players tag @e[tag=zombie_loop_current] remove zombie_loop_not_counted
# We're done with this entity, so we can remove the tag that says it's the
# current entity:
scoreboard players tag @e[tag=zombie_loop_current] remove zombie_loop_current
# Now we'll run the loop iteration code again, but only if there's still at
# at least one uncounted entity.
function test:zombie_loop/loop if @e[tag=zombie_loop_not_counted]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment