Hey everyone, I have a "working" piece of code here,
however I am very new to all this and am confident someone could do this significantly better. Occasionally players get teleported into the void, the horse doesn't get de spawned...
Essentially, right clicking this item puts you on a mount, rightclicking again, or dismount removes the horse (via void tp to avoid in humane death animation). There are a few things in there such as teleport players that helps dismount the player from the horse in order prevent being teleported in the void. I believe it is SkBee responsible for the NBT, I use scoreboard tags so I can check them in game if necessary and so on so on. Oh yes, only horses spawned by the item should be removed on dismount or item toggle! Ideally regular horses would act normally!
Anyone who has any ideas how to optimize, simplify, make this work more consistently, (without vanilla commands would be nice too, but I'll take any help I can get) I'd love to see what you come up with!!
however I am very new to all this and am confident someone could do this significantly better. Occasionally players get teleported into the void, the horse doesn't get de spawned...
Essentially, right clicking this item puts you on a mount, rightclicking again, or dismount removes the horse (via void tp to avoid in humane death animation). There are a few things in there such as teleport players that helps dismount the player from the horse in order prevent being teleported in the void. I believe it is SkBee responsible for the NBT, I use scoreboard tags so I can check them in game if necessary and so on so on. Oh yes, only horses spawned by the item should be removed on dismount or item toggle! Ideally regular horses would act normally!
Anyone who has any ideas how to optimize, simplify, make this work more consistently, (without vanilla commands would be nice too, but I'll take any help I can get) I'd love to see what you come up with!!
Code:
on rightclick holding a emerald:
if name of event-item is "&cHorse Whistle":
if {whistlereset.%player%} is not set:
if player is not riding a horse:
add "Mount_Horse" to the scoreboard tags of event-entity
set {whistlereset.%player%} to true
play sound "entity.parrot.ambient" to player
wait 1 second
play sound "entity.horse.gallop" to player
wait 0.1 second
play sound "entity.horse.ambient" to player
send "&aHorse Summoned"
spawn horse at player
add "{Tame:1b,Variant:259,SaddleItem:{id:saddle,Count:1},Age:0}" to last spawned entity's nbt
make player ride spawned horse
else if player is riding a horse:
make player run command "execute as @a[distance=0..2] at @s run tp @s ~ ~ ~" as op
wait 5 seconds
clear {whistlereset.%player%}
else if {whistlereset.%player%} is set:
message "&c&oThe whistle is still wet with saliva, try again later."
on dismount:
if player has scoreboard tag "Mount_Horse":
send "&cHorse Unsummoned"
make player run command "execute as @a[distance=0..2] at @s run tp @s ~ ~ ~" as op
wait 1 tick
make player run command "tp @e[type=horse,sort=nearest,limit=1] ~ ~-300 ~" as op
wait 10 tick
remove "Mount_Horse" from the scoreboard tags of event-entity