Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,6 @@ MigrationBackup/
.ionide/

# Fody - auto-generated XML schema
FodyWeavers.xsd
FodyWeavers.xsd
Substrate/Substrate/Local.VS.props
Substrate/ZZCakeBuild/Local.VS.props
14 changes: 14 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<!--
Directory.Build.props is automatically imported by MSBuild before .csproj.
We define VINTAGE_STORY here, and allow users to override it with Local.VS.props
-->

<PropertyGroup>
<!-- Default fallback -->
<VINTAGE_STORY>$(MSBuildThisFileDirectory)</VINTAGE_STORY>
</PropertyGroup>

<!-- Optional per-user override file (NOT committed to Git) -->
<Import Project="Local.VS.props" Condition="Exists('Local.VS.props')" />
</Project>
14 changes: 14 additions & 0 deletions Substrate/Substrate/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<!--
Directory.Build.props is automatically imported by MSBuild before .csproj.
We define VINTAGE_STORY here, and allow users to override it with Local.VS.props
-->

<PropertyGroup>
<!-- Default fallback -->
<VINTAGE_STORY>$(MSBuildThisFileDirectory)</VINTAGE_STORY>
</PropertyGroup>

<!-- Optional per-user override file (NOT committed to Git) -->
<Import Project="Local.VS.props" Condition="Exists('Local.VS.props')" />
</Project>
2 changes: 1 addition & 1 deletion Substrate/Substrate/Substrate.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>bin\$(Configuration)\Mods\mod</OutputPath>
</PropertyGroup>
Expand Down
24 changes: 24 additions & 0 deletions Substrate/Substrate/SubstrateConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;

namespace Substrate
{
/// <summary>
/// Configuration for the Substrate mod.
/// Serialized to /ModConfig/substrateconfig.json.
/// </summary>
[Serializable]
public class SubstrateConfig
{
/// <summary>
/// Global multiplier for mushroom harvest size.
/// 1.0 = default behavior, 0.5 = half, 2.0 = double, etc.
/// </summary>
public float HarvestMultiplier { get; set; } = 1.0f;

/// <summary>
/// Clamp for the final effective grow chance (0..1 typically).
/// Keeps things from going too crazy if HarvestMultiplier is very high.
/// </summary>
public float MaxEffectiveChance { get; set; } = 1.0f;
}
}
56 changes: 54 additions & 2 deletions Substrate/Substrate/SubstrateModSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Substrate.Behaviors;
Expand All @@ -21,29 +22,48 @@ namespace Substrate
{
public class SubstrateModSystem : ModSystem
{
private const string ConfigFileName = "substrateconfig.json";

internal static ILogger Logger { get; private set; }

/// <summary>
/// Active configuration for the Substrate mod.
/// Loaded on the server, defaults used if no file exists.
/// </summary>
internal static SubstrateConfig Config { get; private set; } = new SubstrateConfig();

#region Lifecycle

// Called on server and client
// Useful for registering block/entity classes on both sides
public override void Start(ICoreAPI api)
{
// Register blocks / block entities
api.RegisterBlockClass("BlockFruitingBag", typeof(BlockFruitingBag));
api.RegisterBlockClass("BlockGrowBed", typeof(BlockGrowBed));
api.RegisterBlockEntityClass("FruitingBag", typeof(BlockEntityFruitingBag));

api.RegisterBlockClass("BlockSporePaper", typeof(BlockSporePaper));
api.RegisterBlockEntityClass("SporePaper", typeof(BlockEntitySporePaper));

// Behaviors
api.RegisterCollectibleBehaviorClass("UseInventoryShape", typeof(BehaviorShapeInventory));
api.RegisterBlockBehaviorClass("BehaviorMushroomGrower", typeof(BehaviorMushroomGrower));

// Harmony patches
var harmony = new Harmony(Mod.Info.ModID);
harmony.PatchAll(typeof(SubstrateModSystem).Assembly);

// Only the server needs to own the config file (SP server included)
if (api.Side == EnumAppSide.Server)
{
LoadOrCreateConfig(api);
}
}

public override void AssetsFinalize(ICoreAPI api)
{
// Add UseInventoryShape behavior to all spore harvestable mushrooms
// Add UseInventoryShape behavior to all spore-harvestable mushrooms
foreach (var obj in api.World.Collectibles)
{
if (obj == null || obj.Code == null) continue;
Expand All @@ -64,5 +84,37 @@ public override void StartClientSide(ICoreClientAPI api)
{
Logger = Mod.Logger;
}

#endregion

#region Config

private static void LoadOrCreateConfig(ICoreAPI api)
{
try
{
var loaded = api.LoadModConfig<SubstrateConfig>(ConfigFileName);
if (loaded != null)
{
Config = loaded;
}
else
{
// No file yet, create with defaults
Config = new SubstrateConfig();
}

// Write back to ensure the file exists / is updated with new fields
api.StoreModConfig(Config, ConfigFileName);
Logger?.Notification("[Substrate] Loaded config from {0}", ConfigFileName);
}
catch (Exception e)
{
Logger?.Error("[Substrate] Failed to load config {0}: {1}", ConfigFileName, e);
Config = new SubstrateConfig();
}
}

#endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"A": { type: "item", code: "game:axe-*", isTool: true },
"L": {
"type": "item",
"code": "game:firewood"
"code": "game:stick",
quantity: 2
}
},
width: 1,
Expand Down
4 changes: 2 additions & 2 deletions Substrate/Substrate/modinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"modid": "substrate",
"name": "Substrate",
"authors": [
"willis81808"
"Willis81808, SketchFoxsky"
],
"description": "To be added",
"version": "1.1.1",
"version": "1.1.5",
"dependencies": {
"game": ""
}
Expand Down
2 changes: 1 addition & 1 deletion Substrate/ZZCakeBuild/CakeBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>

Expand Down
14 changes: 14 additions & 0 deletions Substrate/ZZCakeBuild/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<!--
Directory.Build.props is automatically imported by MSBuild before .csproj.
We define VINTAGE_STORY here, and allow users to override it with Local.VS.props
-->

<PropertyGroup>
<!-- Default fallback -->
<VINTAGE_STORY>$(MSBuildThisFileDirectory)</VINTAGE_STORY>
</PropertyGroup>

<!-- Optional per-user override file (NOT committed to Git) -->
<Import Project="Local.VS.props" Condition="Exists('Local.VS.props')" />
</Project>