22
22
import org .lwjgl .glfw .GLFW ;
23
23
24
24
import java .util .ArrayList ;
25
+ import java .util .HashMap ;
25
26
import java .util .List ;
26
27
27
28
public class CustomChestMenu extends HandledScreen <CustomChestHandler > implements ScreenHandlerProvider <CustomChestHandler > {
28
29
29
30
private final CustomChestNumbers Size ;
30
31
private double scroll = 0 ;
31
- private final ArrayList < Widget > widgets = new ArrayList <>();
32
+ private final HashMap < Integer , Widget > widgets = new HashMap <>();
32
33
private final ArrayList <VarItem > varItems = new ArrayList <>();
33
34
private boolean update = true ;
34
35
@@ -70,7 +71,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
70
71
super .render (context , mouseX , mouseY , delta );
71
72
context .getMatrices ().push ();
72
73
context .getMatrices ().translate (this .x , this .y , 0 );
73
- for (Widget widget : widgets ) {
74
+ for (Widget widget : widgets . values () ) {
74
75
if (widget instanceof Drawable drawable ) {
75
76
drawable .render (context , mouseX , mouseY , delta );
76
77
}
@@ -132,12 +133,12 @@ private void update(int previousScroll) {
132
133
// widget.setText(named.getName());
133
134
// widget.setFocused(Objects.equals(i,focused));
134
135
var widget = new CustomChestField <>(textRenderer , x , y , Size .WIDGET_WIDTH , 18 , Text .of (varItem .id ), varItem );
135
- widgets .add ( widget );
136
+ widgets .put ( i , widget );
136
137
varItems .add (varItem );
137
138
continue ;
138
139
}
139
140
140
- widgets .add ( new TextWidget (x + 3 ,y ,Size .WIDGET_WIDTH ,16 ,stack .getName (),textRenderer ).alignLeft ());
141
+ widgets .put ( i , new TextWidget (x + 3 ,y ,Size .WIDGET_WIDTH ,16 ,stack .getName (),textRenderer ).alignLeft ());
141
142
}
142
143
}
143
144
@@ -161,7 +162,7 @@ public boolean mouseScrolled(double mouseX, double mouseY, double horizontalAmou
161
162
@ Override
162
163
public boolean mouseClicked (double mouseX , double mouseY , int button ) {
163
164
List <Slot > subList = this .getScreenHandler ().slots .subList ((int ) scroll , Math .min ((int ) scroll + Size .SLOTS ,27 ));
164
- for (Widget widget : widgets ) {
165
+ for (Widget widget : widgets . values () ) {
165
166
if (widget instanceof ClickableWidget clickable ) {
166
167
clickable .setFocused (clickable .isMouseOver (mouseX - this .x , mouseY - this .y ));
167
168
clickable .mouseClicked (mouseX - this .x ,mouseY - this .y ,button );
0 commit comments