Jump to content

Recommended Posts

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

Posted

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

Posted

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

Posted

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!  :)

Posted

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

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