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.

[1.7.2] player.addVelocity won't affect actual user velocity. {Solved}

Featured Replies

Posted

I have resumed modding, and decide to update my mod to 1.7.2, after updating most of the stuff, while testing I find out that a staff item I had, which fired an entity which then affected entity's in area had partially got broken.

The part which I loved the most, the ability to leap up into air is broken, It still works on other living entities.

But player? Nope.

So I tried addVelocity, setVelocity, manualy change motionX,Y,Z.

None of those worked on my player.

Here's an extract of my entity's action on detonation. I took out the other 3 type's of action's for sake of size of code.

public void specialAttack(MovingObjectPosition var1, int type) {

	EntityLivingBase p = this.getThrower();

	if (p == null) {
		this.setDead();
		return;
	}


	switch (type) {
	case 4:
		pool = AxisAlignedBB.getAABBPool().getAABB(
				var1.hitVec.xCoord - getRadius(),
				var1.hitVec.yCoord - getRadius(),
				var1.hitVec.zCoord - getRadius(),
				var1.hitVec.xCoord + getRadius(),
				var1.hitVec.yCoord + getRadius(),
				var1.hitVec.zCoord + this.size);
		entl = this.worldObj.getEntitiesWithinAABB(EntityLivingBase.class, pool);
		if ((entl != null) && (entl.size() > 0))
			for (EntityLivingBase el : entl)
				if ((el != null) && (el != p))
					try {
						double xdir = el.posX - this.getThrower().posX;
						double zdir = el.posZ - this.getThrower().posZ;
						double motionX = xdir * 0.1F;
						double motionY = 5F;
						double motionZ = zdir * 0.1F;
						el.setVelocity(motionX, motionY, motionZ);
					} catch (Throwable ex) {
					}
		if (var1.typeOfHit == MovingObjectType.ENTITY) {
			if (!(var1.entityHit instanceof EntityLivingBase))
				break;
			EntityLivingBase el = (EntityLivingBase) var1.entityHit;
			if ((el != null) && (el != p))
				try {
					double xdir = el.posX - this.getThrower().posX;
					double zdir = el.posZ - this.getThrower().posZ;
					motionX = xdir * 0.1F;
					motionY = 0.1F;
					motionZ = zdir * 0.1F;
					el.setVelocity(motionX, motionY, motionZ);
				} catch (Throwable ex) {
				}
		}

		if (p != null && p instanceof EntityPlayer){


			if ((p.getDistanceToEntity(this) < 3) && ((p.rotationPitch > 70) && (p.rotationPitch < 110))) {
				double ydir = p.posY - this.posY;
				Vec3 dir = p.getLookVec();
				dir.yCoord = 0;
				dir.normalize();
				((EntityPlayer)p).addVelocity(0, 100, 0);
				FMLLog.info("Current motion:" + p.motionX + " " + p.motionY + " " + p.motionZ);
			}
			}
		break;
	case 5:
		specialAttack(var1, 4);

		break;
	default:
		break;
	}
	this.setDead();
}[
/code]
So if anyone know's why changing motion dosen't affect player, please do tell me.

~I was here~

  • Author

I don't suppose anyone has any idea or solution to this uncommon issue?  :-\

~I was here~

  • Author

Thanks for the reply, appreciate it, but only for mobs I used setVelocity.

Which when I replaced with addVelocity (which isn't clientSideOnly)

Worked better than before, I could see why now.

But it still didn't resolve the issue for the player, it used addVelocity in first place.

I will now try writing packet manager to send a packet to server about this stuff.

And see if that resolves anything at all.

~I was here~

You're on the right track - it works for most entities because it is handled on the server, but for players, their motion is actually handled on the client. You need to send a packet telling the player client about its new motion for it to work.

 

After making sure the entity hit is a player and you are on the server, you can use this vanilla packet:

((EntityPlayerMP) mop.entityHit).playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(mop.entityHit));

 

Just be sure you set the player's new motion values first :P

  • Author

And that did the trick, thank you a lot man, I was fighting this problem for 2 days now.

Finally I can enjoy the results :D

Now it's just tweaking it to work properly but that's simple stuff.

/thread

~I was here~

Guest
This topic is now closed to further replies.

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.