forked from Cyrillya/EnchantedGlint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnchantedGlint.cs
86 lines (71 loc) · 3.52 KB
/
EnchantedGlint.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ReLogic.Content;
using System.Collections.Generic;
using Terraria;
using Terraria.ID;
using Terraria.ModLoader;
namespace EnchantedGlint;
public class EffectGlobalItem : GlobalItem
{
public class EnchantedGlint : Mod
{
}
internal static readonly HashSet<int> Prefixes = new() {
PrefixID.Legendary, PrefixID.Legendary2, PrefixID.Godly, PrefixID.Light,
PrefixID.Demonic, PrefixID.Unreal, PrefixID.Mythical, PrefixID.Ruthless,
PrefixID.Warding, PrefixID.Arcane, PrefixID.Lucky, PrefixID.Menacing,
PrefixID.Quick, PrefixID.Violent
};
public override bool PreDrawInInventory(Item item, SpriteBatch sb, Vector2 position, Rectangle frame,
Color drawColor, Color itemColor, Vector2 origin, float scale) {
if (!Prefixes.Contains(item.prefix)) {
return true;
}
var texture = ModContent.Request<Texture2D>("EnchantedGlint/Enchanted");
var shader = ModContent.Request<Effect>("EnchantedGlint/Transform", AssetRequestMode.ImmediateLoad).Value;
shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly * 0.2f);
shader.CurrentTechnique.Passes["EnchantedPass"].Apply();
Main.instance.GraphicsDevice.Textures[1] = texture.Value; // 传入调色板
sb.End();
sb.Begin(SpriteSortMode.Deferred, sb.GraphicsDevice.BlendState, sb.GraphicsDevice.SamplerStates[0],
sb.GraphicsDevice.DepthStencilState, sb.GraphicsDevice.RasterizerState, shader, Main.UIScaleMatrix);
return true;
}
public override void PostDrawInInventory(Item item, SpriteBatch sb, Vector2 position, Rectangle frame,
Color drawColor, Color itemColor, Vector2 origin, float scale) {
if (!Prefixes.Contains(item.prefix)) {
return;
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, sb.GraphicsDevice.BlendState, sb.GraphicsDevice.SamplerStates[0],
sb.GraphicsDevice.DepthStencilState, sb.GraphicsDevice.RasterizerState, null, Main.UIScaleMatrix);
}
public override bool PreDrawInWorld(Item item, SpriteBatch sb, Color lightColor, Color alphaColor,
ref float rotation, ref float scale, int whoAmI) {
if (!Prefixes.Contains(item.prefix)) {
return true;
}
var texture = ModContent.Request<Texture2D>("EnchantedGlint/Enchanted");
var shader = ModContent.Request<Effect>("EnchantedGlint/Transform", AssetRequestMode.ImmediateLoad).Value;
shader.Parameters["uTime"].SetValue(Main.GlobalTimeWrappedHourly * 0.2f);
shader.CurrentTechnique.Passes["EnchantedPass"].Apply();
Main.instance.GraphicsDevice.Textures[1] = texture.Value;
sb.End();
sb.Begin(SpriteSortMode.Deferred, sb.GraphicsDevice.BlendState,
sb.GraphicsDevice.SamplerStates[0],
sb.GraphicsDevice.DepthStencilState, sb.GraphicsDevice.RasterizerState, shader,
Main.GameViewMatrix.TransformationMatrix);
return true;
}
public override void PostDrawInWorld(Item item, SpriteBatch sb, Color lightColor, Color alphaColor, float rotation,
float scale, int whoAmI) {
if (!Prefixes.Contains(item.prefix)) {
return;
}
sb.End();
sb.Begin(SpriteSortMode.Deferred, sb.GraphicsDevice.BlendState, sb.GraphicsDevice.SamplerStates[0],
sb.GraphicsDevice.DepthStencilState, sb.GraphicsDevice.RasterizerState, null,
Main.GameViewMatrix.TransformationMatrix);
}
}