Jump to content

How to stop the player from sprinting


squidlex

Recommended Posts

Hi there!

I'm currently trying to stop the player from sprinting using:

event.player.setSprinting(false);

in the PlayerTickEvent event. This works for double tapping w, however the player can still sprint by holding Left-Control.

 

Here is my full Class for reference:

package com.elenai.elenaihardcore.event;

import com.elenai.elenaidodge2.api.FeathersHelper;
import com.elenai.elenaihardcore.capability.sprint.SprintProvider;

import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.PlayerTickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

public class PlayerEventListener {

	@SubscribeEvent
	public void playerEventListener(PlayerTickEvent event) {
		if (event.side.isServer() && event.phase == TickEvent.Phase.START) {
			event.player.getCapability(SprintProvider.SPRINT_CAP).ifPresent(s -> {
				if (event.player.isSprinting()) {
					s.increase(4);
				}
			});

			if (FeathersHelper.getFeatherLevel((ServerPlayerEntity) event.player) <= 0) {
				event.player.setSprinting(false);
			}
			
			event.player.getCapability(SprintProvider.SPRINT_CAP).ifPresent(s -> {
				if (s.getSprint() >= 20) {
					s.set(0);
					FeathersHelper.decreaseFeathers((ServerPlayerEntity) event.player, 1);
				}
			});
		}

	}

}

^ I have also tested this without the if conditions or capabilities and it still doesn't work. How would I be able to completely prevent the player from sprinting?

 

Thanks for your help!

 

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.

Announcements



×
×
  • Create New...

Important Information

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