Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JEI fixes #20

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package de.dafuqs.revelationary.api.revelations;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.Item;

import java.util.Set;

@Environment(EnvType.CLIENT)
@FunctionalInterface
public interface CloakSetChanged {
Event<CloakSetChanged> EVENT = EventFactory.createArrayBacked(CloakSetChanged.class,
(listeners) -> (addedCloaks, removedCloaks, newCloaks) -> {
for (CloakSetChanged listener : listeners) listener.onChange(addedCloaks, removedCloaks, newCloaks);
MinecraftClient.getInstance().execute(() -> {
for (CloakSetChanged listener : listeners) listener.onChange(addedCloaks, removedCloaks, newCloaks);
});
});
// the diffs matter for JEI, the new cloaks set matters for REI
void onChange(Set<Item> addedCloaks, Set<Item> removedCloaks, Set<Item> newCloaks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public RevelationaryJEIPlugin() {
stacksCache = newStacks;
if (runtime != null) {
var manager = runtime.getIngredientManager();
manager.removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK,
added.stream().map(ItemStack::new).collect(Collectors.toList()));
manager.addIngredientsAtRuntime(VanillaTypes.ITEM_STACK,
removed.stream().map(ItemStack::new).collect(Collectors.toList()));
if(added != null && !added.isEmpty())
manager.removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK,
added.stream().map(ItemStack::new).collect(Collectors.toList()));
if(removed != null && !removed.isEmpty())
manager.addIngredientsAtRuntime(VanillaTypes.ITEM_STACK,
removed.stream().map(ItemStack::new).collect(Collectors.toList()));
}
});
}
Expand All @@ -41,7 +43,7 @@ public RevelationaryJEIPlugin() {
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
runtime = jeiRuntime;
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return;
if (stacksCache != null) runtime.getIngredientManager()
if (stacksCache != null && !stacksCache.isEmpty()) runtime.getIngredientManager()
.removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK,
stacksCache.stream().map(ItemStack::new).collect(Collectors.toList()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public RevelationaryREIPlugin() {
@Override
public void registerBasicEntryFiltering(@SuppressWarnings("UnstableApiUsage") BasicFilteringRule<?> rule) {
// not using .show to not interfere with other filtering rules
//noinspection UnstableApiUsage
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return;
//noinspection UnstableApiUsage
filteringRule = rule.hide(() ->
hiddenStacks.stream()
.map(EntryStacks::of)
Expand Down
Loading