Posted July 9, 201510 yr What is the easiest way to do this? I've tried using rayTrace() but I can't seem to get it to work.
July 9, 201510 yr 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. http://i.imgur.com/NdrFdld.png[/img]
July 9, 201510 yr 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?
July 9, 201510 yr 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? http://i.imgur.com/NdrFdld.png[/img]
July 9, 201510 yr Does attackEntityFrom() work on the client-side? Yes and no - you can use it, but it won't have any real effect. If you want to attack the entity for real (i.e. cause it to take damage), you must do so on the server. http://i.imgur.com/NdrFdld.png[/img]
July 9, 201510 yr 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.
July 9, 201510 yr 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; }
July 9, 201510 yr 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.