Jump to content

[1.11][SOLVED] Get entities in a cone in front of steve


Recommended Posts

Posted

How can i get entities in a cone in front of steve? 3 block length. I tried this from a tutorial:

 

public static List<RayTraceResult> getMouseOverExtendedList(float dist) {
	Minecraft mc = FMLClientHandler.instance().getClient();
	Entity theRenderViewEntity = mc.getRenderViewEntity();
	AxisAlignedBB theViewBoundingBox = 
			new AxisAlignedBB(
					theRenderViewEntity.posX - 2.0D,
					theRenderViewEntity.posY - 0.0D, 
					theRenderViewEntity.posZ - 0.0D, 
					theRenderViewEntity.posX + 2.0D,
					theRenderViewEntity.posY + 1.5D, 
					theRenderViewEntity.posZ + 2.0D);
	RayTraceResult returnMOP = null;
	List<RayTraceResult> returnMOPList = new ArrayList<>();

	if (mc.world != null) {
		double distancia = dist;
		returnMOP = theRenderViewEntity.rayTrace(distancia, 0);
		double calcdist = distancia;
		Vec3d vectorPosicionOjos = theRenderViewEntity.getPositionEyes(0);
		distancia = calcdist;
		if (returnMOP != null) {
			calcdist = returnMOP.hitVec.distanceTo(vectorPosicionOjos);
		}

		Vec3d lookvec = theRenderViewEntity.getLook(0);
		Vec3d lookVectorPlusDistancia = vectorPosicionOjos.addVector(lookvec.xCoord * distancia, lookvec.yCoord * distancia, lookvec.zCoord * distancia);
		float var9 = 1.0F;
		@SuppressWarnings("unchecked")
		List<Entity> list = mc.world.getEntitiesWithinAABBExcludingEntity(theRenderViewEntity,
				theViewBoundingBox.addCoord(lookvec.xCoord * distancia, lookvec.yCoord * distancia, lookvec.zCoord * distancia)
						.expand(var9, var9, var9));
		double d = calcdist;

		for (Entity entity : list) {
			if (entity.canBeCollidedWith()) {
				returnMOPList.add(new RayTraceResult(entity));

			}
		}
	}
	return returnMOPList;
}

 

But it didn't worked as i expected. Any help would be much apreciated.

 

 

Posted

That method, will only work client-side, as you are using client-side only classes (

Minecraft::getRenderViewEntity

etc)

 

What you can do, is;

  • get a list of all entities around the player, using
    World#getEntitiesWithinAABB


  • Create the "cone" or rather, triangle, by assigning 2 points away from the player, at equal distance from the
    player#getLookVec


  • Go over each entity in the list we got earlier, and calculate whether their position is inside the triangle, using Barycentric Coordinates

 

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

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.