diff --git a/Content/Tiles/DenziumOre.cs b/Content/Tiles/DenziumOre.cs index cdaacae..3759827 100644 --- a/Content/Tiles/DenziumOre.cs +++ b/Content/Tiles/DenziumOre.cs @@ -1,5 +1,4 @@ -using System; -using Terraria; +using Terraria; using Terraria.ModLoader; using Terraria.ID; using Microsoft.Xna.Framework; diff --git a/Content/Tiles/TitanForge.cs b/Content/Tiles/TitanForge.cs index e1468ec..52da694 100644 --- a/Content/Tiles/TitanForge.cs +++ b/Content/Tiles/TitanForge.cs @@ -1,51 +1,19 @@ -using Microsoft.Xna.Framework; -using Terraria; +using Decimation.Lib.Tiles; +using Microsoft.Xna.Framework; using Terraria.ID; using Terraria.ModLoader; using Terraria.ObjectData; namespace Decimation.Content.Tiles { - class TitanForge : ModTile + class TitanForge : DecimationMultiTile { - public override void SetDefaults() - { - Main.tileSolidTop[Type] = false; - Main.tileFrameImportant[Type] = true; - Main.tileNoAttach[Type] = true; - TileObjectData.newTile.CopyFrom(TileObjectData.Style3x3); - TileObjectData.newTile.CoordinateHeights = new int[] { 16, 16, 16 }; - TileObjectData.addTile(Type); - ModTranslation name = CreateMapEntryName(); - name.SetDefault("Titan Forge"); - AddMapEntry(new Color(104, 140, 183), name); - dustType = DustID.Iron; - disableSmartCursor = true; - animationFrameHeight = 54; - } - - public override void NumDust(int i, int j, bool fail, ref int num) - { - num = fail ? 1 : 3; - } - - public override void KillMultiTile(int i, int j, int frameX, int frameY) - { - Item.NewItem(i * 16, j * 16, 48, 48, ModContent.ItemType()); - } - - public override void AnimateTile(ref int frame, ref int frameCounter) - { - frameCounter++; - if (frameCounter > 5) - { - frameCounter = 0; - frame++; - if (frame > 4) - { - frame = 0; - } - } - } + public override TileObjectData Style => TileObjectData.Style3x3; + public override string Name => "Titan Forge"; + public override Color MapColor => new Color(104, 140, 183); + public override int DustType => DustID.Iron; + public override int AnimationFrameCount => 8; + public override int? AnimationFrameHeight => 54; + public override int TileItem => ModContent.ItemType(); } -} +} \ No newline at end of file diff --git a/Content/Tiles/TitanForge.png b/Content/Tiles/TitanForge.png index 8886fc7..ddce566 100644 Binary files a/Content/Tiles/TitanForge.png and b/Content/Tiles/TitanForge.png differ diff --git a/Lib/Tiles/DecimationFramedTile.cs b/Lib/Tiles/DecimationFramedTile.cs new file mode 100644 index 0000000..b851736 --- /dev/null +++ b/Lib/Tiles/DecimationFramedTile.cs @@ -0,0 +1,21 @@ +using Terraria; + +namespace Decimation.Lib.Tiles +{ + public abstract class DecimationFramedTile : DecimationTile + { + public override bool Solid => true; + public override bool TilesCanAttach => true; + + public virtual bool MergeDirt { get; set; } = true; + + protected sealed override void InitTile() + { + Main.tileMergeDirt[Type] = MergeDirt; + + InitFramedTile(); + } + + protected abstract void InitFramedTile(); + } +} \ No newline at end of file diff --git a/Lib/Tiles/DecimationMultiTile.cs b/Lib/Tiles/DecimationMultiTile.cs new file mode 100644 index 0000000..bce788d --- /dev/null +++ b/Lib/Tiles/DecimationMultiTile.cs @@ -0,0 +1,61 @@ +using Terraria; +using Terraria.DataStructures; +using Terraria.Enums; +using Terraria.ObjectData; + +namespace Decimation.Lib.Tiles +{ + public abstract class DecimationMultiTile : DecimationTile + { + public override bool DisableSmartCursor => true; + + public virtual bool Table { get; set; } = false; + public virtual Point16 Origin { get; } = new Point16(0, 0); + public virtual int[] CoordinateHeights { get; set; } = { }; + public virtual int CoordinateWidth { get; } = 16; + public virtual int CoordinatePadding { get; } = 2; + public virtual int? Width { get; } = null; + public virtual int? Height { get; } = null; + public virtual bool AnchorBottom { get; } = true; + + public abstract TileObjectData Style { get; } + + private int _width; + private int _height; + + protected sealed override void InitTile() + { + Main.tileTable[Type] = Table; + Main.tileFrameImportant[Type] = true; + + TileObjectData.newTile.CopyFrom(Style); + if (Width.HasValue) TileObjectData.newTile.Width = Width.Value; + if (Height.HasValue) TileObjectData.newTile.Height = Height.Value; + if (CoordinateHeights.Length <= 0) + { + CoordinateHeights = new int[TileObjectData.newTile.Height]; + for (int i = 0; i < TileObjectData.newTile.Height; i++) CoordinateHeights[i] = 16; + } + + TileObjectData.newTile.CoordinateHeights = CoordinateHeights; + TileObjectData.newTile.CoordinateWidth = CoordinateWidth; + TileObjectData.newTile.CoordinatePadding = CoordinatePadding; + if (AnchorBottom) + TileObjectData.newTile.AnchorBottom = + new AnchorData(AnchorType.SolidTile, TileObjectData.newTile.Width - 1, 0); + TileObjectData.addTile(Type); + + _width = TileObjectData.newTile.Width * 16; + _height = TileObjectData.newTile.Height * 16; + } + + public override void KillMultiTile(int i, int j, int frameX, int frameY) + { + Item.NewItem(i * 16, j * 16, _width, _height, TileItem); + } + + protected virtual void InitMultiTile() + { + } + } +} \ No newline at end of file diff --git a/Lib/Tiles/DecimationTile.cs b/Lib/Tiles/DecimationTile.cs new file mode 100644 index 0000000..1f6cdbe --- /dev/null +++ b/Lib/Tiles/DecimationTile.cs @@ -0,0 +1,69 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ModLoader; + +namespace Decimation.Lib.Tiles +{ + public abstract class DecimationTile : ModTile + { + public virtual bool Solid { get; set; } = false; + public virtual bool SolidTop { get; set; } = false; + public virtual bool TilesCanAttach { get; set; } = false; + public virtual bool DisableSmartCursor { get; set; } = false; + public virtual float MineResistance { get; set; } = 1f; + public virtual int DustType { get; } = 0; + public virtual int AnimationFrameCount { get; } = 0; + public virtual int AnimationFps { get; } = 5; + public virtual int? AnimationFrameHeight { get; } = null; + public virtual string Name { get; } = null; + public virtual int MinimumPickaxePower { get; set; } = 0; + + public abstract Color MapColor { get; } + public abstract int TileItem { get; } + + public sealed override void SetDefaults() + { + Main.tileSolid[Type] = Solid; + Main.tileSolidTop[Type] = SolidTop; + Main.tileNoAttach[Type] = !TilesCanAttach; + minPick = MinimumPickaxePower; + mineResist = MineResistance; + dustType = DustType; + drop = TileItem; + disableSmartCursor = DisableSmartCursor; + if (AnimationFrameHeight.HasValue) animationFrameHeight = AnimationFrameHeight.Value; + + if (Name == null) + { + AddMapEntry(MapColor); + } + else + { + ModTranslation translation = CreateMapEntryName(); + translation.SetDefault(Name); + AddMapEntry(MapColor, translation); + } + + InitTile(); + } + + public override void NumDust(int i, int j, bool fail, ref int num) + { + num = fail ? 1 : 3; + } + + public override void AnimateTile(ref int frame, ref int frameCounter) + { + frameCounter++; + if (frameCounter > AnimationFps) + { + frameCounter = 0; + frame++; + + if (frame >= AnimationFrameCount) frame = 0; + } + } + + protected abstract void InitTile(); + } +} \ No newline at end of file