VintageStoryFullMachineAge/AnvilMetalRecovery/MetalRecoverySystem.cs
melchior e08d051014 Entirely NEW method of detecting item expiry,
HotbarObserve class - now obsolete
2021-07-06 21:09:49 -04:00

147 lines
3.7 KiB
C#

using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using Vintagestory.API.Client;
using Vintagestory.API.Common;
using Vintagestory.API.Server;
using Vintagestory.Client.NoObf;
using Vintagestory.Server;
namespace AnvilMetalRecovery
{
public partial class MetalRecoverySystem : ModSystem
{
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 string HotbarChannelName = @"HotbarEvents";
private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
private ICoreAPI CoreAPI;
private ICoreServerAPI ServerAPI;
private ServerCoreAPI ServerCore { get; set; }
private ClientCoreAPI ClientCore { get; set; }
/// <summary>
/// Valid Items that are 'recoverable' (Asset Codes) only
/// </summary>
/// <value>The item filter list.</value>
public List<AssetLocation> ItemFilterList {
get
{
return itemToVoxelLookup.Keys.ToList( );
}
}
/// <summary>
/// ALL Items that have were derivable from smithing recipies (and are tool / durable)
/// </summary>
/// <value>The item filter list.</value>
public Dictionary<AssetLocation, RecoveryEntry> ItemRecoveryTable {
get
{
return itemToVoxelLookup;
}
}
public override bool AllowRuntimeReload {
get { return false; }
}
public override bool ShouldLoad(EnumAppSide forSide)
{
return true;
}
public override double ExecuteOrder( )
{
return 0.11d;
}
public override void Start(ICoreAPI api)
{
this.CoreAPI = api;
RegisterItemMappings( );
#if DEBUG
//Harmony.DEBUG = true;
#endif
var harmony = new Harmony(this.Mod.Info.ModID);
harmony.PatchAll( );
base.Start(api);
}
public override void StartServerSide(ICoreServerAPI api)
{
this.ServerAPI = api;
if (api is ServerCoreAPI) {
ServerCore = api as ServerCoreAPI;
}
else {
Mod.Logger.Error("Cannot access 'ServerCoreAPI' class: API (implimentation) has changed, Contact Developer!");
return;
}
//ServerCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
SetupHotbarObserver( );
Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
#if DEBUG
ServerAPI.RegisterCommand("durability", "edit durability of item", " (Held tool) and #", EditDurability, Privilege.give);
#endif
}
public override void StartClientSide(ICoreClientAPI api)
{
base.StartClientSide(api);
if (api is ClientCoreAPI) {
ClientCore = api as ClientCoreAPI;
}
else {
Mod.Logger.Error("Cannot access 'ClientCoreAPI' class: API (implimentation) has changed, Contact Developer!");
return;
}
//ClientCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
Mod.Logger.VerboseDebug("Anvil Metal Recovery - should be installed...");
}
private void RegisterItemMappings( )
{
this.CoreAPI.RegisterItemClass(@"VariableMetalItem", typeof(VariableMetalItem));
this.CoreAPI.RegisterItemClass(@"SmartSmeltableItem", typeof(SmartSmeltableItem));
}
private void SetupHotbarObserver( ){
//ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior));
ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarChannelName);
//ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect;
}
}
}