-
Notifications
You must be signed in to change notification settings - Fork 109
RemoteCrafting optimisation #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,11 @@ public static bool Prefix(XUiC_LootContainer __instance) { | |
|
|
||
| if (__instance.localTileEntity == null) | ||
| { | ||
| Log.Out("[DropBox] OnClose: localTileEntity is null, skipping."); | ||
| return true; | ||
| } | ||
| var composite = __instance.localTileEntity as TEFeatureStorage; | ||
| if (composite == null) | ||
| { | ||
| Log.Out("[DropBox] OnClose: localTileEntity is not TEFeatureStorage, skipping."); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -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."); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| return true; | ||
| } | ||
|
|
||
|
|
@@ -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}"); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| if (primaryPlayer == null) | ||
| return true; | ||
|
|
||
| if (__instance.localTileEntity.items == null) | ||
| { | ||
| Log.Out("[DropBox] OnClose: items array is null, skipping."); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| return true; | ||
| } | ||
|
|
||
| var items = __instance.localTileEntity.items; | ||
| var tileEntities = RemoteCraftingUtils.GetTileEntities(primaryPlayer, distance, false); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
|
|
||
| if (RemoteCraftingUtils.AddToNearbyContainer(primaryPlayer, items[i], distance)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}."); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| items[i] = ItemStack.Empty.Clone(); | ||
| continue; | ||
| } | ||
|
|
||
| Log.Out($"[DropBox] OnClose: no container accepted {itemName}, leaving in slot {i}."); | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if (!buildsettings.Development) |
||
| __instance.localTileEntity.UpdateSlot(i, items[i]); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
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
?