Example #1
0
        /// <summary>The prefix for the <see cref="StardewValley.Buildings.Mill.draw(Microsoft.Xna.Framework.Graphics.SpriteBatch)"/> method.</summary>
        /// <param name="b">The <see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/> to draw the mill to.</param>
        /// <param name="__instance">The current <see cref="StardewValley.Buildings.Mill"/> instance being patched.</param>
        /// <returns><see lanword="false"/>, meaning the original method will not get ran.</returns>
        /// <remarks>This reimplements the original method to remove the check when drawing the item overlay on the output chest (so any item in the output chest can get drawn).</remarks>
        internal static bool DrawPrefix(SpriteBatch b, Mill __instance)
        {
            if (__instance.isMoving)
            {
                return(false);
            }

            // draw mill differently when under construction
            if (__instance.daysOfConstructionLeft > 0)
            {
                __instance.drawInConstruction(b);
                return(false);
            }

            // get private members
            var baseSourceRect = (Rectangle)typeof(Mill).GetField("baseSourceRect", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
            var alpha          = (NetFloat)typeof(Mill).GetField("alpha", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);
            var hasLoadedToday = (bool)typeof(Mill).GetField("hasLoadedToday", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(__instance);

            __instance.drawShadow(b);

            // draw base
            b.Draw(
                texture: __instance.texture.Value,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(__instance.tileX * 64, __instance.tileY * 64 + __instance.tilesHigh * 64)),
                sourceRectangle: baseSourceRect,
                color: __instance.color.Value * alpha,
                rotation: 0,
                origin: new Vector2(0, __instance.texture.Value.Bounds.Height),
                scale: 4,
                effects: SpriteEffects.None,
                layerDepth: (__instance.tileY + __instance.tilesHigh - 1) * 64 / 10000f
                );

            // draw spinning propeller
            b.Draw(
                texture: __instance.texture.Value,
                position: Game1.GlobalToLocal(
                    viewport: Game1.viewport,
                    globalPosition: new Vector2(__instance.tileX * 64 + 32, __instance.tileY * 64 + __instance.tilesHigh * 64 + 4)),
                sourceRectangle: new Rectangle(
                    x: 64 + (int)Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 800 / 89 * 32 % 160,
                    y: (int)Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 800 / 89 * 32 / 160 * 32,
                    width: 32,
                    height: 32),
                color: __instance.color.Value * alpha,
                rotation: 0,
                origin: new Vector2(0f, __instance.texture.Value.Bounds.Height),
                scale: 4,
                effects: SpriteEffects.None,
                layerDepth: (__instance.tileY + __instance.tilesHigh) * 64 / 10000f
                );

            // draw sprinning gear if something has been placing in it
            if (hasLoadedToday)
            {
                b.Draw(
                    texture: __instance.texture.Value,
                    position: Game1.GlobalToLocal(
                        viewport: Game1.viewport,
                        globalPosition: new Vector2(__instance.tileX * 64 + 52, __instance.tileY * 64 + __instance.tilesHigh * 64 + 276)),
                    sourceRectangle: new Rectangle(64 + (int)Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 700 / 100 * 21, 72, 21, 8),
                    color: __instance.color.Value * alpha,
                    rotation: 0f,
                    origin: new Vector2(0f, __instance.texture.Value.Bounds.Height),
                    scale: 4f,
                    effects: SpriteEffects.None,
                    layerDepth: (__instance.tileY + __instance.tilesHigh) * 64 / 10000f
                    );
            }

            // draw object overlay when output is collectible
            if (__instance.output.Value.items.Count > 0 && __instance.output.Value.items[0] != null)
            {
                float yOffset = 4f * (float)Math.Round(Math.Sin(Game1.currentGameTime.TotalGameTime.TotalMilliseconds / 250.0), 2);
                b.Draw(
                    texture: Game1.mouseCursors,
                    position: Game1.GlobalToLocal(
                        viewport: Game1.viewport,
                        globalPosition: new Vector2(__instance.tileX * 64 + 192, __instance.tileY * 64 - 96 + yOffset)),
                    sourceRectangle: new Rectangle(141, 465, 20, 24),
                    color: Color.White * .75f,
                    rotation: 0,
                    origin: Vector2.Zero,
                    scale: 4,
                    effects: SpriteEffects.None,
                    layerDepth: (__instance.tileY + 1 * 64) / 10000f + .0000001f + __instance.tileX / 10000f
                    );

                b.Draw(
                    texture: Game1.objectSpriteSheet,
                    position: Game1.GlobalToLocal(
                        viewport: Game1.viewport,
                        globalPosition: new Vector2(__instance.tileX * 64 + 192 + 32 + 4, __instance.tileY * 64 - 64 + 8 + yOffset)),
                    sourceRectangle: Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, __instance.output.Value.items[0].parentSheetIndex, 16, 16),
                    color: Color.White * .75f,
                    rotation: 0,
                    origin: new Vector2(8),
                    scale: 4,
                    effects: SpriteEffects.None,
                    layerDepth: (__instance.tileY + 1) * 64 / 10000f + .000001f + __instance.tileX / 10000f
                    );
            }

            return(false);
        }