11package gdavid .psionicutilities .mixin ;
22
3- import com .mojang .blaze3d .vertex .PoseStack ;
4- import com .mojang .blaze3d .vertex .VertexConsumer ;
3+ import com .mojang .blaze3d .vertex .*;
4+ import com .mojang .math .Matrix4f ;
5+ import gdavid .psionicutilities .PsionicUtilities ;
6+ import net .minecraft .client .renderer .MultiBufferSource ;
7+ import net .minecraft .client .resources .model .Material ;
8+ import net .minecraft .network .chat .TextColor ;
9+ import net .minecraft .resources .ResourceLocation ;
510import org .spongepowered .asm .mixin .Mixin ;
611import org .spongepowered .asm .mixin .injection .At ;
12+ import org .spongepowered .asm .mixin .injection .Inject ;
713import org .spongepowered .asm .mixin .injection .Redirect ;
814
915import gdavid .psionicutilities .Util ;
1016import net .minecraftforge .api .distmarker .Dist ;
1117import net .minecraftforge .api .distmarker .OnlyIn ;
18+ import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
19+ import vazkii .psi .api .ClientPsiAPI ;
1220import vazkii .psi .api .spell .IGenericRedirector ;
1321import vazkii .psi .api .spell .SpellParam ;
1422import vazkii .psi .api .spell .SpellPiece ;
1523
24+ import java .util .Arrays ;
25+ import java .util .Optional ;
26+
1627@ Mixin (value = SpellPiece .class , remap = false )
17- public class SpellPieceMixin {
28+ public abstract class SpellPieceMixin {
1829
1930 @ OnlyIn (Dist .CLIENT )
2031 @ Redirect (method = "drawParam(Lcom/mojang/blaze3d/vertex/PoseStack;Lcom/mojang/blaze3d/vertex/VertexConsumer;ILvazkii/psi/api/spell/SpellParam$Side;ILvazkii/psi/api/spell/SpellParam$ArrowType;F)V" , at = @ At (value = "INVOKE" , target = "Lcom/mojang/blaze3d/vertex/VertexConsumer;color(IIII)Lcom/mojang/blaze3d/vertex/VertexConsumer;" , remap = true ))
@@ -29,4 +40,38 @@ private VertexConsumer paramColor(VertexConsumer builder, int r, int g, int b, i
2940 return builder .color (r , g , b , a );
3041 }
3142
43+ @ OnlyIn (Dist .CLIENT )
44+ @ Inject (method = "drawBackground" , at = @ At ("HEAD" ))
45+ private void drawBackground (PoseStack ms , MultiBufferSource buffers , int light , CallbackInfo callback ) {
46+ SpellPiece self = (SpellPiece ) (Object ) this ;
47+ if (self .comment != null ) {
48+ String prefix = "@color=" ;
49+ Optional <String > str = Arrays .stream (self .comment .split (";" )).filter (ln -> ln .startsWith (prefix )).findFirst ().map (ln -> ln .substring (prefix .length ()));
50+ str .ifPresent (color -> {
51+ TextColor value = TextColor .parseColor (color );
52+ if (value != null ) {
53+ drawHighlight (ms , buffers , light , value .getValue ());
54+ }
55+ });
56+ }
57+ }
58+
59+ private void drawHighlight (PoseStack ms , MultiBufferSource buffers , int light , int value ) {
60+ int r = (value >> 16 ) & 0xFF ;
61+ int g = (value >> 8 ) & 0xFF ;
62+ int b = value & 0xFF ;
63+ Material material = new Material (ClientPsiAPI .PSI_PIECE_TEXTURE_ATLAS , new ResourceLocation (PsionicUtilities .modId , "spell/highlight" ));
64+ VertexConsumer buf = material .buffer (buffers , ignore -> SpellPiece .getLayer ());
65+ Matrix4f mat = ms .last ().pose ();
66+ buf .vertex (mat , -1 , 17 , 0 ).color (r , g , b , 128 );
67+ buf .uv (0 , 1 ).uv2 (light ).endVertex ();
68+ buf .vertex (mat , 17 , 17 , 0 ).color (r , g , b , 128 );
69+ buf .uv (1 , 1 ).uv2 (light ).endVertex ();
70+ buf .vertex (mat , 17 , -1 , 0 ).color (r , g , b , 128 );
71+ buf .uv (1 , 0 ).uv2 (light ).endVertex ();
72+ buf .vertex (mat , -1 , -1 , 0 ).color (r , g , b , 128 );
73+ buf .uv (0 , 0 ).uv2 (light ).endVertex ();
74+ ms .translate (0 , 0 , 0.1f );
75+ }
76+
3277}
0 commit comments