namespace MEquipment
{
class MItem : GlobalItem
{
private Item[] singleSlotArray;
double time;
public MItem()
{
singleSlotArray = new Item[1];
}
public override void PostDrawInInventory(Item item, SpriteBatch spriteBatch, Vector2 position, Rectangle frame, Color drawColor, Color itemColor, Vector2 origin, float scale)
{
if (time != Main.time)
{
time = Main.time;
// These 2 lines might not be needed, not sure why there are here.
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend);
DrawUpdateAugments(spriteBatch);
}
base.PostDrawInInventory(item, spriteBatch, position, frame, drawColor, itemColor, origin, scale);
}
private void DrawUpdateAugments(SpriteBatch spriteBatch)
{
if (Main.playerInventory && Main.EquipPage == 0 && MEquipment.augmentsUIEnabled)
{
Point value = new Point(Main.mouseX, Main.mouseY);
Rectangle r = new Rectangle(0, 0, (int)((float)Main.inventoryBackTexture.Width * Main.inventoryScale), (int)((float)Main.inventoryBackTexture.Height * Main.inventoryScale));
MPlayer csp = Main.player[Main.myPlayer].GetModPlayer<MPlayer>(mod);
for (int i = 0; i < 18; i++)
{
Main.inventoryScale = 0.85f;
Item augment = csp.Augments[i];
int num17 = (Main.screenWidth / 2) - 200;
int num18 = 25;
if (Main.netMode == 1) num17 -= 47;
if (i >= 3)
{
r.X = (num17 + (0 + i) * 47) - (i / 3) * 141;
r.Y = num18 + (i / 3) * 47;
}
else
{
r.X = num17 + (0 + i) * 47;
r.Y = num18;
}
if (r.Contains(value))
{
Main.player[Main.myPlayer].mouseInterface = true;
Main.armorHide = true;
singleSlotArray[0] = augment;
ItemSlot.Handle(singleSlotArray, ItemSlot.Context.InventoryItem, 0);
augment = singleSlotArray[0];
}
singleSlotArray[0] = augment;
ItemSlot.Draw(spriteBatch, singleSlotArray, ItemSlot.Context.ChestItem, 0, new Vector2(r.X, r.Y));
//Utils.DrawInvBG(spriteBatch, r1);
//player.inventory[player.selectedItem]
augment = singleSlotArray[0];
csp.Augments[i] = augment;
}
}
#region DrawAugmentInfo
if (Main.playerInventory && Main.EquipPage == 0 && MEquipment.augmentsUIEnabled) // checks if inventory is opened and augments UI is enabled
{
Color color = new Color(.9f, .9f, .9f, .9f);
int num1 = (Main.screenWidth / 2) - 241;
int num2 = 4;
int pickIconPos = 32;
int swordIconPos = 79;
int yoyoIconPos = 126;
int bowIconPos = 173;
int gunIconPos = 220;
int staffIconPos = 267;
Main.spriteBatch.DrawString(Main.fontItemStack, "Augments", new Vector2(num1, num2), color, 0.0f, new Vector2(), 1f, SpriteEffects.None, 0.0f);
Main.spriteBatch.Draw(mod.GetTexture("UI/pickIcon"), new Vector2(num1, pickIconPos), color);
Main.spriteBatch.Draw(mod.GetTexture("UI/swordIcon"), new Vector2(num1, swordIconPos), color);
Main.spriteBatch.Draw(mod.GetTexture("UI/yoyoIcon"), new Vector2(num1, yoyoIconPos), color);
Main.spriteBatch.Draw(mod.GetTexture("UI/bowIcon"), new Vector2(num1, bowIconPos), color);
Main.spriteBatch.Draw(mod.GetTexture("UI/gunIcon"), new Vector2(num1, gunIconPos), color);
Main.spriteBatch.Draw(mod.GetTexture("UI/staffIcon"), new Vector2(num1, staffIconPos), color);
}
#endregion
}
}
}
--------------------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
using MEquipment.Tools;
namespace MEquipment
{
public class MPlayer : ModPlayer
{
public static int SaveVersion = 0; // for saving items in slots
public int maxAugments = 18; // max number of accessory slots, remove
public static int maxAugmentsA = 18;
public Item[] Augments = new Item[maxAugmentsA];
protected double pressedKeyTime;
public override void Initialize()
{
Augments = new Item[maxAugments];
for (int i = 0; i < maxAugments; i++)
{
Augments[i] = new Item();
Augments[i].SetDefaults();
}
}
public override void PreUpdate()
{
BasicMPickaxe pickaxe = new BasicMPickaxe();
for (int i = 0; i < maxAugments; i++)
{
if (Augments[i].type == mod.ItemType("IronHead"))
{
pickaxe.ironHeadInstalled = true;
pickaxe.item.pick += 200;
pickaxe.item.useTime += 20;
pickaxe.item.useAnimation += 25;
if (Math.Abs(Main.time - pressedKeyTime) > 60 && MEquipment.debugMode)
{
pressedKeyTime = Main.time;
Main.NewText("[DEBUG] Iron Head Installed", 0, 150, 150);
Main.NewText(pickaxe.item.pick.ToString());
Main.NewText(pickaxe.ironHeadInstalled.ToString());
}
}
else
{
pickaxe.ironHeadInstalled = false;
}
}
}
public override void LoadCustomData(BinaryReader reader)
{
for (int i = 0; i < maxAugments; i++)
{
Augments[i] = new Item();
Augments[i].SetDefaults();
}
int loadVersion = reader.ReadInt32();
if (loadVersion == 0)
{
maxAugmentsA = reader.ReadInt32();
ReadInventory(Augments, reader, false, false);
}
}
public override void SaveCustomData(BinaryWriter writer)
{
writer.Write(SaveVersion);
writer.Write(maxAugments);
WriteInventory(Augments, writer, false, false);
}
internal static bool WriteInventory(Item[] inv, BinaryWriter writer, bool writeStack = false, bool writeFavorite = false)
{
ushort count = 0;
byte[] data;
using (MemoryStream stream = new MemoryStream())
{
using (BinaryWriter invWriter = new BinaryWriter(stream))
{
for (int k = 0; k < inv.Length; k++)
{
if (IsModItem(inv[k]))
{
invWriter.Write((ushort)k);
Terraria.ModLoader.IO.ItemIO.WriteItem(inv[k], invWriter, writeStack, writeFavorite);
count++;
}
}
}
data = stream.ToArray();
}
if (count > 0)
{
writer.Write(count);
writer.Write(data);
return true;
}
return false;
}
internal static void ReadInventory(Item[] inv, BinaryReader reader, bool readStack = false, bool readFavorite = false)
{
int count = reader.ReadUInt16();
for (int k = 0; k < count; k++)
{
ushort index = reader.ReadUInt16();
Terraria.ModLoader.IO.ItemIO.ReadItem(inv[index], reader, readStack, readFavorite);
}
}
internal static bool IsModItem(Item item)
{
return item.type >= ItemID.Count;
}
}
}
-------------------------------------------------------------------------------------------
using System;
using System.IO;
using Terraria;
using Terraria.ModLoader;
namespace MEquipment.Tools
{
public class BasicMPickaxe : ModItem
{
private const int saveVersion = 0;
protected double pressedKeyTime;
public bool ironHeadInstalled = false;
public override void SetDefaults()
{
item.name = "Basic Modular Pickaxe";
item.toolTip = "A basic pickaxe, nothing special here...";
item.value = Item.sellPrice(0, 5, 0, 0);
item.width = 38;
item.height = 38;
item.melee = true;
item.autoReuse = true;
item.useTurn = true;
item.rare = 9;
item.useStyle = 1;
item.useSound = 1;
item.knockBack = 6;
item.pick = 0;
item.damage = 0;
item.useTime = 0;
item.useAnimation = 0;
}
public override void PostUpdate()
{
if (ironHeadInstalled)
{
item.pick += 200;
item.useTime += 20;
item.useAnimation += 25;
}
}
public override void AddRecipes()
{
/* To-Do */
}
public override void SaveCustomData(BinaryWriter writer)
{
writer.Write(saveVersion);
writer.Write(item.pick);
writer.Write(item.useTime);
writer.Write(item.damage);
}
public override void LoadCustomData(BinaryReader reader)
{
int loadVersion = reader.ReadInt32();
item.useTime = reader.ReadInt32();
item.pick = reader.ReadInt32();
item.damage = reader.ReadInt32();
}
}
}