• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

First Machine Age's Mods (Combined repo.)


コミットメタ情報

リビジョンc6cf34919cf235a68cd6ca6e845e4b9dd8b5c918 (tree)
日時2021-05-04 11:40:15
作者melchior <melchior@user...>
コミッターmelchior

ログメッセージ

probably Fixed Harmony method duplication, asst.
improvments

変更サマリ

差分

--- a/AnvilMetalRecovery/Harmony/AnvilDaptor.cs
+++ b/AnvilMetalRecovery/Harmony/AnvilDaptor.cs
@@ -1,5 +1,6 @@
11 using System;
22 using System.Linq;
3+using System.Reflection;
34 using System.Text;
45
56 using HarmonyLib;
@@ -9,7 +10,7 @@ using Vintagestory.API.Config;
910 using Vintagestory.API.MathTools;
1011 using Vintagestory.GameContent;
1112
12-namespace AnvilMetalRecovery
13+namespace AnvilMetalRecovery.Patches
1314 {
1415 /// <summary>
1516 /// Harmony patcher class to wrap B.E. Anvil class
@@ -17,7 +18,21 @@ namespace AnvilMetalRecovery
1718 [HarmonyPatch(typeof(BlockEntityAnvil))]
1819 public class AnvilDaptor
1920 {
20-
21+
22+ [HarmonyPrepare]
23+ private static bool DeduplicatePatching(MethodBase original, Harmony harmony)
24+ {
25+
26+ if (original != null ) {
27+ foreach(var patched in harmony.GetPatchedMethods())
28+ {
29+ if (patched.Name == original.Name)return false; //SKIPS PATCHING, its already there
30+ }
31+ }
32+
33+ return true;//patch all other methods
34+ }
35+
2136 [HarmonyPrefix]
2237 [HarmonyPatch(nameof(BlockEntityAnvil.OnSplit))]
2338 private static void Prefix_OnSplit(Vec3i voxelPos, BlockEntityAnvil __instance)
@@ -44,15 +59,14 @@ namespace AnvilMetalRecovery
4459 }
4560
4661 [HarmonyPostfix]
47- [HarmonyPatch(nameof(BlockEntityAnvil.GetBlockInfo))]
62+ [HarmonyPatch(nameof(BlockEntityAnvil.GetBlockInfo))]
4863 private static void Postfix_GetBlockInfo(IPlayer forPlayer, StringBuilder dsc, BlockEntityAnvil __instance)
49- {
50- if (__instance.Api.Side.IsServer()) return;
64+ {
5165 var anvil = new SmithAssist(__instance);
5266
5367 if (anvil.BaseMaterial != null && anvil.IsShavable && anvil.SplitCount > 0)
54- {
55- dsc.AppendFormat("[ {0} ÷ {1} ] : {2}\n", anvil.SplitCount, SmithAssist.shavingValue, Lang.GetUnformatted($"fma:item-metal_shaving-{anvil.BaseMetal}"));
68+ {
69+ dsc.AppendFormat("[ {0} ] : {1} × {2}\n", anvil.SplitCount, Lang.GetUnformatted($"fma:item-metal_shaving-{anvil.BaseMetal}"), anvil.ShavingQuantity);
5670 }
5771 }
5872
@@ -73,7 +87,7 @@ namespace AnvilMetalRecovery
7387 private readonly BlockEntityAnvil bea;
7488
7589 internal const string splitCountKey = @"splitCount";
76- internal const uint shavingValue = 5;
90+ internal const int shavingValue = 5;
7791
7892 internal SmithAssist(BlockEntityAnvil a)
7993 {
@@ -87,7 +101,7 @@ namespace AnvilMetalRecovery
87101 }
88102 }
89103
90- internal static AssetLocation MetalShavingsCode {
104+ public static AssetLocation MetalShavingsCode {
91105 get
92106 {
93107 return new AssetLocation(@"fma", @"metal_shaving");
@@ -101,7 +115,7 @@ namespace AnvilMetalRecovery
101115 }
102116
103117
104- internal int SplitCount {
118+ public int SplitCount {
105119 get
106120 {
107121 return bea.WorkItemStack?.Attributes.TryGetInt(splitCountKey) ?? 0;
@@ -112,7 +126,7 @@ namespace AnvilMetalRecovery
112126 }
113127 }
114128
115- internal bool IsShavable {
129+ public bool IsShavable {
116130 get
117131 {
118132 //this.SelectedRecipe <-- things that are recoverable?
@@ -120,6 +134,11 @@ namespace AnvilMetalRecovery
120134 }
121135 }
122136
137+ public int ShavingQuantity
138+ {
139+ get { return (SplitCount / shavingValue); }
140+ }
141+
123142 internal IAnvilWorkable AnvilWorkpiece {
124143 get
125144 {
@@ -137,14 +156,14 @@ namespace AnvilMetalRecovery
137156 }
138157 }
139158
140- internal string BaseMetal {
159+ public string BaseMetal {
141160 get
142161 {
143162 return this?.BaseMaterial?.Collectible.LastCodePart( );
144163 }
145164 }
146165
147- internal int MetalVoxelCount {
166+ public int MetalVoxelCount {
148167 get { return bea.Voxels.OfType<byte>( ).Count(vox => vox == (byte)EnumVoxelMaterial.Metal); }
149168 }
150169