2626import com .cleanroommc .modularui .drawable .text .RichText ;
2727import com .cleanroommc .modularui .factory .PosGuiData ;
2828import com .cleanroommc .modularui .screen .ModularPanel ;
29+ import com .cleanroommc .modularui .utils .Alignment ;
2930import com .cleanroommc .modularui .utils .serialization .IByteBufDeserializer ;
3031import com .cleanroommc .modularui .value .sync .BooleanSyncValue ;
3132import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
4243import java .util .ArrayList ;
4344import java .util .Iterator ;
4445import java .util .List ;
46+ import java .util .function .Consumer ;
4547
4648public abstract class MetaTileEntityMEOutputBase <AEStackType extends IAEStack <AEStackType >, RealStackType >
4749 extends MetaTileEntityAEHostableChannelPart <AEStackType > {
@@ -106,13 +108,7 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManage
106108 getDeserializer ());
107109 panelSyncManager .syncValue ("buffer" , 0 , bufferSync );
108110
109- ScrollableTextWidget textList = new ScrollableTextWidget ()
110- .textBuilder (text -> {
111- for (IWrappedStack <AEStackType , RealStackType > wrappedStack : bufferSync ) {
112- addStackLine (text , wrappedStack );
113- }
114- });
115-
111+ ScrollableTextWidget textList = new ScrollableTextWidget ();
116112 bufferSync .setChangeListener (textList ::markDirty );
117113
118114 return GTGuis .createPanel (this , 176 , 18 + 18 * 4 + 94 )
@@ -124,9 +120,11 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManage
124120 .asWidget ()
125121 .pos (5 , 15 ))
126122 .child (textList .pos (9 , 25 + 4 )
127- .size (158 , 18 * 4 - 8 )
123+ .size (158 , 18 * 4 - 6 )
124+ .textBuilder (text -> bufferSync .cacheForEach (stack -> addStackLine (text , stack )))
125+ .alignment (Alignment .TopLeft )
128126 .background (GTGuiTextures .DISPLAY .asIcon ()
129- .margin (-4 )))
127+ .margin (-2 , - 2 )))
130128 .child (SlotGroupWidget .playerInventory ());
131129 }
132130
@@ -211,7 +209,7 @@ public InaccessibleInfiniteHandler(@NotNull MetaTileEntity holder,
211209 this .strategy = strategy ;
212210 }
213211
214- protected void add (@ NotNull RealStackType stackToAdd , int amount ) {
212+ protected void add (@ NotNull RealStackType stackToAdd , long amount ) {
215213 for (IWrappedStack <AEStackType , RealStackType > bufferedAEStack : internalBuffer ) {
216214 long bufferedAEStackSize = bufferedAEStack .getStackSize ();
217215 RealStackType bufferStack = bufferedAEStack .getDefinition ();
@@ -253,7 +251,7 @@ protected void trigger() {
253251 }
254252
255253 private static class WrappedStackSyncHandler <AEStackType extends IAEStack <AEStackType >,
256- RealStackType > extends SyncHandler implements Iterable < IWrappedStack < AEStackType , RealStackType >> {
254+ RealStackType > extends SyncHandler {
257255
258256 private final List <@ NotNull IWrappedStack <AEStackType , RealStackType >> source ;
259257 private final ObjectArrayList <@ NotNull IWrappedStack <AEStackType , RealStackType >> cache = new ObjectArrayList <>();
@@ -323,11 +321,6 @@ public void readOnServer(int id, PacketBuffer buf) {
323321 // This sync handler is Server -> Client only.
324322 }
325323
326- @ Override
327- public @ NotNull Iterator <IWrappedStack <AEStackType , RealStackType >> iterator () {
328- return cache .iterator ();
329- }
330-
331324 public void setChangeListener (@ NotNull Runnable listener ) {
332325 this .changeListener = listener ;
333326 }
@@ -337,5 +330,11 @@ private void onChange() {
337330 changeListener .run ();
338331 }
339332 }
333+
334+ public void cacheForEach (@ NotNull Consumer <@ NotNull IWrappedStack <AEStackType , RealStackType >> consumer ) {
335+ for (IWrappedStack <AEStackType , RealStackType > stack : cache ) {
336+ consumer .accept (stack );
337+ }
338+ }
340339 }
341340}
0 commit comments