Merge branch 'fix-form-build-gate-chair'

This commit is contained in:
kanym 2026-10-17 19:39:13 +02:00
commit ee154ccab4
2 changed files with 20 additions and 4 deletions

View file

@ -135,7 +135,11 @@ namespace RacesOfValheim
} }
// How far in front of the seat a creature on a chair settles, in metres. // How far in front of the seat a creature on a chair settles, in metres.
private const float ChairForward = 0.5f; private const float ChairForward = 1f;
// And turned a quarter left, counter-clockwise seen from above, so it lies across the front
// of the seat rather than facing out of it.
private static readonly Quaternion ChairTurn = Quaternion.Euler(0f, -90f, 0f);
private static readonly int ChairGroundMask = LayerMask.GetMask("Default", "static_solid", "terrain", "piece", "vehicle"); private static readonly int ChairGroundMask = LayerMask.GetMask("Default", "static_solid", "terrain", "piece", "vehicle");
private static readonly RaycastHit[] chairHits = new RaycastHit[16]; private static readonly RaycastHit[] chairHits = new RaycastHit[16];
private Transform placedRoot; private Transform placedRoot;
@ -154,7 +158,11 @@ namespace RacesOfValheim
bool onChair = player.IsSitting(); bool onChair = player.IsSitting();
if (!onChair) if (!onChair)
{ {
if (placedRoot == root && root.localPosition != Vector3.zero) root.localPosition = Vector3.zero; if (placedRoot == root)
{
if (root.localPosition != Vector3.zero) root.localPosition = Vector3.zero;
if (root.localRotation != Quaternion.identity) root.localRotation = Quaternion.identity;
}
return; return;
} }
placedRoot = root; placedRoot = root;
@ -175,6 +183,7 @@ namespace RacesOfValheim
} }
root.localPosition = body.InverseTransformPoint(new Vector3(target.x, groundY, target.z)); root.localPosition = body.InverseTransformPoint(new Vector3(target.x, groundY, target.z));
root.localRotation = ChairTurn;
} }
/// <summary>The chair or bench the player sits on: the first piece straight under them.</summary> /// <summary>The chair or bench the player sits on: the first piece straight under them.</summary>

View file

@ -31,6 +31,13 @@ namespace RacesOfValheim
// Not public on Player, hence the reflection; resolved once rather than per frame. // Not public on Player, hence the reflection; resolved once rather than per frame.
private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput"); private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput");
/// <summary>
/// Hammer, hoe or cultivator in hand. Right click removes a piece there and middle click picks
/// a snap point, and a form read both as its own attacks: an Ulv building a wall bit the air
/// on every click. Allowed only covered the piece selection panel, not the build mode itself.
/// </summary>
private static bool InBuildMode => Player.m_localPlayer != null && Player.m_localPlayer.InPlaceMode();
public static bool Allowed public static bool Allowed
{ {
get get
@ -156,14 +163,14 @@ namespace RacesOfValheim
/// </summary> /// </summary>
public static bool AttackDown(int mouseButton) public static bool AttackDown(int mouseButton)
{ {
if (RadialOpen) return false; if (RadialOpen || InBuildMode) return false;
return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton); return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton);
} }
/// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary> /// <summary>Held-down counterpart of <see cref="AttackDown"/>.</summary>
public static bool AttackHeld(int mouseButton) public static bool AttackHeld(int mouseButton)
{ {
if (RadialOpen) return false; if (RadialOpen || InBuildMode) return false;
return Input.GetMouseButton(mouseButton) || PadAttackHeld(mouseButton); return Input.GetMouseButton(mouseButton) || PadAttackHeld(mouseButton);
} }