Jump to content

Recommended Posts

Posted

Alright, so I need to stop the player from accessing the sprint option while certain things are true. I can modify the players walk speed quite fine. But, when attempting to stop the player from sprinting, it works for double tapping the forward key, and pressing the sprint key. But, holding the sprint key down allows them to sprint. Any way to prevent this?

 

Here's where I do the changing of movement speed:

@SubscribeEvent
public void onLivingUpdate(LivingUpdateEvent event) {
	if(event.entity instanceof EntityPlayer) {
		EntityPlayer player = (EntityPlayer)event.entity;

		ExtendedPlayer props = ExtendedPlayer.get(player);

		if(props.get(player) != null) {
			if(props.isOverEncumbered()) {
				System.out.println("Player is Overencumbered! Changing walk speed...");

				player.capabilities.setPlayerWalkSpeed(0.05F);

				player.setSprinting(false);
			}else {
				if(player.capabilities.getWalkSpeed() != 0.1F) {
					player.capabilities.setPlayerWalkSpeed(0.1F);
				}
			}
		}
	}
}

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I'll get to that, but what is so different between setting the player walk speed in PlayerCapabilities, and setting it in AttributeModifier?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Ah yes, I read through some older threads while waiting for your reply. So, you can simply use any randomly generated UUID to store your AttributeModifier?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

I got that to work pretty flawlessly. But, I hate how the FOV changes when I lower the speed. :/ I know there is an FOVUpdateEvent, but how will it know when not to change the FOV?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

So, I should get the player's current speed, and subtract my modified speed from it to reset the FOV?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Hm, so I figured that if I check my ExtendedPlayer for the method "isOverEncumbered", I can basically tell the event when I am changing the speed. Should I just make the new FOV, the FOV setting the player may have set? (Just in case they changed their default FOV)

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Hm, I decided, considering I will not be changing how slow you are when you're overencumbered; I would just use the double that is set for the speed after the modifier. Here is what I have:

 

@SubscribeEvent
public void onFOVChanged(FOVUpdateEvent event) {
	if(event.entity != null) {
		EntityPlayer player = event.entity;

		ExtendedPlayer props = ExtendedPlayer.get(player);

		if(props.isOverEncumbered() && player.getActivePotionEffects().isEmpty()) {
			IAttributeInstance iai = player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);

			double speed = iai.getAttributeValue();

			//System.out.println("Speed: " + speed);
			//System.out.println("Compared Speed: " + 0.06000000089406967);

			if(speed == 0.06000000089406967) {
				System.out.println("SPEED IS KEY");

				event.newfov = 1.0F;
			}
		}
	}
}

 

Although, this does help A LOT with my code and such. This does not help me stop the player from sprinting entirely. xD

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

You should most definitely NOT compare floating point values like that using equality... not to mention that there could be other attribute modifiers affecting the players speed besides yours.

 

If you really want to stop the player from sprinting, the only reliable way to do so is to setSprinting(false) every tick and on the client side unset the sprint key:

KeyBinding.setKeyBindState(mc.gameSettings.keyBindSprint.getKeyCode(), false);

Posted

Hm, I might honestly just keep the FOV change as it is not too much of a bother. And, should I do that in my LivingUpdateEvent, or in a client side tick handler?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Gotcha. ;) Although, couldn't I just disable the key once, and re-enable it when the player is not over-encumbered? Or does it need to be disabled every tick?

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

Hm, I will be using the tick handler, but would there be any way of disabling the key input for a time? I feel like if you could, it might save some processing power from constantly setting the state of the key. I may be wrong though, so thanks. :P

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

You both seem to forget the sprint keybind is not the only way to sprint. I still use the the old method of double tapping forward. So the tick handler is the definitely the way to go, I wouldn't be overly concerned about disabling the sprint key considering you could still start sprinting via double tapping forward.

Posted

You disable sprint by doing:

 

 player.setSprinting(false) 

 

within a tick handler. I have to set the state of the KeyBind, in order to stop the player for pressing or holding down CTRL (or whatever they have set it to) to sprint. :P

 

@coolAlias So, I wasn't able to set the key state via ClientTickEvent (ExtendedPlayer couldn't get the props right). So I just check if it is a client world in #onLivingUpdate, and if so, set the KeyBind as false when OverEncumbered.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

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.