Jump to content

I want to make my player boost forwards, back, left or right relative to where they're facing, is there anyway I can do this?


ultra_reemun

Recommended Posts

1.15.2

As the title states ^

Any help would be greatly appreciated, this is my first mod!

 

I currently have it set to a keypress, here's my code:

public class DodgeEvent {
	@SubscribeEvent
    public void onKeyInput(KeyInputEvent event)
    {
        if (Keybinds.dodge.isPressed())
        {
        	PlayerEntity player = Minecraft.getInstance().player;
        	/*
        		
        		Things I'm messing around with:
        	
        	float rotation = player.cameraYaw;
        	Vec3d look = player.getLookVec();
        	System.out.println(rotation + "and" + look.x + "" + look.y);
        	player.addVelocity(look.x, 0, look.y);
        	*/
        }
    }

}

I have a feeling it has something to do with player.moveForward and player.moveStrafe although I can't find any recent documentation on this.

 

Thank you in advance for your help! I'm completely lost!

Edited by ultra_reemun
Grammar
Link to comment
Share on other sites

55 minutes ago, ultra_reemun said:

Any help would be greatly appreciated, this is my first mod!

This is a little more complicated than what you have tried. When the key is pressed down you will need to send a packet to the server. The packet will say hey this player has pressed this button. The server will verify any other conditions then proceed with the appropriate response. In your case it will change the velocity of the player.

Now Minecraft uses xVel, yVel, and zVel so you likely need to use trig depending on exactly what you want to do.

 

PlayerEntity::moveForward and PlayerEntity::moveStrafe are from what I can tell multipliers on the actual motion values. And any change you do to them will be imperceptible because they are changed immediately before the entity moves.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

8 hours ago, Animefan8888 said:

This is a little more complicated than what you have tried. When the key is pressed down you will need to send a packet to the server. The packet will say hey this player has pressed this button. The server will verify any other conditions then proceed with the appropriate response. In your case it will change the velocity of the player.

Now Minecraft uses xVel, yVel, and zVel so you likely need to use trig depending on exactly what you want to do.

 

PlayerEntity::moveForward and PlayerEntity::moveStrafe are from what I can tell multipliers on the actual motion values. And any change you do to them will be imperceptible because they are changed immediately before the entity moves.

Thank you! That's really helped.

 

I've managed to use the code from a snowball to get me started, although I'm still not too experienced in sending packets so I'll look into that now.

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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