November 28, 201410 yr I think ray tracing should be able to work. On the client side, I think you can use Minecraft.getMinecraft().objectMouseOver and check what it is (block or entity). Check out my tutorials here: http://jabelarminecraft.blogspot.com/
December 25, 201410 yr Author MovingObjectPosition mop = player.rayTrace(40, 1.0F); Entity ent = mop.entityHit;
December 25, 201410 yr Hi This line in EntityRenderer.getMouseOver is probably the reason for (int i = 0; i < list.size(); ++i) { Entity entity = (Entity)list.get(i); if (entity.canBeCollidedWith()) // here -> can't collide with EntityItem You might need to copy the code from EntityRenderer.getMouseOver into your own method and alter it. Depending on what you're trying to do, if you want this to work on the server side you probably need to copy the code anyway. -TGG
December 26, 201410 yr Author THANKS!!! Code: public Entity getMouseOver(float partialTicks, double distance, boolean canBeCollidedWith){ Minecraft mc = Minecraft.getMinecraft(); Entity pointedEntity = null; MovingObjectPosition rayTrace = null; if(mc.renderViewEntity != null){ if(mc.theWorld != null){ rayTrace = mc.renderViewEntity.rayTrace(distance, partialTicks); Vec3 positionVec = mc.renderViewEntity.getPosition(partialTicks); double distanceToVec3 = distance; if(rayTrace != null){ distanceToVec3 = rayTrace.hitVec.distanceTo(positionVec); } Vec3 lookVec = mc.renderViewEntity.getLook(partialTicks); Vec3 posDistVec = positionVec.addVector(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance); Vec3 tempVec = null; double boxExpand = 1.0F; List<Entity> entities = mc.theWorld.getEntitiesWithinAABBExcludingEntity(mc.renderViewEntity, mc.renderViewEntity.boundingBox.addCoord(lookVec.xCoord * distance, lookVec.yCoord * distance, lookVec.zCoord * distance).expand(boxExpand, boxExpand, boxExpand)); double vecInsideDist = distanceToVec3; for(int i = 0; i < entities.size(); i++){ Entity entity = entities.get(i); if(!canBeCollidedWith || entity.canBeCollidedWith()){ double borderSize = entity.getCollisionBorderSize(); AxisAlignedBB expEntityBox = entity.boundingBox.expand(borderSize, borderSize, borderSize); MovingObjectPosition calculateInterceptPos = expEntityBox.calculateIntercept(positionVec, posDistVec); if(expEntityBox.isVecInside(positionVec)){ if(0.0D < vecInsideDist || vecInsideDist == 0.0D){ pointedEntity = entity; tempVec = calculateInterceptPos == null ? positionVec : calculateInterceptPos.hitVec; vecInsideDist = 0.0D; } }else if(calculateInterceptPos != null){ double calcInterceptPosDist = positionVec.distanceTo(calculateInterceptPos.hitVec); if(calcInterceptPosDist < vecInsideDist || vecInsideDist == 0.0D){ if(entity == mc.renderViewEntity.ridingEntity && !entity.canRiderInteract()){ if(vecInsideDist == 0.0D){ pointedEntity = entity; tempVec = calculateInterceptPos.hitVec; } }else{ pointedEntity = entity; tempVec = calculateInterceptPos.hitVec; vecInsideDist = calcInterceptPosDist; } } } } } if(pointedEntity != null && (vecInsideDist < distanceToVec3 || rayTrace == null)){ return pointedEntity; } } } return null; }
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.