22
33import dev .isxander .yacl3 .api .utils .Dimension ;
44import dev .isxander .yacl3 .gui .render .ColorGradientRenderState ;
5- import dev .isxander .yacl3 .gui .utils .YACLRenderHelper ;
5+ import dev .isxander .yacl3 .gui .utils .GuiUtils ;
66import net .minecraft .client .Minecraft ;
77import net .minecraft .client .gui .Font ;
8- import net .minecraft .client .gui .GuiGraphics ;
8+ import net .minecraft .client .gui .GuiGraphicsExtractor ;
99import net .minecraft .client .gui .components .Renderable ;
1010import net .minecraft .client .gui .components .events .GuiEventListener ;
1111import net .minecraft .client .gui .narration .NarratableEntry ;
1212import net .minecraft .client .gui .narration .NarrationElementOutput ;
13+ import net .minecraft .client .input .CharacterEvent ;
14+ import net .minecraft .client .input .KeyEvent ;
15+ import net .minecraft .client .input .MouseButtonEvent ;
16+ import net .minecraft .client .renderer .RenderPipelines ;
1317import net .minecraft .client .resources .sounds .SimpleSoundInstance ;
1418import net .minecraft .sounds .SoundEvents ;
1519
1620import java .awt .Color ;
1721
18- //? if >=1.21.9 {
19- import net .minecraft .client .input .CharacterEvent ;
20- import net .minecraft .client .input .KeyEvent ;
21- import net .minecraft .client .input .MouseButtonEvent ;
22- //?}
23-
2422public abstract class AbstractWidget implements GuiEventListener , Renderable , NarratableEntry {
2523 protected final Minecraft client = Minecraft .getInstance ();
2624 protected final Font textRenderer = client .font ;
@@ -68,7 +66,7 @@ public void updateNarration(NarrationElementOutput builder) {
6866
6967 }
7068
71- protected void drawButtonRect (GuiGraphics graphics , int x1 , int y1 , int x2 , int y2 , boolean hovered , boolean enabled ) {
69+ protected void drawButtonRect (GuiGraphicsExtractor graphics , int x1 , int y1 , int x2 , int y2 , boolean hovered , boolean enabled ) {
7270 if (x1 > x2 ) {
7371 int xx1 = x1 ;
7472 x1 = x2 ;
@@ -82,17 +80,22 @@ protected void drawButtonRect(GuiGraphics graphics, int x1, int y1, int x2, int
8280 int width = x2 - x1 ;
8381 int height = y2 - y1 ;
8482
85- YACLRenderHelper .renderButtonTexture (graphics , x1 , y1 , width , height , enabled , hovered );
83+ graphics .blitSprite (
84+ RenderPipelines .GUI_TEXTURED ,
85+ GuiUtils .BUTTON_SPRITES .get (enabled , hovered ),
86+ x1 , y1 ,
87+ width , height
88+ );
8689 }
8790
88- protected void drawOutline (GuiGraphics graphics , int x1 , int y1 , int x2 , int y2 , int width , int color ) {
91+ protected void drawOutline (GuiGraphicsExtractor graphics , int x1 , int y1 , int x2 , int y2 , int width , int color ) {
8992 graphics .fill (x1 , y1 , x2 , y1 + width , color );
9093 graphics .fill (x2 , y1 , x2 - width , y2 , color );
9194 graphics .fill (x1 , y2 , x2 , y2 - width , color );
9295 graphics .fill (x1 , y1 , x1 + width , y2 , color );
9396 }
9497
95- protected void drawRainbowGradient (GuiGraphics graphics , int x1 , int y1 , int x2 , int y2 ) {
98+ protected void drawRainbowGradient (GuiGraphicsExtractor graphics , int x1 , int y1 , int x2 , int y2 ) {
9699 //Draws a rainbow gradient, left to right
97100 int [] colors = new int [] {0xFFFF0000 , 0xFFFFFF00 , 0xFF00FF00 , 0xFF00FFFF , 0xFF0000FF , 0xFFFF00FF , 0xFFFF0000 }; //all the colors in the gradient
98101 int width = x2 - x1 ;
@@ -125,95 +128,4 @@ protected int multiplyColor(int hex, float amount) {
125128 public void playDownSound () {
126129 Minecraft .getInstance ().getSoundManager ().play (SimpleSoundInstance .forUI (SoundEvents .UI_BUTTON_CLICK , 1.0F ));
127130 }
128-
129- //? if >=1.21.9 {
130- @ Override
131- public boolean mouseClicked (MouseButtonEvent mouseButtonEvent , boolean doubleClick ) {
132- return this .onMouseClicked (mouseButtonEvent .x (), mouseButtonEvent .y (), mouseButtonEvent .button ());
133- }
134- //?} else {
135- /*@Override
136- public boolean mouseClicked(double mouseX, double mouseY, int button) {
137- return this.onMouseClicked(mouseX, mouseY, button);
138- }
139- */ //?}
140- public boolean onMouseClicked (double mouseX , double mouseY , int button ) {
141- return false ;
142- }
143-
144- //? if >=1.21.9 {
145- @ Override
146- public boolean mouseReleased (MouseButtonEvent mouseButtonEvent ) {
147- return this .onMouseReleased (mouseButtonEvent .x (), mouseButtonEvent .y (), mouseButtonEvent .button ());
148- }
149- //?} else {
150- /*@Override
151- public boolean mouseReleased(double mouseX, double mouseY, int button) {
152- return this.onMouseReleased(mouseX, mouseY, button);
153- }
154- */ //?}
155- public boolean onMouseReleased (double mouseX , double mouseY , int button ) {
156- return false ;
157- }
158-
159- //? if >=1.21.9 {
160- @ Override
161- public boolean mouseDragged (MouseButtonEvent mouseButtonEvent , double dx , double dy ) {
162- return this .onMouseDragged (mouseButtonEvent .x (), mouseButtonEvent .y (), mouseButtonEvent .button (), dx , dy );
163- }
164- //?} else {
165- /*@Override
166- public boolean mouseDragged(double mouseX, double mouseY, int button, double dx, double dy) {
167- return this.onMouseDragged(mouseX, mouseY, button, dx, dy);
168- }
169- */ //?}
170- public boolean onMouseDragged (double mouseX , double mouseY , int button , double dx , double dy ) {
171- return false ;
172- }
173-
174- //? if >=1.21.9 {
175- @ Override
176- public boolean keyPressed (KeyEvent keyEvent ) {
177- return this .onKeyPressed (keyEvent .key (), keyEvent .scancode (), keyEvent .modifiers ());
178- }
179- //?} else {
180- /*@Override
181- public boolean keyPressed(int keycode, int scancode, int modifiers) {
182- return this.onKeyPressed(keycode, scancode, modifiers);
183- }
184- */ //?}
185- public boolean onKeyPressed (int key , int scancode , int modifiers ) {
186- return false ;
187- }
188-
189- //? if >=1.21.9 {
190- @ Override
191- public boolean keyReleased (KeyEvent keyEvent ) {
192- return this .onKeyReleased (keyEvent .key (), keyEvent .scancode (), keyEvent .modifiers ());
193- }
194- //?} else {
195- /*@Override
196- public boolean keyReleased(int keycode, int scancode, int modifiers) {
197- return this.onKeyReleased(keycode, scancode, modifiers);
198- }
199- */ //?}
200- public boolean onKeyReleased (int key , int scancode , int modifiers ) {
201- return false ;
202- }
203-
204- //? if >=1.21.9 {
205- @ Override
206- public boolean charTyped (CharacterEvent characterEvent ) {
207- return this .onCharTyped ((char ) characterEvent .codepoint (), characterEvent .codepointAsString (), characterEvent .modifiers ());
208- }
209- //?} else {
210- /*@Override
211- public boolean charTyped(char codePoint, int modifiers) {
212- return this.onCharTyped(codePoint, Character.toString(codePoint), modifiers);
213- }
214- */ //?}
215- public boolean onCharTyped (char ch , String cpStr , int modifiers ) {
216- return false ;
217- }
218-
219131}
0 commit comments