From b53dff5d12b93ca9c0cb93c29a6d008599d1d66e Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 19 Jul 2020 01:42:32 +0200 Subject: [PATCH] Remove initializer data once the block is placed --- GamecraftModdingAPI/Block.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/GamecraftModdingAPI/Block.cs b/GamecraftModdingAPI/Block.cs index ade9f9b..dc3fe19 100644 --- a/GamecraftModdingAPI/Block.cs +++ b/GamecraftModdingAPI/Block.cs @@ -82,6 +82,7 @@ namespace GamecraftModdingAPI position, uscale, scale, player, rotation, out var initializer); var bl = New(egid.entityID, egid.groupID); bl.InitData.Group = BlockEngine.InitGroup(initializer); + Placed += bl.OnPlacedInit; return bl; } @@ -352,6 +353,13 @@ namespace GamecraftModdingAPI (GridConnectionsEntityStruct st) => new SimBody(st.machineRigidBodyId)); } + private void OnPlacedInit(object sender, BlockPlacedRemovedEventArgs e) + { //Member method instead of lambda to avoid constantly creating delegates + if (e.ID != Id) return; + Placed -= OnPlacedInit; //And we can reference it + InitData = default; //Remove initializer as it's no longer valid - if the block gets removed it shouldn't be used again + } + public override string ToString() { return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";