Jump to content

Get mobs in front of player at fixed distance


Oen44

Recommended Posts

Hi,

I'm doing special weapon that when right-clicked moves player in short distance and damages all mobs that are in the way.

That's what I've tried

@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
	ItemStack stack = player.getHeldItem(hand);

	Vec3d vec = player.getLookVec();

	player.setVelocity(vec.x * 2, 0, vec.z * 2);
	stack.damageItem(15, player);

	List<Entity> entities = world.getEntitiesWithinAABBExcludingEntity(player, player.getEntityBoundingBox().expand(4, 0, 4));

	for (Entity entity : entities) {
		if (entity instanceof IMob) {
			entity.attackEntityFrom(DamageSource.GENERIC, 5.0f);
		}
	}

	return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
}

 

It's cool and all but getEntitiesWithinAABBExcludingEntity is getting mobs that are around player so I need something completely different.

 

Any tips what to look at and use?

Edited by Oen44
Link to comment
Share on other sites

Use the

player.getPitchYaw();
player.getPosition();

properties along with the

entity.getPosition();

vector and do some quick trig to detect if the entity is infront of the camera's view?

I probably wouldn't be much help with the trig part but I know it's possible. :)

Link to comment
Share on other sites

56 minutes ago, oreo said:

Use the


player.getPitchYaw();
player.getPosition();

properties along with the


entity.getPosition();

vector and do some quick trig to detect if the entity is infront of the camera's view?

I probably wouldn't be much help with the trig part but I know it's possible. :)

Yeah... That didn't help at all.

 

Anyway, tried using RayCasting, saving surrounding mobs to array every tick, on right-click doing some position checking with every mob in array etc. Something worked in some way but not close to what I need.

The worst part is about positioning BETWEEN player position and end position. All depends on player rotation, if player is facing North, leave X, decrease Z etc. I managed to handle this way North, South, West and East. But what about between? That bothers me so much...

 

Anyone knows how to check every position (or block) from Start to End?

Edited by Oen44
Link to comment
Share on other sites

31 minutes ago, Oen44 said:

Anyway, tried using RayCasting, saving surrounding mobs to array every tick, on right-click doing some position checking with every mob in array etc. Something worked in some way but not close to what I need.

 

Just check if the player's look vector intersects with the entity's AABB like I do here.

  • Thanks 1
Link to comment
Share on other sites

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.