dev: tmodporter changes

This commit is contained in:
Jack Bond-Preston 2023-08-17 16:37:16 +01:00
parent d8c4649f92
commit 278a0d9278
Signed by: jack
GPG Key ID: 010071F1482BA852
4 changed files with 150 additions and 150 deletions

View File

@ -1,62 +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.needRefresh = true;
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;
}
}
}
}
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(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);
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.needRefresh = true;
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;
}
}
}
}

View File

@ -1,45 +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;
}
}
}
}
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(Terraria.On_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;
}
}
}
}

View File

@ -1,29 +1,29 @@
using Terraria.ModLoader;
using MagicStorageVoidBag.ILPatches;
using MagicStorageVoidBag.Hooks;
namespace MagicStorageVoidBag {
public class MagicStorageVoidBag : Mod {
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
// IL Patches
private PlayerUpdatePatch playerUpdatePatch = new();
public override void Load() {
IL.Terraria.Player.Update += playerUpdatePatch.Patch;
On.Terraria.Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
On.Terraria.Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
}
public override void Unload() {
IL.Terraria.Player.Update -= playerUpdatePatch.Patch;
On.Terraria.Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
On.Terraria.Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
base.Unload();
}
}
using Terraria.ModLoader;
using MagicStorageVoidBag.ILPatches;
using MagicStorageVoidBag.Hooks;
namespace MagicStorageVoidBag {
public class MagicStorageVoidBag : Mod {
public static MagicStorageVoidBag Instance => ModContent.GetInstance<MagicStorageVoidBag>();
// IL Patches
private PlayerUpdatePatch playerUpdatePatch = new();
public override void Load() {
Terraria.IL_Player.Update += playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault += GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve += ItemSpaceForCofveveHook.Hook;
}
public override void Unload() {
Terraria.IL_Player.Update -= playerUpdatePatch.Patch;
Terraria.On_Player.GetItem_VoidVault -= GetItemVoidVaultHook.Hook;
Terraria.On_Player.ItemSpaceForCofveve -= ItemSpaceForCofveveHook.Hook;
base.Unload();
}
}
}

View File

@ -1,16 +1,16 @@
{
"profiles": {
"Terraria": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "$(tMLPath)",
"workingDirectory": "$(tMLSteamPath)"
},
"TerrariaServer": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "$(tMLServerPath)",
"workingDirectory": "$(tMLSteamPath)"
}
}
{
"profiles": {
"Terraria": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "$(tMLPath)",
"workingDirectory": "$(tMLSteamPath)"
},
"TerrariaServer": {
"commandName": "Executable",
"executablePath": "dotnet",
"commandLineArgs": "$(tMLServerPath)",
"workingDirectory": "$(tMLSteamPath)"
}
}
}