33import gregtech .api .GTValues ;
44import gregtech .api .capability .IDataAccessHatch ;
55import gregtech .api .capability .impl .NotifiableItemStackHandler ;
6- import gregtech .api .gui .GuiTextures ;
7- import gregtech .api .gui .ModularUI ;
8- import gregtech .api .gui .widgets .SlotWidget ;
6+ import gregtech .api .items .itemhandlers .GTItemStackHandler ;
97import gregtech .api .metatileentity .IDataInfoProvider ;
108import gregtech .api .metatileentity .MetaTileEntity ;
119import gregtech .api .metatileentity .interfaces .IGregTechTileEntity ;
1210import gregtech .api .metatileentity .multiblock .AbilityInstances ;
1311import gregtech .api .metatileentity .multiblock .IMultiblockAbilityPart ;
1412import gregtech .api .metatileentity .multiblock .MultiblockAbility ;
1513import gregtech .api .metatileentity .multiblock .MultiblockControllerBase ;
14+ import gregtech .api .mui .GTGuiTextures ;
15+ import gregtech .api .mui .GTGuis ;
1616import gregtech .api .recipes .Recipe ;
1717import gregtech .api .recipes .RecipeMaps ;
1818import gregtech .api .recipes .machines .IResearchRecipeMap ;
2626
2727import net .minecraft .client .resources .I18n ;
2828import net .minecraft .creativetab .CreativeTabs ;
29- import net .minecraft .entity .player .EntityPlayer ;
3029import net .minecraft .item .ItemStack ;
3130import net .minecraft .util .NonNullList ;
3231import net .minecraft .util .ResourceLocation ;
3938import codechicken .lib .render .CCRenderState ;
4039import codechicken .lib .render .pipeline .IVertexOperation ;
4140import codechicken .lib .vec .Matrix4 ;
41+ import com .cleanroommc .modularui .api .drawable .IKey ;
42+ import com .cleanroommc .modularui .drawable .ItemDrawable ;
43+ import com .cleanroommc .modularui .factory .PosGuiData ;
44+ import com .cleanroommc .modularui .screen .ModularPanel ;
45+ import com .cleanroommc .modularui .utils .Alignment ;
46+ import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
47+ import com .cleanroommc .modularui .value .sync .SyncHandlers ;
48+ import com .cleanroommc .modularui .widget .Widget ;
49+ import com .cleanroommc .modularui .widgets .ItemSlot ;
50+ import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
51+ import com .cleanroommc .modularui .widgets .layout .Flow ;
52+ import com .cleanroommc .modularui .widgets .layout .Grid ;
4253import it .unimi .dsi .fastutil .objects .ObjectOpenCustomHashSet ;
4354import it .unimi .dsi .fastutil .objects .ObjectOpenHashSet ;
4455import org .jetbrains .annotations .NotNull ;
@@ -56,7 +67,7 @@ public class MetaTileEntityDataAccessHatch extends MetaTileEntityMultiblockNotif
5667 public MetaTileEntityDataAccessHatch (ResourceLocation metaTileEntityId , int tier , boolean isCreative ) {
5768 super (metaTileEntityId , tier , false );
5869 this .isCreative = isCreative ;
59- this .recipes = isCreative ? Collections .emptySet () : new ObjectOpenHashSet <>();
70+ this .recipes = isCreative ? Collections .emptySet () : new ObjectOpenHashSet <>(importItems . getSlots () );
6071 rebuildData (getController () instanceof MetaTileEntityDataBank );
6172 }
6273
@@ -103,35 +114,77 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
103114 }
104115
105116 @ Override
106- protected ModularUI createUI (EntityPlayer entityPlayer ) {
107- if (isCreative ) return null ;
108- int rowSize = (int ) Math .sqrt (getInventorySize ());
109- ModularUI .Builder builder = ModularUI .builder (GuiTextures .BACKGROUND , 176 , 18 + 18 * rowSize + 94 )
110- .label (6 , 6 , getMetaFullName ());
111-
112- for (int y = 0 ; y < rowSize ; y ++) {
113- for (int x = 0 ; x < rowSize ; x ++) {
114- int index = y * rowSize + x ;
115- builder .widget (new SlotWidget (isExportHatch ? exportItems : importItems , index ,
116- 88 - rowSize * 9 + x * 18 , 18 + y * 18 , true , !isExportHatch )
117- .setBackgroundTexture (GuiTextures .SLOT ));
118- }
119- }
120- return builder .bindPlayerInventory (entityPlayer .inventory , GuiTextures .SLOT , 7 , 18 + 18 * rowSize + 12 )
121- .build (getHolder (), entityPlayer );
117+ protected boolean openGUIOnRightClick () {
118+ return !isCreative ;
122119 }
123120
124121 @ Override
125- protected boolean openGUIOnRightClick () {
126- return !this .isCreative ;
122+ public boolean usesMui2 () {
123+ return true ;
124+ }
125+
126+ @ Override
127+ public ModularPanel buildUI (PosGuiData guiData , PanelSyncManager panelSyncManager ) {
128+ int rowSize = (int ) Math .sqrt (getInventorySize ());
129+ panelSyncManager .registerSlotGroup ("slots" , rowSize );
130+
131+ Widget <?> recipeLogo = GTGuiTextures .getLogo (getUITheme ())
132+ .asWidget ()
133+ .align (Alignment .BottomRight )
134+ .tooltipBuilder (tooltip -> {
135+ if (recipes .isEmpty ()) {
136+ tooltip .addLine (IKey .lang ("gregtech.machine.data_access_hatch.no_recipes" ));
137+ } else {
138+ tooltip .addLine (IKey .lang ("gregtech.machine.data_access_hatch.recipes" ));
139+ tooltip .spaceLine (2 );
140+ }
141+
142+ Set <ItemStack > itemsAdded = new ObjectOpenCustomHashSet <>(ItemStackHashStrategy .comparingAll ());
143+ for (Recipe recipe : recipes ) {
144+ ItemStack output = recipe .getOutputs ().get (0 );
145+ if (itemsAdded .add (output )) {
146+ tooltip .add (new ItemDrawable (output ));
147+ tooltip .space ();
148+ tooltip .addLine (IKey .str (output .getDisplayName ()));
149+ }
150+ }
151+ });
152+
153+ return GTGuis .createPanel (this , 176 , 18 + 18 * rowSize + 94 )
154+ .child (IKey .lang (getMetaFullName ())
155+ .asWidget ()
156+ .pos (5 , 5 ))
157+ .child (Flow .row ()
158+ .top (18 )
159+ .margin (7 , 0 )
160+ .coverChildrenHeight ()
161+ .child (new Grid ()
162+ .height (rowSize * 18 )
163+ .minElementMargin (0 , 0 )
164+ .minColWidth (18 ).minRowHeight (18 )
165+ .alignX (0.5f )
166+ .mapTo (rowSize , rowSize * rowSize , index -> new ItemSlot ()
167+ .slot (SyncHandlers .itemSlot (importItems , index )
168+ .slotGroup ("slots" )
169+ .changeListener ((newItem , onlyAmountChanged , client , init ) -> {
170+ recipeLogo .markTooltipDirty ();
171+ if (onlyAmountChanged &&
172+ importItems instanceof GTItemStackHandler gtHandler ) {
173+ gtHandler .onContentsChanged (index );
174+ }
175+ }))))
176+ .child (recipeLogo ))
177+ .child (SlotGroupWidget .playerInventory ()
178+ .left (7 )
179+ .bottom (7 ));
127180 }
128181
129182 protected int getInventorySize () {
130183 return getTier () == GTValues .LuV ? 16 : 9 ;
131184 }
132185
133186 private void rebuildData (boolean isDataBank ) {
134- if (isCreative || getWorld () == null || getWorld (). isRemote ) return ;
187+ if (isCreative || getWorld () == null ) return ;
135188 recipes .clear ();
136189 for (int i = 0 ; i < this .importItems .getSlots (); i ++) {
137190 ItemStack stack = this .importItems .getStackInSlot (i );
0 commit comments