• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

First Machine Age's Mods (Combined repo.)


Commit MetaInfo

Revision08bdbdb07683ed7e0a401473cbc5099b16fa8121 (tree)
Time2021-08-06 09:10:04
Authormelchior <melchior@user...>
Commitermelchior

Log Message

Workaround for tool shard recycling

Tool shards now scrappable, with servere bending of GridRecipe API.

Change Summary

Incremental Difference

--- a/AnvilMetalRecovery/AnvilMetalRecovery.csproj
+++ b/AnvilMetalRecovery/AnvilMetalRecovery.csproj
@@ -113,6 +113,9 @@
113113 <CopyToOutputDirectory>Always</CopyToOutputDirectory>
114114 </None>
115115 <None Include="EntityBehaviors\HotbarObserverBehavior.cs" />
116+ <None Include="assets\fma\recipes\grid\variableMetal_smash.json">
117+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
118+ </None>
116119 </ItemGroup>
117120 <ItemGroup>
118121 <Folder Include="assets\" />
--- a/AnvilMetalRecovery/BlockEntities/MetalRecovery_BlockEntityAnvil.cs
+++ b/AnvilMetalRecovery/BlockEntities/MetalRecovery_BlockEntityAnvil.cs
@@ -25,7 +25,7 @@ namespace AnvilMetalRecovery
2525 public static AssetLocation MetalShavingsCode {
2626 get
2727 {
28- return new AssetLocation(@"fma", @"metal_shaving");
28+ return new AssetLocation(@"fma", @"metal_shaving");//new AssetLocation(GlobalConstants.Domain, @"metalbit");
2929 }
3030 }
3131
--- a/AnvilMetalRecovery/Items/VariableMetalItem.cs
+++ b/AnvilMetalRecovery/Items/VariableMetalItem.cs
@@ -1,4 +1,5 @@
11 using System;
2+using System.Text;
23 using System.Linq;
34
45 using Vintagestory.API.Client;
@@ -22,12 +23,18 @@ namespace AnvilMetalRecovery
2223 /// <returns>The code.</returns>
2324 /// <param name="itemStack">Item stack.</param>
2425 /// <remarks>If base metal still exists - can still smelt...</remarks>
25- protected AssetLocation MetalCode(ItemStack itemStack)
26+ protected AssetLocation MetalIngotCode(ItemStack itemStack)
2627 {
2728 if (itemStack == null || itemStack.Attributes == null) return new AssetLocation(default_IngotCode);
2829 return new AssetLocation(itemStack.Attributes.GetString(metalIngotCodeKey, default_IngotCode));
2930 }
3031
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+
3138 /// <summary>
3239 /// Store metal VOXEL quantity value.
3340 /// </summary>
@@ -43,7 +50,7 @@ namespace AnvilMetalRecovery
4350 {
4451 //TODO: generic 'material' Language entries...
4552 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(' ');
4754 return String.Join(" ", sliced.Take(sliced.Length - 1));
4855 }
4956
@@ -60,7 +67,7 @@ namespace AnvilMetalRecovery
6067 {
6168 //Set correct material texture from ItemStack attributes
6269 LoadedTexture texturePlaceholder = new LoadedTexture(capi);
63- var ingotCode = MetalCode(itemstack);
70+ var ingotCode = MetalIngotCode(itemstack);
6471 var textureDonatorItem = capi.World.GetItem(ingotCode);
6572 if (textureDonatorItem != null) {
6673 var newTexture = textureDonatorItem.FirstTexture.Base.WithPathAppendixOnce(".png");
@@ -77,40 +84,6 @@ namespace AnvilMetalRecovery
7784 }
7885
7986
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-
11487
11588 public override void GetHeldItemInfo(ItemSlot inSlot, System.Text.StringBuilder dsc, IWorldAccessor world, bool withDebugInfo)
11689 {
@@ -124,12 +97,8 @@ namespace AnvilMetalRecovery
12497 dsc.AppendLine(Lang.Get("fma:metal_worth", metalQuantity, metalName));
12598 }
12699
127- public override void OnModifiedInInventorySlot(IWorldAccessor world, ItemSlot slot, ItemStack extractedStack = null)
128- {
129- if (!slot.Empty) RegenerateCombustablePropsFromStack(slot.Itemstack);
130- }
131100
132- //Merge (same) metal piles together? Upto 100 units.
101+ //TODO: Merge - to the New metal V.S. stock metal bits...?
133102 //TryMergeStacks ???
134103 //virtual bool CanBePlacedInto(ItemStack stack, ItemSlot slot) //?
135104 //virtual void OnModifiedInInventorySlot //Only for new-Inserts (?)
@@ -147,7 +116,7 @@ namespace AnvilMetalRecovery
147116 if (contStack == null ) return null;
148117 //if (contStack.Class == EnumItemClass.Item && contStack.Item.CombustibleProps != null) return contStack.Item.CombustibleProps;
149118
150- var metalCode = MetalCode(contStack);
119+ var metalCode = MetalIngotCode(contStack);
151120 var metalUnits = MetalQuantity(contStack);
152121
153122 if (metalCode != null || metalUnits > 0)
@@ -167,36 +136,41 @@ namespace AnvilMetalRecovery
167136 SmeltedStack = new JsonItemStack( ) { Type = EnumItemClass.Item, Code = sourceMetalItem.Code.Clone( ), Quantity = (int)Math.Floor(metalUnits * MetalRecoverySystem.IngotVoxelEquivalent) }
168137 };
169138 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+
176142 return aCombustibleProps;
177143 }
178144 return null;
179145 }
180146
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)
183155 {
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);
187163
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)
190166 {
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");
198170 }
199- return null;
171+ }
172+
173+ return true;
200174 }
201175 }
202176 }
--- a/AnvilMetalRecovery/assets/fma/itemtypes/metal/fragments.json
+++ b/AnvilMetalRecovery/assets/fma/itemtypes/metal/fragments.json
@@ -2,12 +2,10 @@
22 code: "metal_fragments",
33 class:"VariableMetalItem",
44 maxstacksize: 1,
5- dimensions: { width: 0.1, height: 0.07, length: 0.1 },
65 attributes: {
76 handbook: {
87 exclude: true
9- },
10- allowHeating: true,
8+ }
119 },
1210 storageFlags: 5,
1311 shape: { base: "fma:item/metal/fragments" },
--- a/AnvilMetalRecovery/modinfo.json
+++ b/AnvilMetalRecovery/modinfo.json
@@ -4,7 +4,7 @@
44 "description" : "Get back lost scrap and smithing discards. Plus more.",
55 "authors": ["Melchior"],
66 "ModID":"metalrecovery",
7- "version": "0.1.11",
7+ "version": "0.1.12",
88 "dependencies": {
99 "game": "1.15.3",
1010 "survival": ""