Jump to content

LivingJumpEvent not working


JoeStrout

Recommended Posts

I'm trying to catch LivingJumpEvent and log to the console (following Jabelar's excellent article).  But it's not working — no matter how I jump around, I see no logging in the console.

 

Other events subscribed in the same class do work, so I don't know what the problem could be.  But since I don't know what it might be, here's the whole class:

 

package net.strout.mod1;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.*;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.client.event.*;
import net.minecraftforge.event.entity.living.LivingEvent.*;
import net.minecraftforge.event.entity.player.*;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

// Note: for a great explanation of Forge events, see:
// http://jabelarminecraft.blogspot.com/p/minecraft-forge-172-event-handling.html

@Mod.EventBusSubscriber
public class MyForgeEventHandler {
	private static void SendStatus(String message) {
		Minecraft.getMinecraft().player.sendStatusMessage(new TextComponentString(message), false);		
	}
	
	@SubscribeEvent
	public static void pickupItem(EntityItemPickupEvent event) {
        System.out.println("Item picked up:" + event.getItem());
        SendStatus("You picked up a " + event.getItem());
    } 	


	@SubscribeEvent(priority=EventPriority.HIGHEST, receiveCanceled=true)
	public void onLivingJump(LivingJumpEvent event) {
		if (event.getEntity() instanceof EntityPlayer) {
		    System.out.println("Boing");
	    } else {
	        System.out.println("get LivingJumpEvent, but not with EntityPlayer?!");
	    }
	}
	

	@SubscribeEvent
	public static void onChatReceived(ClientChatReceivedEvent event) {
		ITextComponent msg = event.getMessage();
		String formattedText = msg.getFormattedText();
		System.out.println("Chat type " + event.getType() + " received: " + formattedText);
		String plaintext = msg.getUnformattedText().toLowerCase();
		if (plaintext.contains("hello")) {
			// Cancel the event, so the player doesn't see the given message AFTER our response.
			event.setCanceled(true);
			// Display the given message immediately.
			Minecraft.getMinecraft().player.sendStatusMessage(msg, false);
			// Then, display our response.
			SendStatus("<§rVoice In Your Head§r> §rHi yourself.§r");
		}
	}
	
 	@SubscribeEvent
 	public static void onChat(ClientChatEvent event) {
 		String msg = event.getMessage();
 		if (msg.equals("/test")) {
 			event.setCanceled(true);
 			SendStatus("This is a test.  This is only a test.");
 		} else if (msg.equals("/menu")) {
 			event.setCanceled(true);
 			// Does not actually work in our testing:
 			Minecraft.getMinecraft().displayInGameMenu();
 		} else if (msg.equals("/apparate")) {
 			event.setCanceled(true);
 			Minecraft.getMinecraft().player.setPositionAndUpdate(50, 66, 250);
 			SendStatus("§6You apparate.§r");
 		}
 	}
 	
}

 

(Sorry for the poor indentation — it appears that Eclipse has mixed tabs and spaces, how lovely.)  I've tried the @SubscribeEvent both with and without the optional parameters; no difference.

 

Any idea why my LivingJumpEvent handler isn't getting invoked?

 

Link to comment
Share on other sites

On 12/28/2017 at 10:16 AM, JoeStrout said:

Sorry for the poor indentation — it appears that Eclipse has mixed tabs and spaces, how lovely.

The MinecraftForge project has an official formatter template which I recommend that you download and put in a text file in your workspace then import it with Window | Preferences | Java | Code Style | Formatter | Import... Also  you can choose whether it applies automatically or manually. If you choose to apply it manually, then you can do so by selecting the file in the Project Explorer window and right-clicking and select Source | Format.

 

Or in general you should go through the formatter settings yourself and select things like using spaces for tabs.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

5 hours ago, jabelar said:

The MinecraftForge project has an official formatter template which I recommend that you download and put in a text file in your workspace then import it with Window | Preferences | Java | Code Style | Formatter | Import... Also  you can choose whether it applies automatically or manually. If you choose to apply it manually, then you can do so by selecting the file in the Project Explorer window and right-clicking and select Source | Format.

 

Or in general you should go through the formatter settings yourself and select things like using spaces for tabs.

Is there a built-in link for this kind of style:

	/* Event fired when an entity dies */
	@SubscribeEvent(priority = EventPriority.HIGHEST)
	public void onDeath(LivingDeathEvent event)
	{
		if (event.getEntityLiving() instanceof EntityLiving)
		{
			EntityLiving entityliving = (EntityLiving) event.getEntityLiving();
			entityliving.playSound(SoundEvents.BLOCK_METAL_BREAK, 1.0F, 1.0F);

			World worldIn = entity.worldObj;
			
			for (int i = 0; i < 50; ++i)
			{
				worldIn.spawnParticle(EnumParticleTypes.BLOCK_CRACK, 
					  entityliving.posX, entityliving.posY + (entityliving.height - 0.25D), entityliving.posZ, 
					  Math.random() * 0.2D - 0.1D, Math.random() * 0.25D, Math.random() * 0.2D - 0.1D, 
					  Block.getIdFromBlock(Blocks.REDSTONE_BLOCK)
				   );
			}
		}
	}

(The Minecraft built - in style)?

Link to comment
Share on other sites

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.