• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
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

修订版868f21b19d98ca01b1ae699108861945fe9380b5 (tree)
时间2021-05-01 09:17:19
作者melchior <melchior@user...>
Commitermelchior

Log Message

Item self-applied Smeltable properties for regular (and custom)
Ingots

更改概述

差异

--- a/AnvilMetalRecovery/AnvilMetalRecovery.csproj
+++ b/AnvilMetalRecovery/AnvilMetalRecovery.csproj
@@ -74,6 +74,7 @@
7474 <Compile Include="EntityBehaviors\HotbarObserverData.cs" />
7575 <Compile Include="Data\RecoveryEntry.cs" />
7676 <Compile Include="Items\VariableMetalItem.cs" />
77+ <Compile Include="Items\SmartSmeltableItem.cs" />
7778 </ItemGroup>
7879 <ItemGroup>
7980 <None Include="modinfo.json">
--- a/AnvilMetalRecovery/Helpers.cs
+++ b/AnvilMetalRecovery/Helpers.cs
@@ -1,4 +1,5 @@
11 using System;
2+using System.Linq;
23
34 using Vintagestory.API.Common;
45 using Vintagestory.API.Common.Entities;
@@ -40,6 +41,18 @@ namespace AnvilMetalRecovery
4041 if (itemStack.Attributes.HasAttribute(@"durability"))
4142 itemStack.Attributes.SetInt(@"durability", number);
4243 }
44+
45+ internal static bool BeginingOnly(this AssetLocation checkCode, string term)
46+ {
47+ return checkCode.Valid && checkCode.Path.Split('-').First().Equals(term, StringComparison.OrdinalIgnoreCase);
48+ }
49+
50+ internal static AssetLocation AppendPathVariant(this AssetLocation toAppend, string append)
51+ {
52+ var appendedCode = toAppend.Clone( );
53+ appendedCode.Path += ("-" + append);
54+ return appendedCode;
55+ }
4356 }
4457 }
4558
--- /dev/null
+++ b/AnvilMetalRecovery/Items/SmartSmeltableItem.cs
@@ -0,0 +1,55 @@
1+using System;
2+using System.Linq;
3+
4+using Vintagestory.API.Client;
5+using Vintagestory.API.Common;
6+using Vintagestory.API.Util;
7+
8+
9+namespace AnvilMetalRecovery
10+{
11+ /// <summary>
12+ /// Applies Ingot-{metal} Combustable properties dynamically.
13+ /// </summary>
14+ public class SmartSmeltableItem : Item
15+ {
16+ internal static AssetLocation _ingotPrefix = new AssetLocation(@"game", @"ingot");
17+ public string Metal
18+ { get { return this?.Variant[@"metal"] ?? "copper"; } }
19+
20+ public int Ratio
21+ { get { return this.Attributes[@"ratio"].AsInt(20); } }
22+
23+ public override void OnModifiedInInventorySlot(IWorldAccessor world, ItemSlot slot, ItemStack extractedStack = null)
24+ {
25+ RegenerateCombustablePropsByVariant(slot);
26+ }
27+
28+ protected void RegenerateCombustablePropsByVariant(ItemSlot slot)
29+ {
30+ if (this.CombustibleProps != null || slot.Itemstack.Collectible.CombustibleProps != null) return;
31+
32+ var ingotAssetCode = _ingotPrefix.AppendPathVariant(Metal);//Wildcard find? excluding domain?
33+ var ingotEntry = api.World.GetItem(ingotAssetCode);
34+ var metalSmeltProps = ingotEntry?.CombustibleProps?.Clone( );
35+
36+ if (metalSmeltProps != null)
37+ {
38+ metalSmeltProps.SmeltedRatio = Ratio;
39+
40+ //Back-Inject source Input Item stack - as Firepit checks THAT
41+ slot.Itemstack.Collectible.CombustibleProps = metalSmeltProps.Clone( );
42+ #if DEBUG
43+ api.Logger.VerboseDebug("set SmeltProps, for: {0} from {1}", this.Code.ToString( ), ingotAssetCode.ToString());
44+ #endif
45+ }
46+ else
47+ {
48+ #if DEBUG
49+ api.Logger.VerboseDebug("Non-existant Ingot: {0}", ingotAssetCode.ToString( ));
50+ #endif
51+ }
52+ }
53+ }
54+}
55+
--- a/AnvilMetalRecovery/MetalRecoverySystem.cs
+++ b/AnvilMetalRecovery/MetalRecoverySystem.cs
@@ -18,6 +18,7 @@ namespace AnvilMetalRecovery
1818 {
1919 internal const string anvilKey = @"Anvil";
2020 internal const string metalFragmentsCode = @"fma:metal_fragments";
21+ internal const string metalShavingsCode = @"metal_shaving";
2122 public const float IngotVoxelEquivalent = 2.38f;
2223
2324 private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material?
@@ -61,7 +62,7 @@ namespace AnvilMetalRecovery
6162
6263 public override double ExecuteOrder( )
6364 {
64- return 0.1d;
65+ return 0.11d;
6566 }
6667
6768 public override void Start(ICoreAPI api)
@@ -91,7 +92,7 @@ namespace AnvilMetalRecovery
9192 //ServerAPI.RegisterBlockEntityClass(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
9293 ServerCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil));
9394
94- ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
95+ ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering);
9596
9697 SetupHotbarObserver( );
9798
@@ -100,6 +101,8 @@ namespace AnvilMetalRecovery
100101 #if DEBUG
101102 ServerAPI.RegisterCommand("durability", "edit durability of item", " (Held tool) and #", EditDurability);
102103 #endif
104+
105+
103106 }
104107
105108 public override void StartClientSide(ICoreClientAPI api)
@@ -122,32 +125,11 @@ namespace AnvilMetalRecovery
122125
123126 private void RegisterItemMappings( )
124127 {
125- this.CoreAPI.RegisterItemClass("VariableMetalItem", typeof(VariableMetalItem));
126-
128+ this.CoreAPI.RegisterItemClass(@"VariableMetalItem", typeof(VariableMetalItem));
129+ this.CoreAPI.RegisterItemClass(@"SmartSmeltableItem", typeof(SmartSmeltableItem));
127130 }
128131
129132
130- /*
131- internal void GenerateMetalShavingsItems( )
132- {
133- //TODO: Automatic Generation of Item 'metal_shaving' by metal & alloy list at RUNTIME
134- var genericShaving = ServerAPI.World.ClassRegistry.CreateItem("metal_shaving");
135- //genericShaving.CombustibleProps.
136-
137- var metalProperties = new Dictionary<AssetLocation, MetalProperty>( );
138-
139- foreach (var entry in ServerAPI.Assets.GetMany<MetalProperty>(Mod.Logger, "worldproperties/")) {
140- AssetLocation loc = entry.Key.Clone( );
141- loc.Path = loc.Path.Replace("worldproperties/", "");
142- loc.RemoveEnding( );
143-
144- entry.Value.Code.Domain = entry.Key.Domain;
145-
146- metalProperties.Add(loc, entry.Value);
147-
148- }
149- }
150- */
151133
152134 private void SetupHotbarObserver( ){
153135 ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior));
@@ -273,6 +255,48 @@ namespace AnvilMetalRecovery
273255 }
274256
275257 }
258+
259+ /// <summary>
260+ /// Adds all smelting related 'combustibleProps' fields from known Ingot Codes; (matching variant keys)
261+ /// </summary>
262+ /// <returns>The combuastable properties by code variant.</returns>
263+ /// <param name="updatingCode">PARTIAL Item code.</param>
264+ private void ApplySmeltingPropertiesByCodeVariant(AssetLocation updatingCode, int ratioOverride = 1 )
265+ {
266+ //ALL ????:'ingot-*' type items...
267+ var ingotItems = ServerAPI.World.Items.Where(itm => itm.ItemId > 0 && itm.Code != null && itm.Code.BeginingOnly(@"ingot"));
268+
269+ #if DEBUG
270+ this.Mod.Logger.VerboseDebug("found {0} Ingot type items", ingotItems.Count());
271+ #endif
272+
273+ foreach (var ingotEntry in ingotItems) {
274+ if (ingotEntry == null) continue;
275+ string metalName = ingotEntry?.Variant[@"metal"];
276+ var metalSmeltProps = ingotEntry?.CombustibleProps?.Clone( );
277+
278+ if (metalSmeltProps == null) continue;//SHOULD BE NEVER !
279+ if (string.IsNullOrEmpty(metalName)) continue;
280+
281+ metalSmeltProps.SmeltedRatio = ratioOverride;
282+ AssetLocation shavingCode = updatingCode.AppendPathVariant(metalName);
283+ var shavingEquivalentItem = ServerAPI.World.GetItem(shavingCode);
284+ if (shavingEquivalentItem != null)
285+ {
286+ shavingEquivalentItem.CombustibleProps = metalSmeltProps;
287+ #if DEBUG
288+ ServerAPI.Logger.VerboseDebug("Updated SmeltProps, for: {0}", shavingCode.ToString( ));
289+ #endif
290+ }
291+ else
292+ {
293+ #if DEBUG
294+ ServerAPI.Logger.VerboseDebug("Non-existant item: {0}", shavingCode.ToString( ));
295+ #endif
296+ }
297+ }
298+
299+ }
276300 }
277301
278302
--- a/AnvilMetalRecovery/assets/fma/itemtypes/metal/metal_shavings.json
+++ b/AnvilMetalRecovery/assets/fma/itemtypes/metal/metal_shavings.json
@@ -1,6 +1,6 @@
11 {
2- code: "metal_shaving",
3-
2+ code: "metal_shaving",
3+ class: "SmartSmeltableItem",
44 maxstacksize: 128,
55 attributes: {
66 handbook: {
@@ -13,7 +13,8 @@
1313 "*-blistersteel":true,
1414 "*-uranium": true
1515 }
16- }
16+ },
17+ ratio: 20,
1718 },
1819 variantgroups: [
1920 { code: "metal", states: ["blistersteel"], loadFromProperties: "game:block/metal" },
@@ -25,143 +26,7 @@
2526 "metal": { base: "game:block/metal/ingot/{metal}" },
2627 },
2728 creativeinventory: { "general": ["*"], "items": ["*"] },
28- materialDensityByType: {
29- "*-copper": 8960,
30- "*-brass": 8500,
31- "*-tinbronze": 7600,
32- "*-bismuthbronze": 7900,
33- "*-blackbronze": 9000,
34- "*-iron": 7870,
35- "*-meteoriciron": 7800,
36- "*-steel": 7820,
37- "*-blistersteel": 7720,
38- "*-gold": 19300,
39- "*-lead": 11300,
40- "*-tin": 7260,
41- "*-chromium": 7150,
42- "*-platinum": 21500,
43- "*-titanium": 4510,
44- "*-zinc": 7140,
45- "*-silver": 10500,
46- "*-bismuth": 9790,
47- "*-molybdochalkos": 9600
48- },
49- combustiblePropsByType: {
50- "*-copper": {
51- meltingPoint: 1084,
52- meltingDuration: 30,
53- smeltedRatio: 20,
54- smeltedStack: { type: "item", code: "game:ingot-copper" }
55- },
56- "*-brass": {
57- meltingPoint: 920,
58- meltingDuration: 30,
59- smeltedRatio: 20,
60- smeltedStack: { type: "item", code: "game:ingot-brass" }
61- },
62- "*-tinbronze": {
63- meltingPoint: 950,
64- meltingDuration: 30,
65- smeltedRatio: 20,
66- smeltedStack: { type: "item", code: "game:ingot-tinbronze" }
67- },
68- "*-bismuthbronze": {
69- meltingPoint: 850,
70- meltingDuration: 30,
71- smeltedRatio: 20,
72- smeltedStack: { type: "item", code: "game:ingot-bismuthbronze" }
73- },
74- "*-blackbronze": {
75- meltingPoint: 1020,
76- meltingDuration: 30,
77- smeltedRatio: 20,
78- smeltedStack: { type: "item", code: "game:ingot-blackbronze" }
79- },
80- "*-iron": {
81- meltingPoint: 1482,
82- meltingDuration: 30,
83- smeltedRatio: 20,
84- smeltedStack: { type: "item", code: "game:ingot-iron" }
85- },
86- "*-meteoriciron": {
87- meltingPoint: 1476,
88- meltingDuration: 30,
89- smeltedRatio: 20,
90- smeltedStack: { type: "item", code: "game:ingot-meteoriciron" }
91- },
92- "*-steel": {
93- meltingPoint: 1502,
94- meltingDuration: 30,
95- smeltedRatio: 20,
96- smeltedStack: { type: "item", code: "game:ingot-steel" }
97- },
98- "*-blistersteel": {
99- meltingPoint: 1602,
100- meltingDuration: 30,
101- smeltedRatio: 20,
102- smeltedStack: { type: "item", code: "game:ingot-blistersteel" }
103- },
104- "*-gold": {
105- meltingPoint: 1063,
106- meltingDuration: 30,
107- smeltedRatio: 20,
108- smeltedStack: { type: "item", code: "game:ingot-gold", }
109- },
110- "*-lead": {
111- meltingPoint: 327,
112- meltingDuration: 30,
113- smeltedRatio: 20,
114- smeltedStack: { type: "item", code: "game:ingot-lead" }
115- },
116- "*-tin": {
117- meltingPoint: 232,
118- meltingDuration: 30,
119- smeltedRatio: 20,
120- smeltedStack: { type: "item", code: "game:ingot-tin" }
121- },
122- "*-chromium": {
123- meltingPoint: 1907,
124- meltingDuration: 30,
125- smeltedRatio: 20,
126- smeltedStack: { type: "item", code: "game:ingot-chromium" }
127- },
128- "*-platinum": {
129- meltingPoint: 1770,
130- meltingDuration: 30,
131- smeltedRatio: 20,
132- smeltedStack: { type: "item", code: "game:ingot-platinum" }
133- },
134- "*-titanium": {
135- meltingPoint: 1668,
136- meltingDuration: 30,
137- smeltedRatio: 20,
138- smeltedStack: { type: "item", code: "game:ingot-titanium" }
139- },
140- "*-zinc": {
141- meltingPoint: 419,
142- meltingDuration: 30,
143- smeltedRatio: 20,
144- smeltedStack: { type: "item", code: "game:ingot-zinc" }
145- },
146- "*-silver": {
147- meltingPoint: 961,
148- meltingDuration: 30,
149- smeltedRatio: 20,
150- smeltedStack: { type: "item", code: "game:ingot-silver" }
151- },
152- "*-bismuth": {
153- meltingPoint: 271,
154- meltingDuration: 30,
155- smeltedRatio: 20,
156- smeltedStack: { type: "item", code: "game:ingot-bismuth" }
157- },
158- "*-molybdochalkos": {
159- meltingPoint: 902,
160- meltingDuration: 30,
161- smeltedRatio: 20,
162- smeltedStack: { type: "item", code: "game:ingot-molybdochalkos" }
163- }
164- },
29+ materialDensity: 9000,
16530 guiTransform: {
16631 rotate: true,
16732 translation: { x: -3, y: 0, z: 0 },