4444import net .minecraftforge .fml .common .network .simpleimpl .IMessage ;
4545import net .minecraftforge .fml .common .network .simpleimpl .MessageContext ;
4646
47- import java .util .Optional ;
48-
4947public class KeyBindingHandler implements Packet <KeyBindingHandler > {
5048
5149 ItemStack stack = ItemStack .EMPTY ;
@@ -130,14 +128,11 @@ private void retrieveItem(EntityPlayerMP player, Container container, ItemStack
130128 IGrid grid = gridNode .getGrid ();
131129 if (securityCheck (player , grid , SecurityPermissions .EXTRACT )) {
132130 IStorageGrid storageGrid = grid .getCache (IStorageGrid .class );
133- var iItemStorageChannel = storageGrid .getInventory (AEApi .instance ().storage ().getStorageChannel (IItemStorageChannel .class ));
131+ var items = storageGrid .getInventory (AEApi .instance ().storage ().getStorageChannel (IItemStorageChannel .class ));
134132 var host = c .getTarget ();
135133 if (host instanceof IActionHost h ) {
136- var aeItemO = Optional .ofNullable (iItemStorageChannel .extractItems (AEItemStack .fromItemStack (item ).setStackSize (targetCount ), Actionable .SIMULATE , new PlayerSource (player , h )));
137-
138- if (aeItemO .isPresent ()) {
139- var aeItem = aeItemO .get ();
140- var aeitem = iItemStorageChannel .extractItems (AEItemStack .fromItemStack (item ).setStackSize (aeItem .getStackSize ()), Actionable .MODULATE , new PlayerSource (player , h ));
134+ var aeitem = items .extractItems (AEItemStack .fromItemStack (item ).setStackSize (targetCount ), Actionable .MODULATE , new PlayerSource (player , h ));
135+ if (aeitem != null ) {
141136 player .inventory .placeItemBackInInventory (player .world , aeitem .createItemStack ());
142137 }
143138 }
@@ -148,18 +143,14 @@ private void retrieveItem(EntityPlayerMP player, Container container, ItemStack
148143 private long wirelessRetrieve (EntityPlayerMP player , ItemStack exItem , IGridNode gridNode , long targetCount , WirelessTerminalGuiObject obj ) {
149144 IGrid grid = gridNode .getGrid ();
150145 if (securityCheck (player , grid , SecurityPermissions .EXTRACT )) {
151- IStorageGrid storageGrid = grid .getCache (IStorageGrid .class );
152- var iItemStorageChannel = storageGrid .getInventory (AEApi .instance ().storage ().getStorageChannel (IItemStorageChannel .class ));
153- var aeItemO = Optional .ofNullable (iItemStorageChannel .extractItems (AEItemStack .fromItemStack (exItem ).setStackSize (targetCount ), Actionable .SIMULATE , new PlayerSource (player , obj )));
146+ var items = grid .<IStorageGrid >getCache (IStorageGrid .class ).getInventory (AEApi .instance ().storage ().getStorageChannel (IItemStorageChannel .class ));
147+ var aeitem = items .extractItems (AEItemStack .fromItemStack (exItem ).setStackSize (targetCount ), Actionable .MODULATE , new PlayerSource (player , obj ));
154148
155- if (aeItemO .isPresent ()) {
156- var aeItem = aeItemO .get ();
157- var aeitem = iItemStorageChannel .extractItems (AEItemStack .fromItemStack (exItem ).setStackSize (aeItem .getStackSize ()), Actionable .MODULATE , new PlayerSource (player , obj ));
149+ if (aeitem == null ) return targetCount ;
158150
159- targetCount -= aeitem .getStackSize ();
151+ targetCount -= aeitem .getStackSize ();
160152
161- player .inventory .placeItemBackInInventory (player .world , aeitem .createItemStack ());
162- }
153+ player .inventory .placeItemBackInInventory (player .world , aeitem .createItemStack ());
163154 }
164155 return targetCount ;
165156 }
@@ -200,7 +191,6 @@ private void startCraft(EntityPlayerMP player, Container container, ItemStack it
200191 }
201192 IGrid grid = gridNode .getGrid ();
202193 if (securityCheck (player , grid , SecurityPermissions .CRAFT )) {
203-
204194 RCCraftingGridCache cgc = grid .getCache (ICraftingGrid .class );
205195 IAEItemStack aeItem = AEItemStack .fromItemStack (item ).setStackSize (1 );
206196 boolean isCraftable = cgc .rc$getCraftableItems ().containsKey (aeItem );
@@ -229,9 +219,6 @@ private void startCraft(EntityPlayerMP player, Container container, ItemStack it
229219 private void openWirelessCraft (ItemStack terminal , EntityPlayerMP player , ItemStack exItem , IGridNode gridNode , int i , boolean isBauble ) {
230220 IGrid grid = gridNode .getGrid ();
231221 if (securityCheck (player , grid , SecurityPermissions .CRAFT )) {
232- IStorageGrid storageGrid = grid .getCache (IStorageGrid .class );
233- var iItemStorageChannel = storageGrid .getInventory (AEApi .instance ().storage ().getStorageChannel (IItemStorageChannel .class ));
234-
235222 RCCraftingGridCache cgc = gridNode .getGrid ().getCache (ICraftingGrid .class );
236223 IAEItemStack aeItem = AEItemStack .fromItemStack (exItem ).setStackSize (1 );
237224 boolean isCraftable = cgc .rc$getCraftableItems ().containsKey (aeItem );
0 commit comments