Entirely NEW method of detecting item expiry,
HotbarObserve class - now obsolete
This commit is contained in:
parent
5953960053
commit
e08d051014
10 changed files with 148 additions and 27 deletions
|
|
@ -7,7 +7,7 @@
|
|||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>AnvilMetalRecovery</RootNamespace>
|
||||
<AssemblyName>AnvilMetalRecovery</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
|
@ -73,13 +73,13 @@
|
|||
<Compile Include="MetalRecoverySystem.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Helpers.cs" />
|
||||
<Compile Include="EntityBehaviors\HotbarObserverBehavior.cs" />
|
||||
<Compile Include="EntityBehaviors\HotbarObserverData.cs" />
|
||||
<Compile Include="Data\RecoveryEntry.cs" />
|
||||
<Compile Include="Items\VariableMetalItem.cs" />
|
||||
<Compile Include="Items\SmartSmeltableItem.cs" />
|
||||
<Compile Include="Harmony\AnvilDaptor.cs" />
|
||||
<Compile Include="MetalRecoverySystem_Components.cs" />
|
||||
<Compile Include="Harmony\GenericItemMortalityDetector.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="modinfo.json">
|
||||
|
|
@ -98,7 +98,6 @@
|
|||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="assets\fma\patches\hotbarobserver_for_playerentity.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="modicon.png">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
|
@ -113,6 +112,7 @@
|
|||
<None Include="assets\fma\lang\de.json">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
<None Include="EntityBehaviors\HotbarObserverBehavior.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="assets\" />
|
||||
|
|
|
|||
|
|
@ -13,12 +13,13 @@ using Vintagestory.Server;
|
|||
|
||||
namespace AnvilMetalRecovery
|
||||
{
|
||||
#region OBSOLETE
|
||||
/// <summary>
|
||||
/// Push events to Messagebus on certain INVENTORY hotbar actions
|
||||
/// </summary>
|
||||
public class HotbarObserverBehavior : EntityBehavior
|
||||
{
|
||||
public const string HotbarChannelName = @"HotbarEvents";
|
||||
|
||||
protected static List<AssetLocation> ItemFilterList;
|
||||
protected HotbarObserverData TrackedItemData;
|
||||
public bool Connected { get; private set;}
|
||||
|
|
@ -160,7 +161,7 @@ namespace AnvilMetalRecovery
|
|||
}
|
||||
return false;//When should this be true?
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,13 +9,15 @@ namespace AnvilMetalRecovery
|
|||
public class HotbarObserverData : IAttribute
|
||||
{
|
||||
public AssetLocation ItemCode { get; private set; }
|
||||
public int SlotID { get; private set; }
|
||||
public string InventoryID { get; private set; }
|
||||
public int Inventory_SlotID { get; private set; }
|
||||
public string PlayerUID { get; private set; }
|
||||
|
||||
public HotbarObserverData(int slotID, Item item, string playerUID)
|
||||
public HotbarObserverData(string inventoryID, int slotID, AssetLocation itemCode, string playerUID)
|
||||
{
|
||||
SlotID = slotID;
|
||||
this.ItemCode = item.Code.Clone();
|
||||
InventoryID = inventoryID;
|
||||
Inventory_SlotID = slotID;
|
||||
this.ItemCode = itemCode.Clone();
|
||||
PlayerUID = playerUID;
|
||||
}
|
||||
|
||||
|
|
@ -26,7 +28,8 @@ namespace AnvilMetalRecovery
|
|||
|
||||
public void FromBytes(BinaryReader stream)
|
||||
{
|
||||
SlotID = stream.ReadInt32( );
|
||||
InventoryID = stream.ReadString( );
|
||||
Inventory_SlotID = stream.ReadInt32( );
|
||||
ItemCode = new AssetLocation( stream.ReadString( ));
|
||||
PlayerUID = stream.ReadString( );
|
||||
}
|
||||
|
|
@ -43,7 +46,8 @@ namespace AnvilMetalRecovery
|
|||
|
||||
public void ToBytes(BinaryWriter stream)
|
||||
{
|
||||
stream.Write(SlotID );
|
||||
stream.Write(InventoryID );
|
||||
stream.Write(Inventory_SlotID);
|
||||
stream.Write(ItemCode.ToString());
|
||||
stream.Write(PlayerUID);
|
||||
}
|
||||
|
|
|
|||
87
AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs
Normal file
87
AnvilMetalRecovery/Harmony/GenericItemMortalityDetector.cs
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
using HarmonyLib;
|
||||
|
||||
using Vintagestory.API.Common;
|
||||
using Vintagestory.API.Common.Entities;
|
||||
using Vintagestory.API.Config;
|
||||
using Vintagestory.API.MathTools;
|
||||
using Vintagestory.GameContent;
|
||||
|
||||
namespace AnvilMetalRecovery.Patches
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Harmony patcher class to detect Item (CollectableObject) Hitpoint damage and generate Destruction events from 'Damage' method calls
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(CollectibleObject))]
|
||||
public class GenericItemMortalityDetector
|
||||
{
|
||||
|
||||
[HarmonyPrepare]
|
||||
private static bool DeduplicatePatching(MethodBase original, Harmony harmony)
|
||||
{
|
||||
if (original != null)
|
||||
{
|
||||
foreach (var patched in harmony.GetPatchedMethods( ))
|
||||
{
|
||||
if (patched.Name == original.Name) return false; //SKIPS PATCHING, its already there
|
||||
}
|
||||
}
|
||||
|
||||
return true;//patch all other methods
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(CollectibleObject.DamageItem))]
|
||||
private static void Prefix_DamageItem(IWorldAccessor world, Entity byEntity, ItemSlot itemslot, int amount, CollectibleObject __instance)//Object __state
|
||||
{
|
||||
if (world.Api.Side.IsClient( )) return;
|
||||
#if DEBUG
|
||||
world.Api.Logger.VerboseDebug("Prefix_DamageItem: {0} by {1}", __instance.Code, amount);
|
||||
#endif
|
||||
if (DamageFilterTool.Ignore(world, __instance)) return;
|
||||
#if DEBUG
|
||||
world.Api.Logger.VerboseDebug("InventoryID: {0}, Class: {1}", itemslot.Inventory.InventoryID, itemslot.Inventory.ClassName);//Class: hotbar
|
||||
world.Api.Logger.VerboseDebug("Thing has HP: {0}", itemslot.Itemstack.Hitpoints( ));
|
||||
#endif
|
||||
if (itemslot.Itemstack.Hitpoints( ) <= amount)
|
||||
{
|
||||
#if DEBUG
|
||||
world.Api.Logger.VerboseDebug("Sending Item Expiry Event");
|
||||
#endif
|
||||
var playerEntity = byEntity as EntityPlayer;
|
||||
var hotbarEvent = new HotbarObserverData(itemslot.Inventory.InventoryID, itemslot.Inventory.GetSlotId(itemslot), __instance.Code, (playerEntity == null ? String.Empty : playerEntity.PlayerUID));
|
||||
world.Api.Event.PushEvent(MetalRecoverySystem.HotbarChannelName, hotbarEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Specialized Multitool for Setting / Getting, Checking Item-Filter list; and Ignore non-Items
|
||||
/// </summary>
|
||||
internal static class DamageFilterTool
|
||||
{
|
||||
|
||||
public static bool Ignore(IWorldAccessor world, CollectibleObject that)
|
||||
{
|
||||
if (that.ItemClass != EnumItemClass.Item || that.Durability <= 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = ( Dictionary<AssetLocation, RecoveryEntry> )world.Api.ObjectCache[MetalRecoverySystem.itemFilterListCacheKey];
|
||||
|
||||
if (itemToVoxelLookup.ContainsKey(that.Code)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -16,7 +16,9 @@ namespace AnvilMetalRecovery
|
|||
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?
|
||||
|
||||
|
|
@ -132,9 +134,9 @@ namespace AnvilMetalRecovery
|
|||
|
||||
|
||||
private void SetupHotbarObserver( ){
|
||||
ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior));
|
||||
ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarObserverBehavior.HotbarChannelName);
|
||||
ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect;
|
||||
//ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior));
|
||||
ServerCore.Event.RegisterEventBusListener(HotbarEventReciever, 1.0f, HotbarChannelName);
|
||||
//ServerCore.Event.PlayerNowPlaying += HotbarObserverBehavior.DirectConnect;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -98,6 +98,8 @@ namespace AnvilMetalRecovery
|
|||
}
|
||||
}
|
||||
|
||||
//Cache list too
|
||||
ServerAPI.ObjectCache.Add(itemFilterListCacheKey, itemToVoxelLookup);
|
||||
}
|
||||
|
||||
private bool SmithingRecipieValidator(SmithingRecipe aRecipie )
|
||||
|
|
@ -119,7 +121,7 @@ namespace AnvilMetalRecovery
|
|||
HotbarObserverData hotbarData = data as HotbarObserverData;
|
||||
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("HotbarEvent Rx: Item:{0} Slot#{1} PlayerUID:{2}", hotbarData.ItemCode.ToString( ), hotbarData.SlotID, hotbarData.PlayerUID);
|
||||
Mod.Logger.VerboseDebug("HotbarEvent 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)) {
|
||||
|
|
@ -130,13 +132,13 @@ namespace AnvilMetalRecovery
|
|||
|
||||
var playerTarget = ServerAPI.World.PlayerByUid(hotbarData.PlayerUID);
|
||||
var hotbarInv = playerTarget.InventoryManager.GetHotbarInventory( );
|
||||
var hotSlot = hotbarInv[hotbarData.SlotID];
|
||||
var hotSlot = hotbarInv[hotbarData.Inventory_SlotID];
|
||||
var spim = playerTarget.InventoryManager as ServerPlayerInventoryManager;
|
||||
bool probablyHotbar = hotbarData.InventoryID.StartsWith(@"hotbar", StringComparison.Ordinal);
|
||||
|
||||
|
||||
if (hotSlot.Empty) {
|
||||
if (probablyHotbar && hotSlot.Empty) {
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.SlotID);
|
||||
Mod.Logger.VerboseDebug("Directly inserting fragments into hotbar slot# {0}", hotbarData.Inventory_SlotID);
|
||||
#endif
|
||||
|
||||
VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
|
||||
|
|
@ -149,7 +151,7 @@ namespace AnvilMetalRecovery
|
|||
}
|
||||
else {
|
||||
#if DEBUG
|
||||
Mod.Logger.VerboseDebug("Occupied Hotbar slot# {0}; shoving item in general direction of player...", hotbarData.SlotID);
|
||||
Mod.Logger.VerboseDebug("Hotbar (or crafting?) slot#{0} occupied; shoving {1} in general direction of player...", hotbarData.Inventory_SlotID,hotbarData.ItemCode.ToShortString());
|
||||
#endif
|
||||
|
||||
VariableMetalItem variableMetal = ServerAPI.World.GetItem(new AssetLocation(metalFragmentsCode)) as VariableMetalItem;
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@ using System.Runtime.CompilerServices;
|
|||
// Change them to the values specific to your project.
|
||||
|
||||
[assembly: AssemblyTitle("AnvilMetalRecovery")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("")]
|
||||
[assembly: AssemblyCopyright("librarian")]
|
||||
[assembly: AssemblyDescription("Mod plugin for V.S.")]
|
||||
#if DEBUG
|
||||
[assembly: AssemblyConfiguration("DEBUG")]
|
||||
#else
|
||||
[assembly: AssemblyConfiguration("RELEASE")]
|
||||
#endif
|
||||
[assembly: AssemblyProduct("First_Machine_Age_component")]
|
||||
[assembly: AssemblyCopyright("Melchior")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
|
|
@ -17,7 +20,7 @@ using System.Runtime.CompilerServices;
|
|||
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||
|
||||
[assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.1.9")]
|
||||
|
||||
// The following attributes are used to specify the signing key for the assembly,
|
||||
// if desired. See the Mono documentation for more information about signing.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
"description" : "Get back lost scrap and smithing discards. Plus more.",
|
||||
"authors": ["Melchior"],
|
||||
"ModID":"metalrecovery",
|
||||
"version": "0.1.8",
|
||||
"version": "0.1.9",
|
||||
"dependencies": {
|
||||
"game": "1.14.10",
|
||||
"survival": ""
|
||||
|
|
|
|||
11
Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs
Normal file
11
Machinations/BlockBehaviors/BEMultiphaseGearmesh.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
namespace Machinations
|
||||
{
|
||||
public class BEMultiphaseGearmesh
|
||||
{
|
||||
public BEMultiphaseGearmesh( )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Machinations/Rendering/GearmeshBlockRenderer.cs
Normal file
11
Machinations/Rendering/GearmeshBlockRenderer.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
namespace Machinations
|
||||
{
|
||||
public class GearmeshBlockRenderer
|
||||
{
|
||||
public GearmeshBlockRenderer( )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue