Skip to content

Commit

Permalink
doesn't include null RHL in the handler map
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungOnionMC committed Jan 26, 2025
1 parent be65600 commit 401a253
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default List<IRecipeHandler<?>> getCapabilitiesFlat(IO io, RecipeCapability<?> c
}

default void addHandlerList(RecipeHandlerList handler) {
if (handler == RecipeHandlerList.NO_DATA) return;
IO io = handler.getHandlerIO();
getCapabilitiesProxy().computeIfAbsent(io, i -> new ArrayList<>()).add(handler);
var inner = getCapabilitiesFlat().computeIfAbsent(io, i -> new Reference2ObjectOpenHashMap<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ default boolean canShared() {
/**
* Get all available traits for recipe logic.
*/
@Nullable
RecipeHandlerList getRecipeHandlers();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gregtechceu.gtceu.api.machine.multiblock.part;

import com.gregtechceu.gtceu.api.capability.recipe.IO;
import com.gregtechceu.gtceu.api.capability.recipe.IRecipeHandler;
import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity;
import com.gregtechceu.gtceu.api.machine.MetaMachine;
Expand All @@ -20,6 +19,7 @@

import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.UnmodifiableView;

import java.util.Collections;
Expand Down Expand Up @@ -92,14 +92,15 @@ public SortedSet<IMultiController> getControllers() {
return Collections.unmodifiableSortedSet(controllers);
}

@Nullable
public RecipeHandlerList getRecipeHandlers() {
if (handlerList == null) {
var a = traits.stream()
.filter(IRecipeHandlerTrait.class::isInstance)
.map(IRecipeHandlerTrait.class::cast)
.toList();
if (a.isEmpty()) {
handlerList = new RecipeHandlerList(IO.NONE);
handlerList = RecipeHandlerList.NO_DATA;
return handlerList;
}
handlerList = new RecipeHandlerList(a.get(0).getHandlerIO());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

public class RecipeHandlerList {

public static RecipeHandlerList NO_DATA = new RecipeHandlerList(IO.NONE);

public static final Comparator<RecipeHandlerList> COMPARATOR = (h1, h2) -> {
int cmp = Long.compare(h1.getPriority(), h2.getPriority());
if (cmp != 0) return cmp;
Expand Down

0 comments on commit 401a253

Please sign in to comment.