112 LOG_WARNING(
"Received a PlayerPosition packet without a player");
116 std::scoped_lock<std::shared_mutex> lock(
player->entity_mutex);
117#if PROTOCOL_VERSION < 768
118 if (msg.GetRelativeArguments() & 0x01)
124 player->position.x = msg.GetX();
127 if (msg.GetRelativeArguments() & 0x02)
133 player->position.y = msg.GetY();
136 if (msg.GetRelativeArguments() & 0x04)
142 player->position.z = msg.GetZ();
145 player->yaw = msg.GetRelativeArguments() & 0x08 ?
player->yaw + msg.GetYRot() : msg.GetYRot();
146 player->pitch = msg.GetRelativeArguments() & 0x10 ?
player->pitch + msg.GetXRot() : msg.GetXRot();
152 for (
int i = 0; i < 3; ++i)
154 player->position[i] = msg.GetRelatives() & (1 << i) ?
player->position[i] + msg.GetChange().GetPosition()[i] : msg.GetChange().GetPosition()[i];
156 const float new_yaw = msg.GetRelatives() & (1 << 3) ?
player->yaw + msg.GetChange().GetYRot() : msg.GetChange().GetYRot();
157 const float new_pitch = msg.GetRelatives() & (1 << 4) ?
player->pitch + msg.GetChange().GetXRot() : msg.GetChange().GetXRot();
159 if (msg.GetRelatives() & (1 << 8))
161 const float delta_yaw =
player->yaw - new_yaw;
162 const float delta_pitch =
player->pitch - new_pitch;
166 speed.
y *
static_cast<double>(std::cos(delta_pitch * 0.017453292f )) + speed.
z *
static_cast<double>(std::sin(delta_pitch * 0.017453292f )),
167 speed.
z *
static_cast<double>(std::cos(delta_pitch * 0.017453292f )) - speed.
y *
static_cast<double>(std::sin(delta_pitch * 0.017453292f ))
171 speed.
x *
static_cast<double>(std::cos(delta_yaw * 0.017453292f )) + speed.
z *
static_cast<double>(std::sin(delta_yaw * 0.017453292f )),
173 speed.
z *
static_cast<double>(std::cos(delta_yaw * 0.017453292f )) - speed.
x *
static_cast<double>(std::sin(delta_yaw * 0.017453292f ))
177 player->pitch = new_pitch;
178 for (
int i = 0; i < 3; ++i)
180 player->speed[i] = msg.GetRelatives() & (1 << (5 + i)) ? speed[i] + msg.GetChange().GetDeltaMovement()[i] : msg.GetChange().GetDeltaMovement()[i];
182 for (
int i = 0; i < 3; ++i)
184 player->previous_position[i] = msg.GetRelatives() & (1 << i) ?
player->previous_position[i] + msg.GetChange().GetPosition()[i] : msg.GetChange().GetPosition()[i];
186 player->previous_yaw = msg.GetRelatives() & (1 << 3) ?
player->yaw + msg.GetChange().GetYRot() : msg.GetChange().GetYRot();
187 player->previous_pitch = msg.GetRelatives() & (1 << 4) ?
player->pitch + msg.GetChange().GetXRot() : msg.GetChange().GetXRot();
237 auto end = std::chrono::steady_clock::now();
239 end += std::chrono::microseconds(
static_cast<long long int>(1000.0 *
ms_per_tick));
248 std::scoped_lock<std::shared_mutex> lock(
player->entity_mutex);
253 std::shared_ptr<ServerboundMovePlayerPacketPosRot> updated_position_msg = std::make_shared<ServerboundMovePlayerPacketPosRot>();
254 updated_position_msg->SetX(
player->position.x);
255 updated_position_msg->SetY(
player->position.y);
256 updated_position_msg->SetZ(
player->position.z);
257 updated_position_msg->SetYRot(
player->yaw);
258 updated_position_msg->SetXRot(
player->pitch);
259 updated_position_msg->SetOnGround(
false);
260#if PROTOCOL_VERSION > 767
261 updated_position_msg->SetHorizontalCollision(
false);
264 std::shared_ptr<ServerboundAcceptTeleportationPacket> accept_tp_msg = std::make_shared<ServerboundAcceptTeleportationPacket>();
268#if PROTOCOL_VERSION < 768
279#if PROTOCOL_VERSION > 767
280 std::shared_ptr<ServerboundClientTickEndPacket> tick_end_msg = std::make_shared<ServerboundClientTickEndPacket>();
301#if PROTOCOL_VERSION > 404
302 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget().value_or(0);
304 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget();
306 if (attached_id ==
player->entity_id)
320 static_cast<int>(std::floor(
player->position.x)),
321 static_cast<int>(std::floor(
player->position.y)),
322 static_cast<int>(std::floor(
player->position.z))
327 player->on_ground =
false;
338 player->sprint_double_tap_trigger_time = std::max(0,
player->sprint_double_tap_trigger_time - 1);
351 player->speed.y -= 0.03999999910593033;
361 player->fly_jump_trigger_time = std::max(0,
player->fly_jump_trigger_time - 1);
371 player->jump_delay = std::max(0,
player->jump_delay - 1);
373 if (std::abs(
player->speed.x) < 0.003)
377 if (std::abs(
player->speed.y) < 0.003)
381 if (std::abs(
player->speed.z) < 0.003)
388 player->inputs.forward_axis *= 0.98f;
389 player->inputs.left_axis *= 0.98f;
394 const double m_sin_pitch =
player->front_vector.y;
395 bool condition = m_sin_pitch <= 0.0 ||
player->inputs.jump;
399 static_cast<int>(std::floor(
player->position.x)),
400 static_cast<int>(std::floor(
player->position.y + 1.0 - 0.1)),
401 static_cast<int>(std::floor(
player->position.z))
403 condition = above_block !=
nullptr && above_block->
IsFluid();
407 player->speed.y += (m_sin_pitch -
player->speed.y) * (m_sin_pitch < -0.2 ? 0.085 : 0.06);
411 const double speed_y =
player->speed.y;
415 player->speed.y = 0.6 * speed_y;
435 player->position.x = std::clamp(
player->position.x, -2.9999999E7, 2.9999999E7);
436 player->position.z = std::clamp(
player->position.z, -2.9999999E7, 2.9999999E7);
438#if PROTOCOL_VERSION > 404
446 else if (
player->GetSleepingPosIdImpl())
454 else if (
player->GetDataLivingEntityFlagsImpl() & 0x04)
469 player->SetDataPoseImpl(current_pose);
526 player->under_water =
false;
535 const double eye_height =
player->position.
y +
player->GetEyeHeightImpl();
539 double fluid_relative_height = 0.0;
542 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
545 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
548 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
552 if (block ==
nullptr || !block->
IsFluid() ||
558 double fluid_height = 0.0;
560 ((block_above->IsLava() && block->
IsLava()) || (block_above->IsWater() && block->
IsWater())))
569 if (fluid_height + y < min_aabb.
y)
577 if (fluid_height + y >= eye_height)
579 player->under_water =
true;
587 fluid_relative_height = std::max(fluid_height - min_aabb.
y, fluid_relative_height);
595 if (fluid_relative_height < 0.4)
597 current_push *= fluid_relative_height;
599 push += current_push;
609 push /=
static_cast<double>(num_push);
617 push *=
world->IsInUltraWarmDimension() ? 0.007 : 0.0023333333333333335;
619 const double push_norm = std::sqrt(push.
SqrNorm());
620 if (std::abs(
player->speed.x) < 0.003 && std::abs(
player->speed.z) < 0.003 && push_norm < 0.0045000000000000005)
624 push *= 0.0045000000000000005;
688 const bool was_sneaking =
player->previous_sneak;
689 const bool had_enough_impulse_to_start_sprinting =
player->previous_forward >= (
player->under_water ? 1e-5f : 0.8f);
690 const bool has_enough_impulse_to_start_sprinting =
player->inputs.forward_axis >= (
player->under_water ? 1e-5f : 0.8f);
692#if PROTOCOL_VERSION > 404
695 const bool is_moving_slowly =
player->crouching;
700 player->sprint_double_tap_trigger_time = 0;
703 bool has_blindness =
false;
704 for (
const auto& effect :
player->effects)
708 has_blindness =
true;
713 const bool can_start_sprinting = !(
715 !has_enough_impulse_to_start_sprinting ||
719 (is_moving_slowly && !
player->under_water)
722 if ((
player->on_ground ||
player->under_water) && !was_sneaking && !had_enough_impulse_to_start_sprinting && can_start_sprinting)
724 if (
player->sprint_double_tap_trigger_time > 0 ||
player->inputs.sprint)
734 if ((!
player->in_water ||
player->under_water) && can_start_sprinting &&
player->inputs.sprint)
742 const bool stop_sprint_condition =
player->inputs.forward_axis <= 1e-5 || (
player->food <= 6 && !
player->may_fly);
745 if ((!
player->on_ground && !
player->inputs.sneak && stop_sprint_condition) || !
player->in_water)
750 else if (stop_sprint_condition ||
751 player->horizontal_collision ||
847 player->speed.y += 0.03999999910593033;
853 float jump_boost = 0.0f;
854 for (
const auto& effect :
player->effects)
858 jump_boost = 0.1f * (effect.amplifier + 1);
864 float block_jump_factor = 1.0f;
866 static_cast<int>(std::floor(
player->position.x)),
867 static_cast<int>(std::floor(
player->position.y)),
868 static_cast<int>(std::floor(
player->position.z))
870 if (feet_block ==
nullptr || !feet_block->
IsHoney())
873 if (below_block !=
nullptr && below_block->
IsHoney())
875 block_jump_factor = 0.4f;
880 block_jump_factor = 0.4f;
883#if PROTOCOL_VERSION < 766
884 player->speed.y = 0.42f * block_jump_factor + jump_boost;
887 const float yaw_rad =
player->yaw * 0.017453292f ;
888 player->speed.x -= std::sin(yaw_rad) * 0.2f;
889 player->speed.z += std::cos(yaw_rad) * 0.2f;
892 const float jump_power =
static_cast<float>(
player->GetAttributeJumpStrengthValueImpl()) * block_jump_factor + jump_boost;
893 if (jump_power > 1e-5f)
895 player->speed.y = jump_power;
898 const float yaw_rad =
player->yaw * 0.017453292f ;
899 player->speed.x -=
static_cast<double>(std::sin(yaw_rad)) * 0.2;
900 player->speed.z +=
static_cast<double>(std::cos(yaw_rad)) * 0.2;
938#if PROTOCOL_VERSION > 767
940 const bool shift_key_down =
player->inputs.sneak;
941 if (shift_key_down !=
player->previous_shift_key_down)
943 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_msg = std::make_shared<ServerboundPlayerCommandPacket>();
945 player_command_msg->SetId_(
player->entity_id);
947 player->previous_shift_key_down = shift_key_down;
950 if (
player->last_sent_inputs.sneak !=
player->inputs.sneak ||
952 player->last_sent_inputs.sprint !=
player->inputs.sprint ||
953 player->last_sent_inputs.forward_axis !=
player->inputs.forward_axis ||
954 player->last_sent_inputs.left_axis !=
player->inputs.left_axis)
956 std::shared_ptr<ServerboundPlayerInputPacket> player_input_msg = std::make_shared<ServerboundPlayerInputPacket>();
957 player_input_msg->SetForward(
player->inputs.forward_axis > 0.0f);
958 player_input_msg->SetBackward(
player->inputs.forward_axis < 0.0f);
959 player_input_msg->SetLeft(
player->inputs.left_axis > 0.0f);
960 player_input_msg->SetRight(
player->inputs.left_axis < 0.0f);
961 player_input_msg->SetJump(
player->inputs.jump);
962 player_input_msg->SetShift(
player->inputs.sneak);
963 player_input_msg->SetSprint(
player->inputs.sprint);
970 if (sprinting !=
player->previous_sprinting)
972 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_msg = std::make_shared<ServerboundPlayerCommandPacket>();
974 player_command_msg->SetId_(
player->entity_id);
976 player->previous_sprinting = sprinting;
979#if PROTOCOL_VERSION < 768
981 const bool shift_key_down =
player->inputs.sneak;
982 if (shift_key_down !=
player->previous_shift_key_down)
984 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_msg = std::make_shared<ServerboundPlayerCommandPacket>();
986 player_command_msg->SetId_(
player->entity_id);
988 player->previous_shift_key_down = shift_key_down;
994 if (has_moved && has_rotated)
996 std::shared_ptr<ServerboundMovePlayerPacketPosRot> move_player_msg = std::make_shared<ServerboundMovePlayerPacketPosRot>();
997 move_player_msg->SetX(
player->position.x);
998 move_player_msg->SetY(
player->position.y);
999 move_player_msg->SetZ(
player->position.z);
1000 move_player_msg->SetXRot(
player->pitch);
1001 move_player_msg->SetYRot(
player->yaw);
1002 move_player_msg->SetOnGround(
player->on_ground);
1003#if PROTOCOL_VERSION > 767
1004 move_player_msg->SetHorizontalCollision(
player->horizontal_collision);
1010 std::shared_ptr<ServerboundMovePlayerPacketPos> move_player_msg = std::make_shared<ServerboundMovePlayerPacketPos>();
1011 move_player_msg->SetX(
player->position.x);
1012 move_player_msg->SetY(
player->position.y);
1013 move_player_msg->SetZ(
player->position.z);
1014 move_player_msg->SetOnGround(
player->on_ground);
1015#if PROTOCOL_VERSION > 767
1016 move_player_msg->SetHorizontalCollision(
player->horizontal_collision);
1020 else if (has_rotated)
1022 std::shared_ptr<ServerboundMovePlayerPacketRot> move_player_msg = std::make_shared<ServerboundMovePlayerPacketRot>();
1023 move_player_msg->SetXRot(
player->pitch);
1024 move_player_msg->SetYRot(
player->yaw);
1025 move_player_msg->SetOnGround(
player->on_ground);
1026#if PROTOCOL_VERSION > 767
1027 move_player_msg->SetHorizontalCollision(
player->horizontal_collision);
1031 else if (
player->on_ground !=
player->previous_on_ground
1032#
if PROTOCOL_VERSION > 767
1033 ||
player->horizontal_collision !=
player->previous_horizontal_collision
1037#if PROTOCOL_VERSION > 754
1038 std::shared_ptr<ServerboundMovePlayerPacketStatusOnly> move_player_msg = std::make_shared<ServerboundMovePlayerPacketStatusOnly>();
1040 std::shared_ptr<ServerboundMovePlayerPacket> move_player_msg = std::make_shared<ServerboundMovePlayerPacket>();
1042 move_player_msg->SetOnGround(
player->on_ground);
1043#if PROTOCOL_VERSION > 767
1044 move_player_msg->SetHorizontalCollision(
player->horizontal_collision);
1060#if PROTOCOL_VERSION > 767
1061 player->previous_horizontal_collision =
player->horizontal_collision;
1080 const std::vector<AABB> colliders =
world->GetColliders(aabb, movement);
1082 if (colliders.size() == 0)
1089 AABB moved_aabb = aabb;
1094 if (std::abs(collided_movement.
x) > std::abs(collided_movement.
z))
1106 return collided_movement;
1113 const int this_axis = axis % 3;
1114 const int axis_1 = (axis + 1) % 3;
1115 const int axis_2 = (axis + 2) % 3;
1117 for (
const AABB& collider : colliders)
1119 if (std::abs(movement[this_axis]) < 1.0e-7)
1121 movement[this_axis] = 0.0;
1126 if (max_aabb[axis_1] - 1e-7 > min_collider[axis_1] && min_aabb[axis_1] + 1e-7 < max_collider[axis_1] &&
1127 max_aabb[axis_2] - 1e-7 > min_collider[axis_2] && min_aabb[axis_2] + 1e-7 < max_collider[axis_2])
1129 if (movement[this_axis] > 0.0 && max_aabb[this_axis] - 1e-7 <= min_collider[this_axis])
1131 movement[this_axis] = std::min(min_collider[this_axis] - max_aabb[this_axis], movement[this_axis]);
1133 else if (movement[this_axis] < 0.0 && min_aabb[this_axis] + 1e-7 >= max_collider[this_axis])
1135 movement[this_axis] = std::max(max_collider[this_axis] - min_aabb[this_axis], movement[this_axis]);
1140 translation[this_axis] = movement[this_axis];
1171 const bool going_down =
player->speed.y <= 0.0;
1172 bool has_slow_falling =
false;
1173#if PROTOCOL_VERSION > 340
1174 for (
const auto& effect :
player->effects)
1178 has_slow_falling =
true;
1184#if PROTOCOL_VERSION < 766
1185 const double drag = (going_down && has_slow_falling) ? 0.01 : 0.08;
1187 const double drag = (going_down && has_slow_falling) ? std::min(0.01,
player->GetAttributeGravityValueImpl()) :
player->GetAttributeGravityValueImpl();
1193 const double init_y =
player->position.y;
1195 float inputs_strength = 0.02f;
1197#if PROTOCOL_VERSION < 767
1201 float depth_strider_mult =
static_cast<float>(
player->GetAttributeWaterMovementEfficiencyValueImpl());
1205 depth_strider_mult *= 0.5f;
1207 if (depth_strider_mult > 0.0)
1209 water_slow_down += (0.54600006f - water_slow_down) * depth_strider_mult;
1210 inputs_strength += (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) - inputs_strength) * depth_strider_mult;
1213#if PROTOCOL_VERSION > 340
1214 for (
const auto& effect :
player->effects)
1218 water_slow_down = 0.96f;
1226 if (
player->horizontal_collision &&
player->on_climbable)
1230 player->speed.x *= water_slow_down;
1231 player->speed.y *= 0.800000011920929;
1232 player->speed.z *= water_slow_down;
1237 std::abs(
player->speed.y - 0.005) >= 0.003 &&
1238 std::abs(
player->speed.y - drag / 16.0) < 0.003)
1240 player->speed.y = -0.003;
1244 player->speed.y -= drag / 16.0;
1249 if (
player->horizontal_collision &&
1252 player->speed.y = 0.30000001192092896;
1258 const double init_y =
player->position.y;
1262 player->speed.y -= drag / 4.0;
1264 if (
player->horizontal_collision &&
1267 player->speed.y = 0.30000001192092896;
1275 const double cos_pitch_from_length = std::sqrt(
player->front_vector.x *
player->front_vector.x +
player->front_vector.z *
player->front_vector.z);
1276 const double cos_pitch = std::cos(
static_cast<double>(
player->pitch * 0.017453292f ));
1277 const double cos_pitch_sqr = cos_pitch * cos_pitch;
1280 player->speed.y += drag * (-1.0 + 0.75 * cos_pitch_sqr);
1282 if (
player->speed.y < 0.0 && cos_pitch_from_length > 0.0)
1284 const double delta_speed = -
player->speed.y * 0.1 * cos_pitch_sqr;
1285 player->speed.x +=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1286 player->speed.y += delta_speed;
1287 player->speed.z +=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1289 if (
player->pitch < 0.0 && cos_pitch_from_length > 0.0)
1292 const double delta_speed = horizontal_speed *
player->front_vector.y * 0.04;
1293 player->speed.x -=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1294 player->speed.y += delta_speed * 3.2;
1295 player->speed.z -=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1297 if (cos_pitch_from_length > 0.0)
1299 player->speed.x += (
player->front_vector.x / cos_pitch_from_length * horizontal_speed -
player->speed.x) * 0.1;
1300 player->speed.z += (
player->front_vector.z / cos_pitch_from_length * horizontal_speed -
player->speed.z) * 0.1;
1315 const float friction = below_block ==
nullptr ? 0.6f : below_block->
GetFriction();
1316 const float inertia =
player->on_ground ? friction * 0.91f : 0.91f;
1319 (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) * (0.21600002f / (friction * friction * friction))) :
1320#if PROTOCOL_VERSION < 762
1326 if (
player->on_climbable)
1328 player->speed.x = std::clamp(
player->speed.x, -0.15000000596046448, 0.15000000596046448);
1329 player->speed.y = std::max(
player->speed.y, -0.15000000596046448);
1333 static_cast<int>(std::floor(
player->position.x)),
1334 static_cast<int>(std::floor(
player->position.y)),
1335 static_cast<int>(std::floor(
player->position.z))
1341 player->speed.z = std::clamp(
player->speed.z, -0.15000000596046448, 0.15000000596046448);
1345 if ((
player->horizontal_collision ||
player->inputs.jump) &&
1352 unsigned char levitation = 0;
1353 for (
const auto& effect :
player->effects)
1357 levitation = effect.amplifier + 1;
1363 player->speed.y += (0.05 * levitation -
player->speed.y) * 0.2;
1369 player->speed.x *= inertia;
1370 player->speed.y *= 0.9800000190734863;
1371 player->speed.z *= inertia;
1386 if (
player->stuck_speed_multiplier.SqrNorm() > 1e-7)
1388 movement *=
player->stuck_speed_multiplier;
1389 player->stuck_speed_multiplier *= 0.0;
1393#if PROTOCOL_VERSION < 766
1394 constexpr double max_up_step = 0.6;
1396 const double max_up_step =
player->GetAttributeStepHeightValueImpl();
1398 const AABB player_aabb =
player->GetColliderImpl();
1400 && movement.
y <= 0.0
1405 const double step = 0.05;
1407 while (movement.
x != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(movement.
x, -max_up_step, 0.0)).Inflate(-1e-7),
false))
1409 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1412 while (movement.
z != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(0.0, -max_up_step, movement.
z)).Inflate(-1e-7),
false))
1414 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1417 while (movement.
x != 0.0 && movement.
z != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(movement.
x, -max_up_step, movement.
z)).Inflate(-1e-7),
false))
1419 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1420 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1426 if (movement.
SqrNorm() != 0.0)
1434 if ((
player->on_ground || (movement.
y != movement_before_collisions.
y && movement_before_collisions.
y < 0.0)) &&
1435 (movement.
x != movement_before_collisions.
x || movement.
z != movement_before_collisions.
z))
1439 movement_before_collisions.
x,
1441 movement_before_collisions.
z
1444 if (movement_step_up_only.
y < max_up_step)
1447 if (check.
x * check.
x + check.
z * check.
z > movement_with_step_up.
x * movement_with_step_up.
x + movement_with_step_up.
z * movement_with_step_up.
z)
1449 movement_with_step_up = check;
1452 if (movement_with_step_up.
x * movement_with_step_up.
x + movement_with_step_up.
z * movement_with_step_up.
z > movement.
x * movement.
x + movement.
z * movement.
z)
1454 movement = movement_with_step_up +
CollideBoundingBox(player_aabb + movement_with_step_up,
Vector3<double>(0.0, -movement_with_step_up.
y + movement_before_collisions.
y, 0.0));
1459 if (movement.
SqrNorm() > 1.0e-7)
1461 player->position += movement;
1463 const bool collision_x = movement_before_collisions.
x != movement.
x;
1464 const bool collision_y = movement_before_collisions.
y != movement.
y;
1465 const bool collision_z = movement_before_collisions.
z != movement.
z;
1466 player->horizontal_collision = collision_x || collision_z;
1469 player->on_ground = movement_before_collisions.
y < 0.0 && collision_y;
1473 const double half_width = 0.5 *
player->GetWidthImpl();
1474 const AABB feet_slice_aabb(
1477 player->position.y - 0.5e-6,
1480 std::optional<Position> supporting_block_pos =
world->GetSupportingBlockPos(feet_slice_aabb);
1481 if (supporting_block_pos.has_value() ||
player->on_ground_without_supporting_block)
1483 player->supporting_block_pos = supporting_block_pos;
1489 player->on_ground_without_supporting_block = !
player->supporting_block_pos.has_value();
1493 player->on_ground_without_supporting_block =
false;
1494 player->supporting_block_pos = std::optional<Position>();
1509 if (
player->inputs.sneak)
1516 static_cast<int>(std::floor(
player->position.x)),
1517 static_cast<int>(std::floor(
player->position.y - 0.2)),
1518 static_cast<int>(std::floor(
player->position.z))
1520 double new_speed = 0.0;
1521 if (block_below !=
nullptr)
1525 new_speed = -
player->speed.y;
1527 else if (block_below->
IsBed())
1529 new_speed =
player->speed.y * -0.66f;
1532 player->speed.y = new_speed;
1538#if PROTOCOL_VERSION > 578 && PROTOCOL_VERSION < 767
1539 short soul_speed_lvl = 0;
1544 constexpr short soul_speed_lvl = 0;
1546 float block_speed_factor = 1.0f;
1548 static_cast<int>(std::floor(
player->position.x)),
1549 static_cast<int>(std::floor(
player->position.y)),
1550 static_cast<int>(std::floor(
player->position.z))
1552 if (feet_block !=
nullptr && (feet_block->
IsHoney() || (feet_block->
IsSoulSand() && soul_speed_lvl == 0)))
1554 block_speed_factor = 0.4f;
1556 if (block_speed_factor == 1.0f)
1559 if (below_block !=
nullptr && (below_block->
IsHoney() || (below_block->
IsSoulSand() && soul_speed_lvl == 0)))
1561 block_speed_factor = 0.4f;
1565#if PROTOCOL_VERSION > 766
1566 block_speed_factor = block_speed_factor +
static_cast<float>(
player->GetAttributeMovementEfficiencyValueImpl()) * (1.0f - block_speed_factor);
1569 player->speed.x *= block_speed_factor;
1570 player->speed.z *= block_speed_factor;
1591 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
1594 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
1597 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
1601 if (block ==
nullptr)
1612 if (above_block ==
nullptr || above_block->
IsAir())
1624 if (!
player->on_ground &&
1625 player->position.y <= y + 0.9375 - 1.0e-7 &&
1626 player->speed.y < -0.08 && (
1627 std::abs(x + 0.5 -
player->position.x) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0 ||
1628 std::abs(z + 0.5 -
player->position.z) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0)
1631 if (
player->speed.y < -0.13)
1633 const double factor = -0.05 /
player->speed.y;
1634 player->speed.x *= factor;
1636 player->speed.z *= factor;
1651 static_cast<int>(std::floor(
player->position.x)),
1652 static_cast<int>(std::floor(
player->position.y)),
1653 static_cast<int>(std::floor(
player->position.z))
1655 if (feet_block !=
nullptr && feet_block->
IsPowderSnow())