Skip to content

Commit

Permalink
Merge branch 'master' into docs
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeTwentyThree committed Jul 6, 2023
2 parents c7660e5 + 822e1a4 commit 2815b40
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
69 changes: 69 additions & 0 deletions Example mod/CustomBuildableExample.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using BepInEx;
using Nautilus.Crafting;
using Nautilus.Assets;
using Nautilus.Assets.Gadgets;
using Nautilus.Utility;
using UnityEngine;
using Nautilus.Assets.PrefabTemplates;
#if SUBNAUTICA
using Ingredient = CraftData.Ingredient;
#endif

namespace Nautilus.Examples;

[BepInPlugin("com.snmodding.nautilus.custombuildable", "Nautilus Custom Buildable Example Mod", PluginInfo.PLUGIN_VERSION)]
[BepInDependency("com.snmodding.nautilus")]
public class CustomBuildableExample : BaseUnityPlugin
{
private void Awake()
{
BuildableTallLocker.Register();
}
}

public static class BuildableTallLocker
{
public static PrefabInfo Info { get; } = PrefabInfo.WithTechType("TallLocker", "Tall Locker", "A tall locker.")
// set the icon to that of the vanilla locker:
.WithIcon(SpriteManager.Get(TechType.Locker));

public static void Register()
{
// create prefab:
CustomPrefab prefab = new CustomPrefab(Info);

// copy the model of a vanilla wreck piece (which looks like a taller locker):
CloneTemplate lockerClone = new CloneTemplate(Info, "cd34fecd-794c-4a0c-8012-dd81b77f2840");

// modify the cloned model:
lockerClone.ModifyPrefab += obj =>
{
// allow it to be placced inside bases and submarines on the ground, and can be rotated:
ConstructableFlags constructableFlags = ConstructableFlags.Inside | ConstructableFlags.Rotatable | ConstructableFlags.Ground | ConstructableFlags.Submarine;
// find the object that holds the model:
GameObject model = obj.transform.Find("submarine_locker_04").gameObject;
// this line is only necessary for the tall locker so that the door is also part of the model:
obj.transform.Find("submarine_locker_03_door_01").parent = model.transform;
// add all components necessary for it to be built:
PrefabUtils.AddConstructable(obj, Info.TechType, constructableFlags, model);
// allow it to be opened as a storage container:
PrefabUtils.AddStorageContainer(obj, "StorageRoot", "TallLocker", 3, 8, true);
};

// assign the created clone model to the prefab itself:
prefab.SetGameObject(lockerClone);

// assign it to the correct tab in the builder tool:
prefab.SetPdaGroupCategory(TechGroup.InteriorModules, TechCategory.InteriorModule);

// set recipe:
prefab.SetRecipe(new RecipeData(new Ingredient(TechType.Titanium, 3), new Ingredient(TechType.Glass, 1)));

// finally, register it into the game:
prefab.Register();
}
}
5 changes: 4 additions & 1 deletion Nautilus/Documentation/guides/dev-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ To install the template, run the following command in a terminal:
dotnet new -i Subnautica.Templates
```

> [!NOTE]
> If you receive an error about not having any defined/enabled NuGet sources, you may need to run the following command first: `dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org`
Once the install is completed, you will receive an output similar to the message below displaying the process as successful.
```bash
Template Name Short Name Language Tags
Expand Down Expand Up @@ -125,4 +128,4 @@ Now you can add more code to the project, then build and put the compiled dll in
dotnet new bzmod -n MyBeautifulMod
```

Now you can add more code to the project, then build and put the compiled dll in SubnauticaZero/BepInEx/plugins/.
Now you can add more code to the project, then build and put the compiled dll in SubnauticaZero/BepInEx/plugins/.

0 comments on commit 2815b40

Please sign in to comment.