99import com .cleanroommc .modularui .drawable .Rectangle ;
1010import com .cleanroommc .modularui .drawable .text .AnimatedText ;
1111import com .cleanroommc .modularui .factory .PosGuiData ;
12+ import com .cleanroommc .modularui .network .NetworkUtils ;
1213import com .cleanroommc .modularui .screen .ModularPanel ;
1314import com .cleanroommc .modularui .screen .RichTooltip ;
1415import com .cleanroommc .modularui .screen .UISettings ;
2021import com .cleanroommc .modularui .value .BoolValue ;
2122import com .cleanroommc .modularui .value .IntValue ;
2223import com .cleanroommc .modularui .value .StringValue ;
24+ import com .cleanroommc .modularui .value .sync .DynamicSyncHandler ;
2325import com .cleanroommc .modularui .value .sync .GenericSyncValue ;
2426import com .cleanroommc .modularui .value .sync .IntSyncValue ;
27+ import com .cleanroommc .modularui .value .sync .ItemSlotSH ;
2528import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
2629import com .cleanroommc .modularui .value .sync .SyncHandlers ;
30+ import com .cleanroommc .modularui .widget .EmptyWidget ;
2731import com .cleanroommc .modularui .widget .ParentWidget ;
2832import com .cleanroommc .modularui .widgets .*;
2933import com .cleanroommc .modularui .widgets .layout .Column ;
3236import com .cleanroommc .modularui .widgets .slot .*;
3337import com .cleanroommc .modularui .widgets .textfield .TextFieldWidget ;
3438
39+ import it .unimi .dsi .fastutil .objects .Object2IntMap ;
40+ import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
41+ import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
42+
3543import net .minecraft .init .Blocks ;
3644import net .minecraft .init .Items ;
3745import net .minecraft .item .Item ;
4856
4957import java .util .Collection ;
5058import java .util .Random ;
59+ import java .util .Map ;
5160import java .util .concurrent .atomic .AtomicInteger ;
5261import java .util .concurrent .atomic .AtomicReference ;
5362import java .util .function .Function ;
5463
5564public class TestTile extends TileEntity implements IGuiHolder <PosGuiData >, ITickable {
5665
66+ private static final Object2IntMap <Item > handlerSizeMap = new Object2IntOpenHashMap <>() {{
67+ put (Items .DIAMOND , 9 );
68+ put (Items .EMERALD , 9 );
69+ put (Items .GOLD_INGOT , 7 );
70+ put (Items .IRON_INGOT , 6 );
71+ put (Items .CLAY_BALL , 2 );
72+ defaultReturnValue (3 );
73+ }};
74+
5775 private final FluidTank fluidTank = new FluidTank (10000 );
5876 private final FluidTank fluidTankPhantom = new FluidTank (Integer .MAX_VALUE );
5977 private long time = 0 ;
@@ -78,26 +96,44 @@ public int getSlotLimit(int slot) {
7896 private final FluidTank mixerFluids1 = new FluidTank (16000 );
7997 private final FluidTank mixerFluids2 = new FluidTank (16000 );
8098 private final ItemStackHandler craftingInventory = new ItemStackHandler (10 );
99+ private final ItemStackHandler storageInventory0 = new ItemStackHandler (1 );
100+ private final Map <Item , ItemStackHandler > stackHandlerMap = new Object2ObjectOpenHashMap <>();
81101
82102 private int num = 2 ;
83103
84104 @ Override
85- public ModularPanel buildUI (PosGuiData guiData , PanelSyncManager guiSyncManager , UISettings settings ) {
105+ public ModularPanel buildUI (PosGuiData guiData , PanelSyncManager syncManager , UISettings settings ) {
86106 settings .customContainer (() -> new CraftingModularContainer (3 , 3 , this .craftingInventory ));
87107
88- guiSyncManager .registerSlotGroup ("item_inv" , 3 );
89- guiSyncManager .registerSlotGroup ("mixer_items" , 2 );
108+ syncManager .registerSlotGroup ("item_inv" , 3 );
109+ syncManager .registerSlotGroup ("mixer_items" , 2 );
90110
91- guiSyncManager .syncValue ("mixer_fluids" , 0 , SyncHandlers .fluidSlot (this .mixerFluids1 ));
92- guiSyncManager .syncValue ("mixer_fluids" , 1 , SyncHandlers .fluidSlot (this .mixerFluids2 ));
111+ syncManager .syncValue ("mixer_fluids" , 0 , SyncHandlers .fluidSlot (this .mixerFluids1 ));
112+ syncManager .syncValue ("mixer_fluids" , 1 , SyncHandlers .fluidSlot (this .mixerFluids2 ));
93113 IntSyncValue cycleStateValue = new IntSyncValue (() -> this .cycleState , val -> this .cycleState = val );
94- guiSyncManager .syncValue ("cycle_state" , cycleStateValue );
95- guiSyncManager .syncValue ("display_item" , GenericSyncValue .forItem (() -> this .displayItem , null ));
96- guiSyncManager .bindPlayerInventory (guiData .getPlayer ());
114+ syncManager .syncValue ("cycle_state" , cycleStateValue );
115+ syncManager .syncValue ("display_item" , GenericSyncValue .forItem (() -> this .displayItem , null ));
116+ syncManager .bindPlayerInventory (guiData .getPlayer ());
117+
118+ DynamicSyncHandler dynamicSyncHandler = new DynamicSyncHandler ()
119+ .widgetProvider ((syncManager1 , packet ) -> {
120+ ItemStack itemStack = NetworkUtils .readItemStack (packet );
121+ if (itemStack .isEmpty ()) return new EmptyWidget ();
122+ Item item = itemStack .getItem ();
123+ ItemStackHandler handler = stackHandlerMap .computeIfAbsent (item , k -> new ItemStackHandler (handlerSizeMap .getInt (k )));
124+ String name = item .getRegistryName ().toString ();
125+ Flow flow = Flow .row ();
126+ for (int i = 0 ; i < handler .getSlots (); i ++) {
127+ int finalI = i ;
128+ flow .child (new ItemSlot ()
129+ .syncHandler (syncManager1 .getOrCreateSyncHandler (name , i , ItemSlotSH .class , () -> new ItemSlotSH (new ModularSlot (handler , finalI )))));
130+ }
131+ return flow ;
132+ });
97133
98134 Rectangle colorPickerBackground = new Rectangle ().setColor (Color .RED .main );
99135 ModularPanel panel = new ModularPanel ("test_tile" );
100- IPanelHandler panelSyncHandler = guiSyncManager .panel ("other_panel" , this ::openSecondWindow , true );
136+ IPanelHandler panelSyncHandler = syncManager .panel ("other_panel" , this ::openSecondWindow , true );
101137 IPanelHandler colorPicker = IPanelHandler .simple (panel , (mainPanel , player ) -> new ColorPickerDialog (colorPickerBackground ::setColor , colorPickerBackground .getColor (), true )
102138 .setDraggable (true )
103139 .relative (panel )
@@ -117,7 +153,10 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager,
117153 .child (new PageButton (1 , tabController )
118154 .tab (GuiTextures .TAB_TOP , 0 ))
119155 .child (new PageButton (2 , tabController )
120- .tab (GuiTextures .TAB_TOP , 0 )))
156+ .tab (GuiTextures .TAB_TOP , 0 ))
157+ .child (new PageButton (3 , tabController )
158+ .tab (GuiTextures .TAB_TOP , 0 )
159+ .overlay (new ItemDrawable (Blocks .CHEST ).asIcon ())))
121160 .child (new Expandable ()
122161 .debugName ("expandable" )
123162 .top (0 )
@@ -368,7 +407,22 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager,
368407 .size (14 , 14 ))
369408 .child (IKey .lang ("bogosort.gui.enabled" ).asWidget ()
370409 .height (14 )))))
371- ))
410+ .addPage (new ParentWidget <>()
411+ .debugName ("page 4 storage" )
412+ .sizeRel (1f )
413+ .child (new Column ()
414+ .padding (7 )
415+ .child (new ItemSlot ()
416+ .slot (new ModularSlot (this .storageInventory0 , 0 )
417+ .changeListener (((newItem , onlyAmountChanged , client , init ) -> {
418+ if (client && !onlyAmountChanged ) {
419+ dynamicSyncHandler .notifyUpdate (packet -> NetworkUtils .writeItemStack (packet , newItem ));
420+ }
421+ }))))
422+ .child (new DynamicSyncedWidget <>()
423+ .widthRel (1f )
424+ .syncHandler (dynamicSyncHandler )))
425+ )))
372426 .child (SlotGroupWidget .playerInventory (false ))
373427 );
374428 /*panel.child(new ButtonWidget<>()
0 commit comments