diff --git a/build.gradle b/build.gradle index ec9cfb0..1656e4c 100644 --- a/build.gradle +++ b/build.gradle @@ -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,16 @@ dependencies { modCompileOnly "maven.modrinth:jade:${project.jade_version}" modCompileOnly "mcp.mobius.waila:wthit-api:fabric-${project.wthit_version}" + + modApi "dev.architectury:architectury-fabric:${project.architectury_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.6-fabric-18.0.0.62.jar") } processResources { diff --git a/gradle.properties b/gradle.properties index 091bea3..fe4760c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,17 +2,22 @@ org.gradle.jvmargs = -Xmx2G # Fabric Properties -minecraft_version=1.20.5 -yarn_mappings=1.20.5+build.1 -loader_version=0.15.10 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.3 +loader_version=0.15.11 # Mod Properties -mod_version = 1.3.7+1.20.5 +mod_version = 1.3.8+1.20.6 maven_group = de.dafuqs.revelationary archives_base_name = revelationary # https://fabricmc.net/develop/ -fabric_version=0.97.8+1.20.5 +fabric_version=0.100.0+1.20.6 -jade_version=lwgbRGaY -wthit_version=11.1.2 \ No newline at end of file +jade_version=H9wg0p1c +wthit_version=11.3.1 + +rei_version=16.0.729 +jei_version=18.0.0.62 + +architectury_version=12.1.3 \ No newline at end of file diff --git a/libs/jei-1.20.6-fabric-18.0.0.62.jar b/libs/jei-1.20.6-fabric-18.0.0.62.jar new file mode 100644 index 0000000..553ad5f Binary files /dev/null and b/libs/jei-1.20.6-fabric-18.0.0.62.jar differ diff --git a/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java b/src/main/java/de/dafuqs/revelationary/ClientRevelationHolder.java index cae7aeb..4eaca95 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,7 +26,20 @@ 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()) { @@ -39,24 +54,22 @@ public static void processNewAdvancements(Set doneAdvancements, bool revealedBlocks.add(block); } } + + // Handle edge case of block states revealed but not blocks; + // Checking for revealed blocks isn't necessary as they're derived from revealed block states. + final boolean blocksRevealed = activeBlockStateSwaps.removeAll(revealedBlockStates); - if (!revealedBlockStates.isEmpty()) { + if (!revealedBlocks.isEmpty()) { // uncloak the blocks - for (BlockState revealedBlockState : revealedBlockStates) { - activeBlockStateSwaps.remove(revealedBlockState); - Item blockItem = revealedBlockState.getBlock().asItem(); - if (blockItem != null) { - activeItemSwaps.remove(blockItem); - } - } - rebuildAllChunks(); - } - - for (Block revealedBlock : revealedBlocks) { - if (revealedBlock instanceof RevelationAware revelationAware) { - revelationAware.onUncloak(); + for (Block revealedBlock: revealedBlocks) { + Item blockItem = revealedBlock.asItem(); + if (blockItem != null) activeItemSwaps.remove(blockItem); + if (revealedBlock instanceof RevelationAware revelationAware) revelationAware.onUncloak(); } } + + if (blocksRevealed) rebuildAllChunks(); + for (Item revealedItem : revealedItems) { activeItemSwaps.remove(revealedItem); if (revealedItem instanceof RevelationAware revelationAware) { @@ -68,6 +81,7 @@ public static void processNewAdvancements(Set doneAdvancements, bool for (RevealingCallback callback : callbacks) { callback.trigger(doneAdvancements, revealedBlocks, revealedItems, isJoinPacket); } + onItemSwap(false); } } } @@ -87,16 +101,20 @@ public static void processRemovedAdvancements(@NotNull Set removedAd } } } - - if (!concealedBlockStates.isEmpty()) { + + // Handle edge case of block states concealed but not blocks; + // Checking for concealed blocks isn't necessary as they're derived from concealed block states. + final boolean blocksConcealed = activeBlockStateSwaps.addAll(concealedBlockStates); + + if (!concealedBlocks.isEmpty()) { // uncloak the blocks - for (BlockState concealedBlockState : concealedBlockStates) { - activeBlockStateSwaps.add(concealedBlockState); - Item blockItem = concealedBlockState.getBlock().asItem(); + for (Block concealedBlock : concealedBlocks) { + Item blockItem = concealedBlock.asItem(); if (blockItem != null) activeItemSwaps.add(blockItem); } - rebuildAllChunks(); } + + if (blocksConcealed) rebuildAllChunks(); activeItemSwaps.addAll(concealedItems); @@ -110,6 +128,7 @@ public static void processRemovedAdvancements(@NotNull Set removedAd revelationAware.onCloak(); } } + if (!concealedBlocks.isEmpty() || !concealedItems.isEmpty()) onItemSwap(true); } } @@ -177,6 +196,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..c6e0678 --- /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 + if (!RevelationaryConfig.get().HideCloakedEntriesFromRecipeViewers) return; + //noinspection UnstableApiUsage + 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 a37c2df..d7a1a16 100644 --- a/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java +++ b/src/main/java/de/dafuqs/revelationary/config/RevelationaryConfig.java @@ -21,6 +21,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 f0aaa38..8761400 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": [ @@ -32,7 +38,7 @@ "depends": { "fabricloader": "*", "fabric": "*", - "minecraft": ">=1.20.5", + "minecraft": ">=1.20.6 <1.21", "java": ">=21" }, "suggests": {