I recreated the spawn parkour (Devlog)

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#1
Hello there everyone,

I really like the spawn parkour, it's a really cool concept, so I decided to recreate it in my spare time, just for a bit of fun:

If anyone is interested in my solution to get this working, then feel free to keep reading for the nerdy stuff, else you can just enjoy the conciseness of this post.

How it works:

Generating the Jumps:

So in Minecraft, every single block in a world has associated coordinates, x y and z - you know the ones. If you think of a jump in parkour as just the distance between two blocks, we can calculate this very easily by just finding the difference in the coordinates. This is what is called a relative block mapping and this is what I used to generate each jump.
For example, a 1 block jump will be a coordinate increase of 2 in either the x or z-direction, so their relative coordinates are 2 in either the x or z.

So, now that we know we can get blocks relative to another one, we can just store a relative block mapping to generate that jump.

I built a bunch of parkour jumps, and placed signs with all of their relative block mappings from the starting block -> the target block.

1610551064358.png


So after testing all these jumps, I stored all their relative mappings in the config.yml file:

1610551310005.png


This way, you can easily add/remove/edit any jumps. The one with multiple mappings stores multiple blocks, in this case, a neo jump.

So now, all we need to do is convert these strings (a line of text) to an integer (a number). The reason we have to do this is that in programming, it doesn't recognize "1" as 1. You cannot perform calculations with text, so we have to attempt to parse (convert) them from one to the other.

It's quite simple to do this, we just loop through every value in the list, and convert each mapping to an integer, and store them in an int[] (a list of integers, called an array). For multiple blocks, we just create (now, bear with me!) a multi-dimensional-array (an array inside an array), so it can store every mapping for every block.

And tada, we now have the ability to generate a parkour jump! All that's left to do is create a method for randomly selecting one of these mappings:

1610551916053.png


Realistically, we should only use one instance of ThreadLocalRandom for speed and safety, but for the sakes of this quick botched plugin, it doesn't really matter.

Detecting the player's movements:

There is a starting pressure plate block which teleports the player and begins their parkour challenge. This is surprisingly very easy to recreate.
In Spigot's API, there are a huge number of events that are triggered when different things happen. We can hook into these events and modify the behaviour, such as teleporting the player once they step on a pressure plate.
For this task, we have to use what's called the PlayerInteractEvent, and this is fired whenever the player interacts with anything - an inventory, an entity, when they click, you get the idea.

We don't want every pressure plate to be able to start the parkour, so we store their specific location, and check for that location instead - blocks don't tend to move on their own, so it's much more reliable:

1610552792599.png


We don't want players to constantly run into each other while doing the parkour, so we have to space them out. I do this by teleporting them a multiple of 15 blocks away, depending on how many players are currently doing the parkour. Because we have jumps going in all directions, the player stays in roughly the same position, so I decided that 15 blocks distance was a reasonable amount.

Once the player is doing the pakour, we need to store some data associated with them, like the block they're currently on, the block they're supposed to jump to, any other blocks, their points etc.
To do this, I created a custom data class containing all this data to easily be able to edit everything inside them:

1610553946591.png

blockFrom is the block they started at, blockTo is the block they need to jump to, otherBlocks is a list of any other blocks, points is how many jumps they've made and block is the the type of block, like MELON_BLOCK, LAPIS_BLOCK, etc.

All we need to do now is detect when they land on the correct block and spawn the next one, or if they fall, clear everything. The easiest way to do this is use the PlayerMoveEvent, which is fired every time a players location is changed (including yaw and pitch!).
We can simply get the players location, and the block for their location - and, as we've already established, if we have a block we can get another block relative to it, therefore, getting the block underneath the player is very easy.

We can check if the location of the block underneath the player is the same location as the block they are meant to be jumping to, and if it is, we can spawn another one (and add some fancy effects too, such as simple sound and flame particles):

1610554526460.png


So now that we have detected if the player has landed on the correct block, the question is this:
> How can we accurately detect if the player has missed the block?

There are multiple ways to do this, but the way I decided to do it is check if the players y-level is 2 blocks below the target blocks y-level. This means they've fallen and we can remove their data. I simply checked if the players y-level + 2 is below the target blocks y-level:

1610554868377.png


This just sets all the blocks back to air, and clears any data we are currently holding with the player.

Conclusion:

So this essentially concludes this devlog thing, I haven't included all aspects of the code - I've just focused on the main ideas and mechanics.
I really hope I explained how this works in a way that is friendly to understand, but if you got lost, I don't blame you - when I was starting out I wouldn't have a clue what any word of this means.


If anyone is interested, the full code is on GitHub: https://github.com/ihellsmc/SpawnPK

Happy scrolling, and have a fantastic day!
Brandon
 

Blurpyfied

Forum God
ELITE
Blurpyfied
Blurpyfied
ELITE
Joined
Jan 1, 2017
Posts
1,856
Ratings
985 875
#2
Nice, you should become apart of the dev team lol.
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#3
Nice, you should become apart of the dev team lol.
Haha, I've only been doing Minecraft for development for a matter of months, so I still have much to learn (just as every developer does)!
However, if a position was offered (which is unlikely), I wouldn't hesitate.
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#5
This is really cool! I don’t know a lot about programming in Minecraft but I know @EvanTech likes this kind of stuff.
I'm glad you thought so! I'm studying computer science for a-level so I'm always eager to meet more people that are as passionate as I am!
 

jacobsfunparty

Forum Expert
ELITE
jacobsfunparty
jacobsfunparty
ELITE
Joined
Apr 15, 2020
Posts
465
Ratings
337 6
#6
I'm glad you thought so! I'm studying computer science for a-level so I'm always eager to meet more people that are as passionate as I am!
That’s cool you were able to find a project that interests you that might have to do with something you’re learning
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#7
That’s cool you were able to find a project that interests you that might have to do with something you’re learning
I've always been into coding, I used to play around with scratch when I was around 12.
Minecraft has been my childhood, so to be able to start creating in it is amazing.
 

EvanTech

SrMod | Mentoring
Senior Mod
EvanTech
EvanTech
Senior Mod
Joined
Apr 21, 2020
Posts
719
Ratings
352 39
#8
Thanks Jacob for the callout lol. I've been taking computer science classes at school for 4 years now and I expertly understand all of the concepts and structure that goes into programming. I can efficiently code JavaScript and Java mostly with a touch of HTML but that's all I've gotten around to. A couple months ago I did start learning how to develop plugins for Minecraft because I could already efficiently code in Java and I've been playing the game for like 8 years so now I'm just bridging the gaps between what's happening in the game and how that translates to code. It seems you are significantly ahead of me but I do have a pretty solid learning base right now. The only official project that I've really finished is an AntiNetherRoof plugin that I made a while back for a friend and they've had no issues with it at all. If you're down, I'd like to pick up my progress and keep going with programming and maybe we could even work together! Glad I could share my interest with someone else
:mc_152-0:
 

SSM_GOD

Forum Legend
Joined
Aug 11, 2019
Posts
1,454
Ratings
1,930 46
#9
Challenge: add potion effects and extend the jumps. Speed / jump boost and make the blocks vary even more in distance

Also, be sure to put this in the creation part of forums!
It would be so cool to see this in the Mana Master Pieces!
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#10
Thanks Jacob for the callout lol. I've been taking computer science classes at school for 4 years now and I expertly understand all of the concepts and structure that goes into programming. I can efficiently code JavaScript and Java mostly with a touch of HTML but that's all I've gotten around to. A couple months ago I did start learning how to develop plugins for Minecraft because I could already efficiently code in Java and I've been playing the game for like 8 years so now I'm just bridging the gaps between what's happening in the game and how that translates to code. It seems you are significantly ahead of me but I do have a pretty solid learning base right now. The only official project that I've really finished is an AntiNetherRoof plugin that I made a while back for a friend and they've had no issues with it at all. If you're down, I'd like to pick up my progress and keep going with programming and maybe we could even work together! Glad I could share my interest with someone else
:mc_152-0:
If you already know Java, then all you need to do is spend some time learning the Spigot API, and you'll fly through it. I urge you to continue with it if you have the time, it's really enjoyable for me.
I've also been studying computer science for a number of years - first at GCSE level where the language we started to use was python, but I decided to explore into other languages like c#, js and java. Currently, I'm now at A-level and the language we're focusing on is c#, but our teacher is taking it painfully slowly, we haven't even touched any form of OOP.
I'm glad there's another coding nerd like me here ;)

Challenge: add potion effects and extend the jumps. Speed / jump boost and make the blocks vary even more in distance

Also, be sure to put this in the creation part of forums!
It would be so cool to see this in the Mana Master Pieces!
This is very possible and quite simple to do. All we would have to do is add the effects to the player when the first start, and clear them when they fall. As for the block distances, the way I have them set-up allows you to edit them easily in a file, and you can add as many jumps as you like.
I was unaware of the Creations section of the forums you are referring to, if I decide to do anything like this again, I would post it in the appropriate section, thank you :D
 

Inktest

Forum Expert
ELITE
Inktest
Inktest
ELITE
Joined
Nov 22, 2019
Posts
292
Ratings
234 8
#11
Hello there everyone,

I really like the spawn parkour, it's a really cool concept, so I decided to recreate it in my spare time, just for a bit of fun:

If anyone is interested in my solution to get this working, then feel free to keep reading for the nerdy stuff, else you can just enjoy the conciseness of this post.

How it works:

Generating the Jumps:

So in Minecraft, every single block in a world has associated coordinates, x y and z - you know the ones. If you think of a jump in parkour as just the distance between two blocks, we can calculate this very easily by just finding the difference in the coordinates. This is what is called a relative block mapping and this is what I used to generate each jump.
For example, a 1 block jump will be a coordinate increase of 2 in either the x or z-direction, so their relative coordinates are 2 in either the x or z.

So, now that we know we can get blocks relative to another one, we can just store a relative block mapping to generate that jump.

I built a bunch of parkour jumps, and placed signs with all of their relative block mappings from the starting block -> the target block.

View attachment 42434

So after testing all these jumps, I stored all their relative mappings in the config.yml file:

View attachment 42435

This way, you can easily add/remove/edit any jumps. The one with multiple mappings stores multiple blocks, in this case, a neo jump.

So now, all we need to do is convert these strings (a line of text) to an integer (a number). The reason we have to do this is that in programming, it doesn't recognize "1" as 1. You cannot perform calculations with text, so we have to attempt to parse (convert) them from one to the other.

It's quite simple to do this, we just loop through every value in the list, and convert each mapping to an integer, and store them in an int[] (a list of integers, called an array). For multiple blocks, we just create (now, bear with me!) a multi-dimensional-array (an array inside an array), so it can store every mapping for every block.

And tada, we now have the ability to generate a parkour jump! All that's left to do is create a method for randomly selecting one of these mappings:

View attachment 42436

Realistically, we should only use one instance of ThreadLocalRandom for speed and safety, but for the sakes of this quick botched plugin, it doesn't really matter.

Detecting the player's movements:

There is a starting pressure plate block which teleports the player and begins their parkour challenge. This is surprisingly very easy to recreate.
In Spigot's API, there are a huge number of events that are triggered when different things happen. We can hook into these events and modify the behaviour, such as teleporting the player once they step on a pressure plate.
For this task, we have to use what's called the PlayerInteractEvent, and this is fired whenever the player interacts with anything - an inventory, an entity, when they click, you get the idea.

We don't want every pressure plate to be able to start the parkour, so we store their specific location, and check for that location instead - blocks don't tend to move on their own, so it's much more reliable:

View attachment 42437

We don't want players to constantly run into each other while doing the parkour, so we have to space them out. I do this by teleporting them a multiple of 15 blocks away, depending on how many players are currently doing the parkour. Because we have jumps going in all directions, the player stays in roughly the same position, so I decided that 15 blocks distance was a reasonable amount.

Once the player is doing the pakour, we need to store some data associated with them, like the block they're currently on, the block they're supposed to jump to, any other blocks, their points etc.
To do this, I created a custom data class containing all this data to easily be able to edit everything inside them:

View attachment 42438
blockFrom is the block they started at, blockTo is the block they need to jump to, otherBlocks is a list of any other blocks, points is how many jumps they've made and block is the the type of block, like MELON_BLOCK, LAPIS_BLOCK, etc.

All we need to do now is detect when they land on the correct block and spawn the next one, or if they fall, clear everything. The easiest way to do this is use the PlayerMoveEvent, which is fired every time a players location is changed (including yaw and pitch!).
We can simply get the players location, and the block for their location - and, as we've already established, if we have a block we can get another block relative to it, therefore, getting the block underneath the player is very easy.

We can check if the location of the block underneath the player is the same location as the block they are meant to be jumping to, and if it is, we can spawn another one (and add some fancy effects too, such as simple sound and flame particles):

View attachment 42439

So now that we have detected if the player has landed on the correct block, the question is this:
> How can we accurately detect if the player has missed the block?

There are multiple ways to do this, but the way I decided to do it is check if the players y-level is 2 blocks below the target blocks y-level. This means they've fallen and we can remove their data. I simply checked if the players y-level + 2 is below the target blocks y-level:

View attachment 42440

This just sets all the blocks back to air, and clears any data we are currently holding with the player.

Conclusion:

So this essentially concludes this devlog thing, I haven't included all aspects of the code - I've just focused on the main ideas and mechanics.
I really hope I explained how this works in a way that is friendly to understand, but if you got lost, I don't blame you - when I was starting out I wouldn't have a clue what any word of this means.


If anyone is interested, the full code is on GitHub: https://github.com/ihellsmc/SpawnPK

Happy scrolling, and have a fantastic day!
Brandon
I've also been learning to develop plugins for over a year now, its' great to see you doing it as well :D
 

SSM_GOD

Forum Legend
Joined
Aug 11, 2019
Posts
1,454
Ratings
1,930 46
#12
This is very possible and quite simple to do. All we would have to do is add the effects to the player when the first start, and clear them when they fall. As for the block distances, the way I have them set-up allows you to edit them easily in a file, and you can add as many jumps as you like.
I was unaware of the Creations section of the forums you are referring to, if I decide to do anything like this again, I would post it in the appropriate section, thank you :D
In my head I was thinking more like if the potion effects changed randomly during the parkour, and then the distance is adaptive to the combination of effects. Maybe based on an equation?

I don't really know Java, or programming, but I thought it was super cool that the next block is based on picking up an item. I never thought about that before and probably wouldn't have thought about it if I was making a copy.
Great job on this!
 

Jash

Forum Expert
PATRON+
Jashhy
Jashhy
Patron+
Joined
Nov 9, 2020
Posts
423
Ratings
367 5
#14
Yooo Brandom this looks amazing and I love how you've shown everyone the code you're using to allow us to follow along in your development journey! I've touched on Java myself, but nothing to this degree (Only project I made was an anti-sheep shearing plugin which would break the shears when the player interacts with them)

I'd love to see more from you as this is very interesting! <3
See you around,
Josh!
 

Saltyon

Active Member
ELITE
Saltyon
Saltyon
ELITE
Joined
Nov 29, 2020
Posts
41
Ratings
16 1
#15
An interesting project would be to make it user-friendly. Meaning, through the use of commands / ingame GUI, people could set up their own invis parkour.
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#16
I've also been learning to develop plugins for over a year now, its' great to see you doing it as well :D
That's awesome man, what resources did you use to learn? I started off by following a beginner course on Udemy but moved onto self-taught advanced principles.

In my head I was thinking more like if the potion effects changed randomly during the parkour, and then the distance is adaptive to the combination of effects. Maybe based on an equation?

I don't really know Java, or programming, but I thought it was super cool that the next block is based on picking up an item. I never thought about that before and probably wouldn't have thought about it if I was making a copy.
Great job on this!
This is absolutely possible, and sounds like an interesting idea. Perhaps I could make an algorithm to check if a jump is possible without any effects, and spawn jumps based on that.

I'm glad that you think so! <3

Yooo Brandom this looks amazing and I love how you've shown everyone the code you're using to allow us to follow along in your development journey! I've touched on Java myself, but nothing to this degree (Only project I made was an anti-sheep shearing plugin which would break the shears when the player interacts with them)

I'd love to see more from you as this is very interesting! <3
See you around,
Josh!
Thank you Josh, my goal here was to explain how it worked so people could appreciate how the logic works, and be interested by it. I'll be building on this plugin and posting another devlog soon - I'm glad you enjoyed the read :D

An interesting project would be to make it user-friendly. Meaning, through the use of commands / ingame GUI, people could set up their own invis parkour.
This is possible, the way it works now is by randomly selecting jumps, but we could have players create a set route for their own courses. I'll try something like this out, thanks for the idea ;)
 

Saltyon

Active Member
ELITE
Saltyon
Saltyon
ELITE
Joined
Nov 29, 2020
Posts
41
Ratings
16 1
#17
That's awesome man, what resources did you use to learn? I started off by following a beginner course on Udemy but moved onto self-taught advanced principles.


This is absolutely possible, and sounds like an interesting idea. Perhaps I could make an algorithm to check if a jump is possible without any effects, and spawn jumps based on that.


I'm glad that you think so! <3


Thank you Josh, my goal here was to explain how it worked so people could appreciate how the logic works, and be interested by it. I'll be building on this plugin and posting another devlog soon - I'm glad you enjoyed the read :D


This is possible, the way it works now is by randomly selecting jumps, but we could have players create a set route for their own courses. I'll try something like this out, thanks for the idea ;)

As a computer science student, I love seeing posts like this :3, looking forward to seeing more from you :D
 

Inktest

Forum Expert
ELITE
Inktest
Inktest
ELITE
Joined
Nov 22, 2019
Posts
292
Ratings
234 8
#18
That's awesome man, what resources did you use to learn? I started off by following a beginner course on Udemy but moved onto self-taught advanced principles.


This is absolutely possible, and sounds like an interesting idea. Perhaps I could make an algorithm to check if a jump is possible without any effects, and spawn jumps based on that.


I'm glad that you think so! <3


Thank you Josh, my goal here was to explain how it worked so people could appreciate how the logic works, and be interested by it. I'll be building on this plugin and posting another devlog soon - I'm glad you enjoyed the read :D


This is possible, the way it works now is by randomly selecting jumps, but we could have players create a set route for their own courses. I'll try something like this out, thanks for the idea ;)
I started with yt tutorials, then I started to look at documentation, that's how I learnt
 

Slohth

Active Member
VIP
Slohth
Slohth
VIP
Joined
Dec 3, 2017
Posts
36
Ratings
46 1
#19
As a computer science student, I love seeing posts like this :3, looking forward to seeing more from you :D
Absolutely, I'm glad you found this interesting!

I started with yt tutorials, then I started to look at documentation, that's how I learnt
I found it hard as a beginner looking at documentation - it is an incredibly useful tool.
 

jacobsfunparty

Forum Expert
ELITE
jacobsfunparty
jacobsfunparty
ELITE
Joined
Apr 15, 2020
Posts
465
Ratings
337 6
#20
Oh one thing that I thought of that the manacube spawn parkour has. For the spawn parkour, the blocks only spawn in front of you. This probably is something really simple but I am curious how you would implement that.