11package gregtech .api .mui .factory ;
22
3+ import com .cleanroommc .modularui .factory .inventory .InventoryTypes ;
4+
5+ import com .cleanroommc .modularui .utils .Platform ;
6+
37import gregtech .api .items .metaitem .MetaItem ;
48
59import net .minecraft .entity .player .EntityPlayer ;
1115import com .cleanroommc .modularui .api .IGuiHolder ;
1216import com .cleanroommc .modularui .factory .AbstractUIFactory ;
1317import com .cleanroommc .modularui .factory .GuiManager ;
14- import com .cleanroommc .modularui .factory .HandGuiData ;
18+ import com .cleanroommc .modularui .factory .PlayerInventoryGuiData ;
1519import org .jetbrains .annotations .NotNull ;
1620
1721import java .util .Objects ;
1822
19- public class MetaItemGuiFactory extends AbstractUIFactory <HandGuiData > {
23+ public class MetaItemGuiFactory extends AbstractUIFactory <PlayerInventoryGuiData > {
2024
2125 public static final MetaItemGuiFactory INSTANCE = new MetaItemGuiFactory ();
2226
@@ -27,12 +31,13 @@ private MetaItemGuiFactory() {
2731 public static void open (EntityPlayer player , EnumHand hand ) {
2832 Objects .requireNonNull (player );
2933 Objects .requireNonNull (hand );
30- HandGuiData guiData = new HandGuiData (player , hand );
31- GuiManager .open (INSTANCE , guiData , (EntityPlayerMP ) player );
34+ int index = hand == EnumHand .OFF_HAND ? 40 : Platform .getClientPlayer ().inventory .currentItem ;
35+ PlayerInventoryGuiData guiData = new PlayerInventoryGuiData (player , InventoryTypes .PLAYER , index );
36+ GuiManager .open (INSTANCE , guiData , verifyServerSide (player ));
3237 }
3338
3439 @ Override
35- public @ NotNull IGuiHolder <HandGuiData > getGuiHolder (HandGuiData data ) {
40+ public @ NotNull IGuiHolder <PlayerInventoryGuiData > getGuiHolder (PlayerInventoryGuiData data ) {
3641 ItemStack stack = data .getUsedItemStack ();
3742 if (!(stack .getItem () instanceof MetaItem <?>metaItem )) {
3843 throw new IllegalArgumentException ("Found item is not a valid MetaItem!" );
@@ -45,12 +50,12 @@ public static void open(EntityPlayer player, EnumHand hand) {
4550 }
4651
4752 @ Override
48- public void writeGuiData (HandGuiData guiData , PacketBuffer buffer ) {
49- buffer .writeByte (guiData .getHand (). ordinal ());
53+ public void writeGuiData (PlayerInventoryGuiData guiData , PacketBuffer buffer ) {
54+ buffer .writeByte (guiData .getSlotIndex ());
5055 }
5156
5257 @ Override
53- public @ NotNull HandGuiData readGuiData (EntityPlayer player , PacketBuffer buffer ) {
54- return new HandGuiData (player , EnumHand . values ()[ buffer .readByte ()] );
58+ public @ NotNull PlayerInventoryGuiData readGuiData (EntityPlayer player , PacketBuffer buffer ) {
59+ return new PlayerInventoryGuiData (player , InventoryTypes . PLAYER , buffer .readByte ());
5560 }
5661}
0 commit comments