dev: tmodporter changes
This commit is contained in:
parent
d8c4649f92
commit
278a0d9278
@ -1,62 +1,62 @@
|
|||||||
using MagicStorage;
|
using MagicStorage;
|
||||||
using MagicStorage.Components;
|
using MagicStorage.Components;
|
||||||
using MagicStorageVoidBag.Items;
|
using MagicStorageVoidBag.Items;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using Terraria.Audio;
|
using Terraria.Audio;
|
||||||
using Terraria.DataStructures;
|
using Terraria.DataStructures;
|
||||||
using Terraria.GameContent.Achievements;
|
using Terraria.GameContent.Achievements;
|
||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag.Hooks {
|
namespace MagicStorageVoidBag.Hooks {
|
||||||
internal class GetItemVoidVaultHook {
|
internal class GetItemVoidVaultHook {
|
||||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
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) {
|
public static bool Hook(Terraria.On_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);
|
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||||
|
|
||||||
newItem = newItem.Clone();
|
newItem = newItem.Clone();
|
||||||
|
|
||||||
if (i == null) goto original;
|
if (i == null) goto original;
|
||||||
|
|
||||||
var bag = (MSVoidBag)i.ModItem;
|
var bag = (MSVoidBag)i.ModItem;
|
||||||
|
|
||||||
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
||||||
|
|
||||||
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
|
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 (!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 (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
|
||||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||||
|
|
||||||
TEStorageHeart heart = (TEStorageHeart)te;
|
TEStorageHeart heart = (TEStorageHeart)te;
|
||||||
|
|
||||||
heart.TryDeposit(returnItem);
|
heart.TryDeposit(returnItem);
|
||||||
heart.ResetCompactStage();
|
heart.ResetCompactStage();
|
||||||
StorageGUI.needRefresh = true;
|
StorageGUI.needRefresh = true;
|
||||||
|
|
||||||
if (returnItem.stack != newItem.stack) {
|
if (returnItem.stack != newItem.stack) {
|
||||||
if (newItem.IsACoin) {
|
if (newItem.IsACoin) {
|
||||||
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
|
SoundEngine.PlaySound(SoundID.CoinPickup, player.position);
|
||||||
} else {
|
} else {
|
||||||
SoundEngine.PlaySound(SoundID.Grab, player.position);
|
SoundEngine.PlaySound(SoundID.Grab, player.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!settings.NoText) {
|
if (!settings.NoText) {
|
||||||
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
|
PopupText.NewText(PopupTextContext.ItemPickupToVoidContainer, newItem, returnItem.stack, noStack: false, settings.LongText);
|
||||||
}
|
}
|
||||||
|
|
||||||
AchievementsHelper.NotifyItemPickup(player, returnItem);
|
AchievementsHelper.NotifyItemPickup(player, returnItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (returnItem.stack == 0) return true;
|
if (returnItem.stack == 0) return true;
|
||||||
|
|
||||||
original:
|
original:
|
||||||
if (player.HasItem(ItemID.VoidLens)) {
|
if (player.HasItem(ItemID.VoidLens)) {
|
||||||
return orig(player, plr, inventory, newItem, settings, returnItem);
|
return orig(player, plr, inventory, newItem, settings, returnItem);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,45 @@
|
|||||||
using MagicStorage.Components;
|
using MagicStorage.Components;
|
||||||
using MagicStorageVoidBag.Items;
|
using MagicStorageVoidBag.Items;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Terraria;
|
using Terraria;
|
||||||
using Terraria.DataStructures;
|
using Terraria.DataStructures;
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
using MagicStorage;
|
using MagicStorage;
|
||||||
using Terraria.ID;
|
using Terraria.ID;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag.Hooks {
|
namespace MagicStorageVoidBag.Hooks {
|
||||||
internal class ItemSpaceForCofveveHook {
|
internal class ItemSpaceForCofveveHook {
|
||||||
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
private static readonly log4net.ILog Logger = MagicStorageVoidBag.Instance.Logger;
|
||||||
|
|
||||||
// Despite the constant negative press cofveve
|
// Despite the constant negative press cofveve
|
||||||
public static bool Hook(On.Terraria.Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
|
public static bool Hook(Terraria.On_Player.orig_ItemSpaceForCofveve orig, Player player, Item newItem) {
|
||||||
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
var i = player.inventory.FirstOrDefault(i => i.type == ModContent.ItemType<MSVoidBag>(), null);
|
||||||
if (i == null) goto original;
|
if (i == null) goto original;
|
||||||
|
|
||||||
newItem = newItem.Clone();
|
newItem = newItem.Clone();
|
||||||
|
|
||||||
var bag = (MSVoidBag)i.ModItem;
|
var bag = (MSVoidBag)i.ModItem;
|
||||||
|
|
||||||
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
if (bag.Location.X < 0 || bag.Location.Y < 0) goto original;
|
||||||
|
|
||||||
Tile tile = Main.tile[bag.Location.X, bag.Location.Y];
|
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 (!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 (!TileEntity.ByPosition.TryGetValue(bag.Location, out TileEntity te)) goto original;
|
||||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) goto original;
|
||||||
|
|
||||||
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
|
if (Utility.HeartHasSpaceFor(newItem, (TEStorageHeart)te)) return true;
|
||||||
|
|
||||||
original:
|
original:
|
||||||
if (player.HasItem(ItemID.VoidLens)) {
|
if (player.HasItem(ItemID.VoidLens)) {
|
||||||
return orig(player, newItem);
|
return orig(player, newItem);
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,29 +1,29 @@
|
|||||||
|
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
using MagicStorageVoidBag.ILPatches;
|
using MagicStorageVoidBag.ILPatches;
|
||||||
using MagicStorageVoidBag.Hooks;
|
using MagicStorageVoidBag.Hooks;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag {
|
namespace MagicStorageVoidBag {
|
||||||
public class MagicStorageVoidBag : Mod {
|
public class MagicStorageVoidBag : Mod {
|
||||||
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
|
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
|
||||||
|
|
||||||
// IL Patches
|
// IL Patches
|
||||||
private PlayerUpdatePatch playerUpdatePatch = new();
|
private PlayerUpdatePatch playerUpdatePatch = new();
|
||||||
|
|
||||||
public override void Load() {
|
public override void Load() {
|
||||||
IL.Terraria.Player.Update += playerUpdatePatch.Patch;
|
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
|
||||||
|
|
||||||
On.Terraria.Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
|
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
|
||||||
On.Terraria.Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
|
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Unload() {
|
public override void Unload() {
|
||||||
IL.Terraria.Player.Update -= playerUpdatePatch.Patch;
|
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
|
||||||
|
|
||||||
On.Terraria.Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
|
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
|
||||||
On.Terraria.Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
|
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
|
||||||
|
|
||||||
base.Unload();
|
base.Unload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,16 +1,16 @@
|
|||||||
{
|
{
|
||||||
"profiles": {
|
"profiles": {
|
||||||
"Terraria": {
|
"Terraria": {
|
||||||
"commandName": "Executable",
|
"commandName": "Executable",
|
||||||
"executablePath": "dotnet",
|
"executablePath": "dotnet",
|
||||||
"commandLineArgs": "$(tMLPath)",
|
"commandLineArgs": "$(tMLPath)",
|
||||||
"workingDirectory": "$(tMLSteamPath)"
|
"workingDirectory": "$(tMLSteamPath)"
|
||||||
},
|
},
|
||||||
"TerrariaServer": {
|
"TerrariaServer": {
|
||||||
"commandName": "Executable",
|
"commandName": "Executable",
|
||||||
"executablePath": "dotnet",
|
"executablePath": "dotnet",
|
||||||
"commandLineArgs": "$(tMLServerPath)",
|
"commandLineArgs": "$(tMLServerPath)",
|
||||||
"workingDirectory": "$(tMLSteamPath)"
|
"workingDirectory": "$(tMLSteamPath)"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user