diff --git a/CalPlayer/CalamityPlayerDrawEffects.cs b/CalPlayer/CalamityPlayerDrawEffects.cs index 4646c696c9..2aac159bc0 100644 --- a/CalPlayer/CalamityPlayerDrawEffects.cs +++ b/CalPlayer/CalamityPlayerDrawEffects.cs @@ -501,7 +501,18 @@ namespace CalamityMod.CalPlayer //I feel like having an Interface folder might be good. public interface IExtendedHat { - void DrawExtension(PlayerDrawInfo drawInfo); + /// + /// The texture of the extension + /// + string ExtensionTexture(); + /// + /// Unless you are using custom drawing, mount offsets are taken into account automatically. + /// + Vector2 ExtensionSpriteOffset(PlayerDrawInfo drawInfo); + /// + ///Return true to make the extension get drawn automatically from the texture and offsets provided. Return false if you want to draw it yourself + /// + bool PreDrawExtension(PlayerDrawInfo drawInfo); } public static readonly PlayerLayer HatExtension = new PlayerLayer("CalamityMod", "HatExtension", PlayerLayer.Head, drawInfo => @@ -516,7 +527,27 @@ namespace CalamityMod.CalPlayer if (ModContent.GetModItem(headItemType) is IExtendedHat ExtendedHatDrawer) { - ExtendedHatDrawer.DrawExtension(drawInfo); + if (ExtendedHatDrawer.PreDrawExtension(drawInfo)) + { + int dyeShader = drawPlayer.dye?[0].dye ?? 0; + + //Remember to use drawInfo.position and not drawPlayer.position, or else it will not display properly in the player selection screen. + Vector2 origin = drawInfo.headOrigin; + Vector2 headDrawPosition = drawInfo.position.Floor() + origin - Main.screenPosition; + headDrawPosition.Y -= drawPlayer.gfxOffY; + + //Account for the hellspawns known as mounts + if (drawPlayer.mount.Active) + headDrawPosition.Y += drawPlayer.mount.HeightBoost; + + headDrawPosition += ExtendedHatDrawer.ExtensionSpriteOffset(drawInfo); + + Texture2D extraPieceTexture = ModContent.GetTexture(ExtendedHatDrawer.ExtensionTexture()); + Rectangle frame = extraPieceTexture.Frame(1, 20, 0, drawPlayer.bodyFrame.Y / drawPlayer.bodyFrame.Height); + DrawData pieceDrawData = new DrawData(extraPieceTexture, headDrawPosition, frame, drawInfo.upperArmorColor, drawPlayer.fullRotation, origin, 1f, drawInfo.spriteEffects, 0); + pieceDrawData.shader = dyeShader; + Main.playerDrawData.Add(pieceDrawData); + } } }); diff --git a/Items/Armor/DemonshadeHelm.cs b/Items/Armor/DemonshadeHelm.cs index 50e02ae7da..78da93607f 100644 --- a/Items/Armor/DemonshadeHelm.cs +++ b/Items/Armor/DemonshadeHelm.cs @@ -87,25 +87,8 @@ namespace CalamityMod.Items.Armor recipe.AddRecipe(); } - public void DrawExtension(PlayerDrawInfo drawInfo) - { - Player drawPlayer = drawInfo.drawPlayer; - int dyeShader = drawPlayer.dye?[0].dye ?? 0; - - Vector2 origin = drawInfo.headOrigin; - Vector2 headDrawPosition = drawInfo.position.Floor() + origin - Main.screenPosition; - - if (drawPlayer.mount.Active) - headDrawPosition.Y += drawPlayer.mount.HeightBoost; - - headDrawPosition.X -= drawPlayer.direction == 1f ? 10f : 10f; - headDrawPosition.Y += drawPlayer.gfxOffY - 14f; - - Texture2D extraPieceTexture = ModContent.GetTexture("CalamityMod/Items/Armor/DemonshadeHelm_Extension"); - Rectangle frame = extraPieceTexture.Frame(1, 20, 0, drawPlayer.bodyFrame.Y / drawPlayer.bodyFrame.Height); - DrawData pieceDrawData = new DrawData(extraPieceTexture, headDrawPosition, frame, drawInfo.upperArmorColor, drawPlayer.fullRotation, origin, 1f, drawInfo.spriteEffects, 0); - pieceDrawData.shader = dyeShader; - Main.playerDrawData.Add(pieceDrawData); - } + public string ExtensionTexture() => "CalamityMod/Items/Armor/DemonshadeHelm_Extension"; + public Vector2 ExtensionSpriteOffset(PlayerDrawInfo drawInfo) => new Vector2(-10f, -14f); + public bool PreDrawExtension(PlayerDrawInfo drawInfo) => true; } } diff --git a/Items/Armor/Vanity/ApolloMask.cs b/Items/Armor/Vanity/ApolloMask.cs index a4a453090f..e7e988fe3e 100644 --- a/Items/Armor/Vanity/ApolloMask.cs +++ b/Items/Armor/Vanity/ApolloMask.cs @@ -26,25 +26,8 @@ namespace CalamityMod.Items.Armor.Vanity public override bool DrawHead() => false; - public void DrawExtension(PlayerDrawInfo drawInfo) - { - Player drawPlayer = drawInfo.drawPlayer; - int dyeShader = drawPlayer.dye?[0].dye ?? 0; - - Vector2 origin = drawInfo.headOrigin; - Vector2 headDrawPosition = drawInfo.position.Floor() + origin - Main.screenPosition; - - if (drawPlayer.mount.Active) - headDrawPosition.Y += drawPlayer.mount.HeightBoost; - - headDrawPosition.X -= drawPlayer.direction == 1f ? 16f : 10f; - headDrawPosition.Y += drawPlayer.gfxOffY - 10f; - - Texture2D extraPieceTexture = ModContent.GetTexture("CalamityMod/Items/Armor/Vanity/ApolloMask_Extra"); - Rectangle frame = extraPieceTexture.Frame(1, 20, 0, drawPlayer.bodyFrame.Y / drawPlayer.bodyFrame.Height); - DrawData pieceDrawData = new DrawData(extraPieceTexture, headDrawPosition, frame, drawInfo.upperArmorColor, drawPlayer.fullRotation, origin, 1f, drawInfo.spriteEffects, 0); - pieceDrawData.shader = dyeShader; - Main.playerDrawData.Add(pieceDrawData); - } + public string ExtensionTexture() => "CalamityMod/Items/Armor/Vanity/ApolloMask_Extra"; + public Vector2 ExtensionSpriteOffset(PlayerDrawInfo drawInfo) => new Vector2(drawInfo.drawPlayer.direction == 1f ? -16f : -10f, -10); + public bool PreDrawExtension(PlayerDrawInfo drawInfo) => true; } } diff --git a/Items/Armor/Vanity/ArtemisMask.cs b/Items/Armor/Vanity/ArtemisMask.cs index 63ed993cc9..0e53f824c0 100644 --- a/Items/Armor/Vanity/ArtemisMask.cs +++ b/Items/Armor/Vanity/ArtemisMask.cs @@ -26,25 +26,8 @@ namespace CalamityMod.Items.Armor.Vanity public override bool DrawHead() => false; - public void DrawExtension(PlayerDrawInfo drawInfo) - { - Player drawPlayer = drawInfo.drawPlayer; - int dyeShader = drawPlayer.dye?[0].dye ?? 0; - - Vector2 origin = drawInfo.headOrigin; - Vector2 headDrawPosition = drawInfo.position.Floor() + origin - Main.screenPosition; - - if (drawPlayer.mount.Active) - headDrawPosition.Y += drawPlayer.mount.HeightBoost; - - headDrawPosition.X -= drawPlayer.direction == 1f ? 16f : 10f; - headDrawPosition.Y += drawPlayer.gfxOffY - 10f; - - Texture2D extraPieceTexture = ModContent.GetTexture("CalamityMod/Items/Armor/Vanity/ArtemisMask_Extra"); - Rectangle frame = extraPieceTexture.Frame(1, 20, 0, drawPlayer.bodyFrame.Y / drawPlayer.bodyFrame.Height); - DrawData pieceDrawData = new DrawData(extraPieceTexture, headDrawPosition, frame, drawInfo.upperArmorColor, drawPlayer.fullRotation, origin, 1f, drawInfo.spriteEffects, 0); - pieceDrawData.shader = dyeShader; - Main.playerDrawData.Add(pieceDrawData); - } + public string ExtensionTexture() => "CalamityMod/Items/Armor/Vanity/ArtemisMask_Extra"; + public Vector2 ExtensionSpriteOffset(PlayerDrawInfo drawInfo) => new Vector2( drawInfo.drawPlayer.direction == 1f ? -16f : -10f, -10); + public bool PreDrawExtension(PlayerDrawInfo drawInfo) => true; } }