From cb75c986bfe2db3d2be1bb4aed81161382e27192 Mon Sep 17 00:00:00 2001 From: Urbanyeti Date: Tue, 30 Apr 2024 15:12:05 -0700 Subject: [PATCH] Update --- BetterRanching/BetterRanchingApi.cs | 32 +++++++++++++++++++---------- README.md | 3 ++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/BetterRanching/BetterRanchingApi.cs b/BetterRanching/BetterRanchingApi.cs index df49f73..d7d32ab 100644 --- a/BetterRanching/BetterRanchingApi.cs +++ b/BetterRanching/BetterRanchingApi.cs @@ -4,6 +4,8 @@ using StardewModdingAPI; using StardewValley; using StardewValley.Characters; +using StardewValley.GameData.Pets; +using StardewValley.ItemTypeDefinitions; namespace BetterRanching { @@ -53,10 +55,8 @@ public void DrawHeartBubble(SpriteBatch spriteBatch, float xPosition, float yPos public void DrawItemBubble(SpriteBatch spriteBatch, FarmAnimal animal, bool ranchingInProgress) { - if (!int.TryParse(animal.currentProduce.Value, out var produceId)) - { - produceId = 0; - } + ParsedItemData dataOrErrorItem = ItemRegistry.GetDataOrErrorItem(animal.currentProduce.Value); + int produceId = dataOrErrorItem.SpriteIndex; DrawItemBubble( spriteBatch, @@ -70,13 +70,14 @@ public void DrawItemBubble(SpriteBatch spriteBatch, FarmAnimal animal, bool ranc () => !animal.wasPet.Value, true, false, - animal.friendshipTowardFarmer.Value + animal.friendshipTowardFarmer.Value, + dataOrErrorItem ); } public void DrawItemBubble(SpriteBatch spriteBatch, float xPosition, float yPosition, int spriteWidth, bool isShortTarget, int produceIcon, Func displayItem, Func displayHeart, - bool isFarmAnimal, bool isPet, int friendship) + bool isFarmAnimal, bool isPet, int friendship, ParsedItemData? itemData = null) { var showItem = displayItem() && _config.DisplayProduce; var showHeart = displayHeart() && @@ -102,38 +103,47 @@ public void DrawItemBubble(SpriteBatch spriteBatch, float xPosition, float yPosi if (showHeart) { if (showItem) + { spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2(xPosition + spriteWidth / 2f + 40, yPosition - 25 + num)), sourceRectangle, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), Game1.pixelZoom, SpriteEffects.None, 1); + } else + { spriteBatch.Draw(Game1.mouseCursors, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xPosition + spriteWidth / 2f + Game1.tileSize * 1.1), yPosition - 7 + num)), sourceRectangle, Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), (float)Game1.pixelZoom * 5 / 3, SpriteEffects.None, 1); + } } if (!showItem) return; if (showHeart) + { // Small item icon - spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, + spriteBatch.Draw(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2(xPosition + spriteWidth / 2f + 56, yPosition - 45 + num)), - Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, produceIcon, 16, 16), + Game1.getSourceRectForStandardTileSheet(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, produceIcon, 16, 16), Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), (float)(Game1.pixelZoom * .60), SpriteEffects.None, 1); + } else + { // Big item icon - spriteBatch.Draw(Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, + spriteBatch.Draw(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xPosition + spriteWidth / 2f + Game1.tileSize * .625), - yPosition - 45 + num)), - Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, produceIcon, 16, 16), + yPosition - 45 + num)), + Game1.getSourceRectForStandardTileSheet(itemData != null ? itemData.GetTexture() : Game1.objectSpriteSheet, produceIcon, 16, 16), Color.White * 0.75f, 0.0f, new Vector2(8f, 8f), Game1.pixelZoom, SpriteEffects.None, 1); + } + } diff --git a/README.md b/README.md index 334f0ef..aefd5e1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Stardew Valley mod that prevents failing milking/shearing attempts and adds an i Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4.0.0 or later. -**Update 2.0.4 (2024/04/30)**: Fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets. +**Update 2.0.4 (2024/04/30)**: Fixed a bug that was causing the wrong icon to show for custom items. Thank you to kitsutsune and their awesome [Chocobo Valley](https://www.nexusmods.com/stardewvalley/mods/22226/) mod for bringing this to my attention! Also Fixed a bug causing the "Hide Hearts w/ Max Friendship" setting to be ignored for pets. ![Preview image](/better_ranching_preview.gif)

How to Install:

@@ -78,6 +78,7 @@ Compatible with Stardew Valley 1.6+ on Linux, Mac, and Windows. Requires SMAPI 4 * 2.0.3: * Fixed bug causing animal hearts to display over building they are in. * 2.0.4: + * Added support for custom harvest items to display above animals! * Fixed bug causing "Hide Hearts w/ Max Friendship" setting to be ignored for pets

Other Contributors