72 lines
2.7 KiB
C#
72 lines
2.7 KiB
C#
using Terraria.ID;
|
|
using Terraria;
|
|
using Terraria.ModLoader;
|
|
using Terraria.DataStructures;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using ReLogic.Content;
|
|
using System;
|
|
using Terraria.GameContent;
|
|
using ForgottenWawiTech.Content.Rarities;
|
|
|
|
namespace ForgottenWawiTech.Content.Items.Materials
|
|
{
|
|
public class EnergyCore : ModItem
|
|
{
|
|
private const int TICKS_PER_FRAME = 12;
|
|
private const int FRAME_COUNT = 2;
|
|
|
|
public override void SetStaticDefaults()
|
|
{
|
|
Main.RegisterItemAnimation(Type, new DrawAnimationVertical(TICKS_PER_FRAME, FRAME_COUNT));
|
|
}
|
|
|
|
public override void SetDefaults()
|
|
{
|
|
Item.width = 64;
|
|
Item.height = 64;
|
|
Item.maxStack = 9999;
|
|
Item.rare = ModContent.RarityType<SingularityItem>();
|
|
Item.value = Item.buyPrice(gold: 50);
|
|
}
|
|
|
|
public override void AddRecipes()
|
|
{
|
|
Recipe recipe = CreateRecipe()
|
|
.AddIngredient(ItemID.FallenStar, 5)
|
|
.AddIngredient<ControlledSingularity>(1)
|
|
.AddIngredient(ItemID.FragmentNebula, 2)
|
|
.AddIngredient(ItemID.FragmentSolar, 2)
|
|
.AddIngredient(ItemID.FragmentVortex, 2)
|
|
.AddIngredient(ItemID.FragmentStardust, 2)
|
|
.AddTile(TileID.MythrilAnvil);
|
|
// If Calamity Mod is loaded, add Cosmilite bars to the recipe
|
|
if (ModLoader.TryGetMod("CalamityMod", out Mod calamityMod))
|
|
{
|
|
recipe.AddIngredient(calamityMod.Find<ModItem>("CosmiliteBar").Type, 3);
|
|
}
|
|
recipe.Register();
|
|
}
|
|
|
|
public override bool PreDrawInWorld(SpriteBatch spriteBatch, Color lightColor, Color alphaColor, ref float rotation, ref float scale, int whoAmI)
|
|
{
|
|
Texture2D texture = Terraria.GameContent.TextureAssets.Item[Type].Value;
|
|
|
|
// Protect against incorrect frame count
|
|
int frameHeight = texture.Height / Math.Max(1, FRAME_COUNT);
|
|
int frame = (int)((Main.GameUpdateCount / (ulong)Math.Max(1, TICKS_PER_FRAME)) % (ulong)Math.Max(1, FRAME_COUNT));
|
|
|
|
Rectangle source = new Rectangle(0, frame * frameHeight, texture.Width, frameHeight);
|
|
|
|
Vector2 drawPos = Item.Center - Main.screenPosition;
|
|
Vector2 origin = new Vector2(source.Width / 2f, source.Height / 2f);
|
|
|
|
// Use alphaColor for dropped items (includes item alpha), multiplied by light
|
|
Color drawColor = lightColor;
|
|
|
|
spriteBatch.Draw(texture, drawPos, source, drawColor, rotation, origin, scale, SpriteEffects.None, 0f);
|
|
|
|
return false; // we've handled the draw
|
|
}
|
|
}
|
|
} |