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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
243
Score/RemoteCrafting/Harmony/IngredientsFromContainers.cs
Normal file
243
Score/RemoteCrafting/Harmony/IngredientsFromContainers.cs
Normal file
@@ -0,0 +1,243 @@
|
||||
using Rebirth.RemoteCrafting;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Features.RemoteCrafting
|
||||
{
|
||||
/// <summary>
|
||||
/// Patches to support the Crafting From Remote Storage
|
||||
/// </summary>
|
||||
public class EnhancedRecipeLists
|
||||
{
|
||||
/// <summary>
|
||||
/// Used to determine which recipes the player can craft based on the availability of ingredients in local containers.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(XUiC_RecipeList))]
|
||||
[HarmonyPatch("BuildRecipeInfosList")]
|
||||
public class BuildRecipeInfosList
|
||||
{
|
||||
public static bool Prefix(XUiC_RecipeList __instance, ref List<ItemStack> _items)
|
||||
{
|
||||
var player = __instance.xui.playerUI.entityPlayer;
|
||||
_items.AddRange(RemoteCraftingUtils.SearchNearbyContainers(player));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extends what is considered to be in the player's backpack / tool belt to include local containers.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(XUiM_PlayerInventory))]
|
||||
[HarmonyPatch("GetAllItemStacks")]
|
||||
public class GetAllItemStacks
|
||||
{
|
||||
public static void Postfix(ref List<ItemStack> __result, EntityPlayerLocal ___localPlayer)
|
||||
{
|
||||
__result.AddRange(RemoteCraftingUtils.SearchNearbyContainers(___localPlayer));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hijacks the GetBindingValue so we can get an accurate count of all the items we have available, including from local storage.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(XUiC_IngredientEntry))]
|
||||
[HarmonyPatch("GetBindingValue")]
|
||||
public class GetBindingValue
|
||||
{
|
||||
public static bool Prefix(XUiC_IngredientEntry __instance, ref bool __result, ref string value,
|
||||
string bindingName, CachedStringFormatter<int> ___needcountFormatter,
|
||||
CachedStringFormatter<int> ___havecountFormatter, bool ___materialBased, ItemStack ___ingredient,
|
||||
string ___material, XUiC_RecipeCraftCount ___craftCountControl,
|
||||
CachedStringFormatterXuiRgbaColor ___itemicontintcolorFormatter)
|
||||
{
|
||||
var flag = ___ingredient != null;
|
||||
switch (bindingName)
|
||||
{
|
||||
case "haveneedcount":
|
||||
{
|
||||
var text = (flag
|
||||
? ___needcountFormatter.Format(___ingredient.count * ___craftCountControl.Count)
|
||||
: "");
|
||||
var value1 = 0;
|
||||
var childByType = __instance.WindowGroup.Controller.GetChildByType<XUiC_WorkstationMaterialInputGrid>();
|
||||
if (childByType != null)
|
||||
{
|
||||
if (___materialBased)
|
||||
{
|
||||
value = (flag
|
||||
? (___havecountFormatter.Format(childByType.GetWeight(___material)) + "/" + text)
|
||||
: "");
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (flag
|
||||
? (___havecountFormatter.Format(
|
||||
__instance.xui.PlayerInventory.GetItemCount(___ingredient.itemValue)) + "/" +
|
||||
text)
|
||||
: "");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var childByType2 = __instance.WindowGroup.Controller
|
||||
.GetChildByType<XUiC_WorkstationInputGrid>();
|
||||
if (childByType2 != null)
|
||||
{
|
||||
value = (flag
|
||||
? (___havecountFormatter.Format(
|
||||
childByType2.GetItemCount(___ingredient.itemValue)) + "/" + text)
|
||||
: "");
|
||||
}
|
||||
else
|
||||
{
|
||||
value = (flag
|
||||
? (___havecountFormatter.Format(
|
||||
__instance.xui.PlayerInventory.GetItemCount(___ingredient.itemValue)) + "/" +
|
||||
text)
|
||||
: "");
|
||||
if (flag)
|
||||
{
|
||||
// add items from lootcontainers
|
||||
value1 = __instance.xui.PlayerInventory.GetItemCount(___ingredient.itemValue);
|
||||
var array = RemoteCraftingUtils.SearchNearbyContainers(__instance.xui.playerUI.entityPlayer,
|
||||
___ingredient.itemValue).ToArray();
|
||||
foreach (var t in array)
|
||||
{
|
||||
if (t != null && t.itemValue.type != 0 &&
|
||||
___ingredient.itemValue.type == t.itemValue.type)
|
||||
{
|
||||
value1 += t.count;
|
||||
}
|
||||
}
|
||||
|
||||
value = ___havecountFormatter.Format(value1) + "/" + text;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Expands the HasItems search to include local containers.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(XUiM_PlayerInventory))]
|
||||
[HarmonyPatch("HasItems")]
|
||||
public class HasItems
|
||||
{
|
||||
public static bool Postfix(bool __result, IList<ItemStack> _itemStacks, EntityPlayerLocal ___localPlayer,
|
||||
int _multiplier)
|
||||
{
|
||||
if (__result) return true;
|
||||
|
||||
// We need to make sure we satisfy all of the items.
|
||||
var itemsWeHave = 0;
|
||||
foreach (var itemStack in _itemStacks)
|
||||
{
|
||||
var totalCount = 0;
|
||||
// This is how many we need.
|
||||
var num = itemStack.count * _multiplier;
|
||||
// check player inventory
|
||||
var slots = ___localPlayer.bag.GetSlots();
|
||||
foreach (var entry in slots)
|
||||
{
|
||||
if (entry.IsEmpty()) continue;
|
||||
if (itemStack.itemValue.GetItemOrBlockId() != entry.itemValue.GetItemOrBlockId()) continue;
|
||||
totalCount += entry.count;
|
||||
// We have enough.
|
||||
if (totalCount >= num)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
// We have enough.
|
||||
if (totalCount >= num)
|
||||
{
|
||||
itemsWeHave++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check the toolbelt now.
|
||||
slots = ___localPlayer.inventory.GetSlots();
|
||||
foreach (var entry in slots)
|
||||
{
|
||||
if (entry.IsEmpty()) continue;
|
||||
if (itemStack.itemValue.GetItemOrBlockId() != entry.itemValue.GetItemOrBlockId()) continue;
|
||||
totalCount += entry.count;
|
||||
// We have enough.
|
||||
if (totalCount >= num)
|
||||
break;
|
||||
}
|
||||
|
||||
// We have enough.
|
||||
if (totalCount >= num)
|
||||
{
|
||||
itemsWeHave++;
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
// check container
|
||||
var containers = RemoteCraftingUtils.SearchNearbyContainers(___localPlayer, itemStack.itemValue);
|
||||
foreach (var stack in containers)
|
||||
{
|
||||
if (stack.IsEmpty()) continue;
|
||||
if (itemStack.itemValue.GetItemOrBlockId() != stack.itemValue.GetItemOrBlockId()) continue;
|
||||
totalCount += stack.count;
|
||||
// We have enough.
|
||||
if (totalCount >= num)
|
||||
break;
|
||||
}
|
||||
|
||||
// We don't have enough for this.
|
||||
if (totalCount < num)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (totalCount >= num)
|
||||
{
|
||||
itemsWeHave++;
|
||||
}
|
||||
}
|
||||
|
||||
return itemsWeHave >= _itemStacks.Count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Removes from local storage containers items which we've consumed.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(XUiM_PlayerInventory))]
|
||||
[HarmonyPatch("RemoveItems")]
|
||||
public class RemoveItems
|
||||
{
|
||||
public static bool Prefix(XUiM_PlayerInventory __instance, IList<ItemStack> _itemStacks, EntityPlayerLocal ___localPlayer, int _multiplier, IList<ItemStack> _removedItems
|
||||
, Bag ___backpack, Inventory ___toolbelt)
|
||||
{
|
||||
RemoteCraftingUtils.ConsumeItem(_itemStacks, ___localPlayer, _multiplier, _removedItems, ___backpack, ___toolbelt);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Code from OCB7D2D/OcbPinRecipes
|
||||
// Patch world unload to cleanup and save on exit
|
||||
[HarmonyPatch(typeof(World))]
|
||||
[HarmonyPatch("UnloadWorld")]
|
||||
public class WorldUnloadWorld
|
||||
{
|
||||
static void Postfix()
|
||||
{
|
||||
if (!Broadcastmanager.HasInstance) return;
|
||||
Broadcastmanager.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
322
Score/RemoteCrafting/Harmony/ItemActionRepairPatches.cs
Normal file
322
Score/RemoteCrafting/Harmony/ItemActionRepairPatches.cs
Normal file
@@ -0,0 +1,322 @@
|
||||
using HarmonyLib;
|
||||
using Rebirth.RemoteCrafting;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
// todo - fix as methods have changed
|
||||
namespace Features.RemoteCrafting
|
||||
{
|
||||
/// <summary>
|
||||
/// Patches to support repairing from remote storage
|
||||
/// </summary>
|
||||
public class ItemActionRepairPatches
|
||||
{
|
||||
private struct UpgradeInfo
|
||||
{
|
||||
public string FromBlock;
|
||||
public string ToBlock;
|
||||
public string Item;
|
||||
public int ItemCount;
|
||||
public string Sound;
|
||||
public int Hits;
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ItemActionRepair))]
|
||||
[HarmonyPatch("RemoveRequiredResource")]
|
||||
public class RemoveRequiredResource
|
||||
{
|
||||
private static bool Prefix(ref bool __result, ItemActionRepair __instance, ItemInventoryData data, UpgradeInfo ___currentUpgradeInfo)
|
||||
{
|
||||
if (string.IsNullOrEmpty(___currentUpgradeInfo.Item))
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
var itemValue = ItemClass.GetItem(___currentUpgradeInfo.Item);
|
||||
if (data.holdingEntity.inventory.DecItem(itemValue, ___currentUpgradeInfo.ItemCount) == ___currentUpgradeInfo.ItemCount)
|
||||
{
|
||||
var entityPlayerLocal = data.holdingEntity as EntityPlayerLocal;
|
||||
if (entityPlayerLocal != null && ___currentUpgradeInfo.ItemCount != 0)
|
||||
{
|
||||
entityPlayerLocal.AddUIHarvestingItem(new ItemStack(itemValue, -___currentUpgradeInfo.ItemCount));
|
||||
}
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (data.holdingEntity.bag.DecItem(itemValue, ___currentUpgradeInfo.ItemCount) == ___currentUpgradeInfo.ItemCount)
|
||||
{
|
||||
var entityPlayerLocal2 = data.holdingEntity as EntityPlayerLocal;
|
||||
if (entityPlayerLocal2 != null)
|
||||
{
|
||||
entityPlayerLocal2.AddUIHarvestingItem(new ItemStack(itemValue, -___currentUpgradeInfo.ItemCount));
|
||||
}
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
var primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
var distance = 150f;
|
||||
|
||||
var tileEntities = RemoteCraftingUtils.GetTileEntities(primaryPlayer, distance);
|
||||
|
||||
// counter quantity needed from item
|
||||
var q = ___currentUpgradeInfo.ItemCount;
|
||||
|
||||
var itemStack = new ItemStack(ItemClass.GetItem(___currentUpgradeInfo.Item, false), ___currentUpgradeInfo.ItemCount);
|
||||
|
||||
//check player inventory for materials and reduce counter
|
||||
var slots = primaryPlayer.bag.GetSlots();
|
||||
q = q - slots
|
||||
.Where(x => x.itemValue.ItemClass == itemStack.itemValue.ItemClass)
|
||||
.Sum(y => y.count);
|
||||
|
||||
// check storage boxes
|
||||
foreach (var tileEntity in tileEntities)
|
||||
{
|
||||
if (q <= 0) break;
|
||||
if (tileEntity is not TileEntityLootContainer lootTileEntity) continue;
|
||||
|
||||
// If there's no items in this container, skip.
|
||||
if (!lootTileEntity.HasItem(itemStack.itemValue)) continue;
|
||||
|
||||
for (var y = 0; y < lootTileEntity.items.Length; y++)
|
||||
{
|
||||
var item = lootTileEntity.items[y];
|
||||
if (item.IsEmpty()) continue;
|
||||
if (item.itemValue.ItemClass != itemStack.itemValue.ItemClass) continue;
|
||||
|
||||
// If we can completely satisfy the result, let's do that.
|
||||
if (item.count >= q)
|
||||
{
|
||||
item.count -= q;
|
||||
q = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, let's just count down until we meet the requirement.
|
||||
while (q >= 0)
|
||||
{
|
||||
item.count--;
|
||||
q--;
|
||||
if (item.count <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Update the slot on the container, and do the Setmodified(), so that the dedis can get updated.
|
||||
if (item.count < 1)
|
||||
lootTileEntity.UpdateSlot(y, ItemStack.Empty.Clone());
|
||||
else
|
||||
lootTileEntity.UpdateSlot(y, item);
|
||||
lootTileEntity.SetModified();
|
||||
}
|
||||
}
|
||||
|
||||
primaryPlayer.AddUIHarvestingItem(new ItemStack(itemValue, -___currentUpgradeInfo.ItemCount), false);
|
||||
|
||||
__result = true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ItemActionRepair))]
|
||||
[HarmonyPatch("CanRemoveRequiredResource")]
|
||||
public class CanRemoveRequiredResource
|
||||
{
|
||||
private static bool Prefix(ref bool __result, ItemActionRepair __instance, ItemInventoryData data, BlockValue blockValue, ref UpgradeInfo ___currentUpgradeInfo, string ___allowedUpgradeItems, string ___restrictedUpgradeItems, string ___upgradeActionSound, float ___hitCountOffset)
|
||||
{
|
||||
var block = blockValue.Block;
|
||||
var flag = block.Properties.Values.ContainsKey("UpgradeBlock.Item");
|
||||
var upgradeInfo = default(UpgradeInfo);
|
||||
upgradeInfo.FromBlock = block.GetBlockName();
|
||||
upgradeInfo.ToBlock = block.Properties.Values[Block.PropUpgradeBlockClassToBlock];
|
||||
upgradeInfo.Sound = "";
|
||||
if (flag)
|
||||
{
|
||||
upgradeInfo.Item = block.Properties.Values["UpgradeBlock.Item"];
|
||||
if (___allowedUpgradeItems.Length > 0 && !___allowedUpgradeItems.ContainsCaseInsensitive(upgradeInfo.Item))
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
if (___restrictedUpgradeItems.Length > 0 && ___restrictedUpgradeItems.ContainsCaseInsensitive(upgradeInfo.Item))
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (___upgradeActionSound.Length > 0)
|
||||
{
|
||||
upgradeInfo.Sound = ___upgradeActionSound;
|
||||
}
|
||||
else if (flag)
|
||||
{
|
||||
var item = ItemClass.GetItem(upgradeInfo.Item);
|
||||
if (item != null)
|
||||
{
|
||||
var itemClass = ItemClass.GetForId(item.type);
|
||||
if (itemClass != null)
|
||||
{
|
||||
upgradeInfo.Sound =
|
||||
$"ImpactSurface/{data.holdingEntity.inventory.holdingItem.MadeOfMaterial.SurfaceCategory}hit{itemClass.MadeOfMaterial.SurfaceCategory}";
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!int.TryParse(block.Properties.Values["UpgradeBlock.UpgradeHitCount"], out var num))
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
upgradeInfo.Hits = (int)(num + ___hitCountOffset < 1f ? 1f : num + ___hitCountOffset);
|
||||
if (!int.TryParse(block.Properties.Values[Block.PropUpgradeBlockClassItemCount], out upgradeInfo.ItemCount) && flag)
|
||||
{
|
||||
__result = false;
|
||||
return false;
|
||||
}
|
||||
___currentUpgradeInfo = upgradeInfo;
|
||||
if (___currentUpgradeInfo.FromBlock != null && flag)
|
||||
{
|
||||
var item = ItemClass.GetItem(___currentUpgradeInfo.Item, false);
|
||||
if (data.holdingEntity.inventory.GetItemCount(item) >= ___currentUpgradeInfo.ItemCount)
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
if (data.holdingEntity.bag.GetItemCount(item) >= ___currentUpgradeInfo.ItemCount)
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!flag)
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
var primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
|
||||
var itemStack = new ItemStack(ItemClass.GetItem(___currentUpgradeInfo.Item), ___currentUpgradeInfo.ItemCount);
|
||||
var distance = 150f;
|
||||
|
||||
var totalCount = RemoteCraftingUtils.SearchNearbyContainers(primaryPlayer, itemStack.itemValue, distance).Sum(y => y.count);
|
||||
|
||||
if (totalCount >= ___currentUpgradeInfo.ItemCount)
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
__result = false;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ItemActionRepair))]
|
||||
[HarmonyPatch("removeRequiredItem")]
|
||||
public class RemoveRequiredItem
|
||||
{
|
||||
private static bool Prefix(ref bool __result, ItemActionRepair __instance, ItemInventoryData _data, ItemStack _itemStack)
|
||||
{
|
||||
__result = false;
|
||||
|
||||
__result = _data.holdingEntity.inventory.DecItem(_itemStack.itemValue, _itemStack.count) == _itemStack.count || _data.holdingEntity.bag.DecItem(_itemStack.itemValue, _itemStack.count, false) == _itemStack.count;
|
||||
|
||||
if (__result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
var distance = 150f;
|
||||
|
||||
var tileEntities = RemoteCraftingUtils.GetTileEntities(primaryPlayer, distance);
|
||||
|
||||
// counter quantity needed from item
|
||||
var q = _itemStack.count;
|
||||
|
||||
//check player inventory for materials and reduce counter
|
||||
var slots = primaryPlayer.bag.GetSlots();
|
||||
q -= slots
|
||||
.Where(x => x.itemValue.ItemClass == _itemStack.itemValue.ItemClass)
|
||||
.Sum(y => y.count);
|
||||
|
||||
// check storage boxes
|
||||
foreach (var tileEntity in tileEntities)
|
||||
{
|
||||
if (q <= 0) break;
|
||||
if (tileEntity is not TileEntityLootContainer lootTileEntity) continue;
|
||||
|
||||
// If there's no items in this container, skip.
|
||||
if (!lootTileEntity.HasItem(_itemStack.itemValue)) continue;
|
||||
|
||||
for (var y = 0; y < lootTileEntity.items.Length; y++)
|
||||
{
|
||||
var item = lootTileEntity.items[y];
|
||||
if (item.IsEmpty()) continue;
|
||||
if (item.itemValue.ItemClass != _itemStack.itemValue.ItemClass) continue;
|
||||
|
||||
// If we can completely satisfy the result, let's do that.
|
||||
if (item.count >= q)
|
||||
{
|
||||
item.count -= q;
|
||||
q = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, let's just count down until we meet the requirement.
|
||||
while (q >= 0)
|
||||
{
|
||||
item.count--;
|
||||
q--;
|
||||
if (item.count <= 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//Update the slot on the container, and do the Setmodified(), so that the dedis can get updated.
|
||||
if (item.count < 1)
|
||||
lootTileEntity.UpdateSlot(y, ItemStack.Empty.Clone());
|
||||
else
|
||||
lootTileEntity.UpdateSlot(y, item);
|
||||
lootTileEntity.SetModified();
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ItemActionRepair))]
|
||||
[HarmonyPatch("canRemoveRequiredItem")]
|
||||
public class CanRemoveRequiredItem
|
||||
{
|
||||
private static bool Prefix(ref bool __result, ItemActionRepair __instance, ItemInventoryData _data, ItemStack _itemStack)
|
||||
{
|
||||
__result = false;
|
||||
|
||||
if (_data.holdingEntity.inventory.GetItemCount(_itemStack.itemValue) >= _itemStack.count || _data.holdingEntity.bag.GetItemCount(_itemStack.itemValue) >= _itemStack.count)
|
||||
{
|
||||
__result = true;
|
||||
return false;
|
||||
}
|
||||
|
||||
var primaryPlayer = GameManager.Instance.World.GetPrimaryPlayer();
|
||||
var distance = 150f;
|
||||
|
||||
var totalCount = RemoteCraftingUtils.SearchNearbyContainers(primaryPlayer, _itemStack.itemValue, distance).Sum(y => y.count);
|
||||
|
||||
if (totalCount <= 0) return false;
|
||||
__result = true;
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user