Skip to content

Commit

Permalink
1.0.2-a:
Browse files Browse the repository at this point in the history
Add info notification when performing use actions on broken objects.
Add FarmCave, IslandFarmCave, and IslandWest as valid locations for object placement.
Fix broken objects not using their broken sprite.
Fix broken objects being destroyed when hit by non-destructive tools, and not being destroyed when hit while crops are growing.
Fix object arrangement mismatches when players have differing config preferences; check all game locations regardless of preferences.
  • Loading branch information
b-b-blueberry committed Aug 28, 2021
1 parent 632be90 commit 005d2dc
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 36 deletions.
83 changes: 50 additions & 33 deletions RaisedGardenBeds/OutdoorPot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ public static KeyValuePair<string, int> GetSpriteFromVariantKey(string variantKe
return new KeyValuePair<string, int>(ModEntry.ItemDefinitions[variantKey].SpriteKey, ModEntry.ItemDefinitions[variantKey].SpriteIndex);
}

public static Rectangle GetSpriteSourceRectangle(int spriteIndex)
public static Rectangle GetSpriteSourceRectangle(int spriteIndex, bool isBroken = false)
{
return new Rectangle(Game1.smallestTileSize * OutdoorPot.PreviewIndexInSheet, spriteIndex * Game1.smallestTileSize * 2, Game1.smallestTileSize, Game1.smallestTileSize * 2);
return new Rectangle(Game1.smallestTileSize * (isBroken ? OutdoorPot.BrokenIndexInSheet : OutdoorPot.PreviewIndexInSheet), spriteIndex * Game1.smallestTileSize * 2, Game1.smallestTileSize, Game1.smallestTileSize * 2);
}

public static string GetVariantKeyFromName(string name)
Expand Down Expand Up @@ -323,7 +323,7 @@ public override bool performDropDownAction(Farmer who)

public override void performRemoveAction(Vector2 tileLocation, GameLocation environment)
{
if (this.PopHeldItem())
if (this.PopHeldItem(l: environment))
{
base.performRemoveAction(tileLocation, environment);
OutdoorPot.ArrangeAllOnNextTick(specificLocation: environment);
Expand All @@ -332,13 +332,15 @@ public override void performRemoveAction(Vector2 tileLocation, GameLocation envi

public override bool performToolAction(Tool t, GameLocation location)
{
bool isHeavy = t.isHeavyHitter();

if (this.IsBroken)
{
if (t is StardewValley.Tools.MeleeWeapon)
// Ignore broken interactions with non-whacking tools
if (!(t is StardewValley.Tools.Axe || t is StardewValley.Tools.Pickaxe || t is StardewValley.Tools.Hoe))
{
base.performToolAction(t, location);
if (t is StardewValley.Tools.MeleeWeapon)
{
base.performToolAction(t, location);
}
return false;
}

Expand All @@ -348,7 +350,7 @@ public override bool performToolAction(Tool t, GameLocation location)
location.playSound("axchop");

// Remove object without adjusting neighbours, as neighbours have already adjusted to ignore the broken object
if (this.PopHeldItem(force: true))
if (this.PopHeldItem(l: location, force: true))
{
// visual debris
Game1.createRadialDebris(
Expand Down Expand Up @@ -396,7 +398,7 @@ public override bool performToolAction(Tool t, GameLocation location)
bool isValidAction = base.performToolAction(t, location);
if (isValidAction)
{
if (this.PopHeldItem()
if (this.PopHeldItem(l: location)
&& Game1.createItemDebris(this, Game1.player.getStandingPosition(), Game1.player.FacingDirection) is Debris debris && debris != null
&& location.Objects.Remove(this.TileLocation))
{
Expand Down Expand Up @@ -429,8 +431,14 @@ public override bool performObjectDropInAction(Item dropInItem, bool probe, Farm
}
return true;
}
else
{
Game1.showRedMessage(Translations.GetTranslation("item.inspect.broken"));
}
return false;
}
else if (OutdoorPot.CanAcceptAnything(op: this, ignoreObjects: true) && OutdoorPot.CanAcceptItemNoSeeds(dropInItem))

if (OutdoorPot.CanAcceptAnything(op: this, ignoreObjects: true) && OutdoorPot.CanAcceptItemNoSeeds(dropInItem))
{
// Accept objects if not holding any seeds or crops
if (!probe)
Expand All @@ -439,7 +447,7 @@ public override bool performObjectDropInAction(Item dropInItem, bool probe, Farm
{
return false;
}
else if (this.PopHeldItem())
else if (this.PopHeldItem(l: who.currentLocation))
{
this.HoldItem(dropInItem);
}
Expand All @@ -455,20 +463,22 @@ public override bool performObjectDropInAction(Item dropInItem, bool probe, Farm

public override bool canBePlacedHere(GameLocation l, Vector2 tile)
{
bool okGreenHouse = ModEntry.Config.CanBePlacedInGreenHouse && l.IsGreenhouse;
bool okFarmHouse = ModEntry.Config.CanBePlacedInFarmHouse && (l is FarmHouse || l is IslandFarmHouse);
bool okFarm = (l.IsOutdoors && l.IsFarm) || (!l.IsOutdoors && ModEntry.Config.CanBePlacedInBuildings && l.isStructure.Value);
// Check that this is a valid placeable game location
if (!OutdoorPot.IsLocationValid(l))
{
return false;
}

// Check to ensure there are no obstructions on this tile
bool noTiles = l.isTileLocationTotallyClearAndPlaceableIgnoreFloors(tile);
bool noObjects = !l.Objects.ContainsKey(tile);
bool noCrops = (!l.terrainFeatures.ContainsKey(tile) || l.terrainFeatures[tile] is Flooring || (l.terrainFeatures[tile] is HoeDirt hoeDirt && hoeDirt.crop == null));
bool noFoliage = l.getLargeTerrainFeatureAt((int)tile.X, (int)tile.Y) == null;
bool noStumpsAndBoulders = l.resourceClumps.All(r => !r.occupiesTile((int)tile.X, (int)tile.Y));

bool okLocation = okGreenHouse || okFarmHouse || okFarm;
bool noObstructions = noTiles && noObjects && noCrops && noFoliage && noStumpsAndBoulders;

return !l.isTemp() && okLocation && noObstructions;
return noObstructions;
}

public override bool canStackWith(ISalable other)
Expand All @@ -487,6 +497,7 @@ public override void ApplySprinklerAnimation(GameLocation location)
Vector2 position = (this.TileLocation * Game1.tileSize) - new Vector2(0, this.SoilHeightAboveGround * Game1.pixelZoom);
int delay = Game1.random.Next(1000);
float id = (this.TileLocation.X * 4000) + this.TileLocation.Y;
float scale = radius / 2f;
Color colour = Color.White * 0.4f;
const int frames = 4;
const int interval = 60;
Expand Down Expand Up @@ -536,7 +547,6 @@ public override void ApplySprinklerAnimation(GameLocation location)
break;
default:
{
float scale = radius / 2f;
location.temporarySprites.Add(
new TemporaryAnimatedSprite(
"TileSheets\\animations",
Expand Down Expand Up @@ -687,7 +697,7 @@ public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1
spriteBatch.Draw(
texture: ModEntry.Sprites[this.SpriteKey],
destinationRectangle: destination,
sourceRectangle: OutdoorPot.GetSpriteSourceRectangle(spriteIndex: this.SpriteIndex),
sourceRectangle: OutdoorPot.GetSpriteSourceRectangle(spriteIndex: this.SpriteIndex, isBroken: true),
color: colour,
rotation: 0f,
origin: Vector2.Zero,
Expand Down Expand Up @@ -797,7 +807,7 @@ public override void draw(SpriteBatch spriteBatch, int x, int y, float alpha = 1
offset: new Vector2(Game1.tileSize / 2, 0f));
}

// Objects (eg. Sprinkler)
// Held objects (eg. Sprinkler)
if (this.heldObject.Value != null)
{
int objectOffset = (4 * Game1.pixelZoom) + (this.heldObject.Value.IsSprinkler() ? 0 : Game1.tileSize);
Expand Down Expand Up @@ -861,15 +871,22 @@ public void HoldItem(Item item)
///
/// </summary>
/// <param name="force">If true, ejects the held object as debris regardless of any other conditions.</param>
public bool PopHeldItem(bool force = false)
public bool PopHeldItem(GameLocation l, bool force = false)
{
bool popped = false;

// Pop crops
if (this.hoeDirt.Value.crop != null)
{
if (force && this.hoeDirt.Value.crop.harvest(xTile: (int)this.TileLocation.X, yTile: (int)this.TileLocation.Y, soil: this.hoeDirt.Value))
if (force)
{
if (this.hoeDirt.Value.crop.harvest(xTile: (int)this.TileLocation.X, yTile: (int)this.TileLocation.Y, soil: this.hoeDirt.Value)
|| this.hoeDirt.Value.crop.hitWithHoe((int)this.TileLocation.X, (int)this.TileLocation.Y, location: l, dirt: this.hoeDirt.Value))
{}
else
{
this.hoeDirt.Value.crop.Kill();
}
popped = true;
}
}
Expand Down Expand Up @@ -936,7 +953,7 @@ public void Unbreak(GameLocation location = null, bool adjust = false)
/// </summary>
public static void BreakAll(GameLocation specificLocation = null)
{
foreach (GameLocation location in specificLocation != null ? new[] { specificLocation } : OutdoorPot.GetValidPlacementLocations())
foreach (GameLocation location in specificLocation != null ? new[] { specificLocation } : Game1.locations)
{
List<OutdoorPot> pots = location.Objects.Values.OfType<OutdoorPot>().Where(o => o.IsReadyToBreak).ToList();
pots.ForEach(pot => pot.Break(location: location, arrange: false));
Expand Down Expand Up @@ -980,7 +997,7 @@ private static void Event_ArrangeAllOnNextTick(object sender, StardewModdingAPI.
/// </summary>
public static void ArrangeAll(GameLocation specificLocation = null)
{
foreach (GameLocation location in specificLocation != null ? new[] { specificLocation } : OutdoorPot.GetValidPlacementLocations())
foreach (GameLocation location in specificLocation != null ? new[] { specificLocation } : Game1.locations)
location.Objects.Values.OfType<OutdoorPot>().ToList().ForEach(o => o.Arrange(location: location));
}

Expand Down Expand Up @@ -1057,18 +1074,18 @@ private static bool CanBeArrangedWithNeighbour(OutdoorPot p, StardewValley.Objec
}

/// <summary>
/// Returns a list of locations where <see cref="OutdoorPot"/> objects can be placed depending on <see cref="Config"/> values.
/// Whether a game location is valid for placement based on preferences in <see cref="Config"/>.
/// </summary>
public static IEnumerable<GameLocation> GetValidPlacementLocations()
public static bool IsLocationValid(GameLocation l)
{
var locations = new List<GameLocation> { Game1.getFarm() };
if (ModEntry.Config.CanBePlacedInFarmHouse)
locations.AddRange(new[] { Game1.getLocationFromName("FarmHouse"), Game1.getLocationFromName("IslandFarmHouse") });
if (ModEntry.Config.CanBePlacedInGreenHouse)
locations.Add(Game1.getLocationFromName("Greenhouse"));
if (ModEntry.Config.CanBePlacedInBuildings)
locations.AddRange(Game1.getFarm().buildings.Where(b => b.indoors.Value != null).Select(b => b.indoors.Value));
return locations;
bool okGreenHouse = ModEntry.Config.CanBePlacedInGreenHouse && l.IsGreenhouse;
bool okFarmHouse = ModEntry.Config.CanBePlacedInFarmHouse && (l is FarmHouse || l is IslandFarmHouse);
bool okFarmBuildings = ModEntry.Config.CanBePlacedInBuildings && l.isStructure.Value;
bool okFarm = !l.isStructure.Value && (l.IsFarm || l is FarmCave || l is IslandFarmCave || l is IslandWest);

bool okLocation = okGreenHouse || okFarmHouse || okFarmBuildings || okFarm;

return !l.isTemp() && okLocation;
}
}
}
2 changes: 1 addition & 1 deletion RaisedGardenBeds/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "Raised Garden Beds",
"Author": "blueberry",
"Version": "1.0.1",
"Version": "1.0.2",
"Description": "Garden beds for your farm, usable outdoors with seasonal crops.",
"UniqueID": "blueberry.RaisedGardenBeds",
"EntryDll": "RaisedGardenBeds.dll",
Expand Down
2 changes: 2 additions & 0 deletions [CP] RaisedGardenBeds - English/content.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
"item.description.indoors": "Allows for planting seasonal crops on unsuitable ground.",
"item.description.default": "Dummy object, not spawnable with CJB Item Spawner. Type 'rgb.give' or 'rgb.giveall' into the SMAPI console to get some!",

"item.inspect.broken": "This garden bed is broken and needs replacing.",

"menu.title.new": "New blueprints",

"config.raisedbedsmaybreakwithage.name": "Garden beds break with age",
Expand Down
2 changes: 1 addition & 1 deletion [CP] RaisedGardenBeds - English/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "[CP] Raised Garden Beds Translation: English",
"Author": "blueberry",
"Version": "1.0.1",
"Version": "1.0.2",
"Description": "Translation pack for Raised Garden Beds.",
"UniqueID": "blueberry.RaisedGardenBeds.Translation.English.CP",
"UpdateKeys": [ "Nexus:????" ],
Expand Down
2 changes: 1 addition & 1 deletion [RGB] RaisedGardenBeds/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"Name": "[RGB] Raised Garden Beds",
"Author": "blueberry",
"Version": "1.0.1",
"Version": "1.0.2",
"Description": "Starter pack for Raised Garden Beds.",
"UniqueID": "blueberry.RaisedGardenBeds.RGB",
"UpdateKeys": [ "Nexus:????" ],
Expand Down

0 comments on commit 005d2dc

Please sign in to comment.