Skip to content

Commit

Permalink
prevent dlc crash
Browse files Browse the repository at this point in the history
  • Loading branch information
InvalidArgument3 committed Nov 10, 2024
1 parent 3f80021 commit 749c692
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions ShipyardsRevival/Data/Scripts/ShipyardMod/ProcessShipyardAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Sandbox.Game;
using Sandbox.Game.Entities;
using Sandbox.Game.Weapons;
using Sandbox.Game.World;
using Sandbox.ModAPI;
using ShipyardMod.ItemClasses;
using ShipyardMod.Utility;
Expand Down Expand Up @@ -841,31 +842,39 @@ private bool BuildTarget(BlockTarget target, ShipyardItem item, IMyCubeBlock too
{
IMyProjector projector = target.Projector;
IMySlimBlock block = target.Block;

if (projector == null || block == null)
return false;


// Check if the projector is allowed to build the block
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 (MyAPIGateway.Session.CreativeMode)
{
projector.Build(block, projector.OwnerId, projector.EntityId, false, projector.OwnerId);
return projector.CanBuild(block, true) != BuildCheckResult.OK;
}

//try to remove the first component from inventory
string name = ((MyCubeBlockDefinition)block.BlockDefinition).Components[0].Definition.Id.SubtypeName;
if (_tmpInventory.PullAny(item.ConnectedCargo, name, 1))
// Try to pull required components for building
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);

return projector.CanBuild(block, true) != BuildCheckResult.OK;
}

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

}
}

0 comments on commit 749c692

Please sign in to comment.