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();
242 auto end = std::chrono::steady_clock::now();
244 end += std::chrono::microseconds(
static_cast<long long int>(1000.0 *
ms_per_tick));
253 std::scoped_lock<std::shared_mutex> lock(
player->entity_mutex);
258 std::shared_ptr<ServerboundMovePlayerPacketPosRot> updated_position_packet = std::make_shared<ServerboundMovePlayerPacketPosRot>();
259 updated_position_packet->SetX(
player->position.x);
260 updated_position_packet->SetY(
player->position.y);
261 updated_position_packet->SetZ(
player->position.z);
262 updated_position_packet->SetYRot(
player->yaw);
263 updated_position_packet->SetXRot(
player->pitch);
264 updated_position_packet->SetOnGround(
false);
265#if PROTOCOL_VERSION > 767
266 updated_position_packet->SetHorizontalCollision(
false);
269 std::shared_ptr<ServerboundAcceptTeleportationPacket> accept_tp_packet = std::make_shared<ServerboundAcceptTeleportationPacket>();
273#if PROTOCOL_VERSION < 768
284#if PROTOCOL_VERSION > 767
285 std::shared_ptr<ServerboundClientTickEndPacket> tick_end_packet = std::make_shared<ServerboundClientTickEndPacket>();
303 static_cast<int>(std::floor(
player->position.x)),
304 static_cast<int>(std::floor(
player->position.y)),
305 static_cast<int>(std::floor(
player->position.z))
310 player->on_ground =
false;
321 player->sprint_double_tap_trigger_time = std::max(0,
player->sprint_double_tap_trigger_time - 1);
334 player->speed.y -= 0.03999999910593033;
344 player->fly_jump_trigger_time = std::max(0,
player->fly_jump_trigger_time - 1);
354 player->jump_delay = std::max(0,
player->jump_delay - 1);
356 if (std::abs(
player->speed.x) < 0.003)
360 if (std::abs(
player->speed.y) < 0.003)
364 if (std::abs(
player->speed.z) < 0.003)
371 player->inputs.forward_axis *= 0.98f;
372 player->inputs.left_axis *= 0.98f;
377 const double m_sin_pitch =
player->front_vector.y;
378 bool condition = m_sin_pitch <= 0.0 ||
player->inputs.jump;
382 static_cast<int>(std::floor(
player->position.x)),
383 static_cast<int>(std::floor(
player->position.y + 1.0 - 0.1)),
384 static_cast<int>(std::floor(
player->position.z))
386 condition = above_block !=
nullptr && above_block->
IsFluid();
390 player->speed.y += (m_sin_pitch -
player->speed.y) * (m_sin_pitch < -0.2 ? 0.085 : 0.06);
394 const double speed_y =
player->speed.y;
398 player->speed.y = 0.6 * speed_y;
418 player->position.x = std::clamp(
player->position.x, -2.9999999E7, 2.9999999E7);
419 player->position.z = std::clamp(
player->position.z, -2.9999999E7, 2.9999999E7);
421#if PROTOCOL_VERSION > 404
429 else if (
player->GetSleepingPosIdImpl())
437 else if (
player->GetDataLivingEntityFlagsImpl() & 0x04)
452 player->SetDataPoseImpl(current_pose);
481#if PROTOCOL_VERSION > 404
482 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget().value_or(0);
484 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget();
486 if (attached_id ==
player->entity_id)
533 player->under_water =
false;
542 const double eye_height =
player->position.
y +
player->GetEyeHeightImpl();
546 double fluid_relative_height = 0.0;
549 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
552 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
555 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
559 if (block ==
nullptr || !block->
IsFluid() ||
565 double fluid_height = 0.0;
567 ((block_above->IsLava() && block->
IsLava()) || (block_above->IsWater() && block->
IsWater())))
576 if (fluid_height + y < min_aabb.
y)
584 if (fluid_height + y >= eye_height)
586 player->under_water =
true;
594 fluid_relative_height = std::max(fluid_height - min_aabb.
y, fluid_relative_height);
602 if (fluid_relative_height < 0.4)
604 current_push *= fluid_relative_height;
606 push += current_push;
616 push /=
static_cast<double>(num_push);
624 push *=
world->IsInUltraWarmDimension() ? 0.007 : 0.0023333333333333335;
626 const double push_norm = std::sqrt(push.
SqrNorm());
627 if (std::abs(
player->speed.x) < 0.003 && std::abs(
player->speed.z) < 0.003 && push_norm < 0.0045000000000000005)
631 push *= 0.0045000000000000005;
695 const bool was_sneaking =
player->previous_sneak;
696 const bool had_enough_impulse_to_start_sprinting =
player->previous_forward >= (
player->under_water ? 1e-5f : 0.8f);
697 const bool has_enough_impulse_to_start_sprinting =
player->inputs.forward_axis >= (
player->under_water ? 1e-5f : 0.8f);
699#if PROTOCOL_VERSION > 404
702 const bool is_moving_slowly =
player->crouching;
707 player->sprint_double_tap_trigger_time = 0;
710 bool has_blindness =
false;
711 for (
const auto& effect :
player->effects)
715 has_blindness =
true;
720 const bool can_start_sprinting = !(
722 !has_enough_impulse_to_start_sprinting ||
726 (is_moving_slowly && !
player->under_water)
729 if ((
player->on_ground ||
player->under_water) && !was_sneaking && !had_enough_impulse_to_start_sprinting && can_start_sprinting)
731 if (
player->sprint_double_tap_trigger_time > 0 ||
player->inputs.sprint)
741 if ((!
player->in_water ||
player->under_water) && can_start_sprinting &&
player->inputs.sprint)
749 const bool stop_sprint_condition =
player->inputs.forward_axis <= 1e-5 || (
player->food <= 6 && !
player->may_fly);
752 if ((!
player->on_ground && !
player->inputs.sneak && stop_sprint_condition) || !
player->in_water)
757 else if (stop_sprint_condition ||
758 player->horizontal_collision ||
854 player->speed.y += 0.03999999910593033;
860 float jump_boost = 0.0f;
861 for (
const auto& effect :
player->effects)
865 jump_boost = 0.1f * (effect.amplifier + 1);
871 float block_jump_factor = 1.0f;
873 static_cast<int>(std::floor(
player->position.x)),
874 static_cast<int>(std::floor(
player->position.y)),
875 static_cast<int>(std::floor(
player->position.z))
877 if (feet_block ==
nullptr || !feet_block->
IsHoney())
880 if (below_block !=
nullptr && below_block->
IsHoney())
882 block_jump_factor = 0.4f;
887 block_jump_factor = 0.4f;
890#if PROTOCOL_VERSION < 766
891 player->speed.y = 0.42f * block_jump_factor + jump_boost;
894 const float yaw_rad =
player->yaw * 0.017453292f ;
895 player->speed.x -= std::sin(yaw_rad) * 0.2f;
896 player->speed.z += std::cos(yaw_rad) * 0.2f;
899 const float jump_power =
static_cast<float>(
player->GetAttributeJumpStrengthValueImpl()) * block_jump_factor + jump_boost;
900 if (jump_power > 1e-5f)
902 player->speed.y = jump_power;
905 const float yaw_rad =
player->yaw * 0.017453292f ;
906 player->speed.x -=
static_cast<double>(std::sin(yaw_rad)) * 0.2;
907 player->speed.z +=
static_cast<double>(std::cos(yaw_rad)) * 0.2;
945#if PROTOCOL_VERSION > 767
948#if PROTOCOL_VERSION < 771
949 const bool shift_key_down =
player->inputs.sneak;
950 if (shift_key_down !=
player->previous_shift_key_down)
952 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
953 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShiftKey));
954 player_command_packet->SetId_(
player->entity_id);
956 player->previous_shift_key_down = shift_key_down;
960 if (
player->last_sent_inputs.sneak !=
player->inputs.sneak ||
962 player->last_sent_inputs.sprint !=
player->inputs.sprint ||
963 player->last_sent_inputs.forward_axis !=
player->inputs.forward_axis ||
964 player->last_sent_inputs.left_axis !=
player->inputs.left_axis)
966 std::shared_ptr<ServerboundPlayerInputPacket> player_input_packet = std::make_shared<ServerboundPlayerInputPacket>();
967 player_input_packet->SetForward(
player->inputs.forward_axis > 0.0f);
968 player_input_packet->SetBackward(
player->inputs.forward_axis < 0.0f);
969 player_input_packet->SetLeft(
player->inputs.left_axis > 0.0f);
970 player_input_packet->SetRight(
player->inputs.left_axis < 0.0f);
971 player_input_packet->SetJump(
player->inputs.jump);
972 player_input_packet->SetShift(
player->inputs.sneak);
973 player_input_packet->SetSprint(
player->inputs.sprint);
980 if (sprinting !=
player->previous_sprinting)
982 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
984 player_command_packet->SetId_(
player->entity_id);
986 player->previous_sprinting = sprinting;
989#if PROTOCOL_VERSION < 768
991 const bool shift_key_down =
player->inputs.sneak;
992 if (shift_key_down !=
player->previous_shift_key_down)
994 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
995 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShiftKey));
996 player_command_packet->SetId_(
player->entity_id);
998 player->previous_shift_key_down = shift_key_down;
1004 if (has_moved && has_rotated)
1006 std::shared_ptr<ServerboundMovePlayerPacketPosRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPosRot>();
1007 move_player_packet->SetX(
player->position.x);
1008 move_player_packet->SetY(
player->position.y);
1009 move_player_packet->SetZ(
player->position.z);
1010 move_player_packet->SetXRot(
player->pitch);
1011 move_player_packet->SetYRot(
player->yaw);
1012 move_player_packet->SetOnGround(
player->on_ground);
1013#if PROTOCOL_VERSION > 767
1014 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1020 std::shared_ptr<ServerboundMovePlayerPacketPos> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPos>();
1021 move_player_packet->SetX(
player->position.x);
1022 move_player_packet->SetY(
player->position.y);
1023 move_player_packet->SetZ(
player->position.z);
1024 move_player_packet->SetOnGround(
player->on_ground);
1025#if PROTOCOL_VERSION > 767
1026 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1030 else if (has_rotated)
1032 std::shared_ptr<ServerboundMovePlayerPacketRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketRot>();
1033 move_player_packet->SetXRot(
player->pitch);
1034 move_player_packet->SetYRot(
player->yaw);
1035 move_player_packet->SetOnGround(
player->on_ground);
1036#if PROTOCOL_VERSION > 767
1037 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1041 else if (
player->on_ground !=
player->previous_on_ground
1042#
if PROTOCOL_VERSION > 767
1043 ||
player->horizontal_collision !=
player->previous_horizontal_collision
1047#if PROTOCOL_VERSION > 754
1048 std::shared_ptr<ServerboundMovePlayerPacketStatusOnly> move_player_packet = std::make_shared<ServerboundMovePlayerPacketStatusOnly>();
1050 std::shared_ptr<ServerboundMovePlayerPacket> move_player_packet = std::make_shared<ServerboundMovePlayerPacket>();
1052 move_player_packet->SetOnGround(
player->on_ground);
1053#if PROTOCOL_VERSION > 767
1054 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1070#if PROTOCOL_VERSION > 767
1071 player->previous_horizontal_collision =
player->horizontal_collision;
1090 const std::vector<AABB> colliders =
world->GetColliders(aabb, movement);
1092 if (colliders.size() == 0)
1099 AABB moved_aabb = aabb;
1104 if (std::abs(collided_movement.
x) > std::abs(collided_movement.
z))
1116 return collided_movement;
1123 const int this_axis = axis % 3;
1124 const int axis_1 = (axis + 1) % 3;
1125 const int axis_2 = (axis + 2) % 3;
1127 for (
const AABB& collider : colliders)
1129 if (std::abs(movement[this_axis]) < 1.0e-7)
1131 movement[this_axis] = 0.0;
1136 if (max_aabb[axis_1] - 1e-7 > min_collider[axis_1] && min_aabb[axis_1] + 1e-7 < max_collider[axis_1] &&
1137 max_aabb[axis_2] - 1e-7 > min_collider[axis_2] && min_aabb[axis_2] + 1e-7 < max_collider[axis_2])
1139 if (movement[this_axis] > 0.0 && max_aabb[this_axis] - 1e-7 <= min_collider[this_axis])
1141 movement[this_axis] = std::min(min_collider[this_axis] - max_aabb[this_axis], movement[this_axis]);
1143 else if (movement[this_axis] < 0.0 && min_aabb[this_axis] + 1e-7 >= max_collider[this_axis])
1145 movement[this_axis] = std::max(max_collider[this_axis] - min_aabb[this_axis], movement[this_axis]);
1150 translation[this_axis] = movement[this_axis];
1181 const bool going_down =
player->speed.y <= 0.0;
1182 bool has_slow_falling =
false;
1183#if PROTOCOL_VERSION > 340
1184 for (
const auto& effect :
player->effects)
1188 has_slow_falling =
true;
1194#if PROTOCOL_VERSION < 766
1195 const double drag = (going_down && has_slow_falling) ? 0.01 : 0.08;
1197 const double drag = (going_down && has_slow_falling) ? std::min(0.01,
player->GetAttributeGravityValueImpl()) :
player->GetAttributeGravityValueImpl();
1203 const double init_y =
player->position.y;
1205 float inputs_strength = 0.02f;
1207#if PROTOCOL_VERSION < 767
1211 float depth_strider_mult =
static_cast<float>(
player->GetAttributeWaterMovementEfficiencyValueImpl());
1215 depth_strider_mult *= 0.5f;
1217 if (depth_strider_mult > 0.0)
1219 water_slow_down += (0.54600006f - water_slow_down) * depth_strider_mult;
1220 inputs_strength += (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) - inputs_strength) * depth_strider_mult;
1223#if PROTOCOL_VERSION > 340
1224 for (
const auto& effect :
player->effects)
1228 water_slow_down = 0.96f;
1236 if (
player->horizontal_collision &&
player->on_climbable)
1240 player->speed.x *= water_slow_down;
1241 player->speed.y *= 0.800000011920929;
1242 player->speed.z *= water_slow_down;
1247 std::abs(
player->speed.y - 0.005) >= 0.003 &&
1248 std::abs(
player->speed.y - drag / 16.0) < 0.003)
1250 player->speed.y = -0.003;
1254 player->speed.y -= drag / 16.0;
1259 if (
player->horizontal_collision &&
1262 player->speed.y = 0.30000001192092896;
1268 const double init_y =
player->position.y;
1272 player->speed.y -= drag / 4.0;
1274 if (
player->horizontal_collision &&
1277 player->speed.y = 0.30000001192092896;
1285 const double cos_pitch_from_length = std::sqrt(
player->front_vector.x *
player->front_vector.x +
player->front_vector.z *
player->front_vector.z);
1286 const double cos_pitch = std::cos(
static_cast<double>(
player->pitch * 0.017453292f ));
1287 const double cos_pitch_sqr = cos_pitch * cos_pitch;
1290 player->speed.y += drag * (-1.0 + 0.75 * cos_pitch_sqr);
1292 if (
player->speed.y < 0.0 && cos_pitch_from_length > 0.0)
1294 const double delta_speed = -
player->speed.y * 0.1 * cos_pitch_sqr;
1295 player->speed.x +=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1296 player->speed.y += delta_speed;
1297 player->speed.z +=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1299 if (
player->pitch < 0.0 && cos_pitch_from_length > 0.0)
1302 const double delta_speed = horizontal_speed *
player->front_vector.y * 0.04;
1303 player->speed.x -=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1304 player->speed.y += delta_speed * 3.2;
1305 player->speed.z -=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1307 if (cos_pitch_from_length > 0.0)
1309 player->speed.x += (
player->front_vector.x / cos_pitch_from_length * horizontal_speed -
player->speed.x) * 0.1;
1310 player->speed.z += (
player->front_vector.z / cos_pitch_from_length * horizontal_speed -
player->speed.z) * 0.1;
1325 const float friction = below_block ==
nullptr ? 0.6f : below_block->
GetFriction();
1326 const float inertia =
player->on_ground ? friction * 0.91f : 0.91f;
1329 (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) * (0.21600002f / (friction * friction * friction))) :
1330#if PROTOCOL_VERSION < 762
1336 if (
player->on_climbable)
1338 player->speed.x = std::clamp(
player->speed.x, -0.15000000596046448, 0.15000000596046448);
1339 player->speed.y = std::max(
player->speed.y, -0.15000000596046448);
1343 static_cast<int>(std::floor(
player->position.x)),
1344 static_cast<int>(std::floor(
player->position.y)),
1345 static_cast<int>(std::floor(
player->position.z))
1351 player->speed.z = std::clamp(
player->speed.z, -0.15000000596046448, 0.15000000596046448);
1355 if ((
player->horizontal_collision ||
player->inputs.jump) &&
1362 unsigned char levitation = 0;
1363 for (
const auto& effect :
player->effects)
1367 levitation = effect.amplifier + 1;
1373 player->speed.y += (0.05 * levitation -
player->speed.y) * 0.2;
1379 player->speed.x *= inertia;
1380 player->speed.y *= 0.9800000190734863;
1381 player->speed.z *= inertia;
1396 if (
player->stuck_speed_multiplier.SqrNorm() > 1e-7)
1398 movement *=
player->stuck_speed_multiplier;
1399 player->stuck_speed_multiplier *= 0.0;
1403#if PROTOCOL_VERSION < 766
1404 constexpr double max_up_step = 0.6;
1406 const double max_up_step =
player->GetAttributeStepHeightValueImpl();
1408 const AABB player_aabb =
player->GetColliderImpl();
1410 && movement.
y <= 0.0
1415 const double step = 0.05;
1417 while (movement.
x != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(movement.
x, -max_up_step, 0.0)).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));
1422 while (movement.
z != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(0.0, -max_up_step, movement.
z)).Inflate(-1e-7),
false))
1424 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1427 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))
1429 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1430 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1436 if (movement.
SqrNorm() != 0.0)
1444 if ((
player->on_ground || (movement.
y != movement_before_collisions.
y && movement_before_collisions.
y < 0.0)) &&
1445 (movement.
x != movement_before_collisions.
x || movement.
z != movement_before_collisions.
z))
1449 movement_before_collisions.
x,
1451 movement_before_collisions.
z
1454 if (movement_step_up_only.
y < max_up_step)
1457 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)
1459 movement_with_step_up = check;
1462 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)
1464 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));
1469 if (movement.
SqrNorm() > 1.0e-7)
1471 player->position += movement;
1473 const bool collision_x = movement_before_collisions.
x != movement.
x;
1474 const bool collision_y = movement_before_collisions.
y != movement.
y;
1475 const bool collision_z = movement_before_collisions.
z != movement.
z;
1476 player->horizontal_collision = collision_x || collision_z;
1479 player->on_ground = movement_before_collisions.
y < 0.0 && collision_y;
1483 const double half_width = 0.5 *
player->GetWidthImpl();
1484 const AABB feet_slice_aabb(
1487 player->position.y - 0.5e-6,
1490 std::optional<Position> supporting_block_pos =
world->GetSupportingBlockPos(feet_slice_aabb);
1491 if (supporting_block_pos.has_value() ||
player->on_ground_without_supporting_block)
1493 player->supporting_block_pos = supporting_block_pos;
1499 player->on_ground_without_supporting_block = !
player->supporting_block_pos.has_value();
1503 player->on_ground_without_supporting_block =
false;
1504 player->supporting_block_pos = std::optional<Position>();
1519 if (
player->inputs.sneak)
1526 static_cast<int>(std::floor(
player->position.x)),
1527 static_cast<int>(std::floor(
player->position.y - 0.2)),
1528 static_cast<int>(std::floor(
player->position.z))
1530 double new_speed = 0.0;
1531 if (block_below !=
nullptr)
1535 new_speed = -
player->speed.y;
1537 else if (block_below->
IsBed())
1539 new_speed =
player->speed.y * -0.66f;
1542 player->speed.y = new_speed;
1548#if PROTOCOL_VERSION > 578 && PROTOCOL_VERSION < 767
1549 short soul_speed_lvl = 0;
1554 constexpr short soul_speed_lvl = 0;
1556 float block_speed_factor = 1.0f;
1558 static_cast<int>(std::floor(
player->position.x)),
1559 static_cast<int>(std::floor(
player->position.y)),
1560 static_cast<int>(std::floor(
player->position.z))
1562 if (feet_block !=
nullptr && (feet_block->
IsHoney() || (feet_block->
IsSoulSand() && soul_speed_lvl == 0)))
1564 block_speed_factor = 0.4f;
1566 if (block_speed_factor == 1.0f)
1569 if (below_block !=
nullptr && (below_block->
IsHoney() || (below_block->
IsSoulSand() && soul_speed_lvl == 0)))
1571 block_speed_factor = 0.4f;
1575#if PROTOCOL_VERSION > 766
1576 block_speed_factor = block_speed_factor +
static_cast<float>(
player->GetAttributeMovementEfficiencyValueImpl()) * (1.0f - block_speed_factor);
1579 player->speed.x *= block_speed_factor;
1580 player->speed.z *= block_speed_factor;
1601 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
1604 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
1607 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
1611 if (block ==
nullptr)
1622 if (above_block ==
nullptr || above_block->
IsAir())
1634 if (!
player->on_ground &&
1635 player->position.y <= y + 0.9375 - 1.0e-7 &&
1636 player->speed.y < -0.08 && (
1637 std::abs(x + 0.5 -
player->position.x) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0 ||
1638 std::abs(z + 0.5 -
player->position.z) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0)
1641 if (
player->speed.y < -0.13)
1643 const double factor = -0.05 /
player->speed.y;
1644 player->speed.x *= factor;
1646 player->speed.z *= factor;
1661 static_cast<int>(std::floor(
player->position.x)),
1662 static_cast<int>(std::floor(
player->position.y)),
1663 static_cast<int>(std::floor(
player->position.z))
1665 if (feet_block !=
nullptr && feet_block->
IsPowderSnow())