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:
@ -1,38 +0,0 @@
|
||||
using MagicStorage.Components;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Terraria;
|
||||
using Terraria.DataStructures;
|
||||
using Terraria.Localization;
|
||||
using Terraria.ModLoader;
|
||||
|
||||
namespace MagicStorageVoidBag.Items {
|
||||
internal class GlobalItem : Terraria.ModLoader.GlobalItem {
|
||||
public override bool OnPickup(Item item, Player player) {
|
||||
var i = player.inventory.Where(i => i.type == ModContent.ItemType<MSVoidBag>()).DefaultIfEmpty(null).First();
|
||||
if (i != null && !player.ItemSpace(item).CanTakeItem) {
|
||||
var bag = (MSVoidBag)i.ModItem;
|
||||
|
||||
if (bag.location.X < 0 || bag.location.Y < 0) return false;
|
||||
|
||||
Tile tile = Main.tile[bag.location.X, bag.location.Y];
|
||||
|
||||
if (!tile.HasTile || tile.TileType != ModContent.TileType<StorageHeart>() || tile.TileFrameX != 0 || tile.TileFrameY != 0) return false;
|
||||
if (!TileEntity.ByPosition.TryGetValue(bag.location, out TileEntity te)) return false;
|
||||
if (te.type != ModContent.TileEntityType<TEStorageHeart>()) return false;
|
||||
|
||||
TEStorageHeart heart = (TEStorageHeart)te;
|
||||
|
||||
int oldStack = item.stack;
|
||||
heart.TryDeposit(item);
|
||||
if (item.stack == 0) return true;
|
||||
|
||||
}
|
||||
|
||||
return base.OnPickup(item, player);
|
||||
}
|
||||
}
|
||||
}
|
@ -11,33 +11,6 @@ namespace MagicStorageVoidBag.Items {
|
||||
[ExtendsFromMod("MagicStorage")]
|
||||
public class MSVoidBag : PortableAccess {
|
||||
|
||||
/*
|
||||
Code here largely thanks to original MagicStorage source, which can be found at
|
||||
https://github.com/blushiemagic/MagicStorage/
|
||||
License:
|
||||
MIT License
|
||||
|
||||
Copyright(c) 2017 Kaylee Minsuh Kim
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files(the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
public override void SetStaticDefaults() {
|
||||
CreativeItemSacrificesCatalog.Instance.SacrificeCountNeededByItemId[Type] = 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user