1
1
package dev .isxander .yacl3 .gui ;
2
2
3
3
import com .mojang .blaze3d .platform .InputConstants ;
4
+ import dev .isxander .yacl3 .mixin .AbstractSelectionListAccessor ;
4
5
import net .minecraft .client .Minecraft ;
5
6
import net .minecraft .client .gui .GuiGraphics ;
6
7
import net .minecraft .client .gui .components .AbstractWidget ;
17
18
public class ElementListWidgetExt <E extends ElementListWidgetExt .Entry <E >> extends ContainerObjectSelectionList <E > implements LayoutElement {
18
19
protected static final int SCROLLBAR_WIDTH = 6 ;
19
20
20
- private double smoothScrollAmount = getScrollAmount ();
21
+ private double smoothScrollAmount = scrollAmount ();
21
22
private boolean returnSmoothAmount = false ;
22
23
private final boolean doSmoothScrolling ;
23
24
private boolean usingScrollbar ;
24
25
25
26
public ElementListWidgetExt (Minecraft client , int x , int y , int width , int height , boolean smoothScrolling ) {
26
- /*? if >1.20.2 {*/
27
- super (client , width , x , y , height );
28
- /*?} else {*/
27
+ //? if >=1.21.4 {
28
+ super (client , width , x , y , height , 0 );
29
+ ((AbstractSelectionListAccessor ) this ).setRenderHeader (false );
30
+ //?} elif >=1.20.3 {
31
+ /*super(client, width, x, y, height);
32
+ */ //?} else {
29
33
/*super(client, width, height, y, y + height, 22);
30
34
this.x0 = x;
31
35
this.x1 = x + width;
32
- */ /*?}*/
36
+ */ //?}
33
37
this .doSmoothScrolling = smoothScrolling ;
34
- setRenderHeader (false , 0 );
38
+
39
+ //? if <1.21.4
40
+ /*setRenderHeader(false, 0);*/
35
41
}
36
42
37
43
@ Override
@@ -42,16 +48,35 @@ public boolean mouseScrolled(double mouseX, double mouseY, /*? if >1.20.2 {*/ do
42
48
/*?}*/
43
49
44
50
// default implementation bases scroll step from total height of entries, this is constant
45
- this .setScrollAmount (this .getScrollAmount () - scroll * 20 );
51
+ this .setScrollAmount (this .scrollAmount () - scroll * 20 );
46
52
return true ;
47
53
}
48
54
55
+ //? if <1.21.4 {
56
+ /*protected int scrollBarX() {
57
+ return this.getScrollbarPosition();
58
+ }
49
59
@Override
50
60
protected int getScrollbarPosition() {
61
+ */ //?} else {
62
+ @ Override
63
+ protected int scrollBarX () {
64
+ //?}
51
65
// default implementation does not respect left/right
52
66
return this .getX () + this .getWidth () - SCROLLBAR_WIDTH ;
53
67
}
54
68
69
+ //? if >=1.21.4 {
70
+ @ Override
71
+ protected int scrollBarY () {
72
+ return Math .max (this .getY (), (int )scrollAmount () * (this .height - this .scrollerHeight ()) / this .maxScrollAmount () + this .getY ());
73
+ }
74
+ //?} else {
75
+ /*protected int maxScrollAmount() {
76
+ return this.getMaxPosition();
77
+ }
78
+ */ //?}
79
+
55
80
@ Override
56
81
/*? if >1.20.2 {*/
57
82
public void renderWidget (GuiGraphics graphics , int mouseX , int mouseY , float delta )
@@ -66,7 +91,7 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del
66
91
smoothScrollAmount = Mth .lerp (
67
92
delta * 0.5 ,
68
93
smoothScrollAmount ,
69
- getScrollAmount ()
94
+ scrollAmount ()
70
95
);
71
96
returnSmoothAmount = true ;
72
97
@@ -84,16 +109,16 @@ public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float del
84
109
returnSmoothAmount = false ;
85
110
}
86
111
87
- /*? if >1.20.1 {*/
88
- @ Override
89
- /*?}*/
112
+ /*? if >1.20.1 && <1.21.4 {*/
113
+ /* @Override
114
+ */ /*?}*/
90
115
protected boolean isValidMouseClick (int button ) {
91
116
return button == InputConstants .MOUSE_BUTTON_LEFT || button == InputConstants .MOUSE_BUTTON_RIGHT || button == InputConstants .MOUSE_BUTTON_MIDDLE ;
92
117
}
93
118
94
119
@ Override
95
120
public boolean mouseClicked (double mouseX , double mouseY , int button ) {
96
- if (button == 0 && mouseX >= getScrollbarPosition () && mouseX < getScrollbarPosition () + SCROLLBAR_WIDTH ) {
121
+ if (button == 0 && mouseX >= scrollBarX () && mouseX < scrollBarX () + SCROLLBAR_WIDTH ) {
97
122
usingScrollbar = true ;
98
123
}
99
124
@@ -120,22 +145,36 @@ public void updateDimensions(ScreenRectangle rectangle) {
120
145
* awful code to only use smooth scroll state when rendering,
121
146
* not other code that needs target scroll amount
122
147
*/
148
+ //? if <1.21.4 {
149
+ /*// backwards compatible method to reduce stonecutter comments
150
+ protected double scrollAmount() {
151
+ return this.getScrollAmount();
152
+ }
153
+
123
154
@Override
124
155
public double getScrollAmount() {
156
+ */ //?} else {
157
+ @ Override
158
+ public double scrollAmount () {
159
+ //?}
125
160
if (returnSmoothAmount && doSmoothScrolling )
126
161
return smoothScrollAmount ;
127
162
128
- return super .getScrollAmount ();
163
+ //? if >=1.21.4 {
164
+ return super .scrollAmount ();
165
+ //?} else {
166
+ /*return super.getScrollAmount();
167
+ */ //?}
129
168
}
130
169
131
170
protected void resetSmoothScrolling () {
132
- this .smoothScrollAmount = super .getScrollAmount ();
171
+ this .smoothScrollAmount = /*? if >=1.21.4 {*/ super .scrollAmount () /*?} else {*/ /*super. getScrollAmount()*/ /*?}*/ ;
133
172
}
134
173
135
174
@ Nullable
136
175
@ Override
137
176
protected E getEntryAtPosition (double x , double y ) {
138
- y += getScrollAmount ();
177
+ y += scrollAmount ();
139
178
140
179
if (x < this .getX () || x > this .getX () + this .getWidth ())
141
180
return null ;
@@ -159,8 +198,16 @@ protected E getEntryAtPosition(double x, double y) {
159
198
code is responsible for having dynamic item heights
160
199
*/
161
200
201
+ //? if <1.21.4 {
202
+ /*protected int contentHeight() {
203
+ return this.getMaxPosition();
204
+ }
162
205
@Override
163
206
protected int getMaxPosition() {
207
+ */ //?} else {
208
+ @ Override
209
+ protected int contentHeight () {
210
+ //?}
164
211
return children ().stream ().map (E ::getItemHeight ).reduce (0 , Integer ::sum ) + headerHeight ;
165
212
}
166
213
@@ -175,7 +222,7 @@ protected void centerScrollOn(E entry) {
175
222
@ Override
176
223
/*? if >=1.21.2 {*/ public /*?} else {*/ /*protected */ /*?}*/
177
224
int getRowTop (int index ) {
178
- int integer = getY () + 4 - (int ) this .getScrollAmount () + headerHeight ;
225
+ int integer = getY () + 4 - (int ) this .scrollAmount () + headerHeight ;
179
226
for (int i = 0 ; i < children ().size () && i < index ; i ++)
180
227
integer += children ().get (i ).getItemHeight ();
181
228
return integer ;
@@ -186,12 +233,12 @@ protected void ensureVisible(E entry) {
186
233
int i = this .getRowTop (this .children ().indexOf (entry ));
187
234
int j = i - this .getY () - 4 - entry .getItemHeight ();
188
235
if (j < 0 ) {
189
- this .setScrollAmount (this .getScrollAmount () + j );
236
+ this .setScrollAmount (this .scrollAmount () + j );
190
237
}
191
238
192
239
int k = this .getY () + this .getHeight () - i - entry .getItemHeight () * 2 ;
193
240
if (k < 0 ) {
194
- this .setScrollAmount (this .getScrollAmount () - k );
241
+ this .setScrollAmount (this .scrollAmount () - k );
195
242
}
196
243
}
197
244
0 commit comments