Jump to content

[1.8] Identify which mob a player is looking at


SuperJedi224

Recommended Posts

If you only want to display some information (i.e. client side), the easiest way is to use Minecraft.getMinecraft().objectMouseOver, then check if the entityHit is not null and there you go.

 

Server side is a bit more complicated - ray trace only works for blocks, so you have to do some math using the player's look vector; you can pretty much copy the code from EntityRenderer#getMouseOver.

Link to comment
Share on other sites

I'm doing this for what basically amounts to a helmet of anti-zombie laser vision, so I need to be able to do it from the armor tick method. Any suggestions?

If you only want to display some information (i.e. client side), the easiest way is to use Minecraft.getMinecraft().objectMouseOver, then check if the entityHit is not null and there you go.

 

Server side is a bit more complicated - ray trace only works for blocks, so you have to do some math using the player's look vector; you can pretty much copy the code from EntityRenderer#getMouseOver.

Are those ^^^ not suggestions?

Link to comment
Share on other sites

Here's the portion of the code in question as it currently stands (this is located inside a helmet's onArmorTick method):

 

MovingObjectPosition loc=Minecraft.getMinecraft().objectMouseOver;
Entity b=loc==null?null:loc.entityHit;
if(b==null||!(b instanceof EntityLivingBase))return;
EntityLivingBase c=(EntityLivingBase)b;
try{
c=(EntityLivingBase)MinecraftServer.getServer().worldServerForDimension(p.dimension).getEntitiesWithinAABB(b.getClass(),b.getEntityBoundingBox().expand(0.2,0.2,0.2)).get(0);
}catch(Exception e){
return;
}

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.