Jump to content

Recommended Posts

Posted

I made an enchantment that's supposed to increase the player's speed every level. But walking with the max-level enchanted boots equipped is still the default speed doesn't even happen and instead the world keeps unloading and loading.

My event handler registered and working perfectly fine with other events so I can't figure out what I'm doing wrong.

 

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

		ItemStack item;
		for (int i = 0; i < 4; i++)
		{
			item = player.getCurrentArmor(i);
			if (item != null)
			{
				int j = EnchantmentHelper.getEnchantmentLevel(Worlds.hyperspeed.effectId, item);
				if (j > 0)
				{
					player.capabilities.setPlayerWalkSpeed(player.capabilities.getWalkSpeed() + 1 * j);
					Worlds.log.entry("Speed - " + player.capabilities.getWalkSpeed());
				}
			}
		}

	}
}

Posted

How often does LivingUpdateEvent get called? I may be wrong, but it looks like every update is going to multiply the player's speed again and again until it overflows. Am I reading your expression wrong?

 

I trust you've looked at how a speed potion (or running) produces its effect in vanilla code. Do they use such multiplication in effectively the same place that this event fires?

 

Also, you mention boots but your loop looks at all four armor slots. Is speed intended to work on helms etc?

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

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.