forked from DaFuqs/Revelationary
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REI & JEI entry filtering: 1.20.6 edition
- Loading branch information
1 parent
4c17d66
commit 4f7c4be
Showing
9 changed files
with
178 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/main/java/de/dafuqs/revelationary/api/revelations/CloakSetChanged.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package de.dafuqs.revelationary.api.revelations; | ||
|
||
import net.fabricmc.fabric.api.event.Event; | ||
import net.fabricmc.fabric.api.event.EventFactory; | ||
import net.minecraft.item.Item; | ||
|
||
import java.util.Set; | ||
|
||
@FunctionalInterface | ||
public interface CloakSetChanged { | ||
Event<CloakSetChanged> EVENT = EventFactory.createArrayBacked(CloakSetChanged.class, | ||
(listeners) -> (addedCloaks, removedCloaks, newCloaks) -> { | ||
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); | ||
} |
53 changes: 53 additions & 0 deletions
53
src/main/java/de/dafuqs/revelationary/compat/jei/RevelationaryJEIPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package de.dafuqs.revelationary.compat.jei; | ||
|
||
import de.dafuqs.revelationary.Revelationary; | ||
import de.dafuqs.revelationary.api.revelations.CloakSetChanged; | ||
import de.dafuqs.revelationary.config.RevelationaryConfig; | ||
import mezz.jei.api.IModPlugin; | ||
import mezz.jei.api.constants.VanillaTypes; | ||
import mezz.jei.api.runtime.IJeiRuntime; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.Identifier; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public class RevelationaryJEIPlugin implements IModPlugin { | ||
private IJeiRuntime runtime; | ||
private Set<Item> stacksCache; | ||
|
||
public RevelationaryJEIPlugin() { | ||
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; | ||
CloakSetChanged.EVENT.register((added, removed, newStacks) -> { | ||
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())); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public @NotNull Identifier getPluginUid() { | ||
return new Identifier(Revelationary.MOD_ID, "jei_plugin"); | ||
} | ||
|
||
@Override | ||
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { | ||
runtime = jeiRuntime; | ||
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; | ||
if (stacksCache != null) runtime.getIngredientManager() | ||
.removeIngredientsAtRuntime(VanillaTypes.ITEM_STACK, | ||
stacksCache.stream().map(ItemStack::new).collect(Collectors.toList())); | ||
} | ||
|
||
@Override | ||
public void onRuntimeUnavailable() { | ||
runtime = null; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/de/dafuqs/revelationary/compat/rei/RevelationaryREIPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package de.dafuqs.revelationary.compat.rei; | ||
|
||
import de.dafuqs.revelationary.api.revelations.CloakSetChanged; | ||
import de.dafuqs.revelationary.config.RevelationaryConfig; | ||
import me.shedaniel.rei.api.client.entry.filtering.base.BasicFilteringRule; | ||
import me.shedaniel.rei.api.client.plugins.REIClientPlugin; | ||
import me.shedaniel.rei.api.common.util.EntryStacks; | ||
import net.minecraft.item.Item; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
public class RevelationaryREIPlugin implements REIClientPlugin { | ||
@SuppressWarnings("UnstableApiUsage") | ||
private BasicFilteringRule.MarkDirty filteringRule; | ||
private static Set<Item> hiddenStacks = Set.of(); | ||
|
||
public RevelationaryREIPlugin() { | ||
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; | ||
CloakSetChanged.EVENT.register((added, removed, newStacks) -> { | ||
hiddenStacks = newStacks; | ||
//noinspection UnstableApiUsage | ||
filteringRule.markDirty(); | ||
}); | ||
} | ||
|
||
@Override | ||
public void registerBasicEntryFiltering(@SuppressWarnings("UnstableApiUsage") BasicFilteringRule<?> rule) { | ||
// not using .show to not interfere with other filtering rules | ||
if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; | ||
//noinspection UnstableApiUsage | ||
filteringRule = rule.hide(() -> | ||
hiddenStacks.stream() | ||
.map(EntryStacks::of) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters