Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I want to write a simple autowalk/run mod but I have problems understanding how the Playercontroller works.

 

I had two approaches:

 

1. simulating keypresses

I thought this would be an easy idea using something like this: 

KeyBinding.onTick(minecraft.gameSettings.keyBindUseItem.getKeyCode());

I gues this method executes this keypress for the time of a single tick? So if I want to move consistently i would need to call this method on every tick using PlayerTickEvent and checking a boolean every time if autowalk is on or off? 

I think this idea is not so good as you could not use the chat while autowalking.

 

2. So my next idea was to to access the playercontroller and find some kind of move method. But I could find out how it exactly works and what I need to do to make sure that the player walks like i would just press the W key.

I found some code online but I could not find the methods in my libs: 

player.func_70031_b(true);

the player if from type 

EntityPlayerSP 
Edited by HenryFoster
Posted

Entity#move should work

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
16 hours ago, Cadiboo said:

Entity#move should work

I'm making advancements. I found a way to move the player using the MovementInput class and :

import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;

 

. It worked perfectly however only if I call the method via an event like LeftClickBlock event. When I want to call the method using a keybind:

@SubscribeEvent
	public static void keyPress(KeyInputEvent event)
	{
		
		if(KeyBindings.myKey.isPressed()) {
			if(!pressed) {
				pressed = true;
			}else {
				pressed = false;
			}
			
			if(pressed) {
				pmc.moveStraightTo(0,0,4);
			}else {
				pmc.resetPlayerInput();
			}
		}
	}

I get a NullPointer Exception:

 

Edit: Im an idiot I did not registered the keybind properly

Edited by HenryFoster

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.