Upload from upload_mods.ps1
This commit is contained in:
40
Score/RemoteCrafting/Harmony/DropBoxToContainers.cs
Normal file
40
Score/RemoteCrafting/Harmony/DropBoxToContainers.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using Rebirth.RemoteCrafting;
|
||||
|
||||
namespace Features.RemoteCrafting
|
||||
{
|
||||
public class DropBoxToContainersPatches
|
||||
{
|
||||
[HarmonyPatch(typeof(XUiC_LootContainer))]
|
||||
[HarmonyPatch("OnClose")]
|
||||
public class XUiCLootContainerOnClose
|
||||
{
|
||||
public static bool Prefix(XUiC_LootContainer __instance, BlockValue ___blockValue, TileEntityLootContainer ___localTileEntity)
|
||||
{
|
||||
if (!___blockValue.Block.Properties.Values.ContainsKey("DropBox")) return true;
|
||||
if (___localTileEntity == null) return true;
|
||||
StringParsers.TryParseBool(___blockValue.Block.Properties.Values["DropBox"], out var isDropBox);
|
||||
if (!isDropBox) return true;
|
||||
|
||||
var distance = 150f;
|
||||
|
||||
var primaryPlayer = __instance.xui.playerUI.entityPlayer;
|
||||
var items = ___localTileEntity.GetItems();
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
if (items[i].IsEmpty()) continue;
|
||||
// If we successfully added, clear the stack.
|
||||
if (RemoteCraftingUtils.AddToNearbyContainer(primaryPlayer, items[i], distance))
|
||||
{
|
||||
Debug.Log($"Removing {items[i].itemValue.ItemClass.GetItemName()}");
|
||||
items[i] = ItemStack.Empty.Clone();
|
||||
}
|
||||
___localTileEntity.UpdateSlot(i, items[i]);
|
||||
|
||||
}
|
||||
|
||||
___localTileEntity.SetModified();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user