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

I have been googling this for the last 30 minutes and for the life of me I can't figure out what I did wrong.  When i use this it creates an explosion somewhere that seems to be related to where I am standing and the block I'm looking at but not actually AT the block.  I'm sure it's a really simple thing I overlooked but I'm just not seeing it.

 

	public void execute(ICommandSender sender, String[] args) throws CommandException {
    	BlockPos blk = sender.getEntityWorld().rayTraceBlocks(sender.getPositionVector(), sender.getCommandSenderEntity().getLookVec()).getBlockPos();
    	sender.getEntityWorld().createExplosion(sender.getCommandSenderEntity(),blk.getX(),blk.getY(),blk.getZ(),5, false);
}

The look vector for an entity is not a position in the world. It's just an angle, basically. You're treating it as a position. (Look vector values are only between -1 and 1).

 

To find the position you are looking at, you can a function found here: http://jabelarminecraft.blogspot.com/p/minecraft-modding-extending-reach-of.html

 

That function only works client side, so a universal version is like so:

 




public static MovingObjectPosition getMouseOverExtendedUniversal(Entity theRenderViewEntity, float dist) {

	AxisAlignedBB theViewBoundingBox = new AxisAlignedBB(
			theRenderViewEntity.posX - 0.5D,
			theRenderViewEntity.posY - 0.0D,
			theRenderViewEntity.posZ - 0.5D,
			theRenderViewEntity.posX + 0.5D,
			theRenderViewEntity.posY + 1.5D,
			theRenderViewEntity.posZ + 0.5D
			);

	MovingObjectPosition returnMOP = null;
	if (theRenderViewEntity.worldObj != null)
	{
		double var2 = dist;
		returnMOP = theRenderViewEntity.rayTrace( var2, 0 );
		double calcdist = var2;
		Vec3 pos = getPositionEyes( theRenderViewEntity, 0 );
		var2 = calcdist;
		if (returnMOP != null)
		{
			calcdist = returnMOP.hitVec.distanceTo( pos );
		}

		Vec3 lookvec = theRenderViewEntity.getLook( 0 );
		Vec3 var8 = pos.addVector( lookvec.xCoord * var2,

				lookvec.yCoord * var2,

				lookvec.zCoord * var2 );
		Entity pointedEntity = null;
		float var9 = 1.0F;
		@SuppressWarnings("unchecked")
		List<Entity> list = theRenderViewEntity.worldObj
				.getEntitiesWithinAABBExcludingEntity(

						theRenderViewEntity,

						theViewBoundingBox.addCoord(

								lookvec.xCoord * var2,

								lookvec.yCoord * var2,

								lookvec.zCoord * var2 ).expand( var9, var9,
								var9 ) );
		double d = calcdist;

		for (Entity entity : list)
		{
			if (entity.canBeCollidedWith())
			{
				float bordersize = entity.getCollisionBorderSize();
				AxisAlignedBB aabb = new AxisAlignedBB(

						entity.posX - entity.width / 2,

						entity.posY,

						entity.posZ - entity.width / 2,

						entity.posX + entity.width / 2,

						entity.posY + entity.height,

						entity.posZ + entity.width / 2 );
				aabb.expand( bordersize, bordersize, bordersize );
				MovingObjectPosition mop0 = aabb.calculateIntercept( pos,
						var8 );

				if (aabb.isVecInside( pos ))
				{
					if (0.0D < d || d == 0.0D)
					{
						pointedEntity = entity;
						d = 0.0D;
					}
				} else if (mop0 != null)
				{
					double d1 = pos.distanceTo( mop0.hitVec );

					if (d1 < d || d == 0.0D)
					{
						pointedEntity = entity;
						d = d1;
					}
				}
			}
		}

		if (pointedEntity != null && (d < calcdist || returnMOP == null))
		{
			returnMOP = new MovingObjectPosition( pointedEntity );
		}

	}
	return returnMOP;
}

 

 

The parameter dist is the max distance to check for a position. The moving object position returned is where you want to spawn the explosion.

 

With all due respect, sir: I do, what I do, the way I do it. ~ MacGyver

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.