Jump to content

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


ZetaHunter

Recommended Posts

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~

Link to comment
Share on other sites

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~

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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