Jump to content

Recommended Posts

  • 4 weeks later...
Posted

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

 

 

 

 

Posted

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.

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.