Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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. :)

  • Author
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

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.

  • Author
15 minutes ago, V0idWa1k3r said:

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

Awesome! Works like a charm, thank you!

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...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.