4

I am trying to make double jumping, i.e. jumping again in midair but only once before you hit the ground again. Hitting the ground should reset you to allow another double jump to happen.

What I've got so far doesn't quite work. Is anyone able to have a look?

Here is my code:

a repeating command block with

/scoreboard players set @a[scores={sneak=1}] sneak 0

leading into another repeating command block with conditional on with

/execute at @a[scores={sneak=1,double=0}] if block ~ ~-0.75 ~ air run effect give @p[scores={sneak=1}] minecraft:levitation 1 0 true

which finally leads into another conditional repeating command block with

execute at @a if block ~ ~-0.5 ~ air run effect clear @a minecraft:levitation

which ends that chain.

there are other commands than reset scores when needed, such as

execute at @a if block ~ ~-0.5 ~ air run scoreboard players set @p[scores={sneak=..1}] sneak 0

along with

execute at @a unless block ~ ~-0.5 ~ air run scoreboard players set @p[scores={double=..1}] double 0

But this isn't working. Can I have some help please?

3
  • Hi Sebastian, can you tell us what 'doesn't work'? What exactly happens when you attempt a double jump?
    – Robotnik
    Feb 18, 2019 at 3:25
  • i cant tell. i would tell you, but i cant tell (im pretty new) Feb 19, 2019 at 14:16
  • What happend when you try to run the commands, do you receive errors? Does it partially work (ie you can double jump only once and then never again? or you can continue jumping forever?) It is hard to tell where you are running into the problem.
    – Malco
    Mar 4, 2019 at 14:49

1 Answer 1

2

You can detect if a player sneaks with the help of this command:

/scoreboard objectives add sneaks minecraft.custom:minecraft.sneak_time

Then run this command in a repeating command block to make every player that has sneaked for 1 tick and is not on the ground levitate (which seems to be the way how you want the second jump to work)

/execute as @e[scores={sneaks=1},nbt={OnGround:0b}] run effect give @s minecraft:levitation 1 2 true

You can use a chain command block to the run this command, it will reset the sneak time for any player who is standing on the ground:

/scoreboard players reset @a[nbt={OnGround:1b}] sneaks

If you sneak for a really short time, then you may have a sneak time of 1, which would lead to levitating indefinitely, as the effect would get set repeatedly. To prevent this you can use this command in a second chain command block:

/execute as @a[scores={sneaks=1}] run scoreboard players add @s sneaks 1

When the player hits their head, then you want them to stop levitating and fall again, you can achieve this with yet another chain command block and this command:

/execute as @a[scores={sneaks=2..}] at @s unless block ~ ~1.8 ~ minecraft:air run effect clear @s minecraft:levitation

Edit after some refining

You can put these commands into a repeating command block and 4 chain command blocks, it works similarly to what I explained above, but it feels more like actually jumping mid air, because the levitation effect is much stronger. I added a dummy scoreboard objective called "duration", which gets a value from the ActiveEffects-tag in the 4th command. The 5th command clears the levitation effect 17 ticks (0.85 seconds) before it would usually wear off:

/execute as @e[scores={sneaks=1},nbt={OnGround:0b}] run effect give @s minecraft:levitation 1 20 true
/scoreboard players reset @a[nbt={OnGround:1b}] sneaks
/execute as @a[scores={sneaks=1}] run scoreboard players add @s sneaks 1
/execute as @a store result score @s duration run data get entity @s ActiveEffects[{Id:25b}].Duration 1
/execute as @a[scores={duration=..17}] run effect clear @s

Note: I removed the command that checks if you hit your head, because the levitation effect will be so short that you hardly notice that you levitate against a ceiling.

Note 2: this has the side effect of adding some kind of super jump if you sneak and jump while sneaking, this jump is about 4 blocks high and you cannot perform a double jump from it. A double jump takes you about 3 blocks high.

2
  • So I tried adding nbt={selectedItem:{"id":"minecraft:carrot_on_a_stick"}}, to all of the commands (except the fourth line), so the effect would only work with a carrot_on_a_stick in hand, but it stopped working. Any ideas why?
    – Nik3141
    Jul 6, 2019 at 18:45
  • 1
    @Nik3141 You have to make sure that you spell things correctly in nbt tags, in this case it should be SelectedItem instead of seletedItem. The commands were looking for players with the nbt tag selectedItem, no players had that tag, so no player was targeted.
    – user232393
    Jul 6, 2019 at 22:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .