Even More Modifiers  1.0.0.0
A mod for rolling various bonus stats on items
WeaponDrawEffectsPatch.cs
Go to the documentation of this file.
1 using System.Linq;
2 using Loot.Api.Graphics;
3 using Microsoft.Xna.Framework.Graphics;
4 using Terraria;
5 using Terraria.DataStructures;
6 
7 namespace Loot.ILEditing
8 {
12  internal class WeaponDrawEffectsPatch : ILEdit
13  {
14  public override void Apply(bool dedServ)
15  {
16  if (!dedServ)
17  On.Terraria.DataStructures.DrawData.Draw += DrawDataOnDraw;
18  }
19 
20  private void DrawDataOnDraw(On.Terraria.DataStructures.DrawData.orig_Draw orig, ref DrawData self, SpriteBatch sb)
21  {
22  //bool weaponOutCheck = Main.LocalPlayer.HeldItem.modItem?.mod is Mod mod && mod.Name.Equals("WeaponOut") && Main.LocalPlayer.controlUseItem || (Main.mouseLeft || Main.mouseRight);
23  if (!Main.LocalPlayer.frozen
24  && (Main.LocalPlayer.itemAnimation > 0 && Main.LocalPlayer.HeldItem.useStyle != 0 || Main.LocalPlayer.HeldItem.holdStyle > 0 && !Main.LocalPlayer.pulley) // || weaponOutCheck
25  && Main.LocalPlayer.HeldItem.type > 0 && !Main.LocalPlayer.dead && !Main.LocalPlayer.HeldItem.noUseGraphic && (!Main.LocalPlayer.wet || !Main.LocalPlayer.HeldItem.noWet)
26  && Main.itemTexture[Main.LocalPlayer.HeldItem.type] == self.texture)
27  {
28  var info = GraphicsGlobalItem.GetInfo(Main.LocalPlayer.HeldItem);
29  if (!DrawShaderEntities(info, self, sb) && !DrawGlowmaskEntities(info, self, sb))
30  orig(ref self, sb);
31  }
32  else
33  {
34  orig(ref self, sb);
35  }
36  }
37 
38  private bool DrawShaderEntities(GraphicsGlobalItem info, DrawData self, SpriteBatch sb)
39  {
40  var lightColor = Lighting.GetColor((int)(Main.LocalPlayer.MountedCenter.X / 16), (int)(Main.LocalPlayer.MountedCenter.Y / 16));
41  for (int i = 0; i < info.ShaderEntities.Count; i++)
42  {
43  var entity = info.ShaderEntities[i];
44  if (entity == null) continue;
45  entity.Properties.SkipUpdatingDrawData = true;
46  entity.DrawData = self;
47  entity.DoDrawLayeredEntity(sb, lightColor, self.color, self.scale.LengthSquared(), self.rotation, info.GlowmaskEntities[i]);
48  }
49  return info.HasShaders;
50  }
51 
52  private bool DrawGlowmaskEntities(GraphicsGlobalItem info, DrawData self, SpriteBatch sb)
53  {
54  var lightColor = Lighting.GetColor((int)(Main.LocalPlayer.MountedCenter.X / 16), (int)(Main.LocalPlayer.MountedCenter.Y / 16));
55  foreach (var entity in info.GlowmaskEntities.Where(x => x != null))
56  {
57  entity.Properties.SkipUpdatingDrawData = true;
58  entity.DrawData = self;
59  entity.DoDrawGlowmask(sb, lightColor, self.color, self.rotation, self.scale.LengthSquared(), entity.Entity.whoAmI);
60  }
61 
62  return info.HasGlowmasks;
63  }
64  }
65 }
This class is responsible for handling ShaderEntity and GlowmaskEntity that come from the Modifiers o...
static GraphicsGlobalItem GetInfo(Item item)