Skip to content

Commit

Permalink
randomly spawn item ball every minute
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan committed May 23, 2023
1 parent ff1c699 commit d344c16
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions data/itemballs/functions/loop/every_1200_ticks.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# runs every 1200 ticks (1 minute)

# select random player to attempt item ball spawn
function itemballs:spawn/select_player
tag @a remove itemballs.attempted_spawn

# loop
schedule function itemballs:loop/every_1200_ticks 1200t
3 changes: 2 additions & 1 deletion data/itemballs/functions/on_event/on_load.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ scoreboard players set #10 itemballs.data 10

# init loops
function itemballs:loop/every_10_ticks
function itemballs:loop/every_20_ticks
function itemballs:loop/every_20_ticks
function itemballs:loop/every_1200_ticks
4 changes: 4 additions & 0 deletions data/itemballs/functions/spawn/select_player.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# attempts to spawn an item ball (executes globally)

# randomly select a player
execute as @r[tag=!itemballs.attempted_spawn] at @s run function itemballs:spawn/spawn_check
11 changes: 11 additions & 0 deletions data/itemballs/functions/spawn/spawn_check.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# attempts to spawn an item ball (executes as randomly selected player)

# get item ball count
execute store result score #itemballs.item_ball_count itemballs.temp run execute if entity @e[type=minecraft:armor_stand,tag=itemballs.marker,distance=..200]

# fail, find another player
execute if score #itemballs.item_ball_count itemballs.temp matches 3.. run tag @s add itemballs.attempted_spawn
execute if entity @s[tag=itemballs.attempted_spawn] run function itemballs:spawn/select_player

# success
execute unless entity @s[tag=itemballs.attempted_spawn] run function itemballs:spawn/spawn_item_ball
13 changes: 13 additions & 0 deletions data/itemballs/functions/spawn/spawn_item_ball.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# spawns item ball (executes as viable player)

# spawn location marker
summon minecraft:marker ~ ~ ~ {Tags:["global.ignore","itemballs.spawn_location"]}

# randomly spread
spreadplayers ~ ~ 50 150 false @e[type=minecraft:marker,tag=itemballs.spawn_location,limit=1,sort=nearest]

# spawn item ball at random location
execute at @e[type=minecraft:marker,tag=itemballs.spawn_location,limit=1,sort=nearest] run function itemballs:summon/item_ball

# remove spawn location marker
kill @e[type=minecraft:marker,tag=itemballs.spawn_location]

0 comments on commit d344c16

Please sign in to comment.