11
11
import net .minecraft .client .gui .screens .inventory .CreativeModeInventoryScreen ;
12
12
import net .minecraft .client .multiplayer .MultiPlayerGameMode ;
13
13
import net .minecraft .client .player .LocalPlayer ;
14
+ import net .minecraft .client .resources .sounds .SimpleSoundInstance ;
14
15
import net .minecraft .nbt .CompoundTag ;
16
+ import net .minecraft .sounds .SoundEvents ;
15
17
import net .minecraft .util .Tuple ;
16
18
import net .minecraft .world .entity .player .Inventory ;
17
19
import net .minecraft .world .entity .player .Player ;
@@ -155,12 +157,12 @@ public static Tuple<Integer, Integer> getSortRange(AbstractContainerMenu screenH
155
157
return new Tuple <>(l , r );
156
158
}
157
159
158
- public static boolean sort () {
160
+ public static @ Nullable Runnable sort () {
159
161
Minecraft client = Minecraft .getInstance ();
160
162
161
163
if (!(client .screen instanceof AbstractContainerScreen <?>) ||
162
164
client .screen instanceof CreativeModeInventoryScreen ) {
163
- return false ;
165
+ return null ;
164
166
}
165
167
166
168
AbstractContainerScreen <?> handledScreen = (AbstractContainerScreen <?>) client .screen ;
@@ -170,20 +172,20 @@ public static boolean sort() {
170
172
Slot mouseSlot = ((AccessorAbstractContainerScreen ) handledScreen ).invokeFindSlot (x , y );
171
173
172
174
if (mouseSlot == null ) {
173
- return false ;
175
+ return null ;
174
176
}
175
177
176
178
LocalPlayer player = client .player ;
177
179
178
180
if (client .gameMode == null || player == null ) {
179
- return false ;
181
+ return null ;
180
182
}
181
183
182
184
AbstractContainerMenu screenHandler = player .containerMenu ;
183
185
Tuple <Integer , Integer > sortRange = SortInventoryUtil .getSortRange (screenHandler , mouseSlot );
184
186
185
187
if (sortRange == null ) {
186
- return false ;
188
+ return null ;
187
189
}
188
190
189
191
List <ItemStack > itemStacks = Lists .newArrayList ();
@@ -199,7 +201,11 @@ public static boolean sort() {
199
201
List <Tuple <Integer , Integer >> swapQueue = SortInventoryUtil .quickSort (itemStacks , sortRange .getA (),
200
202
sortRange .getB ());
201
203
SortInventoryUtil .doClick (player , screenHandler .containerId , client .gameMode , mergeQueue , swapQueue );
202
- return !mergeQueue .isEmpty () || !swapQueue .isEmpty ();
204
+ return (!mergeQueue .isEmpty () || !swapQueue .isEmpty ()) ?
205
+ () -> Minecraft .getInstance ().getSoundManager ()
206
+ .play (SimpleSoundInstance .forUI (SoundEvents .UI_BUTTON_CLICK , 1.0F )) :
207
+ () -> Minecraft .getInstance ().getSoundManager ()
208
+ .play (SimpleSoundInstance .forUI (SoundEvents .DISPENSER_FAIL , 1.0F ));
203
209
}
204
210
205
211
public static void doClick (Player player , int syncId , @ NotNull MultiPlayerGameMode interactionManager ,
0 commit comments