Skip to content

Commit

Permalink
fix jei hard dep 💀
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed Sep 23, 2023
1 parent 9c6ad15 commit 52cec98
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
import com.cleanroommc.modularui.api.widget.IGuiElement;
import com.cleanroommc.modularui.api.widget.IWidget;
import mezz.jei.api.gui.IGhostIngredientHandler;
import net.minecraftforge.fml.common.Optional;
import org.jetbrains.annotations.NotNull;

import java.awt.*;

@Optional.Interface(iface = "mezz.jei.api.gui.IGhostIngredientHandler$Target", modid = "jei")
public class GhostIngredientTarget<I> implements IGhostIngredientHandler.Target<I> {

private final IGuiElement guiElement;
Expand Down
20 changes: 14 additions & 6 deletions src/main/java/com/cleanroommc/modularui/screen/JeiSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.awt.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -88,11 +89,18 @@ public java.util.List<JeiGhostIngredientSlot<?>> getJeiGhostIngredientSlots() {

@Optional.Method(modid = "jei")
public <I> List<IGhostIngredientHandler.Target<I>> getAllGhostIngredientTargets(@NotNull I ingredient) {
this.jeiGhostIngredientSlots.removeIf(widget -> !((IWidget) widget).isValid());
return this.jeiGhostIngredientSlots.stream()
.filter(slot -> ((IWidget) slot).isEnabled())
.filter(slot -> slot.castGhostIngredientIfValid(ingredient) != null)
.map(slot -> (IGhostIngredientHandler.Target<I>) GhostIngredientTarget.of(slot))
.collect(Collectors.toList());
List<IGhostIngredientHandler.Target<I>> ghostHandlerTargets = new ArrayList<>();
for (Iterator<JeiGhostIngredientSlot<?>> iterator = this.jeiGhostIngredientSlots.iterator(); iterator.hasNext(); ) {
JeiGhostIngredientSlot<?> slot = iterator.next();
IWidget widget = (IWidget) slot;
if (!widget.isValid()) {
iterator.remove();
continue;
}
if (widget.isEnabled() && slot.castGhostIngredientIfValid(ingredient) != null) {
ghostHandlerTargets.add((IGhostIngredientHandler.Target<I>) new GhostIngredientTarget<>(widget, slot));
}
}
return ghostHandlerTargets;
}
}

0 comments on commit 52cec98

Please sign in to comment.