Jump to content

Recommended Posts

Posted

I want to make it so that the player can move around while they are in their inventory screen. I currently have this:

@SubscribeEvent
public static void keyboardKey(final GuiScreenEvent.KeyboardKeyEvent event) {
	if (event.getGui() instanceof InventoryScreen || event.getGui() instanceof CreativeScreen) {

		ClientPlayerEntity player = Minecraft.getInstance().player;
		if (Minecraft.getInstance().gameSettings.keyBindForward.isPressed()) LOGGER.log("Forward!");
		if (Minecraft.getInstance().gameSettings.keyBindBack.isPressed()) LOGGER.log("Back!");
		if (Minecraft.getInstance().gameSettings.keyBindLeft.isPressed()) LOGGER.log("Left!");
		if (Minecraft.getInstance().gameSettings.keyBindRight.isPressed()) LOGGER.log("Right!");
		if (Minecraft.getInstance().gameSettings.keyBindJump.isPressed() && player.onGround) player.jump();
	}
}

but I have no idea how to simulate moving the character to the left, right, forward, or back (jumping works when holding, but it stops when I leave the inventory). I have tried searching for the vanilla class that controls player movement but to no avail. Any help would be appreciated.

Posted (edited)

Check out ClientPlayerEntity::movementInput.

Edited by DavidM

Some tips:

  Reveal hidden contents

 

Posted
  On 1/9/2020 at 5:15 AM, DavidM said:

Check out ClientPlayerEntity::movementInput.

Expand  

I changed everything to this:

@SubscribeEvent
public static void keyboardKey(final GuiScreenEvent.KeyboardKeyEvent event) {
	if (event.getGui() instanceof InventoryScreen || event.getGui() instanceof CreativeScreen) {
		ClientPlayerEntity player = Minecraft.getInstance().player;
		if (Minecraft.getInstance().gameSettings.keyBindForward.isPressed()) player.movementInput.forwardKeyDown = true;
		if (Minecraft.getInstance().gameSettings.keyBindBack.isPressed()) player.movementInput.backKeyDown = true;
		if (Minecraft.getInstance().gameSettings.keyBindLeft.isPressed()) player.movementInput.leftKeyDown = true;
		if (Minecraft.getInstance().gameSettings.keyBindRight.isPressed()) player.movementInput.rightKeyDown = true;
		if (Minecraft.getInstance().gameSettings.keyBindJump.isPressed()) player.movementInput.jump = true;
		if (Minecraft.getInstance().gameSettings.keyBindSprint.isPressed()) player.setSprinting(true);
	}
}

but nothing is happening when I try it.

  • 2 weeks later...
Posted

Can't you just subscribe to the open GUI event and replace the screen with one that overrides Screen#isPauseScreen to return false?

About Me

  Reveal hidden contents

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)

  • 3 weeks later...
Posted

Subscribing: https://mcforge.readthedocs.io/en/1.15.x/events/intro/

Personally I would PR a hook to avoid incompatibilities with other mods that replace the screen.

About Me

  Reveal hidden contents

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)

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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Greetings! If you clicked on this I can only assume you have at the very least a slight interest in using Minecraft as a vehicle for making nations, roleplaying, and worldbuilding, which is amazing to hear, thank you for your interest and I will do my best to explain this as much as I can here but I would like to start by advising you to join our discord, even if you have the slightest interest you can leave whenever you want and I can explain this whole thing a whole lot better. Our goal is to foster a creative and unified community and thrive on a minecraft server that was made for creating everything from nations to individual cultures. This recruitment post is for the city of Sajurgard (inside a larger nation) on the server of Stoneworks but fear not if you have ambitions to create your own nation/group simply join our discord and we will help you get set up. Our nation is all about making the experience as positive as possible for everyone! If you've never heard of something like this before that's perfect, come on down and we will get you started on your journey! If your a veteran of this type of thing we also welcome you and promise you will find the experience with us enjoyable. I would love to explain more about our lore, history and community and what we have going on here but it wouldn't fit here, so if this at all interests you join our discord and contact us! We would love to have you and are happy to answer all questions and promise to ensure you will enjoy your time with us. discord server: https://discord.gg/ez9XjNUJJj
    • Add the full crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here
    • Add the mod clumps https://www.curseforge.com/minecraft/mc-mods/clumps
    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
  • Topics

×
×
  • Create New...

Important Information

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