Skip to content

How to make an item that launches you into the air (Minecraft mod)

Movement is the entity’s delta movement, a Vec3 added to its position every tick. Set it with setDeltaMovement, then set hurtMarked to true (syncVelocity from 26.3) so the server sends the new speed to the player’s client. Without it the player sees no change. The look angle is a unit vector, so scale it by the strength you want.

Works on Minecraft 1.20.1 to 26.3 on NeoForge; Minecraft 1.16.5 to 26.3 on Fabric; Minecraft 1.16.5 to 1.20.1 on Forge; Minecraft 1.12.2 on Forge. Each example was compiled against its loader and version before it shipped in Linen.

  1. Override use in your item.
  2. On the server, build a Vec3 from getLookAngle and your strength.
  3. Call setDeltaMovement and set hurtMarked to true.
  4. Add a cooldown.

The example uses these values. Change them in the code.

Setting In the example What it does
power 1.5 How strong the launch is. 1 is about a long jump.

The example mod is examplemod in the package com.example.examplemod. Use your own mod id and package.

Fabric and NeoForge 1.20.4 to 1.21.1, NeoForge 1.20.1 to 1.20.2, Fabric 1.16.5 to 1.20.3, Forge 1.17.1 to 1.20.1

Section titled “Fabric and NeoForge 1.20.4 to 1.21.1, NeoForge 1.20.1 to 1.20.2, Fabric 1.16.5 to 1.20.3, Forge 1.17.1 to 1.20.1”

Uses:

  • Entity.setDeltaMovement
  • Entity.getLookAngle
  • Entity.hurtMarked
  • ItemCooldowns.addCooldown

src/main/java/com/example/examplemod/item/RocketBootsItem.java

package com.example.examplemod.item;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
// Rocket Boots: right-click to launch yourself the way you look. The speed is set on the server and sent to the client with hurtMarked.
public class RocketBootsItem extends Item {
public RocketBootsItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
player.setDeltaMovement(player.getLookAngle().scale(1.5F).add(0, 0.4, 0));
player.hurtMarked = true;
player.getCooldowns().addCooldown(this, 20);
}
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), level.isClientSide());
}
}

It’s registered like any other item, as RocketBootsItem: see a new item.

Uses:

  • Entity.setDeltaMovement
  • Entity.getLookAngle
  • Entity.hurtMarked
  • ItemCooldowns.addCooldown

src/main/java/com/example/examplemod/item/RocketBootsItem.java

package com.example.examplemod.item;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
// Rocket Boots: right-click to launch yourself the way you look. The speed is set on the server and sent to the client with hurtMarked.
public class RocketBootsItem extends Item {
public RocketBootsItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
player.setDeltaMovement(player.getLookAngle().scale(1.5F).add(0, 0.4, 0));
player.hurtMarked = true;
player.getCooldowns().addCooldown(player.getItemInHand(hand), 20);
}
return InteractionResult.SUCCESS;
}
}

It’s registered like any other item, as RocketBootsItem: see a new item.

Uses:

  • Entity.setDeltaMovement
  • Entity.getLookAngle
  • Entity.syncVelocity
  • ItemCooldowns.addCooldown

Since 26.3 the hurtMarked flag is named syncVelocity.

src/main/java/com/example/examplemod/item/RocketBootsItem.java

package com.example.examplemod.item;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EntitySpawnReason;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
// Rocket Boots: right-click to launch yourself the way you look. The speed is set on the server and sent to the client by setting syncVelocity.
public class RocketBootsItem extends Item {
public RocketBootsItem(Item.Properties properties) {
super(properties);
}
@Override
public InteractionResult use(Level level, Player player, InteractionHand hand) {
if (!level.isClientSide()) {
player.setDeltaMovement(player.getLookAngle().scale(1.5F).add(0, 0.4, 0));
player.syncVelocity = true;
player.getCooldowns().addCooldown(player.getItemInHand(hand), 20);
}
return InteractionResult.SUCCESS;
}
}

It’s registered like any other item, as RocketBootsItem: see a new item.

Uses:

  • Entity.setDeltaMovement
  • Entity.getLookAngle
  • Entity.hurtMarked
  • CooldownTracker.addCooldown

src/main/java/com/example/examplemod/item/RocketBootsItem.java

package com.example.examplemod.item;
import net.minecraft.util.Hand;
import net.minecraft.util.ActionResult;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
// Rocket Boots: right-click to launch yourself the way you look. The speed is set on the server and sent to the client with hurtMarked.
public class RocketBootsItem extends Item {
public RocketBootsItem(Item.Properties properties) {
super(properties);
}
@Override
public ActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
if (!world.isClientSide()) {
player.setDeltaMovement(player.getLookAngle().scale(1.5F).add(0, 0.4, 0));
player.hurtMarked = true;
player.getCooldowns().addCooldown(this, 20);
}
return ActionResult.sidedSuccess(player.getItemInHand(hand), world.isClientSide());
}
}

It’s registered like any other item, as RocketBootsItem: see a new item.

Uses:

  • Entity.setDeltaMovement
  • Entity.getLookAngle
  • Entity.hurtMarked
  • CooldownTracker.addCooldown

In 1.12.2 you set the entity’s motionX, motionY and motionZ fields and then set velocityChanged to true.

src/main/java/com/example/examplemod/item/RocketBootsItem.java

package com.example.examplemod.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
// Rocket Boots: right-click to launch yourself the way you look. The speed is set on the server and sent to the client with velocityChanged.
public class RocketBootsItem extends Item {
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
if (!world.isRemote) {
Vec3d look = player.getLookVec().scale(1.5F);
player.motionX = look.x;
player.motionY = look.y + 0.4;
player.motionZ = look.z;
player.velocityChanged = true;
player.getCooldownTracker().setCooldown(this, 20);
}
return new ActionResult<>(EnumActionResult.SUCCESS, player.getHeldItem(hand));
}
}

It’s registered like any other item, as RocketBootsItem: see a new item.

Linen’s How-tos library has this page too, with the example for your own mod’s loader and Minecraft version. Hover a name in your code and Linen points to the how-tos that explain it. Both are free. Download Linen.