diff --git a/build.gradle b/build.gradle index d7d0ca6..279bfb7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' + id 'fabric-loom' version '1.5-SNAPSHOT' id 'maven-publish' } @@ -12,9 +12,10 @@ group = project.maven_group repositories { mavenCentral() - maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.terraformersmc.com" } maven { url "https://api.modrinth.com/maven/" } + maven { url "https://maven.blamejared.com/" } + maven { url "https://maven.shedaniel.me/" } maven { url "https://maven2.bai.lol" } } @@ -32,6 +33,15 @@ dependencies { modCompileOnly "maven.modrinth:jade:${project.jade_version}" modCompileOnly "mcp.mobius.waila:wthit-api:fabric-${project.wthit_version}" + + modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}" + + // modCompileOnlyApi "mezz.jei:jei-${project.minecraft_version}-common-api:${project.jei_version}" + // modCompileOnlyApi "mezz.jei:jei-${project.minecraft_version}-fabric-api:${project.jei_version}" + + // required due to stupid mapping error + // revert when this issue is resolved: https://github.com/mezz/JustEnoughItems/issues/3451 + modCompileOnly files("libs/jei-1.20.1-fabric-15.3.0.4.jar") } processResources { diff --git a/gradle.properties b/gradle.properties index 92b4c49..3a1209d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,4 +15,6 @@ archives_base_name = revelationary fabric_version=0.90.0+1.20.1 jade_version=QhvPNPdp -wthit_version=8.5.0 \ No newline at end of file +wthit_version=8.5.0 +rei_version=12.1.725 +jei_version=15.3.0.4 \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index e750102..17655d0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/libs/jei-1.20.1-fabric-15.3.0.4.jar b/libs/jei-1.20.1-fabric-15.3.0.4.jar new file mode 100644 index 0000000..9ea20b3 Binary files /dev/null and b/libs/jei-1.20.1-fabric-15.3.0.4.jar differ diff --git a/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java b/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java index 915a1d5..31f58e4 100644 --- a/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java +++ b/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java @@ -1,5 +1,7 @@ package de.dafuqs.revelationary; +import com.google.common.collect.Sets; +import de.dafuqs.revelationary.api.revelations.CloakSetChanged; import de.dafuqs.revelationary.api.revelations.RevealingCallback; import de.dafuqs.revelationary.api.revelations.RevelationAware; import de.dafuqs.revelationary.api.revelations.WorldRendererAccessor; @@ -24,8 +26,21 @@ public class ClientRevelationHolder { public static List callbacks = new ArrayList<>(); private static final Set activeBlockStateSwaps = new HashSet<>(); + // used for creating diffs for CloakSetChanged event + private static Set previousActiveItemSwaps = new HashSet<>(); private static final Set activeItemSwaps = new HashSet<>(); - + + private static void onItemSwap(boolean cloak) { + var diff = cloak ? Sets.difference(activeItemSwaps, previousActiveItemSwaps) : Sets.difference(previousActiveItemSwaps, activeItemSwaps); + var copy = Set.copyOf(activeItemSwaps); + var emptySet = Set.of(); + // that is a legal expression, apparently + if (cloak) + CloakSetChanged.EVENT.invoker().onChange(diff, emptySet, copy); + else CloakSetChanged.EVENT.invoker().onChange(emptySet, diff, copy); + previousActiveItemSwaps = copy; + } + public static void processNewAdvancements(Set doneAdvancements, boolean isJoinPacket) { if (!doneAdvancements.isEmpty()) { Set revealedItems = new HashSet<>(); @@ -39,15 +54,13 @@ public static void processNewAdvancements(Set doneAdvancements, bool revealedBlocks.add(block); } } - - if (revealedBlockStates.size() > 0) { + activeBlockStateSwaps.removeAll(revealedBlockStates); + + if (!revealedBlocks.isEmpty()) { // uncloak the blocks - for (BlockState revealedBlockState : revealedBlockStates) { - activeBlockStateSwaps.remove(revealedBlockState); - Item blockItem = revealedBlockState.getBlock().asItem(); - if (blockItem != null) { - activeItemSwaps.remove(blockItem); - } + for (Block revealedBlock: revealedBlocks) { + Item blockItem = revealedBlock.asItem(); + if (blockItem != null) activeItemSwaps.remove(blockItem); } rebuildAllChunks(); } @@ -68,6 +81,7 @@ public static void processNewAdvancements(Set doneAdvancements, bool for (RevealingCallback callback : callbacks) { callback.trigger(doneAdvancements, revealedBlocks, revealedItems, isJoinPacket); } + onItemSwap(false); } } } @@ -87,19 +101,13 @@ public static void processRemovedAdvancements(@NotNull Set removedAd } } } - - if (concealedBlockStates.size() > 0) { + + activeBlockStateSwaps.addAll(concealedBlockStates); + if (!concealedBlocks.isEmpty()) { // uncloak the blocks - for (BlockState concealedBlockState : concealedBlockStates) { - if (!activeBlockStateSwaps.contains(concealedBlockState)) { - activeBlockStateSwaps.add(concealedBlockState); - } - Item blockItem = concealedBlockState.getBlock().asItem(); - if (blockItem != null) { - if (!activeItemSwaps.contains(blockItem)) { - activeItemSwaps.add(blockItem); - } - } + for (Block concealedBlock : concealedBlocks) { + Item blockItem = concealedBlock.asItem(); + if (blockItem != null) activeItemSwaps.add(blockItem); } rebuildAllChunks(); } @@ -116,6 +124,7 @@ public static void processRemovedAdvancements(@NotNull Set removedAd revelationAware.onCloak(); } } + if (!concealedBlocks.isEmpty() || !concealedItems.isEmpty()) onItemSwap(true); } } @@ -183,6 +192,7 @@ public static void cloakAll() { cloak(registeredRevelation); } } + onItemSwap(true); } } diff --git a/src/main/java/de/dafuqs/revelationary/api/revelations/CloakSetChanged.java b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakSetChanged.java new file mode 100644 index 0000000..d855eff --- /dev/null +++ b/src/main/java/de/dafuqs/revelationary/api/revelations/CloakSetChanged.java @@ -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 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 addedCloaks, Set removedCloaks, Set newCloaks); +} diff --git a/src/main/java/de/dafuqs/revelationary/compat/jei/RevelationaryJEIPlugin.java b/src/main/java/de/dafuqs/revelationary/compat/jei/RevelationaryJEIPlugin.java new file mode 100644 index 0000000..437570b --- /dev/null +++ b/src/main/java/de/dafuqs/revelationary/compat/jei/RevelationaryJEIPlugin.java @@ -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 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; + } +} diff --git a/src/main/java/de/dafuqs/revelationary/compat/rei/RevelationaryREIPlugin.java b/src/main/java/de/dafuqs/revelationary/compat/rei/RevelationaryREIPlugin.java new file mode 100644 index 0000000..1db4445 --- /dev/null +++ b/src/main/java/de/dafuqs/revelationary/compat/rei/RevelationaryREIPlugin.java @@ -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 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 + //noinspection UnstableApiUsage + if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; + filteringRule = rule.hide(() -> + hiddenStacks.stream() + .map(EntryStacks::of) + .collect(Collectors.toList()) + ); + } +} diff --git a/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java b/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java index 54a780a..085465f 100644 --- a/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java +++ b/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java @@ -22,6 +22,7 @@ public static Config get() { public static class Config { public boolean PreventMiningOfUnrevealedBlocks = false; public boolean UseTargetBlockOrItemNameInsteadOfScatter = false; + public boolean HideCloakedEntriesFromRecipeViewers = true; public String NameForUnrevealedBlocks = ""; public String NameForUnrevealedItems = ""; diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 25f4742..e680013 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -24,6 +24,12 @@ ], "jade": [ "de.dafuqs.revelationary.compat.jade.RevelationaryJadePlugin" + ], + "jei_mod_plugin": [ + "de.dafuqs.revelationary.compat.jei.RevelationaryJEIPlugin" + ], + "rei_client": [ + "de.dafuqs.revelationary.compat.rei.RevelationaryREIPlugin" ] }, "mixins": [