diff --git a/api/build.gradle b/api/build.gradle index 6c428a7d2..b0eeca7df 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -2,6 +2,10 @@ import net.fabricmc.loom.task.RemapJarTask archivesBaseName = rootProject.name + "-" + project.name +loom { + accessWidenerPath = gradle.rootProject.project("fabric").file("src/main/resources/roughlyenoughitems.accessWidener") +} + dependencies { modCompileOnly("net.fabricmc:fabric-loader:${project.fabricloader_version}") modApi("me.shedaniel.cloth:cloth-config:${cloth_config_version}") diff --git a/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java b/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java index f9707be9a..8d4b45d4d 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/display/basic/BasicDisplay.java @@ -23,12 +23,11 @@ package me.shedaniel.rei.api.common.display.basic; -import dev.architectury.utils.EnvExecutor; -import dev.architectury.utils.GameInstance; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.display.SimpleDisplaySerializer; import me.shedaniel.rei.api.common.entry.EntryIngredient; import me.shedaniel.rei.api.common.util.EntryIngredients; +import me.shedaniel.rei.impl.common.InternalRegistryAccess; import net.minecraft.core.RegistryAccess; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; @@ -38,16 +37,12 @@ import java.util.List; import java.util.Optional; -import java.util.function.Supplier; /** * A basic implementation of a display, consisting of a list of inputs, a list of outputs * and a possible display location. */ public abstract class BasicDisplay implements Display { - protected static final Supplier REGISTRY_ACCESS = - EnvExecutor.getEnvSpecific(() -> () -> () -> GameInstance.getClient().player.level().registryAccess(), - () -> () -> () -> GameInstance.getServer().registryAccess()); protected List inputs; protected List outputs; protected Optional location; @@ -64,7 +59,7 @@ public BasicDisplay(List inputs, List outputs, @ApiStatus.Experimental public static RegistryAccess registryAccess() { - return REGISTRY_ACCESS.get(); + return InternalRegistryAccess.getInstance().get(); } /** diff --git a/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java b/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java new file mode 100644 index 000000000..2f1354c4a --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/impl/common/InternalRegistryAccess.java @@ -0,0 +1,86 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022, 2023 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.common; + +import dev.architectury.platform.Platform; +import dev.architectury.utils.Env; +import dev.architectury.utils.GameInstance; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; +import net.minecraft.core.RegistryAccess; +import net.minecraft.core.registries.BuiltInRegistries; +import org.jetbrains.annotations.ApiStatus; + +import java.lang.ref.WeakReference; +import java.util.function.Supplier; + +@ApiStatus.Internal +public final class InternalRegistryAccess implements Supplier { + private static final InternalRegistryAccess INSTANCE = new InternalRegistryAccess(); + private WeakReference registryAccess; + private boolean warned; + + public static InternalRegistryAccess getInstance() { + return INSTANCE; + } + + @Override + public RegistryAccess get() { + RegistryAccess access = this.registryAccess == null ? null : this.registryAccess.get(); + if (access != null) { + return access; + } + + if (Platform.getEnvironment() == Env.CLIENT) { + access = getFromClient(); + } else if (GameInstance.getServer() != null) { + access = GameInstance.getServer().registryAccess(); + } + + if (access == null && !this.warned) { + this.warned = true; + + new NullPointerException("Cannot get registry access!").printStackTrace(); + InternalLogger.getInstance().warn("Cannot get registry access!"); + return RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY); + } + + return access; + } + + @Environment(EnvType.CLIENT) + private static RegistryAccess getFromClient() { + if (Minecraft.getInstance().level != null) { + return Minecraft.getInstance().level.registryAccess(); + } else if (Minecraft.getInstance().getConnection() != null) { + return Minecraft.getInstance().getConnection().registryAccess(); + } else if (Minecraft.getInstance().gameMode != null) { + // Sometimes the packet is sent way too fast and is between the connection and the level, better safe than sorry + return Minecraft.getInstance().gameMode.connection.registryAccess(); + } + + return null; + } +} diff --git a/build.gradle b/build.gradle index ec27f7dba..b116e5321 100755 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,6 @@ plugins { id("architectury-plugin") version("3.4-SNAPSHOT") - id("dev.architectury.loom") version("1.6-SNAPSHOT") apply false + id("dev.architectury.loom") version("1.7-SNAPSHOT") apply false id("org.cadixdev.licenser") version("0.6.1") id("me.shedaniel.unified-publishing") version("0.1.+") id("maven-publish") diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java index 0cb016597..a98ee1563 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/DefaultPlugin.java @@ -64,11 +64,8 @@ public class DefaultPlugin implements BuiltinPlugin, REIServerPlugin { @Override public void registerItemComparators(ItemComparatorRegistry registry) { Function enchantmentTag = stack -> { - if (!stack.has(DataComponents.ENCHANTMENTS)) { - if (stack.has(DataComponents.STORED_ENCHANTMENTS)) { - return stack.get(DataComponents.STORED_ENCHANTMENTS); - } - return null; + if (stack.has(DataComponents.STORED_ENCHANTMENTS)) { + return stack.get(DataComponents.STORED_ENCHANTMENTS); } return stack.get(DataComponents.ENCHANTMENTS); }; diff --git a/fabric/build.gradle b/fabric/build.gradle index 496ea21d4..02676a865 100644 --- a/fabric/build.gradle +++ b/fabric/build.gradle @@ -150,7 +150,7 @@ unifiedPublishing { token = project.hasProperty("modrinth_key") ? project.property("modrinth_key") : System.getenv("modrinth_key") id = "nfn13YXA" version = "$project.version+$project.name" - gameVersions.addAll project.minecraft_version, "1.20.6" + gameVersions.addAll project.minecraft_version } } } diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java index 7a76fd090..660ebefaa 100644 --- a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java +++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java @@ -23,10 +23,10 @@ package me.shedaniel.rei.impl.client.fabric; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.impl.common.InternalLogger; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; -import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.flag.FeatureFlagSet; @@ -35,16 +35,13 @@ import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.ItemStack; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; public class CreativeModeTabCollectorImpl { public static Map> collectTabs() { Map> map = new LinkedHashMap<>(); FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); - CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, BasicDisplay.registryAccess()); for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) { diff --git a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java index 4b4f394e7..4cff54d51 100644 --- a/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java +++ b/fabric/src/main/java/me/shedaniel/rei/mixin/fabric/MixinClientPacketListener.java @@ -25,6 +25,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket; import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; import net.minecraft.world.item.crafting.RecipeManager; @@ -36,12 +37,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPacketListener.class) -public class MixinClientPacketListener { +public abstract class MixinClientPacketListener { @Shadow @Final private RecipeManager recipeManager; + @Shadow public abstract RegistryAccess.Frozen registryAccess(); + @Inject(method = "handleUpdateRecipes", at = @At("HEAD")) private void handleUpdateRecipes(ClientboundUpdateRecipesPacket clientboundUpdateRecipesPacket, CallbackInfo ci) { - RoughlyEnoughItemsCoreClient.PRE_UPDATE_RECIPES.invoker().update(recipeManager); + RoughlyEnoughItemsCoreClient.PRE_UPDATE_RECIPES.invoker().accept(recipeManager, registryAccess()); } @Inject(method = "handleUpdateTags", at = @At("HEAD")) diff --git a/fabric/src/main/resources/roughlyenoughitems.accessWidener b/fabric/src/main/resources/roughlyenoughitems.accessWidener index 2430ce5b4..461372b01 100644 --- a/fabric/src/main/resources/roughlyenoughitems.accessWidener +++ b/fabric/src/main/resources/roughlyenoughitems.accessWidener @@ -39,3 +39,4 @@ accessible field net/minecraft/world/item/crafting/SmithingTrimRecipe base Lnet/ accessible field net/minecraft/world/item/crafting/SmithingTrimRecipe addition Lnet/minecraft/world/item/crafting/Ingredient; accessible field net/minecraft/world/item/CreativeModeTab displayItemsGenerator Lnet/minecraft/world/item/CreativeModeTab$DisplayItemsGenerator; accessible class net/minecraft/world/item/CreativeModeTab$ItemDisplayBuilder +accessible field net/minecraft/client/multiplayer/MultiPlayerGameMode connection Lnet/minecraft/client/multiplayer/ClientPacketListener; \ No newline at end of file diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java index 13f06f360..09c23d298 100644 --- a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java @@ -23,6 +23,7 @@ package me.shedaniel.rei.impl.client.forge; +import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.impl.common.InternalLogger; import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; @@ -37,12 +38,13 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; public class CreativeModeTabCollectorImpl { public static Map> collectTabs() { Map> map = new LinkedHashMap<>(); FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); - CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY)); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, Objects.requireNonNullElseGet(BasicDisplay.registryAccess(), () -> RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY))); for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) { diff --git a/gradle.properties b/gradle.properties index 840816220..8bb2d3117 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,12 +5,12 @@ supported_version=1.21 minecraft_version=1.21 platforms=fabric,neoforge forge_version=49.0.3 -neoforge_version=21.0.10-beta +neoforge_version=21.0.167 neoforge_pr= -fabricloader_version=0.15.11 -cloth_config_version=15.0.127 +fabricloader_version=0.16.0 +cloth_config_version=15.0.130 modmenu_version=11.0.0-rc.2 -fabric_api=0.100.1+1.21 -architectury_version=13.0.1 +fabric_api=0.102.0+1.21 +architectury_version=13.0.6 api_exculde= #api_include=me.shedaniel.cloth:cloth-events,me.shedaniel.cloth:config-2,me.sargunvohra.mcmods:autoconfig1u,org.jetbrains:annotations,net.fabricmc.fabric-api:fabric diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f9014382c..c747c1bd8 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-all.zip diff --git a/neoforge/build.gradle b/neoforge/build.gradle index 3b2fb82a8..6f5b97cbf 100644 --- a/neoforge/build.gradle +++ b/neoforge/build.gradle @@ -227,7 +227,7 @@ unifiedPublishing { token = project.hasProperty("danielshe_curse_api_key") ? project.property("danielshe_curse_api_key") : System.getenv("danielshe_curse_api_key") id = "567899" gameVersions.addAll "Java 17" - gameVersions.addAll project.minecraft_version, "1.20.6" + gameVersions.addAll project.minecraft_version } } @@ -237,7 +237,7 @@ unifiedPublishing { token = project.hasProperty("modrinth_key") ? project.property("modrinth_key") : System.getenv("modrinth_key") id = "OM4ZYSws" version = "$project.version+$project.name" - gameVersions.addAll project.minecraft_version, "1.20.6" + gameVersions.addAll project.minecraft_version } } } diff --git a/neoforge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java b/neoforge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java index b6033245b..57b097ec6 100644 --- a/neoforge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java +++ b/neoforge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java @@ -23,10 +23,8 @@ package me.shedaniel.rei.impl.client.forge; -import com.google.common.base.MoreObjects; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.impl.common.InternalLogger; -import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.flag.FeatureFlagSet; @@ -39,13 +37,12 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; -import java.util.Objects; public class CreativeModeTabCollectorImpl { public static Map> collectTabs() { Map> map = new LinkedHashMap<>(); FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); - CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, Objects.requireNonNullElseGet(BasicDisplay.registryAccess(), () -> RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY))); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, BasicDisplay.registryAccess()); for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) { diff --git a/neoforge/src/main/java/me/shedaniel/rei/mixin/forge/MixinClientPacketListener.java b/neoforge/src/main/java/me/shedaniel/rei/mixin/forge/MixinClientPacketListener.java index 333f8fdbc..7b059f109 100644 --- a/neoforge/src/main/java/me/shedaniel/rei/mixin/forge/MixinClientPacketListener.java +++ b/neoforge/src/main/java/me/shedaniel/rei/mixin/forge/MixinClientPacketListener.java @@ -25,6 +25,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCoreClient; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.core.RegistryAccess; import net.minecraft.network.protocol.common.ClientboundUpdateTagsPacket; import net.minecraft.network.protocol.game.ClientboundUpdateRecipesPacket; import net.minecraft.world.item.crafting.RecipeManager; @@ -36,12 +37,14 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(ClientPacketListener.class) -public class MixinClientPacketListener { +public abstract class MixinClientPacketListener { @Shadow @Final private RecipeManager recipeManager; + @Shadow public abstract RegistryAccess.Frozen registryAccess(); + @Inject(method = "handleUpdateRecipes", at = @At("HEAD")) private void handleUpdateRecipes(ClientboundUpdateRecipesPacket clientboundUpdateRecipesPacket, CallbackInfo ci) { - RoughlyEnoughItemsCoreClient.PRE_UPDATE_RECIPES.invoker().update(recipeManager); + RoughlyEnoughItemsCoreClient.PRE_UPDATE_RECIPES.invoker().accept(recipeManager, registryAccess()); } @Inject(method = "handleUpdateTags", at = @At("HEAD")) diff --git a/neoforge/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/forge/DefaultCraftingDisplayImpl.java b/neoforge/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/forge/DefaultCraftingDisplayImpl.java index 1c3f28a37..0ad27549a 100644 --- a/neoforge/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/forge/DefaultCraftingDisplayImpl.java +++ b/neoforge/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/forge/DefaultCraftingDisplayImpl.java @@ -23,18 +23,7 @@ package me.shedaniel.rei.plugin.common.displays.crafting.forge; -import me.shedaniel.rei.plugin.common.displays.crafting.CraftingRecipeSizeProvider; -import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; -import net.neoforged.neoforge.common.crafting.IShapedRecipe; - public class DefaultCraftingDisplayImpl { public static void registerPlatformSizeProvider() { - DefaultCraftingDisplay.registerSizeProvider(recipe -> { - if (recipe instanceof IShapedRecipe) { - return new CraftingRecipeSizeProvider.Size(((IShapedRecipe) recipe).getWidth(), ((IShapedRecipe) recipe).getHeight()); - } - - return null; - }); } } diff --git a/neoforge/src/main/resources/META-INF/accesstransformer.cfg b/neoforge/src/main/resources/META-INF/accesstransformer.cfg index d1b35d717..2d87bddf1 100644 --- a/neoforge/src/main/resources/META-INF/accesstransformer.cfg +++ b/neoforge/src/main/resources/META-INF/accesstransformer.cfg @@ -48,3 +48,4 @@ public-f net.minecraft.client.gui.font.CodepointMap blockMap # blockMap public-f net.minecraft.client.gui.font.CodepointMap blockConstructor # blockConstructor public net.minecraft.world.item.CreativeModeTab displayItemsGenerator # displayItemsGenerator public net.minecraft.world.item.CreativeModeTab$ItemDisplayBuilder +public net.minecraft.client.multiplayer.MultiPlayerGameMode connection # connection diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java index f25e40735..055f92d38 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCoreClient.java @@ -100,6 +100,7 @@ import net.minecraft.client.gui.screens.recipebook.GhostRecipe; import net.minecraft.client.gui.screens.recipebook.RecipeBookComponent; import net.minecraft.client.resources.language.I18n; +import net.minecraft.core.RegistryAccess; import net.minecraft.data.models.blockstates.PropertyDispatch; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -112,6 +113,7 @@ import net.minecraft.world.item.Items; import net.minecraft.world.item.TooltipFlag; import net.minecraft.world.item.crafting.Ingredient; +import net.minecraft.world.item.crafting.RecipeManager; import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -120,15 +122,12 @@ import java.util.ConcurrentModificationException; import java.util.List; import java.util.concurrent.*; -import java.util.function.BiFunction; -import java.util.function.BooleanSupplier; -import java.util.function.Function; -import java.util.function.Supplier; +import java.util.function.*; import java.util.stream.Stream; @Environment(EnvType.CLIENT) public class RoughlyEnoughItemsCoreClient { - public static final Event PRE_UPDATE_RECIPES = EventFactory.createLoop(); + public static final Event> PRE_UPDATE_RECIPES = EventFactory.createLoop(); public static final Event POST_UPDATE_TAGS = EventFactory.createLoop(); public static boolean isLeftMousePressed = false; private static final ExecutorService RELOAD_PLUGINS = Executors.newSingleThreadScheduledExecutor(task -> { @@ -317,9 +316,9 @@ private void registerEvents() { final ResourceLocation recipeButtonTex = ResourceLocation.withDefaultNamespace("textures/gui/recipe_button.png"); MutableLong startReload = new MutableLong(-1); MutableLong endReload = new MutableLong(-1); - PRE_UPDATE_RECIPES.register(recipeManager -> { + PRE_UPDATE_RECIPES.register((recipeManager, registryAccess) -> { RoughlyEnoughItemsCore.PERFORMANCE_LOGGER.clear(); - reloadPlugins(startReload, ReloadStage.START); + reloadPlugins(startReload, ReloadStage.START, registryAccess); }); ClientRecipeUpdateEvent.EVENT.register(recipeManager -> { reloadPlugins(endReload, ReloadStage.END); @@ -469,6 +468,11 @@ public static boolean resetFocused(Screen screen) { @ApiStatus.Internal public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start) { + reloadPlugins(lastReload, start, null); + } + + @ApiStatus.Internal + public static void reloadPlugins(MutableLong lastReload, @Nullable ReloadStage start, @Nullable RegistryAccess registryAccess) { if (Minecraft.getInstance().level == null) return; if (lastReload != null) { if (lastReload.getValue() > 0 && System.currentTimeMillis() - lastReload.getValue() <= 5000) {