First Machine Age's Mods (Combined repo.)
修订版 | febc126211f2719fa83411f12488aaa359a212c1 (tree) |
---|---|
时间 | 2021-04-08 12:28:00 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Prelimiary unit value mapping
@@ -14,10 +14,12 @@ using Vintagestory.ServerMods; | ||
14 | 14 | namespace AnvilMetalRecovery |
15 | 15 | { |
16 | 16 | public partial class MetalRecoverySystem : ModSystem |
17 | - { | |
17 | + { | |
18 | 18 | internal const string anvilKey = @"Anvil"; |
19 | 19 | internal const float ingotVoxelEquivalent = 2.38f; |
20 | 20 | |
21 | + private Dictionary<AssetLocation, uint> itemToVoxelLookup = new Dictionary<AssetLocation, uint>(); | |
22 | + | |
21 | 23 | private ICoreAPI CoreAPI; |
22 | 24 | private ICoreServerAPI ServerAPI; |
23 | 25 | private ServerCoreAPI ServerCore { get; set; } |
@@ -114,23 +116,45 @@ namespace AnvilMetalRecovery | ||
114 | 116 | //Count out Voxels in smthing recipes for all metal-ingot(?) derived items; |
115 | 117 | var examineList = ServerAPI.World.SmithingRecipes.Where(sr => sr.Enabled && sr.Ingredient.Type == EnumItemClass.Item && sr.Output.Type == EnumItemClass.Item); |
116 | 118 | |
117 | - foreach (var recipie in examineList) { | |
119 | + foreach (var recipie in examineList) | |
120 | + { | |
118 | 121 | CollectibleObject inputObject = recipie.Ingredient.Type == EnumItemClass.Item ? ServerAPI.World.GetItem(recipie.Ingredient.Code) : ServerAPI.World.GetBlock(recipie.Ingredient.Code) as CollectibleObject; |
119 | 122 | Item outputItem = ServerAPI.World.GetItem(recipie.Output.Code); |
120 | 123 | |
121 | - if (inputObject.CombustibleProps != null && inputObject.CombustibleProps.SmeltingType == EnumSmeltType.Smelt && inputObject.CombustibleProps.SmeltedRatio > 0) | |
122 | - { | |
124 | + if (inputObject.CombustibleProps != null && inputObject.CombustibleProps.SmeltingType == EnumSmeltType.Smelt && inputObject.CombustibleProps.SmeltedRatio > 0) { | |
123 | 125 | //Item Input Has a metal Unit value...(Smeltable) |
124 | 126 | //Resolve? |
125 | 127 | int setVoxels = 0; |
126 | - var unsprung = recipie.Voxels.OfType<bool>( ); | |
127 | - setVoxels = unsprung.Count(vox => vox); | |
128 | + setVoxels = recipie.Voxels.OfType<bool>( ).Count(vox => vox); | |
128 | 129 | |
129 | 130 | #if DEBUG |
130 | - Mod.Logger.VerboseDebug($"{recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{inputObject.Code}' voxel = ~{setVoxels*ingotVoxelEquivalent:F1} metal Units"); | |
131 | + Mod.Logger.VerboseDebug($"{recipie.Output.Quantity}* '{outputItem.Code}' -> {setVoxels}x '{inputObject.Code}' voxel = ~{setVoxels * ingotVoxelEquivalent:F1} metal Units"); | |
131 | 132 | #endif |
132 | 133 | |
133 | - } | |
134 | + if (outputItem.Tool.HasValue) | |
135 | + { | |
136 | + itemToVoxelLookup.Add(outputItem.Code.Clone( ), (( uint )(setVoxels / recipie.Output.Quantity))); | |
137 | + #if DEBUG | |
138 | + Mod.Logger.VerboseDebug($"Mapped: (tool) '{outputItem.Code}' -> (tool) '{outputItem.Code}'"); | |
139 | + #endif | |
140 | + } | |
141 | + else | |
142 | + { | |
143 | + //Tool-head map to Tool item | |
144 | + var itemToolCode = ServerAPI.World.GridRecipes.FirstOrDefault(gr => gr.Ingredients.Any(crg => crg.Value.Code.Equals(outputItem.Code)) && gr.Enabled && gr.Output.Type == EnumItemClass.Item)?.Output.Code; | |
145 | + if (itemToolCode != null) | |
146 | + { | |
147 | + var itemTool = ServerAPI.World.GetItem(itemToolCode); | |
148 | + if (itemTool.Tool.HasValue) | |
149 | + { | |
150 | + itemToVoxelLookup.Add(itemToolCode.Clone( ), (( uint )(setVoxels / recipie.Output.Quantity))); | |
151 | + #if DEBUG | |
152 | + Mod.Logger.VerboseDebug($"Mapped: (head) '{outputItem.Code}' -> (tool) '{itemToolCode}'"); | |
153 | + #endif | |
154 | + } | |
155 | + } | |
156 | + } | |
157 | + } | |
134 | 158 | } |
135 | 159 | |
136 | 160 | } |