Skip to content

Commit

Permalink
rev 1.5
Browse files Browse the repository at this point in the history
- 1.20.5 - 1.21 compatibility: new datapack format
- all versions: fixed bug where multiple dragons spawned simultaneously for creative users when
                the admin menu allowed non-book spawning
- all versions: the fireball cooldown is now configurable in the admin menu
  • Loading branch information
Peter Svensson committed Jun 14, 2024
1 parent 5d45693 commit 5c55940
Show file tree
Hide file tree
Showing 86 changed files with 1,107 additions and 10 deletions.
5 changes: 5 additions & 0 deletions 1_20_5/data/minecraft/tags/function/load.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values":[
"ridedragon:z_init"
]
}
5 changes: 5 additions & 0 deletions 1_20_5/data/minecraft/tags/function/tick.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values":[
"ridedragon:z_main"
]
}
14 changes: 14 additions & 0 deletions 1_20_5/data/ridedragon/functions/admin.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Description: Display admin options in chat
# Called by: Player
# Entity @s: Player
#
tellraw @s [{"text":"Rideable Dragons - Admin Options","color":"yellow","bold":true}]
tellraw @s [{"text":"Get book from help: ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.book_help", "color":"green", "clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/book_from_help_toggle"}, "hoverEvent":{"action":"show_text", "contents":{"text":"Click to toggle", "color":"yellow"}}}]
tellraw @s [{"text":"Survival players can summon dragons: ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.can_summon", "color":"green", "clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/can_summon_toggle"}, "hoverEvent":{"action":"show_text", "contents":{"text":"Click to toggle", "color":"yellow"}}}]
tellraw @s [{"text":"Summon without the ","color":"aqua"},{"text":"Book of Dragons","color":"light_purple"},{"text":": ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.summon_without_book", "color":"green", "clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/summon_without_book_toggle"}, "hoverEvent":{"action":"show_text", "contents":{"text":"Click to toggle", "color":"yellow"}}}]
tellraw @s [{"text":"Players can fire dragon fireballs: ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.can_fire", "color":"green", "clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/can_fire_toggle"}, "hoverEvent":{"action":"show_text", "contents":{"text":"Click to toggle", "color":"yellow"}}}]
tellraw @s [{"text":"Fireball cooldown (1/20s): ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.fire_cooldown"},{"text":" (","color":"aqua"},{"text":" + ", "color":"green","clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/fireball_cooldown_increase"},"hoverEvent":{"action":"show_text", "contents":{"text":"Click to increase", "color":"yellow"}}},{"text":"/","color":"aqua"},{"text":" - ", "color":"green","clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/fireball_cooldown_decrease"},"hoverEvent":{"action":"show_text", "contents":{"text":"Click to decrease", "color":"yellow"}}},{"text":")","color":"aqua"}]
tellraw @s [{"text":"Initial dragon health : ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.dragon_health"},{"text":" (","color":"aqua"},{"text":" + ", "color":"green","clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/dragon_health_increase"},"hoverEvent":{"action":"show_text", "contents":{"text":"Click to increase", "color":"yellow"}}},{"text":"/","color":"aqua"},{"text":" - ", "color":"green","clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/dragon_health_decrease"},"hoverEvent":{"action":"show_text", "contents":{"text":"Click to decrease", "color":"yellow"}}},{"text":")","color":"aqua"}]
tellraw @s [{"text":"Vanish all tame tragons", "color":"red", "clickEvent":{"action":"run_command", "value":"/function ridedragon:z_admin/vanish_all"}, "hoverEvent":{"action":"show_text", "contents":{"text":"Click to vanish all loaded tame dragons", "color":"red"}}}]
tellraw @s [{"text":"--------------------------","color":"yellow","bold":true}]
1 change: 1 addition & 0 deletions 1_20_5/data/ridedragon/functions/give_book.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loot give @p loot ridedragon:book
2 changes: 2 additions & 0 deletions 1_20_5/data/ridedragon/functions/silence_dragon.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

execute as @e[type=ender_dragon,tag=dragonvisible,distance=..10,sort=nearest,limit=1] at @s run function ridedragon:z_silence_toggle
20 changes: 20 additions & 0 deletions 1_20_5/data/ridedragon/functions/summon_dragon.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Step the global counter. It is used as a pseudo-uuid that can be stored in the entity data.
scoreboard players add #rd_global_cnt rd_id 1

summon minecraft:horse ~ ~1 ~ {NoAI:1b,Invulnerable:1b,Tags:["dragonseat","dragon_temp"],DeathLootTable:"minecraft:empty",Attributes:[{Name:"generic.knockback_resistance",Base:10000f}],active_effects:[{id:invisibility,amplifier:0,duration:2147483647,show_particles:0b}],Silent:1b}
scoreboard players operation @e[type=minecraft:horse,tag=dragon_temp,distance=..2,limit=1] rd_id = #rd_global_cnt rd_id
tag @e[type=minecraft:horse,tag=dragon_temp,distance=..2,limit=1] remove dragon_temp

#summon minecraft:armor_stand ~ ~1 ~ {Tags:["dragonhelper","dragon_temp"],NoGravity:1b,Invisible:0b,Invulnerable:1b,Attributes:[{Name:"generic.knockback_resistance",Base:10000f}],CustomName:'["",{"text":"Ender Dragon","color":"dark_purple"}]',ShowParticles:0b}
summon minecraft:marker ~ ~1 ~ {Tags:["dragonhelper","dragon_temp"]}
scoreboard players operation @e[type=minecraft:marker,tag=dragon_temp,distance=..2,limit=1] rd_id = #rd_global_cnt rd_id
tag @e[type=minecraft:marker,tag=dragon_temp,distance=..2,limit=1] remove dragon_temp

# Set HurtTime to -1 to keep the knockback effect of the dragon disabled.
summon minecraft:ender_dragon ~ ~0.15 ~ {Tags:["dragonvisible","dragon_temp"],Health:5,HurtTime:-1}
data modify entity @e[tag=dragon_temp,limit=1] Health set from storage ridedragon:settings rd_admin.dragon_health
scoreboard players operation @e[type=minecraft:ender_dragon,tag=dragon_temp,distance=..2,limit=1] rd_id = #rd_global_cnt rd_id
scoreboard players set @e[tag=dragon_temp,limit=1] rd_fire_cooldown 0
tag @e[type=minecraft:ender_dragon,tag=dragon_temp,distance=..2,limit=1] remove dragon_temp

return 1
4 changes: 4 additions & 0 deletions 1_20_5/data/ridedragon/functions/vanish_dragon.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
scoreboard players operation #rd_selected_id rd_id = @e[type=minecraft:ender_dragon,tag=dragonvisible,distance=..10,sort=nearest,limit=1] rd_id
execute as @e[type=minecraft:ender_dragon,tag=dragonvisible,distance=..10] if score @s rd_id = #rd_selected_id rd_id run kill @s
execute as @e[type=minecraft:horse,tag=dragonseat,distance=..17] if score @s rd_id = #rd_selected_id rd_id run kill @s
execute as @e[type=minecraft:marker,tag=dragonhelper,distance=..17] if score @s rd_id = #rd_selected_id rd_id run kill @s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Description: Disable option to get the book directly from the help menu
# Called by: ridedragon:admin via chat link
# Entity @s: player
#
execute store success score #rd_success rd_help run data modify storage ridedragon:settings rd_admin.book_help set value "Disabled"
execute unless score #rd_success rd_help matches 1 run data modify storage ridedragon:settings rd_admin.book_help set value "Enabled"
#
tellraw @s [{"text":"Getting the book from the help menu has been ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.book_help"}]
#
function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Description: Disable fireing of dragon fireballs
# Called by: ridedragon:admin via chat link
# Entity @s: player
#
execute store success score #rd_success rd_help run data modify storage ridedragon:settings rd_admin.can_fire set value "Disabled"
execute unless score #rd_success rd_help matches 1 run data modify storage ridedragon:settings rd_admin.can_fire set value "Enabled"
#
tellraw @s [{"text":"Player fireing of dragon fireballs has been ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.can_fire"}]
#
function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Description: Enable/disable summoning of tame dragons by survival players
# Called by: ridedragon:admin via chat link
# Entity @s: player
#
execute store success score #rd_success rd_help run data modify storage ridedragon:settings rd_admin.can_summon set value "Disabled"
execute unless score #rd_success rd_help matches 1 run data modify storage ridedragon:settings rd_admin.can_summon set value "Enabled"
#
tellraw @s [{"text":"Summoning dragons for survival players has been ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.can_summon"}]
#
function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Description: Disable fireing of dragon fireballs
# Called by: ridedragon:admin via chat link
# Entity @s: player
#

execute store result score #rd_math rd_help run data get storage ridedragon:settings rd_admin.dragon_health
execute if score #rd_math rd_help matches 11.. store result storage ridedragon:settings rd_admin.dragon_health int 1.0 run scoreboard players remove #rd_math rd_help 10

function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Description: Increase the dragon health when spawned
# Called by: ridedragon:admin via chat link
# Entity @s: player
#

execute store result score #rd_math rd_help run data get storage ridedragon:settings rd_admin.dragon_health
execute if score #rd_math rd_help matches ..600 store result storage ridedragon:settings rd_admin.dragon_health int 1.0 run scoreboard players add #rd_math rd_help 10

function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Description: Decrease the cooldown time for dragon fireballs
# Called by: ridedragon:admin via chat link
# Entity @s: player
#

execute store result score #rd_math rd_help run data get storage ridedragon:settings rd_admin.fire_cooldown
execute if score #rd_math rd_help matches 11.. store result storage ridedragon:settings rd_admin.fire_cooldown int 1.0 run scoreboard players remove #rd_math rd_help 10

function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Description: Increase the cooldown time for firing dragon fireballs
# Called by: ridedragon:admin via chat link
# Entity @s: player
#

execute store result score #rd_math rd_help run data get storage ridedragon:settings rd_admin.fire_cooldown
execute if score #rd_math rd_help matches ..600 store result storage ridedragon:settings rd_admin.fire_cooldown int 1.0 run scoreboard players add #rd_math rd_help 10

function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#
# Description: Enable/disable summoning of tame dragons without holding the Book of Dragons
# Called by: ridedragon:admin via chat link
# Entity @s: player
#
execute store success score #rd_success rd_help run data modify storage ridedragon:settings rd_admin.summon_without_book set value "Disabled"
execute unless score #rd_success rd_help matches 1 run data modify storage ridedragon:settings rd_admin.summon_without_book set value "Enabled"
#
tellraw @s [{"text":"Summoning dragons without the Book of Dragons has been ","color":"aqua"},{"storage":"ridedragon:settings", "nbt":"rd_admin.summon_without_book"}]
#
function ridedragon:admin

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kill @e[type=ender_dragon,tag=dragonvisible]
kill @e[type=marker,tag=dragonhelper]
kill @e[type=horse,tag=dragonseat]
6 changes: 6 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_dragon_cleanup.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
execute as @e[type=ender_dragon,tag=dragonvisible] at @s run function ridedragon:z_dragon_cleanup_visible

execute as @e[type=horse,tag=dragonseat] at @s unless entity @e[tag=dragonvisible,distance=..7,limit=1] run kill @s
execute as @e[type=marker,tag=dragonhelper] at @s unless entity @e[tag=dragonvisible,distance=..7,limit=1] run kill @s

schedule function ridedragon:z_dragon_cleanup 23t
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
execute unless entity @e[type=minecraft:horse,tag=dragonseat,distance=..7,limit=1] run kill @s
execute unless entity @e[type=minecraft:marker,tag=dragonhelper,distance=..7,limit=1] run kill @s

26 changes: 26 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_dragon_motion.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# called as dragon_visible, at same

# Fireball cooldown handling
scoreboard players remove @s[scores={rd_fire_cooldown=1..}] rd_fire_cooldown 1

# Find all the parts of the flying stack and tag them as
# dragonvisible_selected, dragonhelper_selected, dragonseat_selected, dragonrider_selected

scoreboard players operation #rd_selected_id rd_id = @s rd_id
tag @s add dragonvisible_selected
execute as @e[type=marker,tag=dragonhelper,distance=..7] if score @s rd_id = #rd_selected_id rd_id run tag @s add dragonhelper_selected
execute as @e[type=horse,tag=dragonseat,distance=..7] if score @s rd_id = #rd_selected_id rd_id run tag @s add dragonseat_selected
tag @a[nbt={RootVehicle:{Entity:{Tags:["dragonseat_selected"]}}},distance=..7,limit=1] add dragonrider_selected

# Reset HurtTime to keep the knockback effect of the dragon disabled. It seems to be reset
# by actual harming of the dragon, so set it back to -1.
data modify entity @s HurtTime set value -1

execute as @a[tag=dragonrider_selected,distance=..7,limit=1] run function ridedragon:z_player_motion
execute as @e[type=marker,tag=dragonhelper_selected,distance=..7,limit=1] unless entity @a[distance=..7,limit=1,tag=dragonrider_selected] run function ridedragon:z_no_player_motion

tag @s remove dragonvisible_selected
tag @a[distance=..7,tag=dragonrider_selected,limit=1] remove dragonrider_selected
tag @e[type=marker,distance=..7,tag=dragonhelper_selected,limit=1] remove dragonhelper_selected
tag @e[type=horse,distance=..7,tag=dragonseat_selected,limit=1] remove dragonseat_selected

10 changes: 10 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_enable.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Periodic reset of triggers on reload
#
scoreboard players enable @p rd_help
scoreboard players enable @p rd_summon
scoreboard players enable @p rd_vanish
scoreboard players enable @p rd_silence

# Repeat every 4 seconds
schedule function ridedragon:z_enable 83t
22 changes: 22 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_fireball_get_motion.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Extraction looking direction to compute motion for the fireball. Inspired by
# https://www.reddit.com/r/MinecraftCommands/wiki/questions/shootfacing/

# this function is executed as the marker entity, positioned at 0 0 0 and still rotated as the player
# (as that wasn't changed with the function call)

# teleport the entity forward by 0.2 block (based on the player rotation and the position 0 0 0).
# this will form the "acceleration_power" of the dragon fireball
tp @s ^ ^ ^0.1

# store the current position in the worlds NBT storage so we don't loose it
data modify storage ridedragon:tmp Motion set from entity @s Pos

# teleport the entity forward by another 0.6 block
# this will form the "direction" of the dragon fireball
tp @s ^ ^ ^0.6

# store the current position in the worlds NBT storage so we don't loose it
data modify storage ridedragon:tmp Motion2 set from entity @s Pos

# we don't need this entity anymore
kill @s
10 changes: 10 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_help/credits.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Description: Display credits in chat
# Called by: ridedragon:z_help_trigger
# Entity @s: Player
#
tellraw @s [{"text":"Rideable Dragons - Credits","color":"yellow","bold":true}]
tellraw @s [{"text":"Created by: ","color":"aqua"},{"text":"ptefar","color":"#87325d","bold":true,"clickEvent":{"action":"open_url","value":"https://www.youtube.com/channel/UC3ro2x7YnyNt8V1t1bUYfXA"}}]
tellraw @s [{"text":"Based on an idea from: ","color":"aqua"},{"text":"John Paul Inso","color":"#0072e5","bold":true,"clickEvent":{"action":"open_url","value":"https://youtu.be/vBUknTYjylc"}}]
tellraw @s [{"text":"Some frameworks from: ","color":"aqua"},{"text":"Armor Statues datapack","color":"#0072e5","bold":true,"clickEvent":{"action":"open_url","value":"https://www.curseforge.com/minecraft/customization/armor-statues-datapack"}}]
tellraw @s [{"text":"--------------------------","color":"yellow","bold":true}]
7 changes: 7 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_help/get_book.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#
# Description: Get book via chat link
# Called by: ridedragon:z_help
# Entity @s: Player
#
function ridedragon:give_book

10 changes: 10 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_help/main.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#
# Description: Display main help options
# Called by: ridedragon:z_help_trigger
# Entity @s: Player
#
tellraw @s [{"text":"Rideable Dragons - Help","color":"yellow","bold":true},{"text":"\nDragons can be summoned via the ","color":"aqua","bold":false},{"text":"Book of Dragons","color":"light_purple","bold":false},{"text":"\nSummoned dragons are mounted by clicking on their necks\nGet the book by:","color":"aqua","bold":false}]
execute if data storage ridedragon:settings rd_admin{book_help:"Enabled"} run tellraw @s [{"text":" - Clicking ","color":"aqua"},{"text":"here","color":"green","clickEvent":{"action":"run_command","value":"/trigger rd_help set 10"}}]
execute if data storage ridedragon:settings rd_admin{can_fire:"Enabled"} run tellraw @s [{"text":"Hold an End Crystal and look below the horizon while mounted to launch dragon fireballs","color":"aqua"}]
tellraw @s [{"text":"Credits","color":"green","clickEvent":{"action":"run_command","value":"/trigger rd_help set 11"}}]
tellraw @s [{"text":"--------------------------","color":"yellow","bold":true}]
14 changes: 14 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_help_trigger.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Description: Display help in chat
# Called by: ridedragon:z_main
# Entity @s: player
#
execute if score @s rd_help matches 10 if data storage ridedragon:settings rd_admin{book_help:"Enabled"} run function ridedragon:z_help/get_book
execute if score @s rd_help matches 11 run function ridedragon:z_help/credits
execute if score @s rd_help matches 1..9 run function ridedragon:z_help/main

#
# Reset trigger score
#
scoreboard players set @s rd_help 0
scoreboard players enable @s rd_help
40 changes: 40 additions & 0 deletions 1_20_5/data/ridedragon/functions/z_init.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#
# Description: Create scoreboards
# Called by: #main:init
# Entity @s: None
#
# Create scoreboards
#
scoreboard objectives add rd_help trigger
scoreboard objectives add rd_summon trigger
scoreboard objectives add rd_vanish trigger
scoreboard objectives add rd_silence trigger
scoreboard objectives add rd_id dummy
# Cooldown timer per dragon, not player
scoreboard objectives add rd_fire_cooldown dummy

#
# Resets triggers on reload
# Also rerun in the z_enable repeating function
#
scoreboard players enable * rd_help
scoreboard players enable * rd_summon
scoreboard players enable * rd_vanish
scoreboard players enable * rd_silence
#

#
# Sets storage settings
#
execute unless data storage ridedragon:settings rd_admin.book_help run data modify storage ridedragon:settings rd_admin.book_help set value "Disabled"
execute unless data storage ridedragon:settings rd_admin.can_summon run data modify storage ridedragon:settings rd_admin.can_summon set value "Disabled"
execute unless data storage ridedragon:settings rd_admin.summon_without_book run data modify storage ridedragon:settings rd_admin.summon_without_book set value "Disabled"
execute unless data storage ridedragon:settings rd_admin.can_fire run data modify storage ridedragon:settings rd_admin.can_fire set value "Disabled"
execute unless data storage ridedragon:settings rd_admin.dragon_health run data modify storage ridedragon:settings rd_admin.dragon_health set value 5
execute unless data storage ridedragon:settings rd_admin.fire_cooldown run data modify storage ridedragon:settings rd_admin.fire_cooldown set value 200

# Schedule function to remove orphaned dragon components every 1 seconds (use a prime number of ticks)
schedule function ridedragon:z_dragon_cleanup 23t

# Schedule function to enable the scoreboard objectives for all players every 4 seconds (use a prime number of ticks)
schedule function ridedragon:z_enable 83t
Loading

0 comments on commit 5c55940

Please sign in to comment.