Skip to content

Commit

Permalink
added TileScanning helper type + v1.0.2 update
Browse files Browse the repository at this point in the history
  • Loading branch information
absoluteAquarian committed Jan 14, 2023
1 parent 9b91801 commit 7a619f3
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
displayName = absoluteAquarian Utilities
author = absoluteAquarian
version = 1.0.1.4
version = 1.0.2
6 changes: 3 additions & 3 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[h1]v1.0.1.4[/h1]
You can find the DLL, PDB and XML files in the mod's [url=https://github.com/absoluteAquarian/SerousCommonLib/releases/tag/v1.0.1.4]GitHub repository[/url]
[h1]v1.0.2[/h1]
You can find the DLL, PDB and XML files in the mod's [url=https://github.com/absoluteAquarian/SerousCommonLib/releases/tag/v1.0.2]GitHub repository[/url]

- Fixed yet another bug in EnhancedItemSlot where it used the wrong Item object for the OnItemChanged event
- Added the [b]TileScanning[/b] helper class
5 changes: 4 additions & 1 deletion description.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
The common library for absoluteAquarian's various mods.

The DLL, PDB and XML files for this mod can be found at:
https://github.com/absoluteAquarian/SerousCommonLib/releases/tag/v1.0.1.4
https://github.com/absoluteAquarian/SerousCommonLib/releases/tag/v1.0.2

Many features are included in this mod, including but not limited to:
- IL/On edit helpers
- Type extensions
- UI element types
- Easy tooltip modification
- Tile scanning information
- ILoot helpers
- and more!
30 changes: 30 additions & 0 deletions src/API/Edits/NearbyEffectsBlocking.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using MonoMod.RuntimeDetour.HookGen;
using SerousCommonLib.API.Helpers;
using System.Reflection;
using Terraria.ModLoader;

namespace SerousCommonLib.API.Edits {
internal class NearbyEffectsBlocking : Edit {
private static readonly MethodInfo TileLoader_NearbyEffects = typeof(TileLoader).GetMethod(nameof(TileLoader.NearbyEffects), BindingFlags.Public | BindingFlags.Static);

private delegate void orig_TileLoader_NearbyEffects(int i, int j, int type, bool closer);
private delegate void hook_TileLoader_NearbyEffects(orig_TileLoader_NearbyEffects orig, int i, int j, int type, bool closer);
private static event hook_TileLoader_NearbyEffects On_TileLoader_NearbyEffects {
add => HookEndpointManager.Add<hook_TileLoader_NearbyEffects>(TileLoader_NearbyEffects, value);
remove => HookEndpointManager.Remove<hook_TileLoader_NearbyEffects>(TileLoader_NearbyEffects, value);
}

public override void LoadEdits() {
On_TileLoader_NearbyEffects += Hook_TileLoader_NearbyEffects;
}

public override void UnloadEdits() {
On_TileLoader_NearbyEffects -= Hook_TileLoader_NearbyEffects;
}

private void Hook_TileLoader_NearbyEffects(orig_TileLoader_NearbyEffects orig, int i, int j, int type, bool closer) {
if (!TileScanning.DoBlockHooks)
orig(i, j, type, closer);
}
}
}
42 changes: 42 additions & 0 deletions src/API/Helpers/TileScanning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.Xna.Framework;
using Terraria;

namespace SerousCommonLib.API.Helpers {
/// <summary>
/// A helper class for retrieving biome information around a given area
/// </summary>
public static class TileScanning {
internal static bool DoBlockHooks;

/// <summary>
/// Performs biome scanning with <paramref name="worldCenter"/> as the center of the scanning area
/// </summary>
/// <param name="worldCenter">The world coordinates for the center of the scanning area</param>
/// <returns>A <see cref="SceneMetrics"/> instance containing biome information, or <see langword="null"/> if an exception was caught</returns>
public static SceneMetrics Scan(Vector2 worldCenter) {
try {
SceneMetrics sceneMetrics = new();

SceneMetricsScanSettings settings = new SceneMetricsScanSettings {
VisualScanArea = null,
BiomeScanCenterPositionInWorld = worldCenter,
ScanOreFinderData = false
};

DoBlockHooks = true;

sceneMetrics.ScanAndExportToMain(settings);

DoBlockHooks = false;

// Reset the player's biomes to reset
Main.LocalPlayer.ForceUpdateBiomes();

return sceneMetrics;
} catch {
// Swallow any exceptions
return null;
}
}
}
}

0 comments on commit 7a619f3

Please sign in to comment.