Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SafeLightning & NoFenceDecay for SDV 1.6 #35

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions NoFenceDecay/FenceFinder.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using StardewModdingAPI;
using StardewValley;
using StardewValley.Locations;
using System.Collections.Generic;
using System.Linq;

Expand Down Expand Up @@ -51,12 +50,12 @@ private IEnumerable<Fence> GetFences(GameLocation l)
yield return f;
}

if (!(l is BuildableGameLocation bLoc))
if (!(l.IsBuildableLocation()))
{
yield break;
}

foreach (Fence f in this.GetFences(bLoc.buildings.Where(item => item != null).Select(item => item.indoors.Value).Where(item => item != null)))
foreach (Fence f in this.GetFences(l.buildings.Where(item => item != null).Select(item => item.indoors.Value).Where(item => item != null)))
{
yield return f;
}
Expand Down
6 changes: 3 additions & 3 deletions NoFenceDecay/NoFenceDecay.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.5.0</Version>
<TargetFramework>net452</TargetFramework>
<Version>1.6.0</Version>
<TargetFramework>net6</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="3.3.0" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions NoFenceDecay/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"Name": "No Fence Decay",
"Author": "Cat",
"Version": "1.5.1",
"Version": "1.6.0",
"Description": "Makes all fences and gates last forever.",
"UniqueID": "cat.nofencedecay",
"EntryDll": "NoFenceDecay.dll",
"MinimumApiVersion": "2.9.0",
"MinimumApiVersion": "4.0.0",
"UpdateKeys": [ "Nexus:1180" ]
}
2 changes: 1 addition & 1 deletion SafeLightning/CommandParsing/Commands/GrowTreesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void Invoke(string[] args)

case FruitTree ft:
ft.daysUntilMature.Value -= 4;
ft.dayUpdate(Game1.getFarm(), item.Key);
ft.dayUpdate();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PrintLocationCommand(IMonitor monitor) : base(monitor, "print_location",
/// <param name="args">The command arguments</param>
public override void Invoke(string[] args)
{
this.monitor.Log($"Okay, player is at {Game1.player.getTileLocation()}.", LogLevel.Info);
this.monitor.Log($"Okay, player is at {Game1.player.Tile}.", LogLevel.Info);
}
}
}
6 changes: 3 additions & 3 deletions SafeLightning/ModEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System;
using Harmony;
using HarmonyLib;
using SafeLightning.CommandParsing;
using StardewModdingAPI;
using System.Reflection;
Expand All @@ -24,7 +24,7 @@ public override void Entry(IModHelper helper)
CommandParser commandParser = new CommandParser(this.Monitor, this.Helper.ConsoleCommands);
commandParser.RegisterCommands();

HarmonyInstance instance = HarmonyInstance.Create(this.Helper.ModRegistry.ModID);
Harmony instance = new Harmony(this.Helper.ModRegistry.ModID);
instance.PatchAll(Assembly.GetExecutingAssembly());
}

Expand Down Expand Up @@ -64,7 +64,7 @@ internal static void StrikeLightningSafelyAt(Vector2 position, bool effects)

if (farm.objects.TryGetValue(position, out StardewValley.Object obj) && obj.bigCraftable.Value && obj.ParentSheetIndex == 9 && obj.heldObject.Value == null)
{
obj.heldObject.Value = new StardewValley.Object(787, 1, false, -1, 0);
obj.heldObject.Value = new StardewValley.Object("787", 1, false, -1, 0);
obj.MinutesUntilReady = Utility.CalculateMinutesUntilMorning(Game1.timeOfDay);
obj.shakeTimer = 1000;

Expand Down
108 changes: 54 additions & 54 deletions SafeLightning/PerformLightningUpdatePatch.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Harmony;
using HarmonyLib;
using Microsoft.Xna.Framework;
using Netcode;
using StardewValley;
using StardewValley.Extensions;
using StardewValley.TerrainFeatures;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -31,9 +32,9 @@ private static MethodBase TargetMethod()
/// <summary>The code to run before the original method.</summary>
/// <returns>Whether to run the original method or not.</returns>
[SuppressMessage("ReSharper", "UnusedMember.Local", Justification = "Method names are defined by Harmony.")]
private static bool Prefix()
private static bool Prefix(int time_of_day)
{
PerformLightningUpdatePatch.PerformLightningUpdate();
PerformLightningUpdatePatch.PerformLightningUpdate(time_of_day);
return false;
}

Expand All @@ -42,89 +43,88 @@ private static bool Prefix()
[SuppressMessage("ReSharper", "All", Justification = "Copied from the vanilla decompilation.")]
[SuppressMessage("SMAPI.CommonErrors", "AvoidNetField", Justification = "Copied from the vanilla decompilation.")]
[SuppressMessage("SMAPI.CommonErrors", "AvoidImplicitNetFieldCast", Justification = "Copied from the vanilla decompilation.")]
private static void PerformLightningUpdate()
private static void PerformLightningUpdate(int time_of_day)
{
Random random = new Random((int)Game1.uniqueIDForThisGame + (int)Game1.stats.DaysPlayed + Game1.timeOfDay);
if (random.NextDouble() < 0.125 + Game1.player.team.AverageDailyLuck((GameLocation)null) + Game1.player.team.AverageLuckLevel((GameLocation)null) / 100.0)
Random random = Utility.CreateRandom(Game1.uniqueIDForThisGame, Game1.stats.DaysPlayed, time_of_day);
if (random.NextDouble() < 0.125 + Game1.player.team.AverageDailyLuck() + Game1.player.team.AverageLuckLevel() / 100.0)
{
Farm.LightningStrikeEvent lightningStrikeEvent = new Farm.LightningStrikeEvent();
lightningStrikeEvent.bigFlash = true;
Farm locationFromName = Game1.getLocationFromName("Farm") as Farm;
List<Vector2> source = new List<Vector2>();
foreach (KeyValuePair<Vector2, Object> pair in locationFromName.objects.Pairs)
Farm farm = Game1.getFarm();
List<Vector2> list = new List<Vector2>();
foreach (KeyValuePair<Vector2, Object> pair in farm.objects.Pairs)
{
if ((bool)((NetFieldBase<bool, NetBool>)pair.Value.bigCraftable) && pair.Value.ParentSheetIndex == 9)
source.Add(pair.Key);
if (pair.Value.QualifiedItemId == "(BC)9")
{
list.Add(pair.Key);
}
}
if (source.Count > 0)

if (list.Count > 0)
{
for (int index1 = 0; index1 < 2; ++index1)
for (int i = 0; i < 2; i++)
{
Vector2 index2 = source.ElementAt<Vector2>(random.Next(source.Count));
if (locationFromName.objects[index2].heldObject.Value == null)
Vector2 vector = random.ChooseFrom(list);
if (farm.objects[vector].heldObject.Value == null)
{
locationFromName.objects[index2].heldObject.Value = new Object(787, 1, false, -1, 0);
locationFromName.objects[index2].minutesUntilReady.Value = Utility.CalculateMinutesUntilMorning(Game1.timeOfDay);
locationFromName.objects[index2].shakeTimer = 1000;
farm.objects[vector].heldObject.Value = ItemRegistry.Create<Object>("(O)787");
farm.objects[vector].minutesUntilReady.Value = Utility.CalculateMinutesUntilMorning(Game1.timeOfDay);
farm.objects[vector].shakeTimer = 1000;
lightningStrikeEvent.createBolt = true;
lightningStrikeEvent.boltPosition = index2 * 64f + new Vector2(32f, 0.0f);
locationFromName.lightningStrikeEvent.Fire(lightningStrikeEvent);
lightningStrikeEvent.boltPosition = vector * 64f + new Vector2(32f, 0f);
farm.lightningStrikeEvent.Fire(lightningStrikeEvent);
return;
}
}
}
if (random.NextDouble() < 0.25 - Game1.player.team.AverageDailyLuck((GameLocation)null) - Game1.player.team.AverageLuckLevel((GameLocation)null) / 100.0)

if (random.NextDouble() < 0.25 - Game1.player.team.AverageDailyLuck() - Game1.player.team.AverageLuckLevel() / 100.0)
{
try
{
KeyValuePair<Vector2, TerrainFeature> keyValuePair = locationFromName.terrainFeatures.Pairs.ElementAt(random.Next(locationFromName.terrainFeatures.Count()));
if (!(keyValuePair.Value is FruitTree))
if (Utility.TryGetRandom(farm.terrainFeatures, out var key, out var value))
{
int num = !(keyValuePair.Value is HoeDirt) || (keyValuePair.Value as HoeDirt).crop == null ? 0 : (!(bool)((NetFieldBase<bool, NetBool>)(keyValuePair.Value as HoeDirt).crop.dead) ? 1 : 0);
if (keyValuePair.Value.performToolAction((Tool)null, 50, keyValuePair.Key, (GameLocation)locationFromName))
FruitTree fruitTree = value as FruitTree;
if (fruitTree != null)
{
//lightningStrikeEvent.destroyedTerrainFeature = true;
//fruitTree.struckByLightningCountdown.Value = 4;
//fruitTree.shake(key, doEvenIfStillShaking: true);
lightningStrikeEvent.createBolt = true;
//locationFromName.terrainFeatures.Remove(keyValuePair.Key);
lightningStrikeEvent.boltPosition = keyValuePair.Key * 64f + new Vector2(32f, (float)sbyte.MinValue);
lightningStrikeEvent.boltPosition = key * 64f + new Vector2(32f, -128f);
}
if (num != 0)
else
{
if (keyValuePair.Value is HoeDirt)
Crop crop = (value as HoeDirt)?.crop;
bool num = crop != null && !crop.dead;
if (value.performToolAction(null, 50, key))
{
//lightningStrikeEvent.destroyedTerrainFeature = true;
lightningStrikeEvent.createBolt = true;
//farm.terrainFeatures.Remove(key);
lightningStrikeEvent.boltPosition = key * 64f + new Vector2(32f, -128f);
}

if (num && (bool)crop.dead)
{
if ((keyValuePair.Value as HoeDirt).crop != null)
{
if ((bool)((NetFieldBase<bool, NetBool>)(keyValuePair.Value as HoeDirt).crop.dead))
{
lightningStrikeEvent.createBolt = true;
lightningStrikeEvent.boltPosition = keyValuePair.Key * 64f + new Vector2(32f, 0.0f);
}
}
lightningStrikeEvent.createBolt = true;
lightningStrikeEvent.boltPosition = key * 64f + new Vector2(32f, 0f);
}
}
}
else if (keyValuePair.Value is FruitTree)
{
//(keyValuePair.Value as FruitTree).struckByLightningCountdown.Value = 4;
//(keyValuePair.Value as FruitTree).shake(keyValuePair.Key, true, (GameLocation)locationFromName);
lightningStrikeEvent.createBolt = true;
lightningStrikeEvent.boltPosition = keyValuePair.Key * 64f + new Vector2(32f, (float)sbyte.MinValue);
}
}
catch (Exception ex)
catch (Exception)
{
}
}
locationFromName.lightningStrikeEvent.Fire(lightningStrikeEvent);

farm.lightningStrikeEvent.Fire(lightningStrikeEvent);
}
else
else if (random.NextDouble() < 0.1)
{
if (random.NextDouble() >= 0.1)
return;
(Game1.getLocationFromName("Farm") as Farm).lightningStrikeEvent.Fire(new Farm.LightningStrikeEvent()
{
smallFlash = true
});
Farm.LightningStrikeEvent lightningStrikeEvent2 = new Farm.LightningStrikeEvent();
lightningStrikeEvent2.smallFlash = true;
Farm farm = Game1.getFarm();
farm.lightningStrikeEvent.Fire(lightningStrikeEvent2);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions SafeLightning/SafeLightning.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.5.0</Version>
<TargetFramework>net452</TargetFramework>
<Version>1.6.0</Version>
<TargetFramework>net6.0</TargetFramework>

<EnableHarmony>true</EnableHarmony>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="3.3.0" />
<PackageReference Include="Pathoschild.Stardew.ModBuildConfig" Version="4.1.1" />
</ItemGroup>
</Project>
6 changes: 3 additions & 3 deletions SafeLightning/manifest.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"Name": "Safe Lightning",
"Author": "Cat",
"Version": "2.1.0",
"Version": "2.2.0",
"Description": "Lightning won't harm your farm.",
"UniqueID": "cat.safelightning",
"EntryDll": "SafeLightning.dll",
"MinimumApiVersion": "3.0.0",
"EntryDLL": "SafeLightning.dll",
"MinimumApiVersion": "4.0.0",
"UpdateKeys": [ "Nexus:2039" ]
}