77import appeng .api .stacks .AEKey ;
88import appeng .api .stacks .AEKeyType ;
99import appeng .api .storage .MEStorage ;
10+ import appeng .helpers .patternprovider .PatternProviderTarget ;
1011import appeng .me .storage .CompositeStorage ;
1112import appeng .parts .automation .StackWorldBehaviors ;
12- import it .unimi .dsi .fastutil .objects .Object2LongMap ;
13+ import appeng .util .ConfigManager ;
14+ import lu .kolja .expandedae .definition .ExpSettings ;
1315import net .minecraft .core .BlockPos ;
1416import net .minecraft .core .Direction ;
17+ import net .minecraft .resources .ResourceLocation ;
1518import net .minecraft .server .level .ServerLevel ;
1619import net .neoforged .neoforge .capabilities .BlockCapabilityCache ;
1720import org .jetbrains .annotations .Nullable ;
2023import java .util .Map ;
2124import java .util .Set ;
2225
26+ /**
27+ * Most code is borrowed from ae2
28+ */
2329public class PatternProviderTargetCache {
30+ private final ResourceLocation programmedCircuit = ResourceLocation .fromNamespaceAndPath ("gtceu" , "programmed_circuit" );
31+
2432 private final BlockCapabilityCache <MEStorage , Direction > cache ;
2533 private final IActionSource src ;
2634 private final Map <AEKeyType , ExternalStorageStrategy > strategies ;
35+ private final ConfigManager configManager ;
2736
28- public PatternProviderTargetCache (ServerLevel l , BlockPos pos , Direction direction , IActionSource src ) {
37+ public PatternProviderTargetCache (ServerLevel l , BlockPos pos , Direction direction , IActionSource src , ConfigManager configManager ) {
2938 this .cache = BlockCapabilityCache .create (AECapabilities .ME_STORAGE , l , pos , direction );
3039 this .src = src ;
3140 this .strategies = StackWorldBehaviors .createExternalStorageStrategies (l , pos , direction );
41+ this .configManager = configManager ;
3242 }
3343
3444 @ Nullable
3545 public PatternProviderTarget find () {
36- MEStorage meStorage = this .cache .getCapability ();
46+ // our capability first: allows any storage channel
47+ var meStorage = cache .getCapability ();
3748 if (meStorage != null ) {
38- return this .wrapMeStorage (meStorage );
39- } else {
40- IdentityHashMap <AEKeyType , MEStorage > externalStorages = new IdentityHashMap (2 );
49+ return wrapMeStorage (meStorage );
50+ }
4151
42- for (Map .Entry <AEKeyType , ExternalStorageStrategy > entry : this .strategies .entrySet ()) {
43- MEStorage wrapper = entry .getValue ().createWrapper (false , () -> {
44- });
45- if (wrapper != null ) {
46- externalStorages .put (entry .getKey (), wrapper );
47- }
52+ // otherwise fall back to the platform capability
53+ var externalStorages = new IdentityHashMap <AEKeyType , MEStorage >(2 );
54+ for (var entry : strategies .entrySet ()) {
55+ var wrapper = entry .getValue ().createWrapper (false , () -> {
56+ });
57+ if (wrapper != null ) {
58+ externalStorages .put (entry .getKey (), wrapper );
4859 }
60+ }
4961
50- if (!externalStorages .isEmpty ()) {
51- return this .wrapMeStorage (new CompositeStorage (externalStorages ));
52- } else {
53- return null ;
54- }
62+ if (!externalStorages .isEmpty ()) {
63+ return wrapMeStorage (new CompositeStorage (externalStorages ));
5564 }
65+
66+ return null ;
5667 }
5768
58- private PatternProviderTarget wrapMeStorage (final MEStorage storage ) {
69+ private PatternProviderTarget wrapMeStorage (MEStorage storage ) {
5970 return new PatternProviderTarget () {
71+ @ Override
6072 public long insert (AEKey what , long amount , Actionable type ) {
61- return storage .insert (what , amount , type , PatternProviderTargetCache . this . src );
73+ return storage .insert (what , amount , type , src );
6274 }
6375
76+ @ Override
6477 public boolean containsPatternInput (Set <AEKey > patternInputs ) {
65- for (Object2LongMap .Entry <AEKey > stack : storage .getAvailableStacks ()) {
66- if (patternInputs .contains (stack .getKey ().dropSecondary ())) {
67- return true ;
78+ switch (configManager .getSetting (ExpSettings .BLOCKING_MODE )) {
79+ case ALL -> {
80+ for (var stack : storage .getAvailableStacks ()) {
81+ if (stack .getKey ().getId ().equals (programmedCircuit )) continue ;
82+ return true ;
83+ }
84+ }
85+ case DEFAULT -> {
86+ for (var stack : storage .getAvailableStacks ()) {
87+ if (stack .getKey ().getId ().equals (programmedCircuit )) continue ;
88+ if (patternInputs .contains (stack .getKey ().dropSecondary ())) return true ;
89+ }
90+ }
91+ case SMART -> {
92+ for (var stack : storage .getAvailableStacks ()) {
93+ if (stack .getKey ().getId ().equals (programmedCircuit )) continue ;
94+ if (!patternInputs .contains (stack .getKey ().dropSecondary ())) return true ;
95+ }
6896 }
6997 }
7098 return false ;
7199 }
72-
73- @ Override
74- public boolean onlyHasPatternInput (Set <AEKey > patternInputs ) {
75- for (var stack : storage .getAvailableStacks ()) {
76- if (patternInputs .contains (stack .getKey ().dropSecondary ())) continue ;
77- return false ;
78- }
79- return true ;
80- }
81-
82- public MEStorage getStorage () {
83- return storage ;
84- }
85100 };
86101 }
87102}
0 commit comments