Skip to content

Commit 56175db

Browse files
authored
Merge pull request #48 from tobeyStraitjacket/dev
SnapBuilder 1.4.1
2 parents 45e032d + e63634c commit 56175db

File tree

7 files changed

+37
-16
lines changed

7 files changed

+37
-16
lines changed

SnapBuilder/ColliderRecord.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ class ColliderRecord
1212
{
1313
private static Type[] ExcludedComponentTypes { get; } = new Type[] {
1414
typeof(CoralBlendWhite), // default mesh is good enough and doesn't work well when upgraded
15-
typeof(BaseCell)
15+
typeof(BaseCell),
16+
typeof(ConstructableBase)
17+
};
18+
19+
private static TechType[] ExcludedTechTypes { get; } = new TechType[]
20+
{
21+
TechType.BaseHatch
1622
};
1723

1824
private static Material material;
@@ -63,7 +69,7 @@ public bool IsImprovable
6369
return (isImprovable = false).Value;
6470
}
6571
}
66-
public bool IsImproved => Collider switch
72+
public bool IsImproved => IsImprovable && Collider switch
6773
{
6874
MeshCollider meshCollider => meshCollider?.sharedMesh is Mesh mesh && mesh == ImprovedMesh,
6975
_ => false
@@ -80,9 +86,10 @@ public ColliderRecord(Collider collider)
8086
private bool IsExcluded()
8187
{
8288
Transform root = Utils.GetEntityRoot(Collider.transform.gameObject)?.transform ?? Collider.transform;
83-
return ExcludedComponentTypes
84-
.Select(type => root.GetComponent(type))
85-
.Any(component => component is Component);
89+
return ExcludedTechTypes.Contains(Builder.constructableTechType)
90+
|| ExcludedComponentTypes
91+
.Select(type => root.GetComponent(type))
92+
.Any(component => component is Component);
8693
}
8794

8895
public void Improve()

SnapBuilder/ExtensionMethods/UnityEngineExtensionMethods.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections;
33
using System.Collections.Generic;
4+
using System.Linq;
45

56
namespace Straitjacket.Subnautica.Mods.SnapBuilder.ExtensionMethods
67
{
@@ -67,7 +68,24 @@ public static void Render(this Collider collider, Material material, float scale
6768
/// <returns></returns>
6869
public static Transform GetOptimalTransform(this RaycastHit hit) => Builder.GetSurfaceType(hit.normal) switch
6970
{
70-
SurfaceType.Ground => hit.transform.parent ?? hit.transform,
71+
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
72+
&& root.GetComponent<BaseCell>() is BaseCell => root,
73+
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
74+
&& root.GetComponent<Base>() is Base => hit.transform,
75+
SurfaceType.Ground when Utils.GetEntityRoot(hit.transform.gameObject)?.transform is Transform root
76+
&& new float[] { 1, 0, 1 / Mathf.Sqrt(2) }
77+
.Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(root.forward, hit.transform.forward))))
78+
=> root,
79+
80+
SurfaceType.Ground when hit.transform.parent is Transform parent
81+
&& parent.GetComponent<BaseCell>() is BaseCell => parent,
82+
SurfaceType.Ground when hit.transform.parent is Transform parent
83+
&& parent.GetComponent<Base>() is Base => hit.transform,
84+
SurfaceType.Ground when hit.transform.parent is Transform parent
85+
&& new float[] { 1, 0, 1 / Mathf.Sqrt(2) }
86+
.Any(dot => Mathf.Approximately(dot, Mathf.Abs(Vector3.Dot(parent.forward, hit.transform.forward))))
87+
=> parent,
88+
7189
_ => hit.transform
7290
};
7391

SnapBuilder/Patches/BuilderPatch.cs

-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public static void BeginHintsPrefix(out bool __state)
2424
[HarmonyPostfix]
2525
public static void BeginHintsPostfix(bool __state)
2626
{
27-
if (Builder.prefab.GetComponent<ConstructableBase>() is ConstructableBase)
28-
{
29-
return;
30-
}
31-
3227
if (__state && Builder.rotationEnabled)
3328
{
3429
ControlHint.Show(Lang.Hint.ToggleFineRotation, SnapBuilder.Config.FineRotation);

SnapBuilder/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
// You can specify all the values or you can default the Build and Revision Numbers
3434
// by using the '*' as shown below:
3535
// [assembly: AssemblyVersion("1.0.*")]
36-
[assembly: AssemblyVersion("1.4.0.0")]
37-
[assembly: AssemblyFileVersion("1.4.0.0")]
36+
[assembly: AssemblyVersion("1.4.1.0")]
37+
[assembly: AssemblyFileVersion("1.4.1.0")]
3838
[assembly: NeutralResourcesLanguage("en-GB")]
3939

SnapBuilder/SnapBuilder.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,10 @@ public static Quaternion CalculateRotation(ref float additiveRotation, RaycastHi
111111
empty.transform.position = hit.point; // Set the parent transform's position to our chosen position
112112

113113
// choose whether we should use the global forward, or the forward of the hitTransform
114-
Vector3 forward = hitTransform.forward.y != 0
114+
Vector3 forward = !Mathf.Approximately(Mathf.Abs(Vector3.Dot(Vector3.up, hitTransform.up)), 1)
115115
&& !Player.main.IsInsideWalkable()
116116
&& hitTransform.GetComponent<BaseCell>() is null
117+
&& hitTransform.GetComponent<Base>() is null
117118
? Vector3.forward
118119
: hitTransform.forward;
119120

SnapBuilder/mod_BELOWZERO.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Id": "SnapBuilder",
33
"DisplayName": "SnapBuilder",
44
"Author": "Tobey Blaber",
5-
"Version": "1.4",
5+
"Version": "1.4.1",
66
"AssemblyName": "Straitjacket.Subnautica.Mods.SnapBuilder.dll",
77
"Enable": true,
88
"Game": "BelowZero",

SnapBuilder/mod_SUBNAUTICA.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"Id": "SnapBuilder",
33
"DisplayName": "SnapBuilder",
44
"Author": "Tobey Blaber",
5-
"Version": "1.4",
5+
"Version": "1.4.1",
66
"AssemblyName": "Straitjacket.Subnautica.Mods.SnapBuilder.dll",
77
"Enable": true,
88
"Game": "Subnautica",

0 commit comments

Comments
 (0)