First Machine Age's Mods (Combined repo.)
Revisión | b3c470593faa82cac96cd917eb426cc129c4430d (tree) |
---|---|
Tiempo | 2022-08-13 08:56:12 |
Autor | melchior <melchior@user...> |
Commiter | melchior |
Mold/Ingot recovery A-OK
Also, steam particles as intended
@@ -14,6 +14,10 @@ namespace AnvilMetalRecovery | ||
14 | 14 | public class MoldDestructionRecovererBehavior : BlockBehavior |
15 | 15 | { |
16 | 16 | public static readonly string BehaviorClassName = @"MoldDestructionRecoverer"; |
17 | + private readonly AssetLocation MetalBits_partial = new AssetLocation(GlobalConstants.DefaultDomain, @"metalbit"); | |
18 | + private const int shavingValue = 5; | |
19 | + | |
20 | + | |
17 | 21 | |
18 | 22 | public MoldDestructionRecovererBehavior(Block block) : base(block) |
19 | 23 | { |
@@ -41,17 +45,53 @@ namespace AnvilMetalRecovery | ||
41 | 45 | #if DEBUG |
42 | 46 | world.Api.Logger.VerboseDebug("{0} Ingot Mold(s) with L {1} Units, R {2} Units", ingotMold.quantityMolds, ingotMold.fillLevelLeft, ingotMold.fillLevelRight); |
43 | 47 | #endif |
44 | - } | |
45 | 48 | |
49 | + if ( ingotMold.fillLevelLeft >= shavingValue && ingotMold.contentsLeft != null) | |
50 | + { | |
51 | + var ingotMetal = ingotMold.contentsLeft.Collectible.Variant[@"metal"]; | |
52 | + SpawnMetalBits(world, pos, ingotMold.fillLevelLeft, ingotMetal); | |
53 | + } | |
54 | + | |
55 | + if ( ingotMold.fillLevelRight >= shavingValue && ingotMold.contentsRight != null) | |
56 | + { | |
57 | + var ingotMetal = ingotMold.contentsLeft.Collectible.Variant[@"metal"]; | |
58 | + SpawnMetalBits(world, pos, ingotMold.fillLevelRight, ingotMetal); | |
59 | + } | |
60 | + | |
61 | + return; | |
62 | + } | |
46 | 63 | |
47 | 64 | if (someBlockEntity is BlockEntityToolMold) { |
48 | 65 | var toolMold = someBlockEntity as BlockEntityToolMold; |
49 | 66 | #if DEBUG |
50 | 67 | world.Api.Logger.VerboseDebug("Tool Mold with {0} Units", toolMold.fillLevel); |
51 | 68 | #endif |
69 | + if ( toolMold.fillLevel >= shavingValue && toolMold.metalContent != null) | |
70 | + { | |
71 | + var metalCode = toolMold.metalContent.Collectible.Variant.AnyKeys(@"metal", @"material"); | |
72 | + SpawnMetalBits(world, pos, toolMold.fillLevel, metalCode); | |
73 | + } | |
52 | 74 | } |
53 | 75 | |
54 | 76 | } |
77 | + | |
78 | + internal void SpawnMetalBits(IWorldAccessor world, BlockPos pos, int unitQuantity, string baseMetalCode) | |
79 | + { | |
80 | + if (unitQuantity > 0) | |
81 | + { | |
82 | + int shavingQty = unitQuantity / shavingValue; | |
83 | + Item metalShavingsItem = world.Api.World.GetItem(MetalBits_partial.AppendPathVariant(baseMetalCode)); | |
84 | + | |
85 | + if (shavingQty >= 1 && metalShavingsItem != null) | |
86 | + { | |
87 | + var metalShavingsStack = new ItemStack(metalShavingsItem, shavingQty); | |
88 | + #if DEBUG | |
89 | + world.Api.Logger.VerboseDebug("Creating '{0}' @{1} *{2} Units",metalShavingsItem, pos, shavingQty); | |
90 | + #endif | |
91 | + world.Api.World.SpawnItemEntity(metalShavingsStack, pos.ToVec3d( ).Add(0.1d, 0, 0)); | |
92 | + } | |
93 | + } | |
94 | + } | |
55 | 95 | } |
56 | 96 | } |
57 | 97 |
@@ -100,6 +100,14 @@ namespace AnvilMetalRecovery | ||
100 | 100 | { |
101 | 101 | return parameters.All(parm => parm != null); |
102 | 102 | } |
103 | + | |
104 | + internal static string AnyKeys(this RelaxedReadOnlyDictionary<string, string> source, params string[ ] keys) | |
105 | + { | |
106 | + foreach (var key in keys) { | |
107 | + if (source.ContainsKey(key)) return source[key]; | |
108 | + } | |
109 | + return String.Empty; | |
110 | + } | |
103 | 111 | } |
104 | 112 | } |
105 | 113 |