initial implementation
This commit is contained in:
parent
15557dfeec
commit
958f3796f8
38
Items/GlobalItem.cs
Normal file
38
Items/GlobalItem.cs
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
76
Items/MSVoidBag.cs
Normal file
76
Items/MSVoidBag.cs
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
using MagicStorage.Items;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Terraria;
|
||||||
|
using Terraria.GameContent.Creative;
|
||||||
|
using Terraria.ID;
|
||||||
|
using Terraria.Localization;
|
||||||
|
using Terraria.ModLoader;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void SetDefaults() {
|
||||||
|
Item.width = 26;
|
||||||
|
Item.height = 34;
|
||||||
|
Item.maxStack = 1;
|
||||||
|
Item.rare = ItemRarityID.Purple;
|
||||||
|
Item.useStyle = ItemUseStyleID.Swing;
|
||||||
|
Item.useAnimation = 28;
|
||||||
|
Item.useTime = 28;
|
||||||
|
Item.value = Item.sellPrice(gold: 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void ModifyTooltips(List<TooltipLine> lines) {
|
||||||
|
bool isSet = location.X >= 0 && location.Y >= 0;
|
||||||
|
for (int k = 0; k < lines.Count; k++)
|
||||||
|
if (isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip1") {
|
||||||
|
lines[k].Text = Language.GetTextValue("Mods.MagicStorage.SetTo", location.X, location.Y);
|
||||||
|
} else if (!isSet && lines[k].Mod == "Terraria" && lines[k].Name == "Tooltip2") {
|
||||||
|
lines.RemoveAt(k);
|
||||||
|
k--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void AddRecipes() {
|
||||||
|
Recipe recipe = CreateRecipe();
|
||||||
|
recipe.AddIngredient<PortableAccess>();
|
||||||
|
recipe.AddIngredient(ItemID.VoidLens);
|
||||||
|
recipe.AddIngredient<RadiantJewel>();
|
||||||
|
recipe.AddTile(TileID.LunarCraftingStation);
|
||||||
|
recipe.Register();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
BIN
Items/MSVoidBag.png
Normal file
BIN
Items/MSVoidBag.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 558 B |
7
Localization/en-US.hjson
Normal file
7
Localization/en-US.hjson
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
Mods: {
|
||||||
|
MagicStorageVoidBag: {
|
||||||
|
ItemName: {
|
||||||
|
MSVoidBag: Magic Void Bag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,57 @@
|
|||||||
|
using Mono.Cecil.Cil;
|
||||||
|
using Mono.Cecil;
|
||||||
|
using MonoMod.Cil;
|
||||||
using Terraria.ModLoader;
|
using Terraria.ModLoader;
|
||||||
|
using MagicStorageVoidBag.Items;
|
||||||
|
|
||||||
namespace MagicStorageVoidBag
|
namespace MagicStorageVoidBag {
|
||||||
{
|
public class MagicStorageVoidBag : Mod {
|
||||||
public class MagicStorageVoidBag : Mod
|
public override void Load() {
|
||||||
{
|
IL.MagicStorage.Components.StorageHeart.RightClick += HeartRightClickPatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Unload() {
|
||||||
|
base.Unload();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Patch MagicStorage IL to change the Storage Heart right click handler to also work with
|
||||||
|
// MSVoidBag.
|
||||||
|
private void HeartRightClickPatch(ILContext il) {
|
||||||
|
if (il == null) {
|
||||||
|
Logger.Error("ILContext null!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Logger.Debug("Patching MagicStorage IL...");
|
||||||
|
|
||||||
|
var c = new ILCursor(il);
|
||||||
|
|
||||||
|
if (!c.TryGotoNext(i => i.MatchCallOrCallvirt("Terraria.ModLoader.ModContent", "ItemType"))) {
|
||||||
|
Logger.Warn("IL patching failed! :(");
|
||||||
|
}
|
||||||
|
c = c.GotoPrev().GotoPrev();
|
||||||
|
|
||||||
|
var c2 = c.Clone();
|
||||||
|
|
||||||
|
// copy IL up to call
|
||||||
|
while (c2.Next.OpCode != OpCodes.Call) {
|
||||||
|
if (c2.Next.Operand != null) {
|
||||||
|
c.Emit(c2.Next.OpCode, c2.Next.Operand);
|
||||||
|
} else {
|
||||||
|
c.Emit(c2.Next.OpCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
c2 = c2.GotoNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
var method = typeof(ModContent).GetMethod("ItemType").MakeGenericMethod(typeof(MSVoidBag));
|
||||||
|
|
||||||
|
c.Emit(c2.Next.OpCode, method);
|
||||||
|
c2.GotoNext();
|
||||||
|
c.Emit(c2.Next.OpCode, c2.Next.Operand);
|
||||||
|
|
||||||
|
Logger.Debug("...MagicStorage IL patching complete!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
@ -10,4 +10,12 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
|
<PackageReference Include="tModLoader.CodeAssist" Version="0.1.*" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="MagicStorage">
|
||||||
|
<HintPath>..\Mod Libraries\MagicStorage.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="MMHOOK_MagicStorage">
|
||||||
|
<HintPath>lib\MMHOOK_MagicStorage.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
25
MagicStorageVoidBag.sln
Normal file
25
MagicStorageVoidBag.sln
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.2.32616.157
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MagicStorageVoidBag", "MagicStorageVoidBag.csproj", "{8310432C-954C-4401-B93A-27A289CF8B1C}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{8310432C-954C-4401-B93A-27A289CF8B1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{8310432C-954C-4401-B93A-27A289CF8B1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{8310432C-954C-4401-B93A-27A289CF8B1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{8310432C-954C-4401-B93A-27A289CF8B1C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {D3ABF40B-5B75-4B1A-A7C8-569E4A3D7101}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
@ -1,3 +1,8 @@
|
|||||||
displayName = Magic Storage Void Bag
|
displayName = Magic Storage Void Bag
|
||||||
author = jack
|
author = jack
|
||||||
version = 0.1
|
version = 0.1
|
||||||
|
modReferences = MagicStorage
|
||||||
|
dllReferences = MMHOOK_MagicStorage
|
||||||
|
sortAfter = MagicStorage
|
||||||
|
includeSource = true
|
||||||
|
homepage = https://github.com/jackbondpreston/MagicStorageVoidBag
|
||||||
|
@ -1 +1,2 @@
|
|||||||
Magic Storage Void Bag is a pretty cool mod, it does...this. Modify this file with a description of your mod.
|
Adds an upgraded void bag that combines functionality of the Void Bag and Portable Remote Storage Access, by putting items into a magic storage system when your inventory is full (and allowing remote access as usual).
|
||||||
|
This item is crafted by combining a Void Bag with a Portable Remote Storage Access, and a Radiant Jewel. To link it with your storage system, right click the Storage Heart with the bag equipped.
|
2
description_workshop.txt
Normal file
2
description_workshop.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
Adds an upgraded void bag that combines functionality of the Void Bag and Portable Remote Storage Access, by putting items into a magic storage system when your inventory is full (and allowing remote access as usual).
|
||||||
|
This item is crafted by combining a Void Bag with a Portable Remote Storage Access, and a Radiant Jewel. To link it with your storage system, right click the Storage Heart with the bag equipped.
|
BIN
icon.png
BIN
icon.png
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.7 KiB |
BIN
lib/MMHOOK_MagicStorage.dll
Normal file
BIN
lib/MMHOOK_MagicStorage.dll
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user