Skip to content

Commit

Permalink
...trycatch the build?
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Nov 10, 2024
1 parent 749c692 commit e8af7ed
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ProcessShipyardAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -850,31 +850,43 @@ private bool BuildTarget(BlockTarget target, ShipyardItem item, IMyCubeBlock too
if (projector.CanBuild(block, false) != BuildCheckResult.OK)
return false;

// Verify if DLC is owned for this block, notify if missing
var blockDefinition = block.BlockDefinition as MyCubeBlockDefinition;
if (blockDefinition != null && !MySession.Static.CheckDLCAndNotify(blockDefinition))
{
Logging.Instance.WriteDebug($"DLC required for block '{blockDefinition.DisplayNameText}' is not owned, skipping build.");
return false; // Skip this block if DLC is required but not owned
}

// If in Creative Mode, build the block immediately
if (MyAPIGateway.Session.CreativeMode)
{
projector.Build(block, projector.OwnerId, projector.EntityId, false, projector.OwnerId);
try
{
projector.Build(block, projector.OwnerId, projector.EntityId, false, projector.OwnerId);
}
catch (NullReferenceException ex)
{
// Log and ignore the exception to prevent a crash
Logging.Instance.WriteDebug($"Build failed due to missing DLC reference: {ex.Message}");
return false;
}
return projector.CanBuild(block, true) != BuildCheckResult.OK;
}

// Try to pull required components for building
// Attempt to pull required components for building in survival mode
var blockDefinition = block.BlockDefinition as MyCubeBlockDefinition;
string componentName = blockDefinition.Components[0].Definition.Id.SubtypeName;
if (_tmpInventory.PullAny(item.ConnectedCargo, componentName, 1))
{
_tmpInventory.Clear();
projector.Build(block, projector.OwnerId, projector.EntityId, false, projector.OwnerId);
try
{
projector.Build(block, projector.OwnerId, projector.EntityId, false, projector.OwnerId);
}
catch (NullReferenceException ex)
{
// Log and ignore the exception to prevent a crash
Logging.Instance.WriteDebug($"Build failed due to missing DLC reference: {ex.Message}");
return false;
}
return projector.CanBuild(block, true) != BuildCheckResult.OK;
}

return false; // Return false if we cannot build the block
return false; // Return false if the block cannot be built
}

}
}

0 comments on commit e8af7ed

Please sign in to comment.