Browse Source

Remove initializer data once the block is placed

tags/v2.2.0
NorbiPeti 4 years ago
parent
commit
16521ab7eb
1 changed files with 8 additions and 0 deletions
  1. +8
    -0
      GamecraftModdingAPI/Block.cs

+ 8
- 0
GamecraftModdingAPI/Block.cs View File

@@ -82,6 +82,7 @@ namespace GamecraftModdingAPI
position, uscale, scale, player, rotation, out var initializer);
var bl = New<T>(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}";


Loading…
Cancel
Save