Jump to content

Recommended Posts

Posted (edited)

Hello

I'm currently making an Item that thrusts you to viewing direction, and I referenced riptide code of trident for my item.

  @Override
    public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) {
        if(!pLevel.isClientSide() && pUsedHand == InteractionHand.MAIN_HAND && pPlayer.isOnGround()){

            Impale(pPlayer, pUsedHand);

            pPlayer.getCooldowns().addCooldown(this, 40);
        }
      
        return super.use(pLevel, pPlayer, pUsedHand);
   }

   public void Impale(Player pPlayer, InteractionHand pUsedHand) {

      float playerYRot = pPlayer.getYRot();
      float xForce = -Mth.sin(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F);
      float yForce = 100.6F;
      float zForce = Mth.cos(playerYRot * ((float)Math.PI / 180F)) * Mth.cos((float)Math.PI / 180F);
      float stabilizedForce = Mth.sqrt(xForce * xForce + zForce * zForce);
      xForce /= stabilizedForce;
      zForce /= stabilizedForce;

      pPlayer.push((double)xForce, (double)yForce, (double)zForce);
      pPlayer.sendSystemMessage(Component.literal(playerYRot + " " + xForce + " " + yForce + " " + zForce + " " + stabilizedForce + "shoo"));
   }

I sure edited a lot from source code but this isn't working somehow?

the sendSystemMessage works correctly. It prints value of variables and string, but the force isn't applying to player.

how can I make this to work?

Thanks.

Edited by Gyumin Kang
  • Gyumin Kang changed the title to Item code that add Velocity to Player?
Posted

Use player.setDeltaMovement(player.getViewAgle().scale(speed)

and then set player.hurtMarked to true.

if your in the server and setting velocity, that doesn’t work, you have to set hurtMarked to true, that sends the update to all the clients. Just try and add that line at the end somewhere.

  • Thanks 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.