Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ public static bool Prefix(XUiC_LootContainer __instance) {

if (__instance.localTileEntity == null)
{
Log.Out("[DropBox] OnClose: localTileEntity is null, skipping.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

return true;
}
var composite = __instance.localTileEntity as TEFeatureStorage;
if (composite == null)
{
Log.Out("[DropBox] OnClose: localTileEntity is not TEFeatureStorage, skipping.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

return true;
}

Expand All @@ -34,7 +32,6 @@ public static bool Prefix(XUiC_LootContainer __instance) {
StringParsers.TryParseBool(dropBoxStr, out var dropBoxBool) && dropBoxBool;
if (block is not BlockDropBoxContainer && !hasDropBoxProperty)
{
Log.Out($"[DropBox] OnClose: block at {pos} ({block.GetBlockName()}) is not a drop box, skipping.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

return true;
}

Expand All @@ -44,29 +41,26 @@ public static bool Prefix(XUiC_LootContainer __instance) {
distance = StringParsers.ParseFloat(strDistance);

var primaryPlayer = __instance.xui.playerUI.entityPlayer;
Log.Out($"[DropBox] OnClose: distributing from {block.GetBlockName()} at {pos}, player={primaryPlayer?.EntityName ?? "null"}, distance={distance}, IsServer={SingletonMonoBehaviour<ConnectionManager>.Instance.IsServer}");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

if (primaryPlayer == null)
return true;

if (__instance.localTileEntity.items == null)
{
Log.Out("[DropBox] OnClose: items array is null, skipping.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

return true;
}

var items = __instance.localTileEntity.items;
var tileEntities = RemoteCraftingUtils.GetTileEntities(primaryPlayer, distance, false);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get tileEntities once before loop instead of repeatedly for each item.

for (var i = 0; i < items.Length; i++)
{
if (items[i].IsEmpty()) continue;
var itemName = items[i].itemValue?.ItemClass?.GetItemName() ?? "unknown";
Log.Out($"[DropBox] OnClose: trying to distribute slot {i}: {itemName} x{items[i].count}");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?


if (RemoteCraftingUtils.AddToNearbyContainer(primaryPlayer, items[i], distance))

@geromet geromet Jul 8, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use new function overload to use cached tileEntitites instead of recalculating them for each item.

if (RemoteCraftingUtils.AddToNearbyContainer(primaryPlayer, items[i], tileEntities))
{
Log.Out($"[DropBox] OnClose: distributed {itemName} successfully, clearing slot {i}.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

items[i] = ItemStack.Empty.Clone();
continue;
}

Log.Out($"[DropBox] OnClose: no container accepted {itemName}, leaving in slot {i}.");

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (!buildsettings.Development)
Log.Out
?

__instance.localTileEntity.UpdateSlot(i, items[i]);
}

Expand Down
Loading