First Machine Age's Mods (Combined repo.)
Revision | 08bdbdb07683ed7e0a401473cbc5099b16fa8121 (tree) |
---|---|
Time | 2021-08-06 09:10:04 |
Author | melchior <melchior@user...> |
Commiter | melchior |
Workaround for tool shard recycling
Tool shards now scrappable, with servere bending of GridRecipe API.
@@ -113,6 +113,9 @@ | ||
113 | 113 | <CopyToOutputDirectory>Always</CopyToOutputDirectory> |
114 | 114 | </None> |
115 | 115 | <None Include="EntityBehaviors\HotbarObserverBehavior.cs" /> |
116 | + <None Include="assets\fma\recipes\grid\variableMetal_smash.json"> | |
117 | + <CopyToOutputDirectory>Always</CopyToOutputDirectory> | |
118 | + </None> | |
116 | 119 | </ItemGroup> |
117 | 120 | <ItemGroup> |
118 | 121 | <Folder Include="assets\" /> |
@@ -25,7 +25,7 @@ namespace AnvilMetalRecovery | ||
25 | 25 | public static AssetLocation MetalShavingsCode { |
26 | 26 | get |
27 | 27 | { |
28 | - return new AssetLocation(@"fma", @"metal_shaving"); | |
28 | + return new AssetLocation(@"fma", @"metal_shaving");//new AssetLocation(GlobalConstants.Domain, @"metalbit"); | |
29 | 29 | } |
30 | 30 | } |
31 | 31 |
@@ -1,4 +1,5 @@ | ||
1 | 1 | using System; |
2 | +using System.Text; | |
2 | 3 | using System.Linq; |
3 | 4 | |
4 | 5 | using Vintagestory.API.Client; |
@@ -22,12 +23,18 @@ namespace AnvilMetalRecovery | ||
22 | 23 | /// <returns>The code.</returns> |
23 | 24 | /// <param name="itemStack">Item stack.</param> |
24 | 25 | /// <remarks>If base metal still exists - can still smelt...</remarks> |
25 | - protected AssetLocation MetalCode(ItemStack itemStack) | |
26 | + protected AssetLocation MetalIngotCode(ItemStack itemStack) | |
26 | 27 | { |
27 | 28 | if (itemStack == null || itemStack.Attributes == null) return new AssetLocation(default_IngotCode); |
28 | 29 | return new AssetLocation(itemStack.Attributes.GetString(metalIngotCodeKey, default_IngotCode)); |
29 | 30 | } |
30 | 31 | |
32 | + protected string MetalCode(ItemStack itemStack) | |
33 | + { | |
34 | + if (itemStack == null || itemStack.Attributes == null) return string.Empty; | |
35 | + return itemStack.Attributes.GetString(metalIngotCodeKey).Split('-').Last(); | |
36 | + } | |
37 | + | |
31 | 38 | /// <summary> |
32 | 39 | /// Store metal VOXEL quantity value. |
33 | 40 | /// </summary> |
@@ -43,7 +50,7 @@ namespace AnvilMetalRecovery | ||
43 | 50 | { |
44 | 51 | //TODO: generic 'material' Language entries... |
45 | 52 | if (itemStack == null || itemStack.Attributes == null) return @"?"; |
46 | - var sliced = Lang.GetUnformatted("item-"+MetalCode(itemStack).Path).Split(' '); | |
53 | + var sliced = Lang.GetUnformatted("item-"+MetalIngotCode(itemStack).Path).Split(' '); | |
47 | 54 | return String.Join(" ", sliced.Take(sliced.Length - 1)); |
48 | 55 | } |
49 | 56 |
@@ -60,7 +67,7 @@ namespace AnvilMetalRecovery | ||
60 | 67 | { |
61 | 68 | //Set correct material texture from ItemStack attributes |
62 | 69 | LoadedTexture texturePlaceholder = new LoadedTexture(capi); |
63 | - var ingotCode = MetalCode(itemstack); | |
70 | + var ingotCode = MetalIngotCode(itemstack); | |
64 | 71 | var textureDonatorItem = capi.World.GetItem(ingotCode); |
65 | 72 | if (textureDonatorItem != null) { |
66 | 73 | var newTexture = textureDonatorItem.FirstTexture.Base.WithPathAppendixOnce(".png"); |
@@ -77,40 +84,6 @@ namespace AnvilMetalRecovery | ||
77 | 84 | } |
78 | 85 | |
79 | 86 | |
80 | - public override bool CanSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemStack inputStack, ItemStack outputStack) | |
81 | - { | |
82 | - var props = LocateCombustableFromInventory(cookingSlotsProvider); | |
83 | - | |
84 | - #if DEBUG | |
85 | - api.Logger.VerboseDebug("CanSmelt? "); | |
86 | - #endif | |
87 | - return (outputStack == null) && props?.SmeltingType == EnumSmeltType.Smelt; | |
88 | - } | |
89 | - | |
90 | - public override float GetMeltingPoint(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot) | |
91 | - { | |
92 | - var props = LocateCombustableFromInventory(cookingSlotsProvider); | |
93 | - | |
94 | - return props?.MeltingPoint ?? 9999f; | |
95 | - } | |
96 | - | |
97 | - public override float GetMeltingDuration(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot) | |
98 | - { | |
99 | - var props = LocateCombustableFromInventory(cookingSlotsProvider); | |
100 | - | |
101 | - return props?.MeltingDuration ?? 9999f; | |
102 | - } | |
103 | - | |
104 | - public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot, ItemSlot outputSlot) | |
105 | - { | |
106 | - RegenerateCombustablePropsFromStack(inputSlot.Itemstack); | |
107 | - #if DEBUG | |
108 | - world.Logger.VerboseDebug("Invoked: 'DoSmelt' CookSlots#{1} In.stk: {0} ", (inputSlot.Empty ? "empty" : inputSlot.Itemstack.Collectible.Code.ToShortString( )), cookingSlotsProvider.Slots.Length); | |
109 | - #endif | |
110 | - | |
111 | - base.DoSmelt(world, cookingSlotsProvider, inputSlot, outputSlot); | |
112 | - } | |
113 | - | |
114 | 87 | |
115 | 88 | public override void GetHeldItemInfo(ItemSlot inSlot, System.Text.StringBuilder dsc, IWorldAccessor world, bool withDebugInfo) |
116 | 89 | { |
@@ -124,12 +97,8 @@ namespace AnvilMetalRecovery | ||
124 | 97 | dsc.AppendLine(Lang.Get("fma:metal_worth", metalQuantity, metalName)); |
125 | 98 | } |
126 | 99 | |
127 | - public override void OnModifiedInInventorySlot(IWorldAccessor world, ItemSlot slot, ItemStack extractedStack = null) | |
128 | - { | |
129 | - if (!slot.Empty) RegenerateCombustablePropsFromStack(slot.Itemstack); | |
130 | - } | |
131 | 100 | |
132 | - //Merge (same) metal piles together? Upto 100 units. | |
101 | + //TODO: Merge - to the New metal V.S. stock metal bits...? | |
133 | 102 | //TryMergeStacks ??? |
134 | 103 | //virtual bool CanBePlacedInto(ItemStack stack, ItemSlot slot) //? |
135 | 104 | //virtual void OnModifiedInInventorySlot //Only for new-Inserts (?) |
@@ -147,7 +116,7 @@ namespace AnvilMetalRecovery | ||
147 | 116 | if (contStack == null ) return null; |
148 | 117 | //if (contStack.Class == EnumItemClass.Item && contStack.Item.CombustibleProps != null) return contStack.Item.CombustibleProps; |
149 | 118 | |
150 | - var metalCode = MetalCode(contStack); | |
119 | + var metalCode = MetalIngotCode(contStack); | |
151 | 120 | var metalUnits = MetalQuantity(contStack); |
152 | 121 | |
153 | 122 | if (metalCode != null || metalUnits > 0) |
@@ -167,36 +136,41 @@ namespace AnvilMetalRecovery | ||
167 | 136 | SmeltedStack = new JsonItemStack( ) { Type = EnumItemClass.Item, Code = sourceMetalItem.Code.Clone( ), Quantity = (int)Math.Floor(metalUnits * MetalRecoverySystem.IngotVoxelEquivalent) } |
168 | 137 | }; |
169 | 138 | aCombustibleProps.SmeltedStack.Resolve(api.World, "VariableMetalItem_regen", true); |
170 | - //Back-Inject source Input Item stack - as Crucible checks THAT | |
171 | - contStack.Item.CombustibleProps = aCombustibleProps.Clone( ); | |
172 | - | |
173 | - #if DEBUG | |
174 | - api.Logger.VerboseDebug("Melt point: {0}, Duration: {1}, Ratio: {2}, Out.stk: {3} * {4}", aCombustibleProps.MeltingPoint, aCombustibleProps.MeltingDuration, aCombustibleProps.SmeltedRatio, aCombustibleProps.SmeltedStack.ResolvedItemstack.Item.Code.ToString(), aCombustibleProps.SmeltedStack.Quantity ); | |
175 | - #endif | |
139 | + | |
140 | + | |
141 | + | |
176 | 142 | return aCombustibleProps; |
177 | 143 | } |
178 | 144 | return null; |
179 | 145 | } |
180 | 146 | |
181 | - | |
182 | - protected CombustibleProperties LocateCombustableFromInventory(ISlotProvider cookingSlotsProvider ) | |
147 | + /// <summary> | |
148 | + /// Bend Crafting output result - to Dynamic item | |
149 | + /// </summary> | |
150 | + /// <returns>The for crafting.</returns> | |
151 | + /// <param name="inputStack">Input stack.</param> | |
152 | + /// <param name="gridRecipe">Grid recipe.</param> | |
153 | + /// <param name="ingredient">Ingredient.</param> | |
154 | + public override bool MatchesForCrafting(ItemStack inputStack, GridRecipe gridRecipe, CraftingRecipeIngredient ingredient) | |
183 | 155 | { |
184 | - if (cookingSlotsProvider is InventorySmelting) | |
185 | - { | |
186 | - var smeltInventory = cookingSlotsProvider as InventorySmelting; | |
156 | + #if DEBUG | |
157 | + api.Logger.VerboseDebug("MatchesForCrafting::'{0}'", this.Code); | |
158 | + #endif | |
159 | + | |
160 | + if (inputStack != null) { | |
161 | + var metalCode = MetalCode(inputStack); | |
162 | + var metalUnits = MetalQuantity(inputStack); | |
187 | 163 | |
188 | - CombustibleProperties props = null; | |
189 | - foreach (var cookSlot in smeltInventory.CookingSlots) | |
164 | + Item metalBits = api.World.GetItem(new AssetLocation(GlobalConstants.DefaultDomain, @"metalbit-" + metalCode)); | |
165 | + if (metalBits != null) | |
190 | 166 | { |
191 | - if (!cookSlot.Empty && cookSlot.Itemstack.Class == EnumItemClass.Item && cookSlot.Itemstack.Item.Code == this.Code) | |
192 | - { | |
193 | - //TODO: Check *ALL* items - for similarity before returning _A_ match | |
194 | - props = RegenerateCombustablePropsFromStack(cookSlot.Itemstack); | |
195 | - return props; | |
196 | - } | |
197 | - } | |
167 | + gridRecipe.Output.Quantity = ( int )(Math.Round(metalUnits * MetalRecoverySystem.IngotVoxelEquivalent) / 5); | |
168 | + gridRecipe.Output.Code = metalBits.Code; | |
169 | + gridRecipe.Output.Resolve(api.World, "VariableMetalItem_crafting"); | |
198 | 170 | } |
199 | - return null; | |
171 | + } | |
172 | + | |
173 | + return true; | |
200 | 174 | } |
201 | 175 | } |
202 | 176 | } |
@@ -2,12 +2,10 @@ | ||
2 | 2 | code: "metal_fragments", |
3 | 3 | class:"VariableMetalItem", |
4 | 4 | maxstacksize: 1, |
5 | - dimensions: { width: 0.1, height: 0.07, length: 0.1 }, | |
6 | 5 | attributes: { |
7 | 6 | handbook: { |
8 | 7 | exclude: true |
9 | - }, | |
10 | - allowHeating: true, | |
8 | + } | |
11 | 9 | }, |
12 | 10 | storageFlags: 5, |
13 | 11 | shape: { base: "fma:item/metal/fragments" }, |
@@ -4,7 +4,7 @@ | ||
4 | 4 | "description" : "Get back lost scrap and smithing discards. Plus more.", |
5 | 5 | "authors": ["Melchior"], |
6 | 6 | "ModID":"metalrecovery", |
7 | - "version": "0.1.11", | |
7 | + "version": "0.1.12", | |
8 | 8 | "dependencies": { |
9 | 9 | "game": "1.15.3", |
10 | 10 | "survival": "" |