Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions botcraft/include/botcraft/Game/Physics/PhysicsManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ namespace Botcraft
std::thread thread_physics; // Thread running to compute position and send it to the server every tick

const Item* elytra_item;
const Item* leather_boots_item;

#if PROTOCOL_VERSION > 764 /* > 1.20.2 */
std::atomic<double> ms_per_tick = 50.0;
Expand Down
31 changes: 28 additions & 3 deletions botcraft/src/Game/Physics/PhysicsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ namespace Botcraft
{
throw std::runtime_error("Unknown item minecraft:elytra");
}

leather_boots_item = AssetsManager::getInstance().GetItem("minecraft:leather_boots");
if (leather_boots_item == nullptr)
{
throw std::runtime_error("Unknown item minecraft:leather_boots");
}
}

PhysicsManager::~PhysicsManager()
Expand Down Expand Up @@ -1280,8 +1286,8 @@ namespace Botcraft
// Move with elytra
else if (player->GetDataSharedFlagsIdImpl(EntitySharedFlagsId::FallFlying))
{
// sqrt(front_vector.x + front_vector.z) to follow vanilla code
// it's equal to cos(pitch) (as -90<=pitch<=90, cos(pitch) >= 0.0)
// sqrt(front_vector.x^2 + front_vector.z^2) to follow vanilla code
// it's equal to cos(pitch) (as -90°<=pitch<=90°, cos(pitch) >= 0.0)
const double cos_pitch_from_length = std::sqrt(player->front_vector.x * player->front_vector.x + player->front_vector.z * player->front_vector.z);
const double cos_pitch = std::cos(static_cast<double>(player->pitch * 0.017453292f /* PI/180 */));
const double cos_pitch_sqr = cos_pitch * cos_pitch;
Expand Down Expand Up @@ -1353,12 +1359,31 @@ namespace Botcraft
ApplyMovement();
// If colliding and in climbable, go up
if ((player->horizontal_collision || player->inputs.jump) &&
(player->on_climbable) // TODO: or in powder snow with leather boots
(player->on_climbable)
)
{
player->speed.y = 0.2;
}

#if PROTOCOL_VERSION > 754 /* > 1.17+ */

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be > 1.17 without the + sign to be consistent with the repo

// If in powder snow with leather boots go up

const Blockstate* feet_block = world->GetBlock(Position(
static_cast<int>(std::floor(player->position.x)),
static_cast<int>(std::floor(player->position.y)),
static_cast<int>(std::floor(player->position.z))
));

if (feet_block != nullptr && feet_block->IsPowderSnow()) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The { should be on the next line to be consistent with the rest of the codebase.
Also the condition in java code is this.wasInPowderSnow, did you check that your feet block check is the exact same thing (i.e. feet block check only and without a tick delay)?

const auto feet_slot = inventory_manager->GetPlayerInventory()->GetSlot(Window::INVENTORY_FEET_ARMOR);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no reason to use auto here it's a ProtocolCraft::Slot and with the using namespace we can just use Slot.


if ((player->horizontal_collision || player->inputs.jump) && feet_slot.GetItemId() == leather_boots_item->GetId())
{
player->speed.y = 0.2;
}
}
#endif

unsigned char levitation = 0;
for (const auto& effect : player->effects)
{
Expand Down