Skip to content

Commit af06545

Browse files
committed
Fix inconsistencies with PlaceTool usage
1 parent c9e5e07 commit af06545

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Tobey.SnapBuilder/AimTransform.cs

+21-3
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,26 @@ private void OnDestroy()
4747
Destroy(GetComponent<ColliderCache>());
4848
}
4949

50-
public static bool Raycast(Vector3 from, Vector3 direction, out RaycastHit hit) =>
51-
Physics.Raycast(from, direction, out hit, Builder.placeMaxDistance, Builder.placeLayerMask, QueryTriggerInteraction.Ignore);
50+
private static PlaceTool GetPlaceTool() => Inventory.main?.GetHeld()?.GetComponent<PlaceTool>();
51+
52+
public static bool Raycast(Vector3 from, Vector3 direction, out RaycastHit hit)
53+
{
54+
var placeTool = GetPlaceTool();
55+
if (placeTool == null)
56+
{
57+
return Physics.Raycast(from, direction, out hit, Builder.placeMaxDistance, Builder.placeLayerMask, QueryTriggerInteraction.Ignore);
58+
}
59+
else
60+
{
61+
int max = UWE.Utils.RaycastIntoSharedBuffer(from, direction, 5f, -5, QueryTriggerInteraction.UseGlobal);
62+
var hits = new ArraySegment<RaycastHit>(UWE.Utils.sharedHitBuffer, 0, max)
63+
.Where(h => !h.collider.isTrigger && !UWE.Utils.SharingHierarchy(placeTool.gameObject, h.collider.gameObject))
64+
.OrderBy(h => h.distance);
65+
66+
hit = hits.FirstOrDefault();
67+
return hits.Any();
68+
}
69+
}
5270

5371
private Transform GetOrientedTransform(Vector3? position = null, Vector3? forward = null)
5472
{
@@ -213,7 +231,7 @@ private static RaycastHit GetWorldSpaceHit(RaycastHit hit, Transform transform =
213231
/// <returns></returns>
214232
private RaycastHit PopHitOntoBestSurface(RaycastHit hit)
215233
{
216-
if (!Player.main.IsInsideWalkable())
234+
if (!Player.main.IsInsideWalkable() || GetPlaceTool() != null)
217235
{
218236
return hit;
219237
}

0 commit comments

Comments
 (0)