Jump to content

Recommended Posts

Posted

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.

Posted

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?

Posted

The solution I wound up using was to grab the client-side entity using the method you mentioned earlier and then use the MinecraftServer class plus some AABB stuff to get the corresponding server-side entity.

Posted

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;
}

Posted

I'm trying to get a server-side copy of the mob (if any) the player is currently looking at, so I can (possibly, if the entity meets some conditions specified later in the method) spawn some particles and inflict magic damage to it.

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.