Skip to content

Commit

Permalink
add functions for scoreboards / part 3
Browse files Browse the repository at this point in the history
  • Loading branch information
fennifith committed Aug 14, 2022
1 parent 6f64668 commit 0bddc23
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
say Hello, world!

# create a new scoreboard to track the number of animals a player has spawned
scoreboard objectives add fennifith.animals_spawned dummy

# create a new scoreboard tracking the "carrot_on_a_stick" statistic
scoreboard objectives add fennifith.animals_carrot_stick minecraft.used:minecraft.carrot_on_a_stick
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# initially, set the max value to 0
scoreboard players set $max fennifith.animals_id 0

# for every pig entity in the game...
# | run a scoreboard operation...
# | | set $max in fennifith.animals_id...
# | | | if the following value is larger...
# | | | | to @s in fennifith.animals_id.
# | | | | |
execute as @e[type=pig] run scoreboard players operation $max fennifith.animals_id > @s fennifith.animals_id

# Tell the player what the max value is
tellraw @s ["The maximum value in the animals_id scoreboard is: ",{"score":{"name":"$max","objective":"fennifith.animals_id"}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# set a $counter variable to 0
scoreboard players set $counter fennifith.animals_id 0

# for every entity in @e[type=pig]...
# | store the result as the entity's "fennifith.animals_id" score
# | | add "1" to the $counter variable
# | | |
execute as @e[type=pig] store result score @s fennifith.animals_id run scoreboard players add $counter fennifith.animals_id 1

# Tell the player what the current counter value is
tellraw @s ["Unique ids have been given to ",{"score":{"name":"$counter","objective":"fennifith.animals_id"}}," entities!"]
11 changes: 11 additions & 0 deletions 3-scoreboards/data/fennifith/functions/animals/spawn.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
summon cow
summon sheep
summon pig
summon goat
summon llama

# Add 5 animals to the player's summoned animals score
scoreboard players add @s fennifith.animals_spawned 5

# Tell the player how many animals they have summoned
tellraw @s ["You have summoned ",{"score":{"name":"@s","objective":"fennifith.animals_spawned"}}," animals!"]
11 changes: 11 additions & 0 deletions 3-scoreboards/data/fennifith/functions/animals/tick.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# for every player in the game...
# | if their score for "carrot_stick" is >= 1
# | | spawn some animals
# | | |
execute as @a if score @s fennifith.animals_carrot_stick matches 1.. run function fennifith:animals/spawn

# set the "carrot_stick" score for all players to 0
scoreboard players set @a fennifith.animals_carrot_stick 0

# create a dummy objective to store unique pig entity ids
scoreboard objectives add fennifith.animals_id dummy
3 changes: 3 additions & 0 deletions 3-scoreboards/data/minecraft/tags/functions/load.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": ["fennifith:animals/load"]
}
3 changes: 3 additions & 0 deletions 3-scoreboards/data/minecraft/tags/functions/tick.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": ["fennifith:animals/tick"]
}
6 changes: 6 additions & 0 deletions 3-scoreboards/pack.mcmeta
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"pack": {
"pack_format": 10,
"description": "Spawns a bunch of animals around the player"
}
}

0 comments on commit 0bddc23

Please sign in to comment.