Remove initializer data once the block is placed
This commit is contained in:
parent
cc4ed3e174
commit
16521ab7eb
1 changed files with 8 additions and 0 deletions
|
@ -82,6 +82,7 @@ namespace GamecraftModdingAPI
|
||||||
position, uscale, scale, player, rotation, out var initializer);
|
position, uscale, scale, player, rotation, out var initializer);
|
||||||
var bl = New<T>(egid.entityID, egid.groupID);
|
var bl = New<T>(egid.entityID, egid.groupID);
|
||||||
bl.InitData.Group = BlockEngine.InitGroup(initializer);
|
bl.InitData.Group = BlockEngine.InitGroup(initializer);
|
||||||
|
Placed += bl.OnPlacedInit;
|
||||||
return bl;
|
return bl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -352,6 +353,13 @@ namespace GamecraftModdingAPI
|
||||||
(GridConnectionsEntityStruct st) => new SimBody(st.machineRigidBodyId));
|
(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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";
|
return $"{nameof(Id)}: {Id}, {nameof(Position)}: {Position}, {nameof(Type)}: {Type}, {nameof(Color)}: {Color}, {nameof(Exists)}: {Exists}";
|
||||||
|
|
Loading…
Reference in a new issue