• 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

Revisiónb73dcb7b88af49474283ff49661e4be2ca152476 (tree)
Tiempo2022-08-21 06:54:35
Autormelchior <melchior@user...>
Commitermelchior

Log Message

Final Split to Empty Voxel grid fix

Cambiar Resumen

Diferencia incremental

--- a/AnvilMetalRecovery/Data/RecoveryEntry.cs
+++ b/AnvilMetalRecovery/Data/RecoveryEntry.cs
@@ -12,8 +12,8 @@ namespace AnvilMetalRecovery
1212 /// Metal Quantity (VOXELS)
1313 /// </summary>
1414 public uint Quantity;
15- public float Melting_Duration;
16- public int Melting_Point;
15+ public float Melting_Duration;//TODO: Replace with 1.17 MetalAlloy mappings
16+ public int Melting_Point;//TODO: Replace with 1.17 MetalAlloy mappings
1717
1818 public RecoveryEntry(AssetLocation coll, AssetLocation ingot, uint qty, float dur, int point)
1919 {
--- a/AnvilMetalRecovery/Harmony/AnvilDaptor.cs
+++ b/AnvilMetalRecovery/Harmony/AnvilDaptor.cs
@@ -26,7 +26,7 @@ namespace AnvilMetalRecovery.Patches
2626
2727 if (original != null ) {
2828 foreach(var patched in harmony.GetPatchedMethods())
29- {
29+ {
3030 if (patched.Name == original.Name)return false; //SKIPS PATCHING, its already there
3131 }
3232 }
@@ -39,24 +39,47 @@ namespace AnvilMetalRecovery.Patches
3939 private static void Prefix_OnSplit(Vec3i voxelPos, BlockEntityAnvil __instance)
4040 {
4141 var anvil = new SmithAssist(__instance);
42+ #if DEBUG
43+ anvil.Logger.VerboseDebug("Prefix_OnSplit");
44+ #endif
4245
4346 if (anvil.IsShavable && anvil.Voxel(voxelPos.X, voxelPos.Y, voxelPos.Z) == EnumVoxelMaterial.Metal) {
47+ #if DEBUG
48+ anvil.Logger.VerboseDebug("{0}, Split into {1} @{2}, Total:{3}",anvil.OutputCode ,anvil.BaseMetal, voxelPos, anvil.SplitCount);
49+ #endif
50+ anvil.SplitCount++;
51+ }
52+ }
53+
54+ [HarmonyPostfix]
55+ [HarmonyPatch(nameof(BlockEntityAnvil.OnSplit))]
56+ private static void Postfix_OnSplit(Vec3i voxelPos, BlockEntityAnvil __instance)
57+ {
58+ var anvil = new SmithAssist(__instance);
59+ if (anvil.World.Side.IsClient( )) return;
60+
4461 #if DEBUG
45- anvil.Logger.VerboseDebug("{0}, Split into {1} @{2}, Total:{3}",anvil.OutputCode ,anvil.BaseMetal, voxelPos, anvil.SplitCount);
62+ anvil.Logger.VerboseDebug("Postfix_OnSplit");
4663 #endif
47- anvil.SplitCount++;
48- }
49-
64+ if (anvil.WorkEntirelySplit( ))
65+ {
66+ #if DEBUG
67+ anvil.Logger.VerboseDebug("Work item entirely split up.");
68+ #endif
69+ anvil.IssueCancelStackEquivalent();//anvil.IssueShavings(null);
70+ anvil.ClearWork();
71+ }
5072 }
5173
74+ //internal void OnUseOver -->
5275 [HarmonyPrefix]
5376 [HarmonyPatch(nameof(BlockEntityAnvil.CheckIfFinished))]
5477 private static void Prefix_CheckIfFinished(IPlayer byPlayer, BlockEntityAnvil __instance)
5578 {
5679 var anvil = new SmithAssist(__instance);
57- if (anvil.WorkMatchesRecipe( )) {
58- anvil.IssueShavings(byPlayer);
59- }
80+ if (anvil.WorkMatchesRecipe( )) {
81+ anvil.IssueShavings(byPlayer);
82+ }
6083 }
6184
6285 [HarmonyPostfix]
@@ -78,7 +101,7 @@ namespace AnvilMetalRecovery.Patches
78101 */
79102
80103
81- }
104+ } /************** HARMONY CLASS ENDS *******************/
82105
83106 /// <summary>
84107 /// Special tools for handling the Anvil's data/state, ect...
@@ -90,6 +113,9 @@ namespace AnvilMetalRecovery.Patches
90113 internal const string splitCountKey = @"splitCount";
91114 internal const int shavingValue = 5;
92115
116+ private AccessTools.FieldRef<BlockEntityAnvil, ItemStack> workItemStack_R = AccessTools.FieldRefAccess<BlockEntityAnvil, ItemStack>(@"workItemStack");
117+ private AccessTools.FieldRef<BlockEntityAnvil, ItemStack> returnOnCancelStack_R = AccessTools.FieldRefAccess<BlockEntityAnvil, ItemStack>(@"returnOnCancelStack");
118+
93119 internal SmithAssist(BlockEntityAnvil a)
94120 {
95121 this.bea = a;
@@ -102,6 +128,13 @@ namespace AnvilMetalRecovery.Patches
102128 }
103129 }
104130
131+ internal IWorldAccessor World {
132+ get
133+ {
134+ return bea.Api.World;
135+ }
136+ }
137+
105138 public static AssetLocation MetalShavingsCode {
106139 get
107140 {
@@ -196,23 +229,29 @@ namespace AnvilMetalRecovery.Patches
196229 if (this.SplitCount > 0) {
197230 int shavingQty = ShavingQuantity;
198231
199- if (shavingQty > 0)
200- {
201- Item metalShavingsItem = bea.Api.World.GetItem(MetalShavingsCode.AppendPathVariant(BaseMetal));
232+ if (shavingQty > 0)
233+ {
234+ Item metalShavingsItem = World.GetItem(MetalShavingsCode.AppendPathVariant(BaseMetal));
202235
203- if (metalShavingsItem != null)
236+ if (metalShavingsItem != null)
204237 {
205- ItemStack metalShavingsStack = new ItemStack(metalShavingsItem, shavingQty);
238+ ItemStack metalShavingsStack = new ItemStack(metalShavingsItem, shavingQty);
206239
207- if (byPlayer != null) {
208- if (byPlayer.InventoryManager.TryGiveItemstack(metalShavingsStack, false) == false) { bea.Api.World.SpawnItemEntity(metalShavingsStack, bea.Pos.ToVec3d().Add(0.1d,0,0) ); }
240+ if (byPlayer != null)
241+ {
242+ if (byPlayer.InventoryManager.TryGiveItemstack(metalShavingsStack, false) == false)
243+ { World.SpawnItemEntity(metalShavingsStack, bea.Pos.ToVec3d( ).Add(0.1d, 0, 0)); }
244+ }
245+ else
246+ {
247+ //Just spew itemstack on top of anvil...Player ran off?
248+ World.SpawnItemEntity(metalShavingsStack, bea.Pos.ToVec3d( ).Add(0.1d, 0, 0));
249+ }
209250 #if DEBUG
210251 Logger.VerboseDebug("RecoveryAnvil: Smithing done - recover: {0} shavings of {1}", shavingQty, metalShavingsItem.Code);
211252 #endif
212- }
213253 }
214- else
215- {
254+ else {
216255 Logger.Warning("Missing or Invalid Item: {0} ", MetalShavingsCode.WithPathAppendix("-" + BaseMaterial));
217256 }
218257 }
@@ -242,6 +281,22 @@ namespace AnvilMetalRecovery.Patches
242281 return true;
243282 }
244283
284+ /// <summary>
285+ /// If the Work voxels are _GONE_ and everything is split UP?
286+ /// </summary>
287+ /// <returns>If entirely split.</returns>
288+ internal bool WorkEntirelySplit( )
289+ {
290+ if ( SplitCount > 0 && bea.SelectedRecipe != null) { //Work-Item stack OK; for post split check...
291+ foreach (EnumVoxelMaterial voxel in bea.Voxels) {
292+ if (voxel == EnumVoxelMaterial.Metal || voxel == EnumVoxelMaterial.Slag) return false;
293+ }
294+ return true;
295+ }
296+
297+ return false;
298+ }
299+
245300 internal bool PrefixMatcher(List<AssetLocation> nameList, AssetLocation target)
246301 {
247302 if (nameList == null || nameList.Count == 0 || target == null) return false;
@@ -252,6 +307,46 @@ namespace AnvilMetalRecovery.Patches
252307
253308 return false;
254309 }
310+
311+ internal void IssueCancelStackEquivalent( )
312+ {
313+
314+ if (bea.SelectedRecipeId > 0 && bea.SelectedRecipe != null )
315+ {
316+ var itemToVoxelLookup = MetalRecoverySystem.GetCachedLookupTable(World);
317+ if (itemToVoxelLookup.ContainsKey(bea.SelectedRecipe.Output.Code)) {
318+ var result = itemToVoxelLookup[bea.SelectedRecipe.Output.Code];
319+ #if DEBUG
320+ Logger.VerboseDebug("(old) Selected Recipe: {0} base-material: '{1}' worth {2} units; spawning", bea.SelectedRecipe.Output.Code, result.IngotCode, result.Quantity);
321+ #endif
322+
323+ int shavingQty = ( int )(result.Quantity / MetalRecoverySystem.IngotVoxelDefault);
324+
325+ if (shavingQty > 0) {
326+ Item metalShavingsItem = World.GetItem(MetalShavingsCode.AppendPathVariant(result.IngotCode.PathEnding()));
327+
328+ if (metalShavingsItem != null) {
329+ ItemStack metalShavingsStack = new ItemStack(metalShavingsItem, shavingQty);
330+ World.SpawnItemEntity(metalShavingsStack, bea.Pos.ToVec3d( ).Add(0.1d, 0, 0));
331+ }
332+ }
333+ }
334+ }
335+ }
336+
337+ internal void ClearWork( )
338+ {
339+ #if DEBUG
340+ Logger.Debug("Manually Clearing Work Item stack & Anvil state...the hard way.");
341+ #endif
342+
343+ workItemStack_R(bea) = null;//bea.workItemStack = null;
344+ returnOnCancelStack_R(bea) = null; //Needed?
345+ bea.Voxels = new byte[16, 6, 16];
346+ bea.rotation = 0;
347+ bea.SelectedRecipeId = -1;
348+ bea.MarkDirty(false, null);
349+ }
255350 }
256351 }
257352
--- a/AnvilMetalRecovery/Helpers.cs
+++ b/AnvilMetalRecovery/Helpers.cs
@@ -89,6 +89,11 @@ namespace AnvilMetalRecovery
8989 return checkCode.Valid && checkCode.Path.Split('-').First().Equals(term, StringComparison.OrdinalIgnoreCase);
9090 }
9191
92+ internal static string PathEnding(this AssetLocation inputCode)
93+ {
94+ return inputCode.Path.Split('-').Last( );
95+ }
96+
9297 internal static AssetLocation AppendPathVariant(this AssetLocation toAppend, string append)
9398 {
9499 var appendedCode = toAppend.Clone( );
@@ -110,4 +115,3 @@ namespace AnvilMetalRecovery
110115 }
111116 }
112117 }
113-
--- a/AnvilMetalRecovery/modinfo.json
+++ b/AnvilMetalRecovery/modinfo.json
@@ -1,7 +1,7 @@
11 {
22 "type": "code",
33 "name": "Anvil Metal Recovery+",
4- "description" : "Get back smithing discards and broken tool scrap! Plus lots more.",
4+ "description" : "Get back smithing discards, broken tool scrap, failed molds; and MORE!",
55 "authors": ["Melchior"],
66 "ModID":"metalrecovery",
77 "version": "0.1.18-rc.1",