Configurable settings
Now adjustable constants, and Recovery enable/disable by config file (server sided)
This commit is contained in:
parent
08bdbdb076
commit
563068fadd
7 changed files with 113 additions and 18 deletions
|
|
@ -68,6 +68,10 @@
|
|||
<HintPath>vs_libs\0Harmony.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="protobuf-net">
|
||||
<HintPath>vs_libs\protobuf-net.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="MetalRecoverySystem.cs" />
|
||||
|
|
@ -80,6 +84,7 @@
|
|||
<Compile Include="Harmony\AnvilDaptor.cs" />
|
||||
<Compile Include="MetalRecoverySystem_Components.cs" />
|
||||
<Compile Include="Harmony\GenericItemMortalityDetector.cs" />
|
||||
<Compile Include="Data\AMR_Config.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="modinfo.json">
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ namespace AnvilMetalRecovery.Patches
|
|||
|
||||
if (anvil.BaseMaterial != null && anvil.IsShavable && anvil.SplitCount > 0)
|
||||
{
|
||||
dsc.AppendFormat("[ {0} ] : {1} × {2}\n", anvil.SplitCount, Lang.GetUnformatted($"fma:item-metal_shaving-{anvil.BaseMetal}"), anvil.ShavingQuantity);
|
||||
dsc.AppendFormat("[ {0} ] : {1} × {2}\n", anvil.SplitCount, Lang.GetUnformatted($"game:item-metalbit-{anvil.BaseMetal}"), anvil.ShavingQuantity);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +104,7 @@ namespace AnvilMetalRecovery.Patches
|
|||
public static AssetLocation MetalShavingsCode {
|
||||
get
|
||||
{
|
||||
return new AssetLocation(@"fma", @"metal_shaving");
|
||||
return new AssetLocation(GlobalConstants.DefaultDomain, @"metalbit");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -114,6 +114,12 @@ namespace AnvilMetalRecovery.Patches
|
|||
return (EnumVoxelMaterial)bea.Voxels[X, Y, Z];
|
||||
}
|
||||
|
||||
private AMRConfig CachedConfiguration {
|
||||
get
|
||||
{
|
||||
return ( AMRConfig )bea.Api.ObjectCache[MetalRecoverySystem._configFilename];
|
||||
}
|
||||
}
|
||||
|
||||
public int SplitCount {
|
||||
get
|
||||
|
|
@ -136,7 +142,7 @@ namespace AnvilMetalRecovery.Patches
|
|||
|
||||
public int ShavingQuantity
|
||||
{
|
||||
get { return (SplitCount / shavingValue); }
|
||||
get { return ( int )(Math.Round(SplitCount * CachedConfiguration.VoxelEquivalentValue) / shavingValue); }
|
||||
}
|
||||
|
||||
internal IAnvilWorkable AnvilWorkpiece {
|
||||
|
|
@ -171,7 +177,7 @@ namespace AnvilMetalRecovery.Patches
|
|||
internal void IssueShavings(IPlayer byPlayer )
|
||||
{
|
||||
if (this.SplitCount > 0) {
|
||||
int shavingQty = ( int )(SplitCount / shavingValue);
|
||||
int shavingQty = ShavingQuantity;
|
||||
|
||||
if (shavingQty > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ namespace AnvilMetalRecovery
|
|||
public override void GetHeldItemInfo(ItemSlot inSlot, System.Text.StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
|
||||
{
|
||||
var metalName = MetalName(inSlot.Itemstack);
|
||||
var metalQuantity = ( int )Math.Floor(MetalQuantity(inSlot.Itemstack) * MetalRecoverySystem.IngotVoxelEquivalent);
|
||||
var metalQuantity = ( int )Math.Floor(MetalQuantity(inSlot.Itemstack) * AnvilMetalRecoveryMod.CachedConfiguration.VoxelEquivalentValue);
|
||||
var props = RegenerateCombustablePropsFromStack(inSlot.Itemstack);
|
||||
|
||||
if (props != null && props.MeltingPoint > 0) {
|
||||
|
|
@ -133,7 +133,7 @@ namespace AnvilMetalRecovery
|
|||
MaxTemperature = sourceMetalItem.CombustibleProps.MaxTemperature,
|
||||
SmokeLevel = sourceMetalItem.CombustibleProps.SmokeLevel,
|
||||
SmeltedRatio = 100,
|
||||
SmeltedStack = new JsonItemStack( ) { Type = EnumItemClass.Item, Code = sourceMetalItem.Code.Clone( ), Quantity = (int)Math.Floor(metalUnits * MetalRecoverySystem.IngotVoxelEquivalent) }
|
||||
SmeltedStack = new JsonItemStack( ) { Type = EnumItemClass.Item, Code = sourceMetalItem.Code.Clone( ), Quantity = (int)Math.Floor(metalUnits * AnvilMetalRecoveryMod.CachedConfiguration.VoxelEquivalentValue) }
|
||||
};
|
||||
aCombustibleProps.SmeltedStack.Resolve(api.World, "VariableMetalItem_regen", true);
|
||||
|
||||
|
|
@ -164,7 +164,7 @@ namespace AnvilMetalRecovery
|
|||
Item metalBits = api.World.GetItem(new AssetLocation(GlobalConstants.DefaultDomain, @"metalbit-" + metalCode));
|
||||
if (metalBits != null)
|
||||
{
|
||||
gridRecipe.Output.Quantity = ( int )(Math.Round(metalUnits * MetalRecoverySystem.IngotVoxelEquivalent) / 5);
|
||||
gridRecipe.Output.Quantity = ( int )(Math.Round(metalUnits * AnvilMetalRecoveryMod.CachedConfiguration.VoxelEquivalentValue) / 5);
|
||||
gridRecipe.Output.Code = metalBits.Code;
|
||||
gridRecipe.Output.Resolve(api.World, "VariableMetalItem_crafting");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,14 +12,18 @@ using Vintagestory.Server;
|
|||
namespace AnvilMetalRecovery
|
||||
{
|
||||
public partial class MetalRecoverySystem : ModSystem
|
||||
{
|
||||
{
|
||||
internal const string _configFilename = @"amr_config.json";
|
||||
internal const string anvilKey = @"Anvil";
|
||||
internal const string metalFragmentsCode = @"fma:metal_fragments";
|
||||
internal const string metalShavingsCode = @"metal_shaving";
|
||||
internal const string itemFilterListCacheKey = @"AMR_ItemFilters";
|
||||
public const float IngotVoxelEquivalent = 2.38f;
|
||||
public const float IngotVoxelDefault = 2.38f;
|
||||
public const string ItemDamageChannelName = @"ItemDamageEvents";
|
||||
|
||||
internal IServerNetworkChannel _ConfigDownlink;
|
||||
internal IClientNetworkChannel _ConfigUplink;
|
||||
|
||||
private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
|
||||
|
||||
private ICoreAPI CoreAPI;
|
||||
|
|
@ -27,6 +31,17 @@ namespace AnvilMetalRecovery
|
|||
private ServerCoreAPI ServerCore { get; set; }
|
||||
private ClientCoreAPI ClientCore { get; set; }
|
||||
|
||||
internal AMRConfig CachedConfiguration {
|
||||
get
|
||||
{
|
||||
return ( AMRConfig )CoreAPI.ObjectCache[_configFilename];
|
||||
}
|
||||
set
|
||||
{
|
||||
CoreAPI.ObjectCache.Add(_configFilename, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Valid Items that are 'recoverable' (Asset Codes) only
|
||||
|
|
@ -90,8 +105,11 @@ namespace AnvilMetalRecovery
|
|||
else {
|
||||
Mod.Logger.Error("Cannot access 'ServerCoreAPI' class: API (implimentation) has changed, Contact Developer!");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
PrepareServersideConfig( );
|
||||
PrepareDownlinkChannel( );
|
||||
ServerAPI.Event.PlayerJoin += SendClientConfigMessage;
|
||||
ServerAPI.Event.ServerRunPhase(EnumServerRunPhase.Shutdown, PersistServersideConfig);
|
||||
ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
|
||||
|
||||
SetupGeneralObservers( );
|
||||
|
|
@ -117,8 +135,7 @@ namespace AnvilMetalRecovery
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
ListenForServerConfigMessage( );
|
||||
Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
|
||||
}
|
||||
|
||||
|
|
@ -135,6 +152,68 @@ namespace AnvilMetalRecovery
|
|||
ServerCore.Event.RegisterEventBusListener(Item_DamageEventReciever, 1.0f, ItemDamageChannelName);
|
||||
}
|
||||
|
||||
private void PrepareServersideConfig( )
|
||||
{
|
||||
AMRConfig config = ServerAPI.LoadModConfig<AMRConfig>(_configFilename);
|
||||
|
||||
if (config == null) {
|
||||
//Regen default
|
||||
Mod.Logger.Warning("Regenerating default config as it was missing / unparsable...");
|
||||
ServerAPI.StoreModConfig<AMRConfig>(new AMRConfig( ), _configFilename);
|
||||
config = ServerAPI.LoadModConfig<AMRConfig>(_configFilename);
|
||||
}
|
||||
|
||||
this.CachedConfiguration = config;
|
||||
}
|
||||
|
||||
private void PersistServersideConfig( )
|
||||
{
|
||||
if (this.CachedConfiguration != null) {
|
||||
Mod.Logger.Notification("Persisting configuration.");
|
||||
ServerAPI.StoreModConfig<AMRConfig>(this.CachedConfiguration, _configFilename);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareDownlinkChannel( )
|
||||
{
|
||||
_ConfigDownlink = ServerAPI.Network.RegisterChannel(_configFilename);
|
||||
_ConfigDownlink.RegisterMessageType<AMRConfig>( );
|
||||
}
|
||||
|
||||
private void SendClientConfigMessage(IServerPlayer byPlayer)
|
||||
{
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("Sending joiner: {0} a copy of config data.", byPlayer.PlayerName);
|
||||
#endif
|
||||
|
||||
_ConfigDownlink.SendPacket<AMRConfig>(this.CachedConfiguration, byPlayer);
|
||||
}
|
||||
|
||||
private void ListenForServerConfigMessage( )
|
||||
{
|
||||
_ConfigUplink = ClientCore.Network.RegisterChannel(_configFilename);
|
||||
_ConfigUplink = _ConfigUplink.RegisterMessageType<AMRConfig>( );
|
||||
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("Registered RX channel: '{0}'", _ConfigUplink.ChannelName);
|
||||
#endif
|
||||
|
||||
_ConfigUplink.SetMessageHandler<AMRConfig>(RecievedConfigMessage);
|
||||
}
|
||||
|
||||
private void RecievedConfigMessage(AMRConfig networkMessage)
|
||||
{
|
||||
#if DEBUG
|
||||
Mod.Logger.Debug("Got Config message!");
|
||||
#endif
|
||||
|
||||
if (networkMessage != null) {
|
||||
Mod.Logger.Debug("Message value; Recover Broken Tools:{0}, VoxelEquiv#{1:F2}", networkMessage.ToolFragmentRecovery, networkMessage.VoxelEquivalentValue);
|
||||
this.CachedConfiguration = networkMessage;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace AnvilMetalRecovery
|
|||
setVoxels = recipie.Voxels.OfType<bool>( ).Count(vox => vox);
|
||||
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug($"Info: {recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{metalObject.Code}' voxel = ~{setVoxels * IngotVoxelEquivalent:F1} metal Units");
|
||||
Mod.Logger.VerboseDebug($"Info: {recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{metalObject.Code}' voxel = ~{setVoxels * CachedConfiguration.VoxelEquivalentValue:F1} metal Units");
|
||||
#endif
|
||||
//Direct output *IS* tool or tool-like Durability type item (chisel )
|
||||
if (outputItem.Tool.HasValue || outputItem.Durability > 1) {
|
||||
|
|
@ -125,11 +125,11 @@ namespace AnvilMetalRecovery
|
|||
Mod.Logger.VerboseDebug("Item_Damage Rx: Item:{0} InventoryID '{1}' Slot#{2} PlayerUID:{3}", hotbarData.ItemCode.ToString( ), hotbarData.InventoryID, hotbarData.Inventory_SlotID, hotbarData.PlayerUID);
|
||||
#endif
|
||||
|
||||
if (ItemFilterList.Contains(hotbarData.ItemCode)) {
|
||||
if (CachedConfiguration.ToolFragmentRecovery && ItemFilterList.Contains(hotbarData.ItemCode)) {
|
||||
|
||||
RecoveryEntry rec = itemToVoxelLookup[hotbarData.ItemCode];
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("broken-item {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ), (rec.Quantity * IngotVoxelEquivalent), rec.IngotCode.ToShortString( ));
|
||||
Mod.Logger.VerboseDebug("broken-item {0} WORTH: {1:F1}*{2} units", hotbarData.ItemCode.ToString( ), (rec.Quantity * CachedConfiguration.VoxelEquivalentValue), rec.IngotCode.ToShortString( ));
|
||||
#endif
|
||||
|
||||
if (String.IsNullOrEmpty(hotbarData.PlayerUID) || String.IsNullOrEmpty(hotbarData.InventoryID)) return;
|
||||
|
|
@ -163,7 +163,11 @@ namespace AnvilMetalRecovery
|
|||
VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
|
||||
ItemStack metalFragmentsStack = new ItemStack(variableMetal, 1);
|
||||
variableMetal.ApplyMetalProperties(rec, ref metalFragmentsStack);
|
||||
spim.TryGiveItemstack(metalFragmentsStack, true);
|
||||
if (spim.TryGiveItemstack(metalFragmentsStack, true) == false)
|
||||
{
|
||||
//Player with full Inv.
|
||||
ServerAPI.World.SpawnItemEntity(metalFragmentsStack, playerTarget.Entity.Pos.XYZ);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,5 +24,6 @@
|
|||
"fma:item-metal_shaving-uranium": "Uranium Shavings",
|
||||
"fma:item-metal_shaving-zinc": "Zinc Shavings",
|
||||
"fma:item-metal_fragments":"Broken metal fragments.",
|
||||
"fma:itemdesc-item-metal_fragments": "Try, chopping it apart with a Chisel...",
|
||||
"fma:metal_worth":"Worth {0} units of {1}.",
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
"description" : "Get back lost scrap and smithing discards. Plus more.",
|
||||
"authors": ["Melchior"],
|
||||
"ModID":"metalrecovery",
|
||||
"version": "0.1.12",
|
||||
"version": "0.1.13",
|
||||
"dependencies": {
|
||||
"game": "1.15.3",
|
||||
"survival": ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue