From dd6ee0450cd01a52385686b280038382d3d18c34 Mon Sep 17 00:00:00 2001 From: TheCrunchy Date: Sun, 30 Oct 2022 16:44:16 +0000 Subject: [PATCH] loop through grids invent to see if items can be added to it --- TetherSE/Tether.cs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/TetherSE/Tether.cs b/TetherSE/Tether.cs index 944b943..4738fe9 100644 --- a/TetherSE/Tether.cs +++ b/TetherSE/Tether.cs @@ -6,6 +6,7 @@ using Sandbox.Game; using Sandbox.Game.Entities; using Sandbox.Game.Entities.Character; +using Sandbox.Game.Entities.Cube; using Sandbox.Game.World; using Sandbox.ModAPI; using VRage.Game.Entity; @@ -13,6 +14,7 @@ using Sandbox.Game.Entities.Inventory; using Sandbox.Game.Weapons; using VRage.Game; +using VRage.Game.ModAPI.Ingame; using VRageMath; @@ -93,11 +95,19 @@ public static void DoGrinder() if (!objectId.Content.GetObjectId().ToString().ToLower().Contains("ore") && !objectId.Content.GetObjectId().ToString().ToLower().Contains("ingot") && !objectId.Content.GetObjectId().ToString().ToLower().Contains("component")) continue; - MyConstants.DEFAULT_INTERACTIVE_DISTANCE = 10000; - MyInventory.TransferByPlanner(MySession.Static.LocalCharacter.GetInventory(), inventory, objectId.Content.GetObjectId(), MyItemFlags.None, objectId.Amount); - MyConstants.DEFAULT_INTERACTIVE_DISTANCE = 10; + + foreach (var block in (MySession.Static.ControlledGrid).GetFatBlocks().OfType()) + { + if (!block.HasInventory) continue; + var invent = block.GetInventory(); + if (!invent.CanItemsBeAdded(objectId.Amount, objectId.GetDefinitionId())) continue; + MyConstants.DEFAULT_INTERACTIVE_DISTANCE = 10000; + MyInventory.TransferByPlanner(MySession.Static.LocalCharacter.GetInventory(), invent, objectId.Content.GetObjectId(), MyItemFlags.None, objectId.Amount); + MyConstants.DEFAULT_INTERACTIVE_DISTANCE = 10; + } } } + public static void DoDrill() { var inventory = (MyInventory)GetTargetedBlock.selectedBlock.GetInventory();