Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello,

 

I'm trying to add a flight system that uses velocity rather than the stiff minecraft creative flight. I have managed to make a prototype that sort of works how I wanted it to, but it has two major flaws:

 

1. When the movement starts it propells the player once, waits for some ticks and then resumes moving. No idea why that happens

2. Pressing any other button causes the forward button to not be in a pressed state anymore, which shouldn't be the case...


Code:

@SideOnly(Side.CLIENT)
	@SubscribeEvent
	public void onTestKeyPress(KeyInputEvent event){
		GameSettings settings =Minecraft.getMinecraft().gameSettings;
		EntityPlayerSP player = Minecraft.getMinecraft().player;
		
		if (settings.keyBindForward.isKeyDown()){
			settings.keyBindForward.unPressAllKeys();
			Vec3d vec = player.getLookVec().normalize().scale(2);
			player.setVelocity(0, 0, 0);
			player.addVelocity(vec.xCoord, vec.yCoord, vec.zCoord);
			player.setNoGravity(true);
		} else {
			player.setNoGravity(false);
		}
		
	}

 

I know it's very bad, but I only needed a proof of concept before pursuing this path any further. Is there perhaps a better way of doing this? What I basically want to do is:

1. Capture the key press for movement and disable it

2. Propell player in the direction of the movement key based on current camera look vector.

 

Any feedback is appreciated.

I do pony stuff :3

You are going to want to use the ClientTickEvent and in there check if your key is down to apply movement every tick. KeyInputEvent should only be called every so often.

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.

  • Author
1 hour ago, Animefan8888 said:

You are going to want to use the ClientTickEvent and in there check if your key is down to apply movement every tick. KeyInputEvent should only be called every so often.

Okay, thanks, I'll try that. KeyInputEvent will be called regardless of anything, and I have other things checking it as well.

 

EDIT: That didn't help any of the issues I described

Edited by Zethariel

I do pony stuff :3

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.