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 (packet.GetRelativeArguments() & 0x01)
120 player->position.x =
player->position.x + packet.GetX();
124 player->position.x = packet.GetX();
127 if (packet.GetRelativeArguments() & 0x02)
129 player->position.y =
player->position.y + packet.GetY();
133 player->position.y = packet.GetY();
136 if (packet.GetRelativeArguments() & 0x04)
138 player->position.z =
player->position.z + packet.GetZ();
142 player->position.z = packet.GetZ();
145 player->yaw = packet.GetRelativeArguments() & 0x08 ?
player->yaw + packet.GetYRot() : packet.GetYRot();
146 player->pitch = packet.GetRelativeArguments() & 0x10 ?
player->pitch + packet.GetXRot() : packet.GetXRot();
152 for (
int i = 0; i < 3; ++i)
154 player->position[i] = packet.GetRelatives() & (1 << i) ?
player->position[i] + packet.GetChange().GetPosition()[i] : packet.GetChange().GetPosition()[i];
156 const float new_yaw = packet.GetRelatives() & (1 << 3) ?
player->yaw + packet.GetChange().GetYRot() : packet.GetChange().GetYRot();
157 const float new_pitch = packet.GetRelatives() & (1 << 4) ?
player->pitch + packet.GetChange().GetXRot() : packet.GetChange().GetXRot();
159 if (packet.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] = packet.GetRelatives() & (1 << (5 + i)) ? speed[i] + packet.GetChange().GetDeltaMovement()[i] : packet.GetChange().GetDeltaMovement()[i];
182 for (
int i = 0; i < 3; ++i)
184 player->previous_position[i] = packet.GetRelatives() & (1 << i) ?
player->previous_position[i] + packet.GetChange().GetPosition()[i] : packet.GetChange().GetPosition()[i];
186 player->previous_yaw = packet.GetRelatives() & (1 << 3) ?
player->yaw + packet.GetChange().GetYRot() : packet.GetChange().GetYRot();
187 player->previous_pitch = packet.GetRelatives() & (1 << 4) ?
player->pitch + packet.GetChange().GetXRot() : packet.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_packet = std::make_shared<ServerboundMovePlayerPacketPosRot>();
254 updated_position_packet->SetX(
player->position.x);
255 updated_position_packet->SetY(
player->position.y);
256 updated_position_packet->SetZ(
player->position.z);
257 updated_position_packet->SetYRot(
player->yaw);
258 updated_position_packet->SetXRot(
player->pitch);
259 updated_position_packet->SetOnGround(
false);
260#if PROTOCOL_VERSION > 767
261 updated_position_packet->SetHorizontalCollision(
false);
264 std::shared_ptr<ServerboundAcceptTeleportationPacket> accept_tp_packet = std::make_shared<ServerboundAcceptTeleportationPacket>();
268#if PROTOCOL_VERSION < 768
279#if PROTOCOL_VERSION > 767
280 std::shared_ptr<ServerboundClientTickEndPacket> tick_end_packet = 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
941#if PROTOCOL_VERSION < 771
942 const bool shift_key_down =
player->inputs.sneak;
943 if (shift_key_down !=
player->previous_shift_key_down)
945 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
946 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShifKey));
947 player_command_packet->SetId_(
player->entity_id);
949 player->previous_shift_key_down = shift_key_down;
953 if (
player->last_sent_inputs.sneak !=
player->inputs.sneak ||
955 player->last_sent_inputs.sprint !=
player->inputs.sprint ||
956 player->last_sent_inputs.forward_axis !=
player->inputs.forward_axis ||
957 player->last_sent_inputs.left_axis !=
player->inputs.left_axis)
959 std::shared_ptr<ServerboundPlayerInputPacket> player_input_packet = std::make_shared<ServerboundPlayerInputPacket>();
960 player_input_packet->SetForward(
player->inputs.forward_axis > 0.0f);
961 player_input_packet->SetBackward(
player->inputs.forward_axis < 0.0f);
962 player_input_packet->SetLeft(
player->inputs.left_axis > 0.0f);
963 player_input_packet->SetRight(
player->inputs.left_axis < 0.0f);
964 player_input_packet->SetJump(
player->inputs.jump);
965 player_input_packet->SetShift(
player->inputs.sneak);
966 player_input_packet->SetSprint(
player->inputs.sprint);
973 if (sprinting !=
player->previous_sprinting)
975 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
977 player_command_packet->SetId_(
player->entity_id);
979 player->previous_sprinting = sprinting;
982#if PROTOCOL_VERSION < 768
984 const bool shift_key_down =
player->inputs.sneak;
985 if (shift_key_down !=
player->previous_shift_key_down)
987 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
988 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShifKey));
989 player_command_packet->SetId_(
player->entity_id);
991 player->previous_shift_key_down = shift_key_down;
997 if (has_moved && has_rotated)
999 std::shared_ptr<ServerboundMovePlayerPacketPosRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPosRot>();
1000 move_player_packet->SetX(
player->position.x);
1001 move_player_packet->SetY(
player->position.y);
1002 move_player_packet->SetZ(
player->position.z);
1003 move_player_packet->SetXRot(
player->pitch);
1004 move_player_packet->SetYRot(
player->yaw);
1005 move_player_packet->SetOnGround(
player->on_ground);
1006#if PROTOCOL_VERSION > 767
1007 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1013 std::shared_ptr<ServerboundMovePlayerPacketPos> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPos>();
1014 move_player_packet->SetX(
player->position.x);
1015 move_player_packet->SetY(
player->position.y);
1016 move_player_packet->SetZ(
player->position.z);
1017 move_player_packet->SetOnGround(
player->on_ground);
1018#if PROTOCOL_VERSION > 767
1019 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1023 else if (has_rotated)
1025 std::shared_ptr<ServerboundMovePlayerPacketRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketRot>();
1026 move_player_packet->SetXRot(
player->pitch);
1027 move_player_packet->SetYRot(
player->yaw);
1028 move_player_packet->SetOnGround(
player->on_ground);
1029#if PROTOCOL_VERSION > 767
1030 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1034 else if (
player->on_ground !=
player->previous_on_ground
1035#
if PROTOCOL_VERSION > 767
1036 ||
player->horizontal_collision !=
player->previous_horizontal_collision
1040#if PROTOCOL_VERSION > 754
1041 std::shared_ptr<ServerboundMovePlayerPacketStatusOnly> move_player_packet = std::make_shared<ServerboundMovePlayerPacketStatusOnly>();
1043 std::shared_ptr<ServerboundMovePlayerPacket> move_player_packet = std::make_shared<ServerboundMovePlayerPacket>();
1045 move_player_packet->SetOnGround(
player->on_ground);
1046#if PROTOCOL_VERSION > 767
1047 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1063#if PROTOCOL_VERSION > 767
1064 player->previous_horizontal_collision =
player->horizontal_collision;
1083 const std::vector<AABB> colliders =
world->GetColliders(aabb, movement);
1085 if (colliders.size() == 0)
1092 AABB moved_aabb = aabb;
1097 if (std::abs(collided_movement.
x) > std::abs(collided_movement.
z))
1109 return collided_movement;
1116 const int this_axis = axis % 3;
1117 const int axis_1 = (axis + 1) % 3;
1118 const int axis_2 = (axis + 2) % 3;
1120 for (
const AABB& collider : colliders)
1122 if (std::abs(movement[this_axis]) < 1.0e-7)
1124 movement[this_axis] = 0.0;
1129 if (max_aabb[axis_1] - 1e-7 > min_collider[axis_1] && min_aabb[axis_1] + 1e-7 < max_collider[axis_1] &&
1130 max_aabb[axis_2] - 1e-7 > min_collider[axis_2] && min_aabb[axis_2] + 1e-7 < max_collider[axis_2])
1132 if (movement[this_axis] > 0.0 && max_aabb[this_axis] - 1e-7 <= min_collider[this_axis])
1134 movement[this_axis] = std::min(min_collider[this_axis] - max_aabb[this_axis], movement[this_axis]);
1136 else if (movement[this_axis] < 0.0 && min_aabb[this_axis] + 1e-7 >= max_collider[this_axis])
1138 movement[this_axis] = std::max(max_collider[this_axis] - min_aabb[this_axis], movement[this_axis]);
1143 translation[this_axis] = movement[this_axis];
1174 const bool going_down =
player->speed.y <= 0.0;
1175 bool has_slow_falling =
false;
1176#if PROTOCOL_VERSION > 340
1177 for (
const auto& effect :
player->effects)
1181 has_slow_falling =
true;
1187#if PROTOCOL_VERSION < 766
1188 const double drag = (going_down && has_slow_falling) ? 0.01 : 0.08;
1190 const double drag = (going_down && has_slow_falling) ? std::min(0.01,
player->GetAttributeGravityValueImpl()) :
player->GetAttributeGravityValueImpl();
1196 const double init_y =
player->position.y;
1198 float inputs_strength = 0.02f;
1200#if PROTOCOL_VERSION < 767
1204 float depth_strider_mult =
static_cast<float>(
player->GetAttributeWaterMovementEfficiencyValueImpl());
1208 depth_strider_mult *= 0.5f;
1210 if (depth_strider_mult > 0.0)
1212 water_slow_down += (0.54600006f - water_slow_down) * depth_strider_mult;
1213 inputs_strength += (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) - inputs_strength) * depth_strider_mult;
1216#if PROTOCOL_VERSION > 340
1217 for (
const auto& effect :
player->effects)
1221 water_slow_down = 0.96f;
1229 if (
player->horizontal_collision &&
player->on_climbable)
1233 player->speed.x *= water_slow_down;
1234 player->speed.y *= 0.800000011920929;
1235 player->speed.z *= water_slow_down;
1240 std::abs(
player->speed.y - 0.005) >= 0.003 &&
1241 std::abs(
player->speed.y - drag / 16.0) < 0.003)
1243 player->speed.y = -0.003;
1247 player->speed.y -= drag / 16.0;
1252 if (
player->horizontal_collision &&
1255 player->speed.y = 0.30000001192092896;
1261 const double init_y =
player->position.y;
1265 player->speed.y -= drag / 4.0;
1267 if (
player->horizontal_collision &&
1270 player->speed.y = 0.30000001192092896;
1278 const double cos_pitch_from_length = std::sqrt(
player->front_vector.x *
player->front_vector.x +
player->front_vector.z *
player->front_vector.z);
1279 const double cos_pitch = std::cos(
static_cast<double>(
player->pitch * 0.017453292f ));
1280 const double cos_pitch_sqr = cos_pitch * cos_pitch;
1283 player->speed.y += drag * (-1.0 + 0.75 * cos_pitch_sqr);
1285 if (
player->speed.y < 0.0 && cos_pitch_from_length > 0.0)
1287 const double delta_speed = -
player->speed.y * 0.1 * cos_pitch_sqr;
1288 player->speed.x +=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1289 player->speed.y += delta_speed;
1290 player->speed.z +=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1292 if (
player->pitch < 0.0 && cos_pitch_from_length > 0.0)
1295 const double delta_speed = horizontal_speed *
player->front_vector.y * 0.04;
1296 player->speed.x -=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1297 player->speed.y += delta_speed * 3.2;
1298 player->speed.z -=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1300 if (cos_pitch_from_length > 0.0)
1302 player->speed.x += (
player->front_vector.x / cos_pitch_from_length * horizontal_speed -
player->speed.x) * 0.1;
1303 player->speed.z += (
player->front_vector.z / cos_pitch_from_length * horizontal_speed -
player->speed.z) * 0.1;
1318 const float friction = below_block ==
nullptr ? 0.6f : below_block->
GetFriction();
1319 const float inertia =
player->on_ground ? friction * 0.91f : 0.91f;
1322 (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) * (0.21600002f / (friction * friction * friction))) :
1323#if PROTOCOL_VERSION < 762
1329 if (
player->on_climbable)
1331 player->speed.x = std::clamp(
player->speed.x, -0.15000000596046448, 0.15000000596046448);
1332 player->speed.y = std::max(
player->speed.y, -0.15000000596046448);
1336 static_cast<int>(std::floor(
player->position.x)),
1337 static_cast<int>(std::floor(
player->position.y)),
1338 static_cast<int>(std::floor(
player->position.z))
1344 player->speed.z = std::clamp(
player->speed.z, -0.15000000596046448, 0.15000000596046448);
1348 if ((
player->horizontal_collision ||
player->inputs.jump) &&
1355 unsigned char levitation = 0;
1356 for (
const auto& effect :
player->effects)
1360 levitation = effect.amplifier + 1;
1366 player->speed.y += (0.05 * levitation -
player->speed.y) * 0.2;
1372 player->speed.x *= inertia;
1373 player->speed.y *= 0.9800000190734863;
1374 player->speed.z *= inertia;
1389 if (
player->stuck_speed_multiplier.SqrNorm() > 1e-7)
1391 movement *=
player->stuck_speed_multiplier;
1392 player->stuck_speed_multiplier *= 0.0;
1396#if PROTOCOL_VERSION < 766
1397 constexpr double max_up_step = 0.6;
1399 const double max_up_step =
player->GetAttributeStepHeightValueImpl();
1401 const AABB player_aabb =
player->GetColliderImpl();
1403 && movement.
y <= 0.0
1408 const double step = 0.05;
1410 while (movement.
x != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(movement.
x, -max_up_step, 0.0)).Inflate(-1e-7),
false))
1412 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1415 while (movement.
z != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(0.0, -max_up_step, movement.
z)).Inflate(-1e-7),
false))
1417 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1420 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))
1422 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1423 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1429 if (movement.
SqrNorm() != 0.0)
1437 if ((
player->on_ground || (movement.
y != movement_before_collisions.
y && movement_before_collisions.
y < 0.0)) &&
1438 (movement.
x != movement_before_collisions.
x || movement.
z != movement_before_collisions.
z))
1442 movement_before_collisions.
x,
1444 movement_before_collisions.
z
1447 if (movement_step_up_only.
y < max_up_step)
1450 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)
1452 movement_with_step_up = check;
1455 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)
1457 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));
1462 if (movement.
SqrNorm() > 1.0e-7)
1464 player->position += movement;
1466 const bool collision_x = movement_before_collisions.
x != movement.
x;
1467 const bool collision_y = movement_before_collisions.
y != movement.
y;
1468 const bool collision_z = movement_before_collisions.
z != movement.
z;
1469 player->horizontal_collision = collision_x || collision_z;
1472 player->on_ground = movement_before_collisions.
y < 0.0 && collision_y;
1476 const double half_width = 0.5 *
player->GetWidthImpl();
1477 const AABB feet_slice_aabb(
1480 player->position.y - 0.5e-6,
1483 std::optional<Position> supporting_block_pos =
world->GetSupportingBlockPos(feet_slice_aabb);
1484 if (supporting_block_pos.has_value() ||
player->on_ground_without_supporting_block)
1486 player->supporting_block_pos = supporting_block_pos;
1492 player->on_ground_without_supporting_block = !
player->supporting_block_pos.has_value();
1496 player->on_ground_without_supporting_block =
false;
1497 player->supporting_block_pos = std::optional<Position>();
1512 if (
player->inputs.sneak)
1519 static_cast<int>(std::floor(
player->position.x)),
1520 static_cast<int>(std::floor(
player->position.y - 0.2)),
1521 static_cast<int>(std::floor(
player->position.z))
1523 double new_speed = 0.0;
1524 if (block_below !=
nullptr)
1528 new_speed = -
player->speed.y;
1530 else if (block_below->
IsBed())
1532 new_speed =
player->speed.y * -0.66f;
1535 player->speed.y = new_speed;
1541#if PROTOCOL_VERSION > 578 && PROTOCOL_VERSION < 767
1542 short soul_speed_lvl = 0;
1547 constexpr short soul_speed_lvl = 0;
1549 float block_speed_factor = 1.0f;
1551 static_cast<int>(std::floor(
player->position.x)),
1552 static_cast<int>(std::floor(
player->position.y)),
1553 static_cast<int>(std::floor(
player->position.z))
1555 if (feet_block !=
nullptr && (feet_block->
IsHoney() || (feet_block->
IsSoulSand() && soul_speed_lvl == 0)))
1557 block_speed_factor = 0.4f;
1559 if (block_speed_factor == 1.0f)
1562 if (below_block !=
nullptr && (below_block->
IsHoney() || (below_block->
IsSoulSand() && soul_speed_lvl == 0)))
1564 block_speed_factor = 0.4f;
1568#if PROTOCOL_VERSION > 766
1569 block_speed_factor = block_speed_factor +
static_cast<float>(
player->GetAttributeMovementEfficiencyValueImpl()) * (1.0f - block_speed_factor);
1572 player->speed.x *= block_speed_factor;
1573 player->speed.z *= block_speed_factor;
1594 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
1597 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
1600 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
1604 if (block ==
nullptr)
1615 if (above_block ==
nullptr || above_block->
IsAir())
1627 if (!
player->on_ground &&
1628 player->position.y <= y + 0.9375 - 1.0e-7 &&
1629 player->speed.y < -0.08 && (
1630 std::abs(x + 0.5 -
player->position.x) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0 ||
1631 std::abs(z + 0.5 -
player->position.z) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0)
1634 if (
player->speed.y < -0.13)
1636 const double factor = -0.05 /
player->speed.y;
1637 player->speed.x *= factor;
1639 player->speed.z *= factor;
1654 static_cast<int>(std::floor(
player->position.x)),
1655 static_cast<int>(std::floor(
player->position.y)),
1656 static_cast<int>(std::floor(
player->position.z))
1658 if (feet_block !=
nullptr && feet_block->
IsPowderSnow())