Carpet

Carpet

2M Downloads

Fake Players take no knockback

poombus opened this issue ยท 3 comments

commented

Intentional? If so, could you consider adding the option to enable it?

commented

Knockback is client-side IIRC. Therefore the server is expecting the fake players to make their own knock back, that won't because they are server-side.

Therefore, the knockback would need to be reimplemented (unless it's available in the server-side) (possible, just maybe not the most important thing)

commented

not the most important thing. I was aware of that, but knew that knockback is a client thing, that's why everyone is so laggy in uhcs. Likely noones gonna work towards it. Feel free to close it.

commented

Knockback is not a client-side only thing.

The reason why fake player doesnt take knockback from player is that there's a ServerPlayerEntity type check when a player dealt damage and knockback to the target

// in net.minecraft.entity.player.PlayerEntity#attack
if (target instanceof ServerPlayerEntity && target.velocityModified) {
   ((ServerPlayerEntity)target).networkHandler.sendPacket(new EntityVelocityUpdateS2CPacket(target));
   target.velocityModified = false;
   target.setVelocity(vec3d);  // reset the target's velocity
}

Since fake player (EntityPlayerMPFake) is also a ServerPlayerEntity, it will go into the if statement and reset the velocity of the fake player, that's what we don't want to see

It's not hard to be fixed. It can be fixed by a redirect mixin for example:

@Mixin(PlayerEntity.class)
public abstract class PlayerEntityMixin
{
	@Redirect(
			method = "attack",
			at = @At(
					value = "FIELD",
					target = "Lnet/minecraft/entity/Entity;velocityModified:Z",
					ordinal = 0
			)
	)
	private boolean velocityModifiedAndNotCarpetFakePlayer(Entity target)
	{
		return target.velocityModified && !(target instanceof EntityPlayerMPFake);
	}
}