MrArcane111 Posted October 20, 2013 Posted October 20, 2013 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. Quote
TheGreyGhost Posted October 20, 2013 Posted October 20, 2013 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 Quote
GotoLink Posted October 20, 2013 Posted October 20, 2013 Do you know how many player events there is ? And you are using all of them simultaneously...choose one, please Quote
MrArcane111 Posted October 20, 2013 Author Posted October 20, 2013 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. Quote
MrArcane111 Posted October 20, 2013 Author Posted October 20, 2013 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! Quote
coolAlias Posted October 20, 2013 Posted October 20, 2013 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. Quote http://i.imgur.com/NdrFdld.png[/img]
GotoLink Posted October 20, 2013 Posted October 20, 2013 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. Quote
Recommended Posts
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.