Jump to content

Recommended Posts

Posted

I want to make a light grenade as in CS.

How can I verify that the entity grenades on the screen and there are no obstacles (blocks)?

I have tried so, but I did not work:

@SubscribeEvent
public void check(RenderTickEvent e){
	if(Minecraft.getMinecraft().currentScreen == null && Minecraft.getMinecraft().renderViewEntity != null){
		EntityLivingBase entity = Minecraft.getMinecraft().renderViewEntity;
		double d0 = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double)e.renderTickTime;
		double d1 = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double)e.renderTickTime;
		double d2 = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double)e.renderTickTime;
		Frustrum frustrum = new Frustrum();
		frustrum.setPosition(d0, d1, d2);
		Minecraft.getMinecraft().renderGlobal.clipRenderersByFrustum(frustrum, e.renderTickTime);
		List<EntityPig> arrows = Minecraft.getMinecraft().theWorld.getEntitiesWithinAABB(EntityPig.class, AxisAlignedBB.getBoundingBox(d0 - 10, d1 - 10, d2 - 10, d0 + 10, d1 + 10, d2 + 10));
		for(EntityPig arrow : arrows){
		    System.out.println(frustrum.isBoundingBoxInFrustum(arrow.boundingBox));
		}
	}

}

Posted

A few things:

 

I don't think you need the line with the clipRenderersByFrustum() because you're not actually trying to render and you've already got a frustum instance to check the bounding box again.

 

Why is your arrow field of type EntityPig? Your code is basically looking for pigs, not arrows. Did you do that for debugging?

 

Is it your intention to only detect pigs within 10 blocks of the camera? Or do you want everything in the full range of view to distance? Because your code would only detect pigs within 10 blocks. When you were testing the code were your pigs that close? If you want all pigs into the distance, I think you could just iterate through all the pigs in the world instead.

 

None of that code will detect if obstacles are in the way. Why do you want to know if obstacles are in the way? Anyway, if you do, you'll want to do a "ray trace". There are methods in the world class for that -- you just specify the end points of the "ray" and it will return if any blocks are along that line. So I think you could take each pig and ray trace back to the frustum position.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I wouldn't do that this way, but well. Your choice.

Direct answer to your direct question:

 

Entity viewPoint = mc.getRenderViewEntity();
entity.isInRangeToRender3d(viewX, viewY, viewZ) // check render view - your d, d1, d2
entity.isEntityAlive() // check if not dead
entity.getDistanceToEntity(viewPoint) // check range
entity.canEntityBeSeen(viewPoint) // check obstacles - rayTracing

 

Those will give you working code. Consider not using Frustrum and AABB, no need - you can go with math (rotation) and:

for (Object o : mc.theWorld.getLoadedEntityList())

I've always preferred math solutions.

1.7.10 is no longer supported by forge, you are on your own.

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.