12
12
import java .util .List ;
13
13
import java .util .SequencedSet ;
14
14
import java .util .function .BiConsumer ;
15
+ import java .util .function .Consumer ;
15
16
16
17
sealed abstract class AbstractPagedGui <C >
17
18
extends AbstractGui
@@ -21,9 +22,7 @@ sealed abstract class AbstractPagedGui<C>
21
22
22
23
protected int [] contentListSlots ;
23
24
24
- private final Runnable bakeFn = this ::bake ;
25
-
26
- private MutableProperty <Integer > page ;
25
+ private final MutableProperty <Integer > page ;
27
26
private Property <? extends List <? extends C >> content ;
28
27
private final List <BiConsumer <? super Integer , ? super Integer >> pageChangeHandlers = new ArrayList <>(0 );
29
28
private final List <BiConsumer <? super Integer , ? super Integer >> pageCountChangeHandlers = new ArrayList <>(0 );
@@ -36,9 +35,9 @@ public AbstractPagedGui(
36
35
) {
37
36
super (width , height );
38
37
this .page = MutableProperty .of (0 );
39
- page .observe (this ::update );
38
+ page .observeWeak (this , AbstractPagedGui ::update );
40
39
this .content = content ;
41
- content .observe ( bakeFn );
40
+ content .observeWeak ( this , AbstractPagedGui :: bake );
42
41
this .contentListSlots = SlotUtils .toSlotIndices (contentListSlots , getWidth ());
43
42
}
44
43
@@ -49,9 +48,9 @@ public AbstractPagedGui(
49
48
) {
50
49
super (structure .getWidth (), structure .getHeight ());
51
50
this .page = page ;
52
- page .observe (this ::update );
51
+ page .observeWeak (this , AbstractPagedGui ::update );
53
52
this .content = content ;
54
- content .observe ( bakeFn );
53
+ content .observeWeak ( this , AbstractPagedGui :: bake );
55
54
this .contentListSlots = structure .getIngredientMatrix ().findContentListSlots ();
56
55
super .applyStructure (structure ); // super call to avoid bake() through applyStructure override
57
56
}
@@ -116,7 +115,7 @@ private void updatePageContent() {
116
115
117
116
@ Override
118
117
public void setContent (List <? extends C > content ) {
119
- this .content .unobserve ( bakeFn );
118
+ this .content .unobserveWeak ( this );
120
119
this .content = Property .of (content );
121
120
bake ();
122
121
}
0 commit comments