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
This commit is contained in:
62
Hooks/GetItemVoidVaultHook.cs
Normal file
62
Hooks/GetItemVoidVaultHook.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using MagicStorage;
|
||||
using MagicStorage.Components;
|
||||
using MagicStorageVoidBag.Items;
|
||||
using System.Linq;
|
||||
using Terraria;
|
||||
using Terraria.Audio;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.GameContent.Achievements;
|
||||
using Terraria.ID;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace MagicStorageVoidBag.Hooks {
|
||||
internal class GetItemVoidVaultHook {
|
||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||
public static bool Hook(On.Terraria.Player.orig_GetItem_VoidVault orig, Player player, int plr, Item[] inventory, Item newItem, GetItemSettings settings, Item returnItem) {
|
||||
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||
|
||||
newItem = newItem.Clone();
|
||||
|
||||
if (i == null) goto original;
|
||||
|
||||
var bag = (MSVoidBag)i.ModItem;
|
||||
|
||||
if (bag.location.X < 0 || bag.location.Y < 0) goto original;
|
||||
|
||||
Tile tile = Main.tile[bag.location.X, bag.location.Y];
|
||||
|
||||
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
|
||||
if (!TileEntity.ByPosition.TryGetValue(bag.location, out TileEntity te)) goto original;
|
||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||
|
||||
TEStorageHeart heart = (TEStorageHeart)te;
|
||||
|
||||
heart.TryDeposit(returnItem);
|
||||
heart.ResetCompactStage();
|
||||
StorageGUI.modSearchBox.OnChanged();
|
||||
|
||||
if (returnItem.stack != newItem.stack) {
|
||||
if (newItem.IsACoin) {
|
||||
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
|
||||
} else {
|
||||
SoundEngine.PlaySound(SoundID.Grab, player.position);
|
||||
}
|
||||
|
||||
if (!settings.NoText) {
|
||||
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
|
||||
}
|
||||
|
||||
AchievementsHelper.NotifyItemPickup(player, returnItem);
|
||||
}
|
||||
|
||||
if (returnItem.stack == 0) return true;
|
||||
|
||||
original:
|
||||
if (player.HasItem(ItemID.VoidLens)) {
|
||||
return orig(player, plr, inventory, newItem, settings, returnItem);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
45
Hooks/ItemSpaceForCofveveHook.cs
Normal file
45
Hooks/ItemSpaceForCofveveHook.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using MagicStorage.Components;
|
||||
using MagicStorageVoidBag.Items;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.ModLoader;
|
||||
using MagicStorage;
|
||||
using Terraria.ID;
|
||||
|
||||
namespace MagicStorageVoidBag.Hooks {
|
||||
internal class ItemSpaceForCofveveHook {
|
||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||
|
||||
// Despite the constant negative press cofveve
|
||||
public static bool Hook(On.Terraria.Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
|
||||
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||
if (i == null) goto original;
|
||||
|
||||
newItem = newItem.Clone();
|
||||
|
||||
var bag = (MSVoidBag)i.ModItem;
|
||||
|
||||
if (bag.location.X < 0 || bag.location.Y < 0) goto original;
|
||||
|
||||
Tile tile = Main.tile[bag.location.X, bag.location.Y];
|
||||
|
||||
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) goto original;
|
||||
if (!TileEntity.ByPosition.TryGetValue(bag.location, out TileEntity te)) goto original;
|
||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||
|
||||
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
|
||||
|
||||
original:
|
||||
if (player.HasItem(ItemID.VoidLens)) {
|
||||
return orig(player, newItem);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
33
Hooks/StorageHeartRightClickHook.cs
Normal file
33
Hooks/StorageHeartRightClickHook.cs
Normal file
@ -0,0 +1,33 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user