First Machine Age's Mods (Combined repo.)
修订版 | 868f21b19d98ca01b1ae699108861945fe9380b5 (tree) |
---|---|
时间 | 2021-05-01 09:17:19 |
作者 | melchior <melchior@user...> |
Commiter | melchior |
Item self-applied Smeltable properties for regular (and custom)
Ingots
@@ -74,6 +74,7 @@ | ||
74 | 74 | <Compile Include="EntityBehaviors\HotbarObserverData.cs" /> |
75 | 75 | <Compile Include="Data\RecoveryEntry.cs" /> |
76 | 76 | <Compile Include="Items\VariableMetalItem.cs" /> |
77 | + <Compile Include="Items\SmartSmeltableItem.cs" /> | |
77 | 78 | </ItemGroup> |
78 | 79 | <ItemGroup> |
79 | 80 | <None Include="modinfo.json"> |
@@ -1,4 +1,5 @@ | ||
1 | 1 | using System; |
2 | +using System.Linq; | |
2 | 3 | |
3 | 4 | using Vintagestory.API.Common; |
4 | 5 | using Vintagestory.API.Common.Entities; |
@@ -40,6 +41,18 @@ namespace AnvilMetalRecovery | ||
40 | 41 | if (itemStack.Attributes.HasAttribute(@"durability")) |
41 | 42 | itemStack.Attributes.SetInt(@"durability", number); |
42 | 43 | } |
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 | + } | |
43 | 56 | } |
44 | 57 | } |
45 | 58 |
@@ -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 | + |
@@ -18,6 +18,7 @@ namespace AnvilMetalRecovery | ||
18 | 18 | { |
19 | 19 | internal const string anvilKey = @"Anvil"; |
20 | 20 | internal const string metalFragmentsCode = @"fma:metal_fragments"; |
21 | + internal const string metalShavingsCode = @"metal_shaving"; | |
21 | 22 | public const float IngotVoxelEquivalent = 2.38f; |
22 | 23 | |
23 | 24 | private Dictionary<AssetLocation, RecoveryEntry> itemToVoxelLookup = new Dictionary<AssetLocation, RecoveryEntry>();//Ammount & Material? |
@@ -61,7 +62,7 @@ namespace AnvilMetalRecovery | ||
61 | 62 | |
62 | 63 | public override double ExecuteOrder( ) |
63 | 64 | { |
64 | - return 0.1d; | |
65 | + return 0.11d; | |
65 | 66 | } |
66 | 67 | |
67 | 68 | public override void Start(ICoreAPI api) |
@@ -91,7 +92,7 @@ namespace AnvilMetalRecovery | ||
91 | 92 | //ServerAPI.RegisterBlockEntityClass(anvilKey, typeof(MetalRecovery_BlockEntityAnvil)); |
92 | 93 | ServerCore.ClassRegistryNative.ReplaceBlockEntityType(anvilKey, typeof(MetalRecovery_BlockEntityAnvil)); |
93 | 94 | |
94 | - ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering); | |
95 | + ServerCore.Event.ServerRunPhase(EnumServerRunPhase.GameReady, MaterialDataGathering); | |
95 | 96 | |
96 | 97 | SetupHotbarObserver( ); |
97 | 98 |
@@ -100,6 +101,8 @@ namespace AnvilMetalRecovery | ||
100 | 101 | #if DEBUG |
101 | 102 | ServerAPI.RegisterCommand("durability", "edit durability of item", " (Held tool) and #", EditDurability); |
102 | 103 | #endif |
104 | + | |
105 | + | |
103 | 106 | } |
104 | 107 | |
105 | 108 | public override void StartClientSide(ICoreClientAPI api) |
@@ -122,32 +125,11 @@ namespace AnvilMetalRecovery | ||
122 | 125 | |
123 | 126 | private void RegisterItemMappings( ) |
124 | 127 | { |
125 | - this.CoreAPI.RegisterItemClass("VariableMetalItem", typeof(VariableMetalItem)); | |
126 | - | |
128 | + this.CoreAPI.RegisterItemClass(@"VariableMetalItem", typeof(VariableMetalItem)); | |
129 | + this.CoreAPI.RegisterItemClass(@"SmartSmeltableItem", typeof(SmartSmeltableItem)); | |
127 | 130 | } |
128 | 131 | |
129 | 132 | |
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 | - */ | |
151 | 133 | |
152 | 134 | private void SetupHotbarObserver( ){ |
153 | 135 | ServerCore.RegisterEntityBehaviorClass(@"HotbarObserver", typeof(HotbarObserverBehavior)); |
@@ -273,6 +255,48 @@ namespace AnvilMetalRecovery | ||
273 | 255 | } |
274 | 256 | |
275 | 257 | } |
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 | + } | |
276 | 300 | } |
277 | 301 | |
278 | 302 |
@@ -1,6 +1,6 @@ | ||
1 | 1 | { |
2 | - code: "metal_shaving", | |
3 | - | |
2 | + code: "metal_shaving", | |
3 | + class: "SmartSmeltableItem", | |
4 | 4 | maxstacksize: 128, |
5 | 5 | attributes: { |
6 | 6 | handbook: { |
@@ -13,7 +13,8 @@ | ||
13 | 13 | "*-blistersteel":true, |
14 | 14 | "*-uranium": true |
15 | 15 | } |
16 | - } | |
16 | + }, | |
17 | + ratio: 20, | |
17 | 18 | }, |
18 | 19 | variantgroups: [ |
19 | 20 | { code: "metal", states: ["blistersteel"], loadFromProperties: "game:block/metal" }, |
@@ -25,143 +26,7 @@ | ||
25 | 26 | "metal": { base: "game:block/metal/ingot/{metal}" }, |
26 | 27 | }, |
27 | 28 | 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, | |
165 | 30 | guiTransform: { |
166 | 31 | rotate: true, |
167 | 32 | translation: { x: -3, y: 0, z: 0 }, |