Skip to content
Merged
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
16 changes: 16 additions & 0 deletions src/client/PerlinInteraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ namespace perlin {
},
{camera.x, camera.y, camera.z}, glm::dvec3(targeting::ViewVector(camera.yaw, camera.pitch)), PickRange(creative, 1),
EntityPickRange(creative));
// looking down past an edge with nothing in reach (pick 0x144E090C0): clip 2 blocks straight down
// from the eye; that block becomes the target, on the face of the look's dominant horizontal axis
const glm::dvec3 look(targeting::ViewVector(camera.yaw, camera.pitch));
if (aimHit.kind == AimHit::Kind::None && look.y < -0.7) {
const std::vector<entity::Entity> noEntities;
AimHit below = Raycast(
live ? live->NetLevel() : *previewLevel, &levelRenderer->Blocks(), noEntities,
[](const entity::Entity&) { return glm::vec2(0.0f); }, {camera.x, camera.y, camera.z},
glm::dvec3(0.0, -1.0, 0.0), 2.0, 0.0);
if (below.kind == AimHit::Kind::Block) {
below.face = std::fabs(look.x) > std::fabs(look.z) ? (look.x < 0.0 ? 4 : 5) : (look.z < 0.0 ? 2 : 3);
below.buildAssist = true;
aimHit = below;
}
}
}
if (PERLIN_ENV("PERLIN_AIM_DEBUG"))
Log("aim", "kind {} block {},{},{} face {} dist {}", static_cast<int>(aimHit.kind), aimHit.bx,
Expand Down Expand Up @@ -313,6 +328,7 @@ namespace perlin {
if (bedrockBuild && inputManager.IsDown(Action::Use) && !inputManager.Pressed(Action::Use)) {
heldbuild::Hit hit;
hit.block = aimHit.kind == AimHit::Kind::Block;
hit.assist = aimHit.buildAssist;
hit.target = {{aimHit.bx, aimHit.by, aimHit.bz}, aimHit.face};
hit.point = aimHit.kind != AimHit::Kind::None ? glm::vec3(aimHit.point)
: buildEye + glm::normalize(camera.Direction()) *
Expand Down
2 changes: 1 addition & 1 deletion src/client/player/HeldBuild.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace perlin::heldbuild {
if (!SegmentHitsCell(eye, hit.point, nextBuild))
return std::nullopt;
click = {nextBuild - direction, continueFacing};
} else if (hit.block) {
} else if (hit.block && !hit.assist) {
click = hit.target;
const float xy = velocity.x * velocity.x + velocity.y * velocity.y;
if (lastSnappable && !hasDirection && hasLastBuilt && velocity.z * velocity.z + xy > 0.0099999998f) {
Expand Down
1 change: 1 addition & 0 deletions src/client/player/HeldBuild.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ namespace perlin::heldbuild {

struct Hit {
bool block = false; // crosshair on a block (direct hit)
bool assist = false; // the block is the look-down pick under the player, not a ray hit
Target target;
glm::vec3 point{}; // where the ray stopped: hit point, or eye + look * reach without a hit
};
Expand Down
2 changes: 2 additions & 0 deletions src/client/player/Interaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace perlin {
uint64_t entity = 0;
glm::dvec3 boxLo{0.0}, boxHi{0.0};
std::vector<std::pair<glm::dvec3, glm::dvec3>> shape;
// block under the player picked when looking down past an edge (HitResult +0x84): held repeats skip it
bool buildAssist = false;
};

// world hit on the padded pick box, like HitResult::mPos: the game sends it as the entity click pos
Expand Down
Loading