2 using System.Collections.Generic;
7 using Microsoft.Xna.Framework;
8 using Microsoft.Xna.Framework.Graphics;
13 namespace Loot.ModSupport
15 internal class WeaponOutSupport : ModSupport
17 public override string ModName =>
"WeaponOut";
19 public override bool CheckValidity(
Mod mod) => mod.Version >=
new Version(1, 6, 4);
21 public override void AddClientSupport(
Mod mod)
23 On.Terraria.Main.DrawPlayer += MainOnDrawPlayer;
24 On.Terraria.DataStructures.DrawData.Draw += DrawDataOnDraw;
25 mod.Call(
"AddCustomPreDrawMethod", (Func<Player, Item, DrawData, bool>)CustomPreDraw);
33 private void MainOnDrawPlayer(On.Terraria.Main.orig_DrawPlayer orig, Main
self, Player drawplayer, Vector2 position,
float rotation, Vector2 rotationorigin,
float shadow)
37 orig(
self, drawplayer, position, rotation, rotationorigin, shadow);
45 private void DrawDataOnDraw(On.Terraria.DataStructures.DrawData.orig_Draw orig, ref DrawData
self, SpriteBatch sb)
47 _lightColor = _lightColor ?? Lighting.GetColor((
int)(Main.LocalPlayer.MountedCenter.X / 16), (
int)(Main.LocalPlayer.MountedCenter.Y / 16));
48 if (!DrawWeaponOutFists(
self, sb) && !DrawWeaponOutFromCache(
self, sb))
53 private const int WEAPONOUT_FISTS_USESTYLE = 102115116;
55 private bool DrawWeaponOutFists(DrawData
self, SpriteBatch sb)
57 if (Main.LocalPlayer.HeldItem.useStyle != WEAPONOUT_FISTS_USESTYLE)
return false;
58 bool isHandOn = Main.LocalPlayer.handon > 0 &&
self.texture == Main.accHandsOnTexture[Main.LocalPlayer.handon];
59 bool isHandOff = Main.LocalPlayer.handoff > 0 &&
self.texture == Main.accHandsOffTexture[Main.LocalPlayer.handoff];
60 if (!isHandOn && !isHandOff)
return false;
65 for (
int i = 0; i < info.ShaderEntities.Count; i++)
68 if (entity == null)
continue;
69 entity.Properties.SkipUpdatingDrawData =
true;
70 entity.DrawData =
self;
71 entity.DoDrawLayeredEntity(sb, _lightColor.Value,
self.color,
self.scale.LengthSquared(),
self.rotation,
72 info.GlowmaskEntities[i],
self.texture,
self.texture,
self.texture);
78 foreach (var entity
in info.GlowmaskEntities.Where(x => x != null))
80 entity.Properties.SkipUpdatingDrawData =
true;
81 entity.DrawData =
self;
82 entity.DoDrawGlowmask(sb, _lightColor.Value,
self.color,
self.rotation,
self.scale.LengthSquared(), entity.Entity.whoAmI,
self.texture);
85 return info.HasGlowmasks;
88 private bool DrawWeaponOutFromCache(DrawData
self, SpriteBatch sb)
91 var cachedDatas = _cache.Where(x => x.drawData.texture == data.texture).ToList();
92 if (cachedDatas.Any())
94 foreach (var cachedData
in cachedDatas)
96 var shaderEntity = cachedData.shaderEntity;
97 var glowmaskEntity = cachedData.glowmaskEntity;
98 var plr = cachedData.player;
99 _lightColor = _lightColor ?? Lighting.GetColor((
int)(plr.MountedCenter.X / 16), (
int)(plr.MountedCenter.Y / 16));
101 if (shaderEntity != null)
103 shaderEntity.Properties.SkipUpdatingDrawData =
true;
104 shaderEntity.DrawData =
self;
105 shaderEntity.DoDrawLayeredEntity(sb, _lightColor.Value,
self.color,
self.scale.LengthSquared(),
self.rotation, glowmaskEntity);
107 else if (glowmaskEntity != null)
109 glowmaskEntity.Properties.SkipUpdatingDrawData =
true;
110 glowmaskEntity.DrawData =
self;
111 glowmaskEntity.DoDrawGlowmask(sb, _lightColor.Value,
self.color,
self.rotation,
self.scale.LengthSquared(), glowmaskEntity.Entity.whoAmI);
121 private Color? _lightColor;
122 private readonly List<(DrawData drawData, Player player, ShaderEntity shaderEntity, GlowmaskEntity glowmaskEntity)> _cache
123 =
new List<(DrawData, Player, ShaderEntity, GlowmaskEntity)>();
131 private bool CustomPreDraw(Player player, Item item, DrawData drawDrata)
136 for (
int i = 0; i < info.ShaderEntities.Count; i++)
141 _cache.Add((drawDrata, player, entity, info.GlowmaskEntities[i]));
145 else if (info.HasGlowmasks)
147 foreach (var entity
in info.GlowmaskEntities.Where(x => x != null))
149 _cache.Add((drawDrata, player, null, entity));
This class is responsible for handling ShaderEntity and GlowmaskEntity that come from the Modifiers o...
Defines a Shader entity, part of GraphicsEntity<T> The entity defines a particular 'shader' "of" the ...
List< ShaderEntity > ShaderEntities
static GraphicsGlobalItem GetInfo(Item item)