示例#1
0
        private static int ComputeItemQuantity(int fromInventory, Piece.Requirement item, Player player)
        {
            Stopwatch delta;

            GameObject pos = player.GetCurrentCraftingStation()?.gameObject;

            if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench)
            {
                pos   = player.gameObject;
                delta = Inventory_NearbyChests_Cache.delta;
            }
            else
            {
                delta = GameObjectAssistant.GetStopwatch(pos);
            }

            int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            return(fromInventory + InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), item.m_resItem.m_itemData));
        }
示例#2
0
        private static void AddItemFromNearbyChests(Fermenter __instance)
        {
            if (!Configuration.Current.Fermenter.autoFuel || __instance.GetStatus() != Fermenter.Status.Empty || !__instance.m_nview.IsOwner())
            {
                return;
            }

            Stopwatch delta = GameObjectAssistant.GetStopwatch(__instance.gameObject);

            if (!delta.IsRunning || delta.ElapsedMilliseconds > 1000)
            {
                List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(__instance.gameObject, Configuration.Current.Fermenter.autoRange, !Configuration.Current.Fermenter.ignorePrivateAreaCheck);
                foreach (Container c in nearbyChests)
                {
                    ItemDrop.ItemData item = __instance.FindCookableItem(c.GetInventory());
                    if (item != null)
                    {
                        if (InventoryAssistant.RemoveItemFromChest(c, item) == 0)
                        {
                            continue;
                        }

                        __instance.m_nview.InvokeRPC("AddItem", new object[] { item.m_dropPrefab.name });
                        ZLog.Log("Added " + item.m_shared.m_name + " to " + __instance.m_name);
                        break;
                    }
                }
                delta.Restart();
            }
        }
示例#3
0
        private static bool ReplaceInventoryRefByChest(ref Inventory inventory, ItemDrop.ItemData item, Fireplace fireplace)
        {
            if (inventory.HaveItem(item.m_shared.m_name))
            {
                return(true);                                          // original code
            }
            Stopwatch delta          = GameObjectAssistant.GetStopwatch(fireplace.gameObject);
            int       lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                nearbyChests = InventoryAssistant.GetNearbyChests(fireplace.gameObject, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            foreach (Container c in nearbyChests)
            {
                if (c.GetInventory().HaveItem(item.m_shared.m_name))
                {
                    inventory = c.GetInventory();
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
            private static void AddFuelFromNearbyChests(Fireplace __instance)
            {
                int toMaxFuel = (int)__instance.m_maxFuel - (int)Math.Ceiling(__instance.m_nview.GetZDO().GetFloat("fuel"));

                if (toMaxFuel > 0)
                {
                    Stopwatch delta = GameObjectAssistant.GetStopwatch(__instance.gameObject);

                    if (delta.IsRunning && delta.ElapsedMilliseconds < 1000)
                    {
                        return;
                    }
                    delta.Restart();

                    ItemDrop.ItemData fuelItemData = __instance.m_fuelItem.m_itemData;

                    int addedFuel = InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(__instance.gameObject, Helper.Clamp(Configuration.Current.FireSource.autoRange, 1, 50), fuelItemData, toMaxFuel, !Configuration.Current.FireSource.ignorePrivateAreaCheck);
                    for (int i = 0; i < addedFuel; i++)
                    {
                        __instance.m_nview.InvokeRPC("AddFuel", new object[] { });
                    }
                    if (addedFuel > 0)
                    {
                        ZLog.Log("Added " + addedFuel + " fuel(" + fuelItemData.m_shared.m_name + ") in " + __instance.m_name);
                    }
                }
            }
示例#5
0
        private static bool DropItemToNearbyChest(Fermenter __instance, ref Fermenter.ItemConversion itemConversion)
        {
            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(__instance.gameObject, Configuration.Current.Fermenter.autoRange, !Configuration.Current.Fermenter.ignorePrivateAreaCheck);

            int spawnedInChests = 0;

            for (int i = 0; i < itemConversion.m_producedItems; i++)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_to.gameObject.name);

                ZNetView.m_forceDisableInit = true;
                GameObject itemObject = Object.Instantiate <GameObject>(itemPrefab);
                ZNetView.m_forceDisableInit = false;

                ItemDrop comp = itemObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(itemObject);
                if (!result)
                {
                    itemConversion.m_producedItems -= spawnedInChests;

                    return(false);
                }
                spawnedInChests++;
            }

            return(true);

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }

                    InventoryAssistant.ConveyContainerToNetwork(chest);

                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }
        }
示例#6
0
        private static void RemoveItemsFromInventoryAndNearbyChests(Player player, Piece.Requirement item, int amount)
        {
            GameObject pos = player.GetCurrentCraftingStation()?.gameObject;

            if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench)
            {
                pos = player.gameObject;
            }

            int inventoryAmount = player.m_inventory.CountItems(item.m_resItem.m_itemData.m_shared.m_name);

            player.m_inventory.RemoveItem(item.m_resItem.m_itemData.m_shared.m_name, amount);
            amount -= inventoryAmount;
            if (amount <= 0)
            {
                return;
            }

            InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), item.m_resItem.m_itemData, amount, !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
        }
示例#7
0
        private static ItemDrop.ItemData PullCookableItemFromNearbyChests(CookingStation station)
        {
            if (station.GetFreeSlot() == -1)
            {
                return(null);
            }

            Stopwatch delta = GameObjectAssistant.GetStopwatch(station.gameObject);

            int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;

            if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
            {
                nearbyChests = InventoryAssistant.GetNearbyChests(station.gameObject, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50), !Configuration.Current.CraftFromChest.ignorePrivateAreaCheck);
                delta.Restart();
            }

            foreach (CookingStation.ItemConversion itemConversion in station.m_conversion)
            {
                ItemDrop.ItemData itemData = itemConversion.m_from.m_itemData;

                foreach (Container c in nearbyChests)
                {
                    if (c.GetInventory().HaveItem(itemData.m_shared.m_name))
                    {
                        // Remove one item from chest
                        InventoryAssistant.RemoveItemFromChest(c, itemData);
                        // Instantiate cookabled GameObject
                        GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_from.gameObject.name);

                        ZNetView.m_forceDisableInit = true;
                        GameObject cookabledItem = UnityEngine.Object.Instantiate <GameObject>(itemPrefab);
                        ZNetView.m_forceDisableInit = false;

                        return(cookabledItem.GetComponent <ItemDrop>().m_itemData);
                    }
                }
            }
            return(null);
        }
示例#8
0
        private static bool Prefix(Transform elementRoot, Piece.Requirement req, Player player, bool craft, int quality, ref bool __result)
        {
            if (!Configuration.Current.Hud.IsEnabled && !Configuration.Current.CraftFromChest.IsEnabled || !Configuration.Current.Hud.showRequiredItems && !Configuration.Current.CraftFromChest.IsEnabled)
            {
                return(true);
            }

            Image     component  = elementRoot.transform.Find("res_icon").GetComponent <Image>();
            Text      component2 = elementRoot.transform.Find("res_name").GetComponent <Text>();
            Text      component3 = elementRoot.transform.Find("res_amount").GetComponent <Text>();
            UITooltip component4 = elementRoot.GetComponent <UITooltip>();

            if (req.m_resItem != null)
            {
                component.gameObject.SetActive(true);
                component2.gameObject.SetActive(true);
                component3.gameObject.SetActive(true);
                component.sprite  = req.m_resItem.m_itemData.GetIcon();
                component.color   = Color.white;
                component4.m_text = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                component2.text   = Localization.instance.Localize(req.m_resItem.m_itemData.m_shared.m_name);
                int num    = player.GetInventory().CountItems(req.m_resItem.m_itemData.m_shared.m_name);
                int amount = req.GetAmount(quality);

                if (amount <= 0)
                {
                    InventoryGui.HideRequirement(elementRoot);
                    __result = false;
                    return(false);
                }

                if (Configuration.Current.CraftFromChest.IsEnabled)
                {
                    Stopwatch delta;

                    GameObject pos = player.GetCurrentCraftingStation()?.gameObject;
                    if (!pos || !Configuration.Current.CraftFromChest.checkFromWorkbench)
                    {
                        pos   = player.gameObject;
                        delta = Inventory_NearbyChests_Cache.delta;
                    }
                    else
                    {
                        delta = GameObjectAssistant.GetStopwatch(pos);
                    }

                    int lookupInterval = Helper.Clamp(Configuration.Current.CraftFromChest.lookupInterval, 1, 10) * 1000;
                    if (!delta.IsRunning || delta.ElapsedMilliseconds > lookupInterval)
                    {
                        Inventory_NearbyChests_Cache.chests = InventoryAssistant.GetNearbyChests(pos, Helper.Clamp(Configuration.Current.CraftFromChest.range, 1, 50));
                        delta.Restart();
                    }
                    num += InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(Inventory_NearbyChests_Cache.chests), req.m_resItem.m_itemData);
                }

                component3.text = num + "/" + amount.ToString();

                if (num < amount)
                {
                    component3.color = ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white);
                }
                else
                {
                    component3.color = Color.white;
                }

                component3.fontSize = 14;
                if (component3.text.Length > 5)
                {
                    component3.fontSize -= component3.text.Length - 5;
                }
            }

            __result = true;
            return(false);
        }
示例#9
0
        private static bool Prefix(string ore, int stack, ref Smelter __instance)
        {
            Smelter smelter = __instance; // allowing access to local function

            if (!smelter.m_nview.IsOwner())
            {
                return(true);
            }

            if (__instance.m_name.Equals(SmelterDefinitions.KilnName) && Configuration.Current.Kiln.IsEnabled && Configuration.Current.Kiln.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Kiln.autoRange, 1, 50), Configuration.Current.Kiln.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.SmelterName) && Configuration.Current.Smelter.IsEnabled && Configuration.Current.Smelter.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Smelter.autoRange, 1, 50), Configuration.Current.Smelter.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.FurnaceName) && Configuration.Current.Furnace.IsEnabled && Configuration.Current.Furnace.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Furnace.autoRange, 1, 50), Configuration.Current.Furnace.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.WindmillName) && Configuration.Current.Windmill.IsEnabled && Configuration.Current.Windmill.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.Windmill.autoRange, 1, 50), Configuration.Current.Windmill.ignorePrivateAreaCheck));
            }
            if (__instance.m_name.Equals(SmelterDefinitions.SpinningWheelName) && Configuration.Current.SpinningWheel.IsEnabled && Configuration.Current.SpinningWheel.autoDeposit)
            {
                return(spawn(Helper.Clamp(Configuration.Current.SpinningWheel.autoRange, 1, 50), Configuration.Current.Windmill.ignorePrivateAreaCheck));
            }
            bool spawn(float autoDepositRange, bool ignorePrivateAreaCheck)
            {
                List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(smelter.gameObject, autoDepositRange, !ignorePrivateAreaCheck);

                if (nearbyChests.Count == 0)
                {
                    return(true);
                }

                if (autoDepositRange > 50)
                {
                    autoDepositRange = 50;
                }
                else if (autoDepositRange < 1)
                {
                    autoDepositRange = 1;
                }

                // Replicating original code, just "spawning/adding" the item inside the chest makes it "not have a prefab"
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(smelter.GetItemConversion(ore).m_to.gameObject.name);

                // Also replication of original code, really have no idead what it is for, didn't bother look
                ZNetView.m_forceDisableInit = true;
                GameObject spawnedOre = Object.Instantiate <GameObject>(itemPrefab);

                ZNetView.m_forceDisableInit = false;

                // assign stack size, nobody wants a 0/20 stack of metals (its not very usefull)
                ItemDrop comp = spawnedOre.GetComponent <ItemDrop>();

                comp.m_itemData.m_stack = stack;

                bool result = spawnNearbyChest(true);

                Object.Destroy(spawnedOre);

                bool spawnNearbyChest(bool mustHaveItem)
                {
                    foreach (Container chest in nearbyChests)
                    {
                        Inventory cInventory = chest.GetInventory();
                        if (mustHaveItem && !cInventory.HaveItem(comp.m_itemData.m_shared.m_name))
                        {
                            continue;
                        }

                        bool added = cInventory.AddItem(comp.m_itemData);
                        if (!added)
                        {
                            // Chest full, move to the next
                            continue;
                        }

                        smelter.m_produceEffects.Create(smelter.transform.position, smelter.transform.rotation, null, 1f);
                        InventoryAssistant.ConveyContainerToNetwork(chest);
                        return(false);
                    }

                    if (mustHaveItem)
                    {
                        return(spawnNearbyChest(false));
                    }

                    return(true);
                }

                return(result);
            }

            return(true);
        }
示例#10
0
        static void Prefix(Smelter __instance)
        {
            if (__instance == null || !Player.m_localPlayer || __instance.m_nview == null || !__instance.m_nview.IsOwner())
            {
                return;
            }

            Smelter smelter = __instance;

            Stopwatch delta = GameObjectAssistant.GetStopwatch(smelter.gameObject);

            if (delta.IsRunning && delta.ElapsedMilliseconds < 1000)
            {
                return;
            }
            delta.Restart();

            float autoFuelRange          = 0f;
            bool  ignorePrivateAreaCheck = false;
            bool  isKiln = false;

            if (smelter.m_name.Equals(SmelterDefinitions.KilnName))
            {
                if (!Configuration.Current.Kiln.IsEnabled || !Configuration.Current.Kiln.autoFuel)
                {
                    return;
                }
                isKiln                 = true;
                autoFuelRange          = Configuration.Current.Kiln.autoRange;
                ignorePrivateAreaCheck = Configuration.Current.Kiln.ignorePrivateAreaCheck;
            }
            else if (smelter.m_name.Equals(SmelterDefinitions.SmelterName))
            {
                if (!Configuration.Current.Smelter.IsEnabled || !Configuration.Current.Smelter.autoFuel)
                {
                    return;
                }
                autoFuelRange          = Configuration.Current.Smelter.autoRange;
                ignorePrivateAreaCheck = Configuration.Current.Smelter.ignorePrivateAreaCheck;
            }
            else if (smelter.m_name.Equals(SmelterDefinitions.FurnaceName))
            {
                if (!Configuration.Current.Furnace.IsEnabled || !Configuration.Current.Furnace.autoFuel)
                {
                    return;
                }
                autoFuelRange          = Configuration.Current.Furnace.autoRange;
                ignorePrivateAreaCheck = Configuration.Current.Furnace.ignorePrivateAreaCheck;
            }
            else if (__instance.m_name.Equals(SmelterDefinitions.WindmillName))
            {
                if (!Configuration.Current.Windmill.IsEnabled || !Configuration.Current.Windmill.autoFuel)
                {
                    return;
                }
                autoFuelRange          = Configuration.Current.Windmill.autoRange;
                ignorePrivateAreaCheck = Configuration.Current.Windmill.ignorePrivateAreaCheck;
            }
            else if (__instance.m_name.Equals(SmelterDefinitions.SpinningWheelName))
            {
                if (!Configuration.Current.SpinningWheel.IsEnabled || !Configuration.Current.SpinningWheel.autoFuel)
                {
                    return;
                }
                autoFuelRange          = Configuration.Current.SpinningWheel.autoRange;
                ignorePrivateAreaCheck = Configuration.Current.SpinningWheel.ignorePrivateAreaCheck;
            }

            autoFuelRange = Helper.Clamp(autoFuelRange, 1, 50);

            int toMaxOre  = smelter.m_maxOre - smelter.GetQueueSize();
            int toMaxFuel = smelter.m_maxFuel - (int)System.Math.Ceiling(smelter.GetFuel());

            if (smelter.m_fuelItem && toMaxFuel > 0)
            {
                ItemDrop.ItemData fuelItemData = smelter.m_fuelItem.m_itemData;

                // Check for fuel in nearby containers
                int addedFuel = InventoryAssistant.RemoveItemInAmountFromAllNearbyChests(smelter.gameObject, autoFuelRange, fuelItemData, toMaxFuel, !ignorePrivateAreaCheck);
                for (int i = 0; i < addedFuel; i++)
                {
                    smelter.m_nview.InvokeRPC("AddFuel", new object[] { });
                }
                if (addedFuel > 0)
                {
                    ZLog.Log("Added " + addedFuel + " fuel(" + fuelItemData.m_shared.m_name + ") in " + smelter.m_name);
                }
            }
            if (toMaxOre > 0)
            {
                List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(smelter.gameObject, autoFuelRange);
                foreach (Container c in nearbyChests)
                {
                    foreach (Smelter.ItemConversion itemConversion in smelter.m_conversion)
                    {
                        if (isKiln)
                        {
                            if (Configuration.Current.Kiln.dontProcessFineWood && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(WoodDefinitions.FineWoodName))
                            {
                                continue;
                            }
                            if (Configuration.Current.Kiln.dontProcessRoundLog && itemConversion.m_from.m_itemData.m_shared.m_name.Equals(WoodDefinitions.RoundLogName))
                            {
                                continue;
                            }

                            int threshold = Configuration.Current.Kiln.stopAutoFuelThreshold < 0 ? 0 : Configuration.Current.Kiln.stopAutoFuelThreshold;
                            if (threshold > 0 && InventoryAssistant.GetItemAmountInItemList(InventoryAssistant.GetNearbyChestItemsByContainerList(nearbyChests), itemConversion.m_to.m_itemData) >= threshold)
                            {
                                return;
                            }
                        }

                        ItemDrop.ItemData oreItem = itemConversion.m_from.m_itemData;
                        int addedOres             = InventoryAssistant.RemoveItemFromChest(c, oreItem, toMaxOre);
                        if (addedOres > 0)
                        {
                            GameObject orePrefab = ObjectDB.instance.GetItemPrefab(itemConversion.m_from.gameObject.name);

                            for (int i = 0; i < addedOres; i++)
                            {
                                smelter.m_nview.InvokeRPC("AddOre", new object[] { orePrefab.name });
                            }
                            toMaxOre -= addedOres;
                            if (addedOres > 0)
                            {
                                ZLog.Log("Added " + addedOres + " ores(" + oreItem.m_shared.m_name + ") in " + smelter.m_name);
                            }
                            if (toMaxOre == 0)
                            {
                                return;
                            }
                        }
                    }
                }
            }
        }
示例#11
0
        private static bool Prefix(long caller, ref Beehive __instance)
        {
            // Allows for access for linq
            Beehive beehive = __instance; // allowing access to local function

            if (!Configuration.Current.Beehive.autoDeposit || !Configuration.Current.Beehive.IsEnabled || !beehive.m_nview.IsOwner())
            {
                return(true);
            }

            // if behive is empty
            if (beehive.GetHoneyLevel() <= 0)
            {
                return(true);
            }

            float autoDepositRange = Helper.Clamp(Configuration.Current.Beehive.autoDepositRange, 1, 50);

            // find nearby chests
            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(beehive.gameObject, autoDepositRange);

            if (nearbyChests.Count == 0)
            {
                return(true);
            }

            while (beehive.GetHoneyLevel() > 0)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(__instance.m_honeyItem.gameObject.name);

                ZNetView.m_forceDisableInit = true;
                GameObject honeyObject = Object.Instantiate <GameObject>(itemPrefab);
                ZNetView.m_forceDisableInit = false;

                ItemDrop comp = honeyObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(honeyObject);

                if (!result)
                {
                    // Couldn't drop in chest, letting original code handle things
                    return(true);
                }
            }

            if (beehive.GetHoneyLevel() == 0)
            {
                beehive.m_spawnEffect.Create(beehive.m_spawnPoint.position, Quaternion.identity);
            }

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }
                    beehive.m_nview.GetZDO().Set("level", beehive.GetHoneyLevel() - 1);
                    InventoryAssistant.ConveyContainerToNetwork(chest);
                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }

            return(true);
        }
示例#12
0
        private static void AutoDepositToChest(ref Beehive __instance)
        {
            Beehive beehive = __instance;

            List <Container> nearbyChests = InventoryAssistant.GetNearbyChests(beehive.gameObject, Helper.Clamp(Configuration.Current.Beehive.autoDepositRange, 1, 50));

            if (beehive.GetHoneyLevel() != beehive.m_maxHoney)
            {
                return;
            }

            while (beehive.GetHoneyLevel() > 0)
            {
                GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(beehive.m_honeyItem.gameObject.name);

                ZNetView.m_forceDisableInit = true;
                GameObject honeyObject = Object.Instantiate <GameObject>(itemPrefab);
                ZNetView.m_forceDisableInit = false;

                ItemDrop comp = honeyObject.GetComponent <ItemDrop>();

                bool result = spawnNearbyChest(comp, true);
                Object.Destroy(honeyObject);

                if (!result)
                {
                    // Couldn't drop in chest, letting original code handle things
                    return;
                }
            }

            if (beehive.GetHoneyLevel() == 0)
            {
                beehive.m_spawnEffect.Create(beehive.m_spawnPoint.position, Quaternion.identity);
            }

            bool spawnNearbyChest(ItemDrop item, bool mustHaveItem)
            {
                foreach (Container chest in nearbyChests)
                {
                    Inventory cInventory = chest.GetInventory();
                    if (mustHaveItem && !cInventory.HaveItem(item.m_itemData.m_shared.m_name))
                    {
                        continue;
                    }

                    if (!cInventory.AddItem(item.m_itemData))
                    {
                        //Chest full, move to the next
                        continue;
                    }
                    beehive.m_nview.GetZDO().Set("level", beehive.GetHoneyLevel() - 1);
                    InventoryAssistant.ConveyContainerToNetwork(chest);
                    return(true);
                }

                if (mustHaveItem)
                {
                    return(spawnNearbyChest(item, false));
                }

                return(false);
            }
        }