11package gregtech .integration .exnihilo .recipes ;
22
3- import exnihilocreatio .registries .types .Siftable ;
4-
53import gregtech .api .unification .OreDictUnifier ;
64import gregtech .integration .IntegrationModule ;
75import gregtech .integration .exnihilo .ExNihiloConfig ;
86
9- import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
10-
117import net .minecraft .block .Block ;
128import net .minecraft .item .ItemStack ;
139import net .minecraft .item .crafting .Ingredient ;
10+ import net .minecraftforge .oredict .OreIngredient ;
1411
1512import exnihilocreatio .registries .manager .ExNihiloRegistryManager ;
13+ import exnihilocreatio .registries .types .Siftable ;
1614import exnihilocreatio .util .ItemInfo ;
17-
15+ import it . unimi . dsi . fastutil . objects . Object2ObjectOpenHashMap ;
1816
1917import java .util .ArrayList ;
18+ import java .util .Arrays ;
2019import java .util .List ;
21-
20+ import java . util . Optional ;
2221
2322/**
24- * Used for adding/removing recipes to the Sieve for CEu (and addons), drops will be added at {@link net.minecraftforge.fml.common.event.FMLInitializationEvent} to the Ex Nihilo sifting list.
23+ * Used for adding/removing recipes to the Sieve for CEu (and addons), drops will be added at
24+ * {@link net.minecraftforge.fml.common.event.FMLInitializationEvent} to the Ex Nihilo sifting list.
2525 */
2626public class SieveDrops {
2727
@@ -49,7 +49,8 @@ private static boolean validateDrops(ItemStack output, int meshlevel, float chan
4949
5050 @ SuppressWarnings ("unused" )
5151 public static void removeDrop (ItemStack input , ItemStack output ) {
52- siftables .entrySet ().removeIf (siftable -> siftable .getKey ().test (input ) && siftable .getValue ().removeIf (drop -> drop .getDrop ().getItemStack ().isItemEqual (output )));
52+ siftables .entrySet ().removeIf (siftable -> siftable .getKey ().test (input ) &&
53+ siftable .getValue ().removeIf (drop -> drop .getDrop ().getItemStack ().isItemEqual (output )));
5354 }
5455
5556 public static void addDrop (Block input , ItemStack output , int meshLevel , float chance ) {
@@ -71,7 +72,7 @@ public static void addDrop(String oredict, ItemStack output, int meshLevel, floa
7172 IntegrationModule .logger .error ("Cannot find oredict {}!" , oredict , new Throwable ());
7273 return ;
7374 }
74- addDrop (Ingredient . fromStacks ( stacks . toArray ( new ItemStack [ 0 ]) ), output , meshLevel , chance );
75+ addDrop (new OreIngredient ( oredict ), output , meshLevel , chance );
7576 }
7677
7778 public static void addDrop (Ingredient ingredient , ItemStack output , int meshLevel , float chance ) {
@@ -82,11 +83,17 @@ public static void addDrop(Ingredient ingredient, Siftable siftable) {
8283 if (!validateDrops (siftable .getDrop ().getItemStack (), siftable .getMeshLevel (), siftable .getChance ())) {
8384 return ;
8485 }
85- if (siftables .containsKey (ingredient )) {
86- siftables .get (ingredient ).add (siftable );
87- return ;
86+ ItemStack [] matchingStacks = ingredient .getMatchingStacks ();
87+ Optional <Ingredient > optionalIngredient = siftables .keySet ().stream ()
88+ .filter (ingredient1 -> Arrays .stream (ingredient1 .getMatchingStacks ()).allMatch (stack -> Arrays
89+ .stream (matchingStacks ).anyMatch (stack1 -> ItemStack .areItemsEqual (stack , stack1 ))))
90+ .findFirst ();
91+ if (!optionalIngredient .isPresent ()) {
92+ siftables .put (ingredient , new ArrayList <>());
93+ } else {
94+ ingredient = optionalIngredient .get ();
8895 }
89- siftables .put (ingredient , new ArrayList <>() {{ add (siftable ); }} );
96+ siftables .get (ingredient ). add (siftable );
9097 }
9198
9299 public static void registerSiftingRecipes () {
@@ -97,11 +104,12 @@ public static void registerSiftingRecipes() {
97104 ExNihiloRegistryManager .SIEVE_REGISTRY .getRegistry ().clear ();
98105 if (!siftablesDirt .isEmpty ()) {
99106 ExNihiloRegistryManager .SIEVE_REGISTRY .register (
100- Ingredient .fromStacks (OreDictUnifier .getAllWithOreDictionaryName ("dirt" ).toArray (new ItemStack [0 ])),
107+ Ingredient .fromStacks (
108+ OreDictUnifier .getAllWithOreDictionaryName ("dirt" ).toArray (new ItemStack [0 ])),
101109 siftablesDirt );
102110 }
103111 }
104- siftables .forEach (( ExNihiloRegistryManager .SIEVE_REGISTRY ::register ) );
112+ siftables .forEach (ExNihiloRegistryManager .SIEVE_REGISTRY ::register );
105113
106114 siftables = null ; // let this get GC'd, no more eating my memory
107115 }
0 commit comments