MagicStorageVoidBag/Hooks/StorageHeartRightClickHook.cs
Jack Bond-Preston ff2bf51bc0
fix: hook vanilla void bag logic to fix various issues
- rewrite most logic
- remove GlobalItem
- use a hook for changing StorageHeart.RightClick instead of manual IL edit
2022-07-04 12:01:09 +01:00

34 lines
1.3 KiB
C#

using MagicStorage.Components;
using MagicStorageVoidBag.Items;
using Terraria;
using Terraria.DataStructures;
using Terraria.Localization;
using Terraria.ModLoader;
namespace MagicStorageVoidBag.Hooks {
internal class StorageHeartRightClickHook {
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
public static bool Hook(On.MagicStorage.Components.StorageHeart.orig_RightClick orig, StorageHeart heart, int i, int j) {
// https://github.com/blushiemagic/MagicStorage/blob/1.4-stable/Components/StorageHeart.cs#L23
Player player = Main.LocalPlayer;
Item item = player.HeldItem;
if (item.type == ModContent.ItemType<MSVoidBag>()) {
if (Main.tile[i, j].TileFrameX % 36 == 18) i--;
if (Main.tile[i, j].TileFrameY % 36 == 18) j--;
MSVoidBag bag = (MSVoidBag)item.ModItem;
bag.location = new Point16(i, j);
if (player.selectedItem == 58) {
Main.mouseItem = item.Clone();
}
Main.NewText(Language.GetTextValue("Mods.MagicStorage.LocatorSet", i, j));
return true;
}
return orig(heart, i, j);
}
}
}