Skip to content

Commit

Permalink
Merge pull request #2 from petersv5/dragon_fireballs
Browse files Browse the repository at this point in the history
players can trigger dragon fireballs
  • Loading branch information
petersv5 authored Sep 18, 2023
2 parents 9162a79 + 406bab6 commit 2751846
Show file tree
Hide file tree
Showing 12 changed files with 107 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rev 0.2
-------

- Clean up the temporary tags from the dragon and the armor stand
- Add player launched dragon fireballs


10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ Players can use "/trigger rd_help" for mor information.
OPs can configure if the Book Of dragons is required to summon a dragon as well as how the book
can be obtained via the admin interface which is opened with the command "/function ridedragon:admin".

OPs can also control if the players are able to trigger dragon fireballs while mounted by holding
an end crystal. Fireballs are limited to one per 10 seconds per dragon and can only be fired in a
downwards direction.

It is recommended to use the "Anti Ender Dragon Grief" data pack
(https://www.planetminecraft.com/member/dragon3025/) by Dragon3025 to prevent the dragons from
erasing parts of the world as they are flown around.

This datapack was inspired by the video https://www.youtube.com/watch?v=vBUknTYjylc&t=284s by John
Paul Inso. That design was not safe for multiple simultaneous players.
Paul Inso. That design was not safe for multiple simultaneous players which inspired me to make my
own version.

For further support or questions please use the Discord at: https://discord.gg/6eJxzG5jkA or
visit the github repository: https://github.com/petersv5/RideDragon

1 change: 1 addition & 0 deletions data/ridedragon/functions/admin.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ tellraw @s [{"text":"Rideable Dragons - Admin Options","color":"yellow","bold":"
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":"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 data/ridedragon/functions/summon_dragon.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ tag @e[type=minecraft:marker,tag=dragon_temp,distance=..2,limit=1] remove dragon
# 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}
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
12 changes: 12 additions & 0 deletions data/ridedragon/functions/z_admin/can_fire_toggle.mcfunction
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

6 changes: 6 additions & 0 deletions data/ridedragon/functions/z_dragon_motion.mcfunction
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 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
Expand Down
22 changes: 22 additions & 0 deletions 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 "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
1 change: 1 addition & 0 deletions data/ridedragon/functions/z_help/main.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
#
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 with an empty hand\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 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"}]
3 changes: 3 additions & 0 deletions data/ridedragon/functions/z_init.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ 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
Expand All @@ -26,6 +28,7 @@ scoreboard players enable * rd_silence
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"

# Schedule function to remove orphaned dragon components every 1 seconds (use a prime number of ticks)
schedule function ridedragon:z_dragon_cleanup 23t
29 changes: 29 additions & 0 deletions data/ridedragon/functions/z_launch_fireball.mcfunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Summon a new dragon fireball
#summon minecraft:dragon_fireball ~ ~4 ~ {Tags:["dragon_fireball_selected","dragon_fireball"],direction:[0.5,0.0,0.0],power:[0.1,-0.1,0.0],Owner:[I;1,1,1,1]}
summon minecraft:dragon_fireball ^ ^ ^8 {Tags:["dragon_fireball_selected","dragon_fireball"]}

# Mark the dragon as the owner so that the dragon's breath can be collected from the
# area_effect_cloud after the dragon fireball lands
data modify entity @e[tag=dragon_fireball_selected,distance=..10,limit=1] Owner set from entity @e[tag=dragonvisible_selected,distance=..10,limit=1] UUID

# Start the cooldown to 10 seconds = 200 ticks for the dragon
scoreboard players set @e[tag=dragonvisible_selected,limit=1] rd_fire_cooldown 200

# Set up motion. Inspired by
# https://www.reddit.com/r/MinecraftCommands/wiki/questions/shootfacing/
# summon the temporary entity at the players position
summon marker ~ ~ ~ {Tags:["direction_marker"]}

# execute the below function as the marker entity, so it doesn't get lost from being unloaded
# run positioned at the world zero point. this will remove the marker
execute as @e[tag=direction_marker,distance=..10,limit=1] positioned 0.0 0.0 0.0 run function ridedragon:z_fireball_get_motion

# store the previously stored Motion into the projectile entity
# Note that dragon fireballs use "direction" for the initial direction and
# "power" for the constant acceleration countering drag.
data modify entity @e[tag=dragon_fireball_selected,limit=1] power set from storage ridedragon:tmp Motion
data modify entity @e[tag=dragon_fireball_selected,limit=1] direction set from storage ridedragon:tmp Motion2
# clean up the tag
tag @e[tag=dragon_fireball_selected] remove dragon_fireball_selected


2 changes: 2 additions & 0 deletions data/ridedragon/functions/z_player_motion.mcfunction
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ execute if entity @s[x_rotation=10..90,predicate=ridedragon:book_holder_mainhand
execute if entity @s[x_rotation=10..90,predicate=ridedragon:book_holder_offhand] as @e[type=horse,distance=..7,tag=dragonseat_selected,limit=1] at @s rotated ~ 0 positioned ^ ^ ^-2.7 rotated as @s positioned ^ ^ ^-2.2 rotated as @s run tp @e[type=ender_dragon,tag=dragonvisible_selected,limit=1,sort=nearest,distance=..7] ~ ~-0.7 ~ ~-180 ~


# Check if dragon fireballs are enabled the trigger held and looking sufficiently below the horizon (10 degrees or more)
execute if data storage ridedragon:settings rd_admin{can_fire:"Enabled"} run execute if entity @s[x_rotation=10..90,predicate=ridedragon:is_holding_trigger_item] at @s run execute if entity @e[tag=dragonvisible_selected,limit=1,scores={rd_fire_cooldown=0}] run function ridedragon:z_launch_fireball
14 changes: 14 additions & 0 deletions data/ridedragon/predicates/is_holding_trigger_item.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"type": "minecraft:player",
"equipment": {
"mainhand": {
"items": [
"minecraft:end_crystal"
]
}
}
}
}

0 comments on commit 2751846

Please sign in to comment.