33import appeng .api .config .Actionable ;
44import appeng .api .networking .security .IActionSource ;
55import appeng .api .networking .storage .IStorageGrid ;
6+ import appeng .api .storage .IMEInventoryHandler ;
67import appeng .api .storage .IMEMonitor ;
78import appeng .api .storage .IStorageChannel ;
89import appeng .api .storage .data .IAEItemStack ;
2021import com .llamalad7 .mixinextras .sugar .Share ;
2122import com .llamalad7 .mixinextras .sugar .ref .LocalBooleanRef ;
2223import org .objectweb .asm .Opcodes ;
24+ import org .spongepowered .asm .mixin .Final ;
2325import org .spongepowered .asm .mixin .Mixin ;
2426import org .spongepowered .asm .mixin .Shadow ;
2527import org .spongepowered .asm .mixin .Unique ;
2830import org .spongepowered .asm .mixin .injection .callback .CallbackInfo ;
2931import org .spongepowered .asm .mixin .injection .callback .CallbackInfoReturnable ;
3032
31- @ SuppressWarnings ("DataFlowIssue" )
32- @ Mixin (value = NetworkInventoryHandler .class , remap = false )
33+ import java .util .Deque ;
34+ import java .util .List ;
35+ import java .util .NavigableMap ;
36+
37+ @ SuppressWarnings ({"DataFlowIssue" , "unchecked" })
38+ @ Mixin (value = NetworkInventoryHandler .class , remap = false , priority = 1001 )
3339public abstract class MixinNetworkInventoryHandler <T extends IAEStack <T >> implements FCNetworkInventoryHandler {
3440
3541 @ Unique
@@ -47,6 +53,13 @@ public abstract class MixinNetworkInventoryHandler<T extends IAEStack<T>> implem
4753 @ Shadow
4854 protected abstract boolean diveList (NetworkInventoryHandler <T > networkInventoryHandler , Actionable type );
4955
56+ @ Shadow
57+ @ Final
58+ private NavigableMap <Integer , List <IMEInventoryHandler <T >>> priorityInventory ;
59+
60+ @ Shadow
61+ protected abstract Deque <?> getDepth (Actionable type );
62+
5063 @ Inject (method = "<init>" , at = @ At ("TAIL" ))
5164 public void onInit (final IStorageChannel <?> chan , final SecurityCache security , final CallbackInfo ci ) {
5265 monitor = security .getGrid ().<IStorageGrid >getCache (IStorageGrid .class ).getInventory (Util .getItemChannel ());
@@ -58,13 +71,32 @@ private void notItemInject(final T input, final Actionable mode, final IActionSo
5871 if (src instanceof FakeMonitor .FakeMonitorSource || mode == Actionable .SIMULATE ) return ;
5972 final var drop = Util .packAEStackToDrop (input );
6073 if (drop != null ) {
61- this .surface ((NetworkInventoryHandler <T >) (Object ) this , mode );
74+ if (! this . getDepth ( mode ). isEmpty ()) this .surface ((NetworkInventoryHandler <T >) (Object ) this , mode );
6275 cir .setReturnValue (FakeItemRegister .getAEStack (monitor .injectItems (drop , mode , src )));
6376 this .diveList ((NetworkInventoryHandler <T >) (Object ) this , mode );
6477 } else return ;
6578 this .surface ((NetworkInventoryHandler <T >) (Object ) this , mode );
6679 }
6780
81+ @ Inject (method = "injectItems" , at = @ At (value = "FIELD" , target = "Lappeng/me/storage/NetworkInventoryHandler;priorityInventory:Ljava/util/NavigableMap;" , opcode = Opcodes .GETFIELD ), cancellable = true )
82+ private void injectItemsN (final T input , final Actionable mode , final IActionSource src , final CallbackInfoReturnable <T > cir , @ Share ("fc$fakeInput" ) final LocalBooleanRef fakeInput ) {
83+ if (input == null || fakeInput .get () || !this .priorityInventory .isEmpty ()) return ;
84+ if (input instanceof final IAEItemStack i ) {
85+ if (i .getItem () == FCItems .FLUID_DROP ) {
86+ cir .setReturnValue ((T ) fluidMonitor .injectItems (i , mode , src ));
87+ } else if (ModAndClassUtil .GAS && i .getItem () == FCGasItems .GAS_DROP ) {
88+ cir .setReturnValue ((T ) gasMonitor .injectItems (i , mode , src ));
89+ } else {
90+ fakeInput .set (true );
91+ return ;
92+ }
93+ } else {
94+ fakeInput .set (true );
95+ return ;
96+ }
97+ this .surface ((NetworkInventoryHandler <T >) (Object ) this , mode );
98+ }
99+
68100 @ Inject (method = "injectItems" , at = @ At (value = "INVOKE" , target = "Ljava/util/List;iterator()Ljava/util/Iterator;" , ordinal = 2 ), cancellable = true )
69101 private void injectItems (final T input , final Actionable mode , final IActionSource src , final CallbackInfoReturnable <T > cir , @ Share ("fc$fakeInput" ) final LocalBooleanRef fakeInput ) {
70102 if (input == null || fakeInput .get ()) return ;
@@ -110,7 +142,7 @@ public void extractItems(final T request, final Actionable mode, final IActionSo
110142 }
111143
112144 @ Override
113- public void init (final FCNetworkMonitor monitor ) {
145+ public void init (final FCNetworkMonitor <?> monitor ) {
114146 fluidMonitor = monitor .getFluidMonitor ();
115147 gasMonitor = monitor .getGasMonitor ();
116148 }
0 commit comments