Skip to content

Commit

Permalink
Added placeable Coin Piles.
Browse files Browse the repository at this point in the history
Cleaned up names to be consistent with how other Valheim items are named.
Added configurable comfort levels for the Coin Pile and the Gold Stack.
Gold stacks now act like stone when it comes to support and placement.
Added LOD to Gold Stack.
Configs are server synced and enforceable.
Added NexusId for NexusUpdate
  • Loading branch information
Digitalroot committed Aug 22, 2021
1 parent dec76f9 commit 08a065c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
Binary file modified Digitalroot.Valheim.GoldBars/Assets/goldbar
Binary file not shown.
4 changes: 2 additions & 2 deletions Digitalroot.Valheim.GoldBars/Assets/goldbar.manifest
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ManifestFileVersion: 0
CRC: 2071901047
CRC: 1034725428
Hashes:
AssetFileHash:
serializedVersion: 2
Hash: 9dae3f13c352580b18fc6cd9662ab161
Hash: 5ce449734985d83597488d68658ba38f
TypeTreeHash:
serializedVersion: 2
Hash: 00e7c6fed9bd803af65bb04f52de1402
Expand Down
71 changes: 47 additions & 24 deletions Digitalroot.Valheim.GoldBars/Main.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx;
using BepInEx.Configuration;
using JetBrains.Annotations;
using Jotunn.Configs;
using Jotunn.Entities;
Expand All @@ -13,12 +14,16 @@ namespace Digitalroot.Valheim.GoldBars
[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.Minor)]
public class Main : BaseUnityPlugin
{
public const string Version = "1.0.0";
public const string Version = "1.1.0";
public const string Name = "Digitalroot GoldBars";
public const string Guid = "digitalroot.mods.GoldBars";
public const string Namespace = "Digitalroot.Valheim.GoldBars";
public static Main Instance;

public static ConfigEntry<int> NexusId;
public static ConfigEntry<int> CoinPilePieceComfort;
public static ConfigEntry<int> GoldStackPieceComfort;

private GameObject _goldBar;
private GameObject _coinPile;
private GameObject _coinPilePiece;
Expand All @@ -28,6 +33,9 @@ public class Main : BaseUnityPlugin
public Main()
{
Instance = this;
NexusId = Config.Bind("General", "NexusID", 1448, new ConfigDescription("Nexus mod ID for updates", null, new ConfigurationManagerAttributes { IsAdminOnly = false, Browsable = false, ReadOnly = true }));
CoinPilePieceComfort = Config.Bind("General", "CoinPilePieceComfort", 1, new ConfigDescription("Coin Pile Comfort Level", null, new ConfigurationManagerAttributes { IsAdminOnly = true }));
GoldStackPieceComfort = Config.Bind("General", "GoldStackPieceComfort", 2, new ConfigDescription("Gold Stack Comfort Level", null, new ConfigurationManagerAttributes { IsAdminOnly = true }));
}

[UsedImplicitly]
Expand Down Expand Up @@ -70,7 +78,7 @@ private void LoadPrefabs()

private void LoadRecipes()
{
CustomRecipe coinRecipe = new CustomRecipe(new RecipeConfig()
CustomRecipe coinRecipe = new CustomRecipe(new RecipeConfig
{
Amount = 200, Item = "Coins", // Name of the item prefab to be crafted
Name = "PileToCoins"
Expand All @@ -81,7 +89,7 @@ private void LoadRecipes()
});
ItemManager.Instance.AddRecipe(coinRecipe);

CustomRecipe coinRecipe2 = new CustomRecipe(new RecipeConfig()
CustomRecipe coinRecipe2 = new CustomRecipe(new RecipeConfig
{
Amount = 100, Item = "Coins", CraftingStation = "forge", Name = "GoldIngotToCoins", MinStationLevel = 2, Requirements = new[] // Resources and amount needed for it to be crafted
{
Expand All @@ -102,42 +110,57 @@ private void LoadConversion()

private void LoadPieces()
{
_goldStackPiece = _assetBundle.LoadAsset<GameObject>("assets/goldingot/piece_goldstack.prefab");
AddGoldStack();
AddCoinPile();
}

private void AddCoinPile()
{
_coinPilePiece = _assetBundle.LoadAsset<GameObject>("assets/goldingot/piece_coinpile.prefab");
#if DEBUG
Jotunn.Logger.LogDebug($"_goldStackPiece == null : {_goldStackPiece == null}"); // This is null?
Jotunn.Logger.LogDebug($"_coinPilePiece == null : {_coinPilePiece == null}"); // This is null?
#endif

var goldBarStack = new CustomPiece(_goldStackPiece,
var coinPilePiece = new CustomPiece(_coinPilePiece,
new PieceConfig
{
PieceTable = "_HammerPieceTable",
CraftingStation = "",
Enabled = true,
Requirements = new[]
PieceTable = "_HammerPieceTable", CraftingStation = "", Enabled = true, Requirements = new[]
{
new RequirementConfig { Item = "GoldIngot", Amount = 48, Recover = true },
new RequirementConfig { Item = "Coins", Amount = 200, Recover = true },
}
});
PieceManager.Instance.AddPiece(goldBarStack);

})
{
Piece =
{
m_comfort = CoinPilePieceComfort.Value
}
};
PieceManager.Instance.AddPiece(coinPilePiece);
}

_coinPilePiece = _assetBundle.LoadAsset<GameObject>("assets/goldingot/piece_coinpile.prefab");
private void AddGoldStack()
{
_goldStackPiece = _assetBundle.LoadAsset<GameObject>("assets/goldingot/piece_goldstack.prefab");
#if DEBUG
Jotunn.Logger.LogDebug($"_coinPilePiece == null : {_coinPilePiece == null}"); // This is null?
Jotunn.Logger.LogDebug($"_goldStackPiece == null : {_goldStackPiece == null}"); // This is null?
#endif

var coinPilePiece = new CustomPiece(_coinPilePiece,
var goldBarStack = new CustomPiece(_goldStackPiece,
new PieceConfig
{
PieceTable = "_HammerPieceTable",
CraftingStation = "",
Enabled = true,
Requirements = new[]
PieceTable = "_HammerPieceTable", CraftingStation = "", Enabled = true, Requirements = new[]
{
new RequirementConfig { Item = "Coins", Amount = 200, Recover = true },
new RequirementConfig { Item = "GoldIngot", Amount = 48, Recover = true },
}
});
PieceManager.Instance.AddPiece(coinPilePiece);
,
})
{
Piece =
{
m_comfort = GoldStackPieceComfort.Value
}
};
PieceManager.Instance.AddPiece(goldBarStack);
}
}
}

0 comments on commit 08a065c

Please sign in to comment.