Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

        I am creating a mod that adds more enchantments to the game. I am using the Forge Hooks (which are amazing, by the way) to insert the new effects of the enchantment into the base classes. One of my added enchantments was a jump boost which would increase the player's jump height if the boots contain the corresponding enchantment. I've discovered something very odd, however, with the PlayerEvent hook:

 

@ForgeSubscribe
@SideOnly(Side.CLIENT)
public void playerFallen(PlayerEvent event)
{
        Minecraft minecraft = Minecraft.getMinecraft();
EntityPlayer player = event.entityPlayer;
ItemStack stack = player.inventory.armorItemInSlot(0);

if(EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.jumpBoost.effectId, stack) > 0)
{	
	canJumpBoost = true;
}

if(canJumpBoost == true && Keyboard.isKeyDown(minecraft.gameSettings.keyBindJump.keyCode) && player.motionY > 0.0D)
{
	player.motionY += 0.069;
} 
}

 

(Brief note: the canJumpBoost boolean is publicly declared in my hook container class.)

 

        The code works fine except for one thing: the jump boost only takes effect when you are trying to break a block. As far as I can tell, the PlayerEvent has no fields or arguments which require the player to be breaking blocks in order to execute an action. In fact, when I plug in EntityPlayer booleans such as

 player.setInvisible(true); 

it works just fine. Also, I add "System.out" within my if-statements to make sure the method is being called --which it is. If any of you could help me figure out what is going on here, I would be much obliged. Thank you for taking the time to read this, and have a wonderful day.  ;)

Hi

 

So you are saying that in all cases it executes both of the if statements in playerFallen, and adds 0.069 to the player.motionY.  But adding 0.069 has no effect on the actual jump height unless you are breaking a block while jumping?

 

-TGG

Do you know how many player events there is ?

And you are using all of them simultaneously...choose one, please  :-\

  • Author

    Yes, both if-statements are being executed correctly...only when the player is trying to break a block and is jumping. There are many player events, but the PlayerEvent is the main one, correct? Also, as I said above, code like

 player.setInvisible(true); 

works correctly without having to try breaking blocks. I have looked at the Forge Hook page, and it is perfectly valid, I believe, to use a hook with the PlayerEvent. I am just utterly perplexed.  :(

  • Author

Alright, a little update: I have figured out how to call the player's jump action, even without calling the key code of the Minecraft class too. In the LivingEvent, there is a LivingJumpEvent, which I am now using. Here is my code:

 

@ForgeSubscribe
public void playerFallen(LivingJumpEvent event)
{
EntityLivingBase living = event.entityLiving;
EntityPlayer player = (EntityPlayer) living;
ItemStack stack = player.inventory.armorItemInSlot(0);

if(EnchantmentHelper.getEnchantmentLevel(ArcaneEnchantments.jumpBoost.effectId, stack) > 0)
{
        if(player.motionY > 0.0D)
	{
		player.motionY += 0.069;
	}
}
}

 

Granted, the higher jump effect is still not working quite yet, but I believe I am on the road to success. It just took some fresh eyes and a break from coding to figure it out. Thank you guys for your assistance, and I hope anybody reading this in the future can fix their problem as well!  :)

That's because you are only adding motionY if motionY is already greater than zero, which it will never be because the LivingJumpEvent is called when the player jumps (i.e. presses the space bar) but before any upward motion is applied. Removing that if statement should fix your problem.

Just to be clear, PlayerEvent is a parent event. It is only called through its children.

Look at the type hierarchy. It has 17 child events at this point.

No, it is not a good idea to use PlayerEvent, unless you want to use most of them for whatever reason.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.