The first thing we need to make our grappling hook is a custom recipe. You should probably know how to do this by now, but you can always review your Explode Bow and Nuclear Bow recipes to remember how it's done.
Make your recipe match the ingredients, display name, and lore in this image.
To make the grappling action, we are going to used the Projectile Hit Event, just like we did with the Nuclear Bow. Read what it says in the Bukkit API:
So here, you can use the
.getEntity() method with just
You may have noticed that the Projectile Hit event does not have a method to tell us the person who shot it.
The Projectile Class does, however! You can read more about it here
Remember that we can use the
.getShooter() method as just
.shooter in ScriptCraft.
Whenever you see a method with
.setShooter(), you could just use
Your challenge is to keep the player from getting hurt while using the grappling hook. We did this with the flying broomstick that you made after the Explode Bow and Nuclear Bow.
We're going to use the
entityDamage event for this one as well, but with a different
damageCause and a different
Check out this list of all the different damage causes in Minecraft. See if you can figure out which one to use here!
The next item we will be building is a Mirror Shield, that can reflect projectiles back when you block with it. We're going to do this by removing the projectile and shooting one of the same type.
So, to test this out, we're going to need a turret.
We have used lots of different locations so far in this project, which we know require an X, Y, and Z coordinate. We can also get a direction represented by something called a vector.
We're going to add this code so that we can see the vector for the velocity of the arrows when they hit you.
Save, deploy, reload on your server, turn on the turret, and see what velocity the arrows have. Try getting closer and further away from the turret to see how it changes.
As you get hit by arrows, notice the different numbers that get broadcast
Figure out what number you need to add to this code block so that this message is only sent if you are facing the projectile source enough to block with the shield.
Save, deploy, and reload on your server. Turn on your turret, and see what it broadcasts when the arrows hit you. If this works, try it out with different types of projectiles.
Take a look at this code from the Custom Projectiles lesson.
To make the mirror shield reflect projectiles, we're going to remove the projectile that hits it, and launch a new one in the direction that the player is facing.
Now that we know if the player is facing the projectile, if they are holding the mirror shield, and the class of projectile that hits, we need to:
We do NOT need to: