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>();
306#if PROTOCOL_VERSION > 404
307 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget().value_or(0);
309 const int attached_id =
reinterpret_cast<const FireworkRocketEntity*
>(e.second.get())->GetDataAttachedToTarget();
311 if (attached_id ==
player->entity_id)
325 static_cast<int>(std::floor(
player->position.x)),
326 static_cast<int>(std::floor(
player->position.y)),
327 static_cast<int>(std::floor(
player->position.z))
332 player->on_ground =
false;
343 player->sprint_double_tap_trigger_time = std::max(0,
player->sprint_double_tap_trigger_time - 1);
356 player->speed.y -= 0.03999999910593033;
366 player->fly_jump_trigger_time = std::max(0,
player->fly_jump_trigger_time - 1);
376 player->jump_delay = std::max(0,
player->jump_delay - 1);
378 if (std::abs(
player->speed.x) < 0.003)
382 if (std::abs(
player->speed.y) < 0.003)
386 if (std::abs(
player->speed.z) < 0.003)
393 player->inputs.forward_axis *= 0.98f;
394 player->inputs.left_axis *= 0.98f;
399 const double m_sin_pitch =
player->front_vector.y;
400 bool condition = m_sin_pitch <= 0.0 ||
player->inputs.jump;
404 static_cast<int>(std::floor(
player->position.x)),
405 static_cast<int>(std::floor(
player->position.y + 1.0 - 0.1)),
406 static_cast<int>(std::floor(
player->position.z))
408 condition = above_block !=
nullptr && above_block->
IsFluid();
412 player->speed.y += (m_sin_pitch -
player->speed.y) * (m_sin_pitch < -0.2 ? 0.085 : 0.06);
416 const double speed_y =
player->speed.y;
420 player->speed.y = 0.6 * speed_y;
440 player->position.x = std::clamp(
player->position.x, -2.9999999E7, 2.9999999E7);
441 player->position.z = std::clamp(
player->position.z, -2.9999999E7, 2.9999999E7);
443#if PROTOCOL_VERSION > 404
451 else if (
player->GetSleepingPosIdImpl())
459 else if (
player->GetDataLivingEntityFlagsImpl() & 0x04)
474 player->SetDataPoseImpl(current_pose);
531 player->under_water =
false;
540 const double eye_height =
player->position.
y +
player->GetEyeHeightImpl();
544 double fluid_relative_height = 0.0;
547 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
550 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
553 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
557 if (block ==
nullptr || !block->
IsFluid() ||
563 double fluid_height = 0.0;
565 ((block_above->IsLava() && block->
IsLava()) || (block_above->IsWater() && block->
IsWater())))
574 if (fluid_height + y < min_aabb.
y)
582 if (fluid_height + y >= eye_height)
584 player->under_water =
true;
592 fluid_relative_height = std::max(fluid_height - min_aabb.
y, fluid_relative_height);
600 if (fluid_relative_height < 0.4)
602 current_push *= fluid_relative_height;
604 push += current_push;
614 push /=
static_cast<double>(num_push);
622 push *=
world->IsInUltraWarmDimension() ? 0.007 : 0.0023333333333333335;
624 const double push_norm = std::sqrt(push.
SqrNorm());
625 if (std::abs(
player->speed.x) < 0.003 && std::abs(
player->speed.z) < 0.003 && push_norm < 0.0045000000000000005)
629 push *= 0.0045000000000000005;
693 const bool was_sneaking =
player->previous_sneak;
694 const bool had_enough_impulse_to_start_sprinting =
player->previous_forward >= (
player->under_water ? 1e-5f : 0.8f);
695 const bool has_enough_impulse_to_start_sprinting =
player->inputs.forward_axis >= (
player->under_water ? 1e-5f : 0.8f);
697#if PROTOCOL_VERSION > 404
700 const bool is_moving_slowly =
player->crouching;
705 player->sprint_double_tap_trigger_time = 0;
708 bool has_blindness =
false;
709 for (
const auto& effect :
player->effects)
713 has_blindness =
true;
718 const bool can_start_sprinting = !(
720 !has_enough_impulse_to_start_sprinting ||
724 (is_moving_slowly && !
player->under_water)
727 if ((
player->on_ground ||
player->under_water) && !was_sneaking && !had_enough_impulse_to_start_sprinting && can_start_sprinting)
729 if (
player->sprint_double_tap_trigger_time > 0 ||
player->inputs.sprint)
739 if ((!
player->in_water ||
player->under_water) && can_start_sprinting &&
player->inputs.sprint)
747 const bool stop_sprint_condition =
player->inputs.forward_axis <= 1e-5 || (
player->food <= 6 && !
player->may_fly);
750 if ((!
player->on_ground && !
player->inputs.sneak && stop_sprint_condition) || !
player->in_water)
755 else if (stop_sprint_condition ||
756 player->horizontal_collision ||
852 player->speed.y += 0.03999999910593033;
858 float jump_boost = 0.0f;
859 for (
const auto& effect :
player->effects)
863 jump_boost = 0.1f * (effect.amplifier + 1);
869 float block_jump_factor = 1.0f;
871 static_cast<int>(std::floor(
player->position.x)),
872 static_cast<int>(std::floor(
player->position.y)),
873 static_cast<int>(std::floor(
player->position.z))
875 if (feet_block ==
nullptr || !feet_block->
IsHoney())
878 if (below_block !=
nullptr && below_block->
IsHoney())
880 block_jump_factor = 0.4f;
885 block_jump_factor = 0.4f;
888#if PROTOCOL_VERSION < 766
889 player->speed.y = 0.42f * block_jump_factor + jump_boost;
892 const float yaw_rad =
player->yaw * 0.017453292f ;
893 player->speed.x -= std::sin(yaw_rad) * 0.2f;
894 player->speed.z += std::cos(yaw_rad) * 0.2f;
897 const float jump_power =
static_cast<float>(
player->GetAttributeJumpStrengthValueImpl()) * block_jump_factor + jump_boost;
898 if (jump_power > 1e-5f)
900 player->speed.y = jump_power;
903 const float yaw_rad =
player->yaw * 0.017453292f ;
904 player->speed.x -=
static_cast<double>(std::sin(yaw_rad)) * 0.2;
905 player->speed.z +=
static_cast<double>(std::cos(yaw_rad)) * 0.2;
943#if PROTOCOL_VERSION > 767
946#if PROTOCOL_VERSION < 771
947 const bool shift_key_down =
player->inputs.sneak;
948 if (shift_key_down !=
player->previous_shift_key_down)
950 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
951 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShiftKey));
952 player_command_packet->SetId_(
player->entity_id);
954 player->previous_shift_key_down = shift_key_down;
958 if (
player->last_sent_inputs.sneak !=
player->inputs.sneak ||
960 player->last_sent_inputs.sprint !=
player->inputs.sprint ||
961 player->last_sent_inputs.forward_axis !=
player->inputs.forward_axis ||
962 player->last_sent_inputs.left_axis !=
player->inputs.left_axis)
964 std::shared_ptr<ServerboundPlayerInputPacket> player_input_packet = std::make_shared<ServerboundPlayerInputPacket>();
965 player_input_packet->SetForward(
player->inputs.forward_axis > 0.0f);
966 player_input_packet->SetBackward(
player->inputs.forward_axis < 0.0f);
967 player_input_packet->SetLeft(
player->inputs.left_axis > 0.0f);
968 player_input_packet->SetRight(
player->inputs.left_axis < 0.0f);
969 player_input_packet->SetJump(
player->inputs.jump);
970 player_input_packet->SetShift(
player->inputs.sneak);
971 player_input_packet->SetSprint(
player->inputs.sprint);
978 if (sprinting !=
player->previous_sprinting)
980 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
982 player_command_packet->SetId_(
player->entity_id);
984 player->previous_sprinting = sprinting;
987#if PROTOCOL_VERSION < 768
989 const bool shift_key_down =
player->inputs.sneak;
990 if (shift_key_down !=
player->previous_shift_key_down)
992 std::shared_ptr<ServerboundPlayerCommandPacket> player_command_packet = std::make_shared<ServerboundPlayerCommandPacket>();
993 player_command_packet->SetAction(
static_cast<int>(shift_key_down ? PlayerCommandAction::PressShiftKey : PlayerCommandAction::ReleaseShiftKey));
994 player_command_packet->SetId_(
player->entity_id);
996 player->previous_shift_key_down = shift_key_down;
1002 if (has_moved && has_rotated)
1004 std::shared_ptr<ServerboundMovePlayerPacketPosRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPosRot>();
1005 move_player_packet->SetX(
player->position.x);
1006 move_player_packet->SetY(
player->position.y);
1007 move_player_packet->SetZ(
player->position.z);
1008 move_player_packet->SetXRot(
player->pitch);
1009 move_player_packet->SetYRot(
player->yaw);
1010 move_player_packet->SetOnGround(
player->on_ground);
1011#if PROTOCOL_VERSION > 767
1012 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1018 std::shared_ptr<ServerboundMovePlayerPacketPos> move_player_packet = std::make_shared<ServerboundMovePlayerPacketPos>();
1019 move_player_packet->SetX(
player->position.x);
1020 move_player_packet->SetY(
player->position.y);
1021 move_player_packet->SetZ(
player->position.z);
1022 move_player_packet->SetOnGround(
player->on_ground);
1023#if PROTOCOL_VERSION > 767
1024 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1028 else if (has_rotated)
1030 std::shared_ptr<ServerboundMovePlayerPacketRot> move_player_packet = std::make_shared<ServerboundMovePlayerPacketRot>();
1031 move_player_packet->SetXRot(
player->pitch);
1032 move_player_packet->SetYRot(
player->yaw);
1033 move_player_packet->SetOnGround(
player->on_ground);
1034#if PROTOCOL_VERSION > 767
1035 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1039 else if (
player->on_ground !=
player->previous_on_ground
1040#
if PROTOCOL_VERSION > 767
1041 ||
player->horizontal_collision !=
player->previous_horizontal_collision
1045#if PROTOCOL_VERSION > 754
1046 std::shared_ptr<ServerboundMovePlayerPacketStatusOnly> move_player_packet = std::make_shared<ServerboundMovePlayerPacketStatusOnly>();
1048 std::shared_ptr<ServerboundMovePlayerPacket> move_player_packet = std::make_shared<ServerboundMovePlayerPacket>();
1050 move_player_packet->SetOnGround(
player->on_ground);
1051#if PROTOCOL_VERSION > 767
1052 move_player_packet->SetHorizontalCollision(
player->horizontal_collision);
1068#if PROTOCOL_VERSION > 767
1069 player->previous_horizontal_collision =
player->horizontal_collision;
1088 const std::vector<AABB> colliders =
world->GetColliders(aabb, movement);
1090 if (colliders.size() == 0)
1097 AABB moved_aabb = aabb;
1102 if (std::abs(collided_movement.
x) > std::abs(collided_movement.
z))
1114 return collided_movement;
1121 const int this_axis = axis % 3;
1122 const int axis_1 = (axis + 1) % 3;
1123 const int axis_2 = (axis + 2) % 3;
1125 for (
const AABB& collider : colliders)
1127 if (std::abs(movement[this_axis]) < 1.0e-7)
1129 movement[this_axis] = 0.0;
1134 if (max_aabb[axis_1] - 1e-7 > min_collider[axis_1] && min_aabb[axis_1] + 1e-7 < max_collider[axis_1] &&
1135 max_aabb[axis_2] - 1e-7 > min_collider[axis_2] && min_aabb[axis_2] + 1e-7 < max_collider[axis_2])
1137 if (movement[this_axis] > 0.0 && max_aabb[this_axis] - 1e-7 <= min_collider[this_axis])
1139 movement[this_axis] = std::min(min_collider[this_axis] - max_aabb[this_axis], movement[this_axis]);
1141 else if (movement[this_axis] < 0.0 && min_aabb[this_axis] + 1e-7 >= max_collider[this_axis])
1143 movement[this_axis] = std::max(max_collider[this_axis] - min_aabb[this_axis], movement[this_axis]);
1148 translation[this_axis] = movement[this_axis];
1179 const bool going_down =
player->speed.y <= 0.0;
1180 bool has_slow_falling =
false;
1181#if PROTOCOL_VERSION > 340
1182 for (
const auto& effect :
player->effects)
1186 has_slow_falling =
true;
1192#if PROTOCOL_VERSION < 766
1193 const double drag = (going_down && has_slow_falling) ? 0.01 : 0.08;
1195 const double drag = (going_down && has_slow_falling) ? std::min(0.01,
player->GetAttributeGravityValueImpl()) :
player->GetAttributeGravityValueImpl();
1201 const double init_y =
player->position.y;
1203 float inputs_strength = 0.02f;
1205#if PROTOCOL_VERSION < 767
1209 float depth_strider_mult =
static_cast<float>(
player->GetAttributeWaterMovementEfficiencyValueImpl());
1213 depth_strider_mult *= 0.5f;
1215 if (depth_strider_mult > 0.0)
1217 water_slow_down += (0.54600006f - water_slow_down) * depth_strider_mult;
1218 inputs_strength += (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) - inputs_strength) * depth_strider_mult;
1221#if PROTOCOL_VERSION > 340
1222 for (
const auto& effect :
player->effects)
1226 water_slow_down = 0.96f;
1234 if (
player->horizontal_collision &&
player->on_climbable)
1238 player->speed.x *= water_slow_down;
1239 player->speed.y *= 0.800000011920929;
1240 player->speed.z *= water_slow_down;
1245 std::abs(
player->speed.y - 0.005) >= 0.003 &&
1246 std::abs(
player->speed.y - drag / 16.0) < 0.003)
1248 player->speed.y = -0.003;
1252 player->speed.y -= drag / 16.0;
1257 if (
player->horizontal_collision &&
1260 player->speed.y = 0.30000001192092896;
1266 const double init_y =
player->position.y;
1270 player->speed.y -= drag / 4.0;
1272 if (
player->horizontal_collision &&
1275 player->speed.y = 0.30000001192092896;
1283 const double cos_pitch_from_length = std::sqrt(
player->front_vector.x *
player->front_vector.x +
player->front_vector.z *
player->front_vector.z);
1284 const double cos_pitch = std::cos(
static_cast<double>(
player->pitch * 0.017453292f ));
1285 const double cos_pitch_sqr = cos_pitch * cos_pitch;
1288 player->speed.y += drag * (-1.0 + 0.75 * cos_pitch_sqr);
1290 if (
player->speed.y < 0.0 && cos_pitch_from_length > 0.0)
1292 const double delta_speed = -
player->speed.y * 0.1 * cos_pitch_sqr;
1293 player->speed.x +=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1294 player->speed.y += delta_speed;
1295 player->speed.z +=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1297 if (
player->pitch < 0.0 && cos_pitch_from_length > 0.0)
1300 const double delta_speed = horizontal_speed *
player->front_vector.y * 0.04;
1301 player->speed.x -=
player->front_vector.x * delta_speed / cos_pitch_from_length;
1302 player->speed.y += delta_speed * 3.2;
1303 player->speed.z -=
player->front_vector.z * delta_speed / cos_pitch_from_length;
1305 if (cos_pitch_from_length > 0.0)
1307 player->speed.x += (
player->front_vector.x / cos_pitch_from_length * horizontal_speed -
player->speed.x) * 0.1;
1308 player->speed.z += (
player->front_vector.z / cos_pitch_from_length * horizontal_speed -
player->speed.z) * 0.1;
1323 const float friction = below_block ==
nullptr ? 0.6f : below_block->
GetFriction();
1324 const float inertia =
player->on_ground ? friction * 0.91f : 0.91f;
1327 (
static_cast<float>(
player->GetAttributeMovementSpeedValueImpl()) * (0.21600002f / (friction * friction * friction))) :
1328#if PROTOCOL_VERSION < 762
1334 if (
player->on_climbable)
1336 player->speed.x = std::clamp(
player->speed.x, -0.15000000596046448, 0.15000000596046448);
1337 player->speed.y = std::max(
player->speed.y, -0.15000000596046448);
1341 static_cast<int>(std::floor(
player->position.x)),
1342 static_cast<int>(std::floor(
player->position.y)),
1343 static_cast<int>(std::floor(
player->position.z))
1349 player->speed.z = std::clamp(
player->speed.z, -0.15000000596046448, 0.15000000596046448);
1353 if ((
player->horizontal_collision ||
player->inputs.jump) &&
1360 unsigned char levitation = 0;
1361 for (
const auto& effect :
player->effects)
1365 levitation = effect.amplifier + 1;
1371 player->speed.y += (0.05 * levitation -
player->speed.y) * 0.2;
1377 player->speed.x *= inertia;
1378 player->speed.y *= 0.9800000190734863;
1379 player->speed.z *= inertia;
1394 if (
player->stuck_speed_multiplier.SqrNorm() > 1e-7)
1396 movement *=
player->stuck_speed_multiplier;
1397 player->stuck_speed_multiplier *= 0.0;
1401#if PROTOCOL_VERSION < 766
1402 constexpr double max_up_step = 0.6;
1404 const double max_up_step =
player->GetAttributeStepHeightValueImpl();
1406 const AABB player_aabb =
player->GetColliderImpl();
1408 && movement.
y <= 0.0
1413 const double step = 0.05;
1415 while (movement.
x != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(movement.
x, -max_up_step, 0.0)).Inflate(-1e-7),
false))
1417 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1420 while (movement.
z != 0.0 &&
world->IsFree((player_aabb +
Vector3<double>(0.0, -max_up_step, movement.
z)).Inflate(-1e-7),
false))
1422 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1425 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))
1427 movement.
x = (movement.
x < step && movement.
x >= -step) ? 0.0 : (movement.
x > 0.0 ? (movement.
x - step) : (movement.
x + step));
1428 movement.
z = (movement.
z < step && movement.
z >= -step) ? 0.0 : (movement.
z > 0.0 ? (movement.
z - step) : (movement.
z + step));
1434 if (movement.
SqrNorm() != 0.0)
1442 if ((
player->on_ground || (movement.
y != movement_before_collisions.
y && movement_before_collisions.
y < 0.0)) &&
1443 (movement.
x != movement_before_collisions.
x || movement.
z != movement_before_collisions.
z))
1447 movement_before_collisions.
x,
1449 movement_before_collisions.
z
1452 if (movement_step_up_only.
y < max_up_step)
1455 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)
1457 movement_with_step_up = check;
1460 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)
1462 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));
1467 if (movement.
SqrNorm() > 1.0e-7)
1469 player->position += movement;
1471 const bool collision_x = movement_before_collisions.
x != movement.
x;
1472 const bool collision_y = movement_before_collisions.
y != movement.
y;
1473 const bool collision_z = movement_before_collisions.
z != movement.
z;
1474 player->horizontal_collision = collision_x || collision_z;
1477 player->on_ground = movement_before_collisions.
y < 0.0 && collision_y;
1481 const double half_width = 0.5 *
player->GetWidthImpl();
1482 const AABB feet_slice_aabb(
1485 player->position.y - 0.5e-6,
1488 std::optional<Position> supporting_block_pos =
world->GetSupportingBlockPos(feet_slice_aabb);
1489 if (supporting_block_pos.has_value() ||
player->on_ground_without_supporting_block)
1491 player->supporting_block_pos = supporting_block_pos;
1497 player->on_ground_without_supporting_block = !
player->supporting_block_pos.has_value();
1501 player->on_ground_without_supporting_block =
false;
1502 player->supporting_block_pos = std::optional<Position>();
1517 if (
player->inputs.sneak)
1524 static_cast<int>(std::floor(
player->position.x)),
1525 static_cast<int>(std::floor(
player->position.y - 0.2)),
1526 static_cast<int>(std::floor(
player->position.z))
1528 double new_speed = 0.0;
1529 if (block_below !=
nullptr)
1533 new_speed = -
player->speed.y;
1535 else if (block_below->
IsBed())
1537 new_speed =
player->speed.y * -0.66f;
1540 player->speed.y = new_speed;
1546#if PROTOCOL_VERSION > 578 && PROTOCOL_VERSION < 767
1547 short soul_speed_lvl = 0;
1552 constexpr short soul_speed_lvl = 0;
1554 float block_speed_factor = 1.0f;
1556 static_cast<int>(std::floor(
player->position.x)),
1557 static_cast<int>(std::floor(
player->position.y)),
1558 static_cast<int>(std::floor(
player->position.z))
1560 if (feet_block !=
nullptr && (feet_block->
IsHoney() || (feet_block->
IsSoulSand() && soul_speed_lvl == 0)))
1562 block_speed_factor = 0.4f;
1564 if (block_speed_factor == 1.0f)
1567 if (below_block !=
nullptr && (below_block->
IsHoney() || (below_block->
IsSoulSand() && soul_speed_lvl == 0)))
1569 block_speed_factor = 0.4f;
1573#if PROTOCOL_VERSION > 766
1574 block_speed_factor = block_speed_factor +
static_cast<float>(
player->GetAttributeMovementEfficiencyValueImpl()) * (1.0f - block_speed_factor);
1577 player->speed.x *= block_speed_factor;
1578 player->speed.z *= block_speed_factor;
1599 for (
int y =
static_cast<int>(std::floor(min_aabb.
y)); y <= static_cast<int>(std::floor(max_aabb.
y)); ++y)
1602 for (
int z =
static_cast<int>(std::floor(min_aabb.
z)); z <= static_cast<int>(std::floor(max_aabb.
z)); ++z)
1605 for (
int x =
static_cast<int>(std::floor(min_aabb.
x)); x <= static_cast<int>(std::floor(max_aabb.
x)); ++x)
1609 if (block ==
nullptr)
1620 if (above_block ==
nullptr || above_block->
IsAir())
1632 if (!
player->on_ground &&
1633 player->position.y <= y + 0.9375 - 1.0e-7 &&
1634 player->speed.y < -0.08 && (
1635 std::abs(x + 0.5 -
player->position.x) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0 ||
1636 std::abs(z + 0.5 -
player->position.z) + 1.0e-7 > 0.4375 +
player->GetWidthImpl() / 2.0)
1639 if (
player->speed.y < -0.13)
1641 const double factor = -0.05 /
player->speed.y;
1642 player->speed.x *= factor;
1644 player->speed.z *= factor;
1659 static_cast<int>(std::floor(
player->position.x)),
1660 static_cast<int>(std::floor(
player->position.y)),
1661 static_cast<int>(std::floor(
player->position.z))
1663 if (feet_block !=
nullptr && feet_block->
IsPowderSnow())