11package com .circulation .random_complement .mixin .ae2 ;
22
3- import appeng .api .util .AEPartLocation ;
4- import appeng .container .ContainerOpenContext ;
53import appeng .container .implementations .ContainerCraftAmount ;
64import appeng .container .implementations .ContainerCraftConfirm ;
7- import appeng .core .sync .AppEngPacket ;
85import appeng .core .sync .GuiBridge ;
9- import appeng .core .sync .network .INetworkInfo ;
106import appeng .core .sync .packets .PacketCraftRequest ;
11- import appeng .util .Platform ;
127import baubles .api .BaublesApi ;
13- import com .circulation .random_complement .RandomComplement ;
148import com .circulation .random_complement .common .interfaces .RCAEBaseContainer ;
15- import com .circulation . random_complement . common . network . ContainerRollBACK ;
16- import com .circulation . random_complement . common . util . MEHandler ;
9+ import com .llamalad7 . mixinextras . injector . wrapoperation . Operation ;
10+ import com .llamalad7 . mixinextras . injector . wrapoperation . WrapOperation ;
1711import com .llamalad7 .mixinextras .sugar .Local ;
1812import net .minecraft .entity .player .EntityPlayer ;
1913import net .minecraft .entity .player .EntityPlayerMP ;
2014import net .minecraft .inventory .Container ;
21- import net .minecraft .inventory .ContainerPlayer ;
2215import net .minecraft .item .ItemStack ;
2316import net .minecraftforge .fml .common .Optional ;
2417import org .spongepowered .asm .mixin .Final ;
2518import org .spongepowered .asm .mixin .Mixin ;
2619import org .spongepowered .asm .mixin .Shadow ;
2720import org .spongepowered .asm .mixin .Unique ;
2821import org .spongepowered .asm .mixin .injection .At ;
29- import org .spongepowered .asm .mixin .injection .Inject ;
3022import org .spongepowered .asm .mixin .injection .Redirect ;
31- import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
3223
3324import javax .annotation .Nonnull ;
3425
@@ -45,46 +36,18 @@ public class MixinPacketCraftRequest {
4536 return BaublesApi .getBaublesHandler (player ).getStackInSlot (slot );
4637 }
4738
48- @ Redirect (method = "serverPacketData" , at = @ At (value = "INVOKE" , target = "Lappeng/util/Platform;openGUI(Lnet/minecraft/entity/player/EntityPlayer;ILappeng/core/sync/GuiBridge;Z)V" ))
49- public void serverPacketData (@ Nonnull EntityPlayer p , int slot , @ Nonnull GuiBridge type , boolean isBauble ) {
50- if (heldShift ) {
51- if (p instanceof EntityPlayerMP entityPlayerMP ) {
52- Container old = null ;
53- if (p .openContainer instanceof RCAEBaseContainer c ) {
54- old = c .rc$getOldContainer ();
55- }
56-
57- entityPlayerMP .getNextWindowId ();
58- entityPlayerMP .closeContainer ();
59- int windowId = entityPlayerMP .currentWindowId ;
60- var newContainer = new ContainerCraftConfirm (p .inventory ,
61- MEHandler .getTerminalGuiObject (
62- isBauble ? r$readBaubles (p , slot ) : p .inventory .getStackInSlot (slot ),
63- p , slot , isBauble ? 1 : 0
64- ));
65- var context = new ContainerOpenContext (null );
66- context .setSide (AEPartLocation .INTERNAL );
67- newContainer .setOpenContext (context );
68-
69- entityPlayerMP .openContainer = newContainer ;
70- entityPlayerMP .openContainer .windowId = windowId ;
71-
72- if (newContainer instanceof RCAEBaseContainer c && old != null ) {
73- c .rc$setOldContainer (old );
74- }
39+ @ WrapOperation (method = "serverPacketData" , at = @ At (value = "INVOKE" , target = "Lappeng/util/Platform;openGUI(Lnet/minecraft/entity/player/EntityPlayer;ILappeng/core/sync/GuiBridge;Z)V" ))
40+ public void serverPacketData (@ Nonnull EntityPlayer p , int slot , @ Nonnull GuiBridge type , boolean isBauble , Operation <Void > original ) {
41+ if (p instanceof EntityPlayerMP entityPlayerMP ) {
42+ Container old = null ;
43+ if (p .openContainer instanceof RCAEBaseContainer c ) {
44+ old = c .rc$getOldContainer ();
7545 }
76- } else {
77- if (p instanceof EntityPlayerMP entityPlayerMP ) {
78- Container old = null ;
79- if (p .openContainer instanceof RCAEBaseContainer c ) {
80- old = c .rc$getOldContainer ();
81- }
8246
83- Platform . openGUI (p , slot , type , isBauble );
47+ original . call (p , slot , type , isBauble );
8448
85- if (p .openContainer instanceof RCAEBaseContainer c && old != null ) {
86- c .rc$setOldContainer (old );
87- }
49+ if (p .openContainer instanceof RCAEBaseContainer c && old != null ) {
50+ c .rc$setOldContainer (old );
8851 }
8952 }
9053 }
@@ -93,26 +56,4 @@ public void serverPacketData(@Nonnull EntityPlayer p, int slot, @Nonnull GuiBrid
9356 public void detectAndSendChanges (ContainerCraftAmount instance , @ Local (name = "ccc" ) ContainerCraftConfirm ccc ) {
9457 ccc .detectAndSendChanges ();
9558 }
96-
97- @ Inject (method = "serverPacketData" , at = @ At ("TAIL" ))
98- public void ContainerRollBACK (INetworkInfo manager , AppEngPacket packet , EntityPlayer player , CallbackInfo ci ) {
99- if (!heldShift ) return ;
100- if (player .openContainer instanceof RCAEBaseContainer rac ) {
101- if (player instanceof EntityPlayerMP entityPlayerMP ) {
102- var oldContainer = rac .rc$getOldContainer ();
103- if (oldContainer != null ) {
104- if (oldContainer instanceof ContainerPlayer ) {
105- entityPlayerMP .closeContainer ();
106- } else {
107- entityPlayerMP .getNextWindowId ();
108- entityPlayerMP .closeContainer ();
109- int windowId = entityPlayerMP .currentWindowId ;
110- entityPlayerMP .openContainer = oldContainer ;
111- entityPlayerMP .openContainer .windowId = windowId ;
112- }
113- }
114- RandomComplement .NET_CHANNEL .sendTo (new ContainerRollBACK (), entityPlayerMP );
115- }
116- }
117- }
11859}
0 commit comments