Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

  • Author

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?

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?

  • Author

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.

  • Author

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

  • Author

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

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.