Example #1
0
        /// <summary>Prevents debris sinking if it contains or represents an item.</summary>
        /// <param name="debris">The sinking debris.</param>
        /// <param name="__instance">The <see cref="GameLocation"/> on which this method was called.</param>
        /// <param name="__result">The original method's return value. True if the debris should sink, false otherwise.</param>
        public static bool sinkDebris_Prefix(Debris debris, GameLocation __instance, ref bool __result)
        {
            try
            {
                if (debris != null)                                  //if the debris exists
                {
                    if (debris.IsAnItem())                           //if this debris represents an item
                    {
                        if (ModEntry.Config.TeleportItemsOutOfWater) //if this item should teleport out of water
                        {
                            TeleportDebrisOutOfWater(__instance, debris);
                        }

                        __result = false; //return false instead of the original result
                        return(false);    //skip the rest of the original method (note: this also skips any other patches on the method, depending on order)
                    }
                }

                return(true); //run the original method
            }
            catch (Exception ex)
            {
                ModEntry.Instance.Monitor.LogOnce($"Harmony patch \"{nameof(sinkDebris_Prefix)}\" has encountered an error:\n{ex.ToString()}", LogLevel.Error);
                return(true); //run the original method
            }
        }