1010import com .envyful .api .player .PlayerManager ;
1111import com .envyful .api .type .Pair ;
1212import com .google .common .collect .Lists ;
13- import com .google .common .collect .Maps ;
1413import net .minecraft .entity .player .EntityPlayer ;
1514import net .minecraft .entity .player .EntityPlayerMP ;
1615import net .minecraft .inventory .ClickType ;
2221import net .minecraft .util .NonNullList ;
2322import net .minecraft .util .text .ITextComponent ;
2423import net .minecraft .util .text .TextComponentString ;
24+ import scala .xml .dtd .REQUIRED ;
2525
2626import java .util .List ;
27- import java .util .Map ;
28- import java .util .UUID ;
2927
3028/**
3129 *
@@ -82,7 +80,7 @@ public void open(EnvyPlayer<?> player) {
8280
8381 public void update () {
8482 for (ForgeGuiContainer value : this .containers ) {
85- value .update (this .panes );
83+ value .update (this .panes , false );
8684 }
8785 }
8886
@@ -95,21 +93,33 @@ private final class ForgeGuiContainer extends Container {
9593
9694 private final ForgeGui gui ;
9795 private final EntityPlayerMP player ;
96+ private final List <EmptySlot > emptySlots = Lists .newArrayList ();
9897
9998 public ForgeGuiContainer (ForgeGui gui , EntityPlayerMP player ) {
10099 this .windowId = 1 ;
101100 this .gui = gui ;
102101 this .player = player ;
103102
104- this .update (this .gui .panes );
103+ this .update (this .gui .panes , true );
105104 }
106105
107- public void update (ForgeSimplePane [] panes ) {
106+ public void update (ForgeSimplePane [] panes , boolean force ) {
108107 this .inventorySlots = Lists .newArrayList ();
109108 this .inventoryItemStacks = NonNullList .create ();
109+ boolean createEmptySlots = this .emptySlots .isEmpty ();
110+
111+ if (!createEmptySlots ) {
112+ this .inventorySlots .addAll (this .emptySlots );
113+ }
110114
111115 for (int i = 0 ; i < (9 * this .gui .height ); i ++) {
112- this .inventorySlots .add (new EmptySlot (this .gui .parentPane , i ));
116+ if (createEmptySlots ) {
117+ EmptySlot emptySlot = new EmptySlot (this .gui .parentPane , i );
118+
119+ this .emptySlots .add (emptySlot );
120+ this .inventorySlots .add (emptySlot );
121+ }
122+
113123 this .inventoryItemStacks .add (ItemStack .EMPTY );
114124 }
115125
@@ -133,13 +143,19 @@ public void update(ForgeSimplePane[] panes) {
133143 }
134144
135145 for (int i = 9 ; i < 36 ; i ++) {
136- inventorySlots .add (new Slot (this .player .inventory , i - 9 , 0 , 0 ));
137- inventoryItemStacks .add (this .player .inventory .getStackInSlot (i ));
146+ ItemStack itemStack = player .inventory .mainInventory .get (i );
147+ inventorySlots .add (new Slot (player .inventory , i , 0 , 0 ));
148+ inventoryItemStacks .add (itemStack );
138149 }
139-
150+ // Sets the slots for the hotbar.
140151 for (int i = 0 ; i < 9 ; i ++) {
141- inventorySlots .add (new Slot (this .player .inventory , i + 27 , 0 , 0 ));
142- inventoryItemStacks .add (this .player .inventory .getStackInSlot (i ));
152+ ItemStack itemStack = player .inventory .mainInventory .get (i );
153+ inventorySlots .add (new Slot (player .inventory , i , 0 , 0 ));
154+ inventoryItemStacks .add (itemStack );
155+ }
156+
157+ if (force || ForgeGuiTracker .requiresUpdate (this .player )) {
158+ this .refreshPlayerContents ();
143159 }
144160 }
145161
@@ -208,6 +224,7 @@ public ItemStack slotClick(int slot, int dragType, ClickType clickTypeIn, Entity
208224
209225 ForgeSimplePane .SimpleDisplayableSlot simpleDisplayableSlot = pane .getItems ()[panePosition .getY ()][panePosition .getX ()];
210226 simpleDisplayableSlot .getDisplayable ().onClick (envyPlayer , clickType );
227+ ForgeGuiTracker .enqueueUpdate (envyPlayer );
211228 }
212229
213230 return ItemStack .EMPTY ;
@@ -223,9 +240,8 @@ private Displayable.ClickType convertClickType(int id) {
223240 }
224241
225242 private void refreshPlayerContents () {
226- player .sendAllContents (player .openContainer , inventoryItemStacks );
227- player .inventoryContainer .detectAndSendChanges ();
228- player .sendAllContents (player .inventoryContainer , player .inventoryContainer .inventoryItemStacks );
243+ this .player .sendAllContents (this , this .inventoryItemStacks );
244+ ForgeGuiTracker .dequeueUpdate (this .player );
229245 }
230246
231247 private void clearPlayerCursor () {
0 commit comments