Skip to content

Commit 616f511

Browse files
authored
Remove hatch duplication on Research Computer, add Error for when that happens (#4126)
1 parent e4de172 commit 616f511

3 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/main/java/com/gregtechceu/gtceu/api/capability/recipe/IRecipeCapabilityHolder.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.gregtechceu.gtceu.api.capability.recipe;
22

3+
import com.gregtechceu.gtceu.GTCEu;
34
import com.gregtechceu.gtceu.api.machine.trait.RecipeHandlerList;
45

56
import it.unimi.dsi.fastutil.objects.Reference2ObjectOpenHashMap;
@@ -9,6 +10,7 @@
910
import java.util.Collections;
1011
import java.util.List;
1112
import java.util.Map;
13+
import java.util.stream.Collectors;
1214

1315
public 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();

src/main/java/com/gregtechceu/gtceu/api/machine/trait/RecipeHandlerList.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ public Map<RecipeCapability<?>, List<Object>> handleRecipe(IO io, GTRecipe recip
196196
return copy;
197197
}
198198

199+
public List<IRecipeHandler<?>> getHandlersFlat() {
200+
List<IRecipeHandler<?>> handlerList = new ArrayList<>();
201+
for (var handlerEntry : getHandlerMap().entrySet()) {
202+
handlerList.addAll(handlerEntry.getValue());
203+
}
204+
return handlerList;
205+
}
206+
199207
private record Subscription(List<ISubscription> subs) implements ISubscription {
200208

201209
@Override

src/main/java/com/gregtechceu/gtceu/common/machine/multiblock/electric/research/ResearchStationMachine.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import com.gregtechceu.gtceu.api.machine.feature.multiblock.IMultiPart;
1313
import com.gregtechceu.gtceu.api.machine.multiblock.MultiblockDisplayText;
1414
import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine;
15-
import com.gregtechceu.gtceu.api.machine.trait.RecipeHandlerList;
1615
import com.gregtechceu.gtceu.api.machine.trait.RecipeLogic;
1716
import com.gregtechceu.gtceu.api.recipe.ActionResult;
1817
import com.gregtechceu.gtceu.api.recipe.GTRecipe;
@@ -64,7 +63,6 @@ public void onStructureFormed() {
6463
return;
6564
}
6665
this.objectHolder = iObjectHolder;
67-
addHandlerList(RecipeHandlerList.of(IO.IN, iObjectHolder.getAsHandler()));
6866
}
6967

7068
part.self().holder.self()

0 commit comments

Comments
 (0)