11package com .gregtechceu .gtceu .api .capability .recipe ;
22
3+ import com .gregtechceu .gtceu .GTCEu ;
34import com .gregtechceu .gtceu .api .machine .trait .RecipeHandlerList ;
45
56import it .unimi .dsi .fastutil .objects .Reference2ObjectOpenHashMap ;
910import java .util .Collections ;
1011import java .util .List ;
1112import java .util .Map ;
13+ import java .util .stream .Collectors ;
1214
1315public interface IRecipeCapabilityHolder {
1416
@@ -34,11 +36,25 @@ default List<IRecipeHandler<?>> getCapabilitiesFlat(IO io, RecipeCapability<?> c
3436 .getOrDefault (cap , Collections .emptyList ());
3537 }
3638
37- default void addHandlerList (RecipeHandlerList handler ) {
38- if (handler == RecipeHandlerList .NO_DATA ) return ;
39- IO io = handler .getHandlerIO ();
40- getCapabilitiesProxy ().computeIfAbsent (io , i -> new ArrayList <>()).add (handler );
41- var entrySet = handler .getHandlerMap ().entrySet ();
39+ default void addHandlerList (RecipeHandlerList handlerList ) {
40+ if (handlerList == RecipeHandlerList .NO_DATA ) return ;
41+ IO io = handlerList .getHandlerIO ();
42+
43+ var existingHandlers = getCapabilitiesProxy ().getOrDefault (io , Collections .emptyList ()).stream ()
44+ .flatMap (tempHandlerList -> tempHandlerList .getHandlersFlat ().stream ())
45+ .collect (Collectors .toSet ());
46+
47+ for (var handler : handlerList .getHandlersFlat ()) {
48+ if (existingHandlers .contains (handler )) {
49+ GTCEu .LOGGER .error ("Do not add the same handler twice, as this could cause duplication bugs! " +
50+ "Handler {} in List {}" ,
51+ handler .getClass ().getName (),
52+ handlerList .getClass ().getName ());
53+ }
54+ }
55+
56+ getCapabilitiesProxy ().computeIfAbsent (io , i -> new ArrayList <>()).add (handlerList );
57+ var entrySet = handlerList .getHandlerMap ().entrySet ();
4258 var inner = getCapabilitiesFlat ().computeIfAbsent (io , i -> new Reference2ObjectOpenHashMap <>(entrySet .size ()));
4359 for (var entry : entrySet ) {
4460 var entryList = entry .getValue ();
0 commit comments