diff --git a/patches/net/minecraft/client/multiplayer/ClientPacketListener.java.patch b/patches/net/minecraft/client/multiplayer/ClientPacketListener.java.patch index ba17981ad6..c244326521 100644 --- a/patches/net/minecraft/client/multiplayer/ClientPacketListener.java.patch +++ b/patches/net/minecraft/client/multiplayer/ClientPacketListener.java.patch @@ -8,14 +8,16 @@ @Nullable private LevelLoadStatusManager levelLoadStatusManager; private boolean serverEnforcesSecureChat; -@@ -366,6 +_,7 @@ +@@ -366,7 +_,8 @@ p_253924_.gui.getChat().restoreState(p_295121_.chatState()); } +- this.potionBrewing = PotionBrewing.bootstrap(this.enabledFeatures); + this.connectionType = p_295121_.connectionType(); - this.potionBrewing = PotionBrewing.bootstrap(this.enabledFeatures); ++ this.potionBrewing = PotionBrewing.bootstrap(this.enabledFeatures, this.registryAccess); } + public ClientSuggestionProvider getSuggestionsProvider() { @@ -427,12 +_,13 @@ this.minecraft.debugRenderer.clear(); diff --git a/patches/net/minecraft/server/MinecraftServer.java.patch b/patches/net/minecraft/server/MinecraftServer.java.patch index 5d60f55f4d..cebd24b556 100644 --- a/patches/net/minecraft/server/MinecraftServer.java.patch +++ b/patches/net/minecraft/server/MinecraftServer.java.patch @@ -9,6 +9,15 @@ thread.setUncaughtExceptionHandler((p_177909_, p_177910_) -> LOGGER.error("Uncaught exception in server thread", p_177910_)); if (Runtime.getRuntime().availableProcessors() > 4) { thread.setPriority(8); +@@ -315,7 +_,7 @@ + this.structureTemplateManager = new StructureTemplateManager(p_236726_.resourceManager(), p_236724_, p_236728_, holdergetter); + this.serverThread = p_236723_; + this.executor = Util.backgroundExecutor(); +- this.potionBrewing = PotionBrewing.bootstrap(this.worldData.enabledFeatures()); ++ this.potionBrewing = PotionBrewing.bootstrap(this.worldData.enabledFeatures(), this.registryAccess()); + } + } + @@ -372,6 +_,7 @@ this.readScoreboard(dimensiondatastorage); this.commandStorage = new CommandStorage(dimensiondatastorage); diff --git a/patches/net/minecraft/world/item/alchemy/PotionBrewing.java.patch b/patches/net/minecraft/world/item/alchemy/PotionBrewing.java.patch index 9c3be6f23f..7612a5fff4 100644 --- a/patches/net/minecraft/world/item/alchemy/PotionBrewing.java.patch +++ b/patches/net/minecraft/world/item/alchemy/PotionBrewing.java.patch @@ -56,11 +56,22 @@ Optional> optional = p_43531_.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion(); if (optional.isEmpty()) { return p_43531_; -@@ -127,6 +_,7 @@ +@@ -124,9 +_,18 @@ + } + } + ++ /** ++ * @deprecated Use {@link #bootstrap(FeatureFlagSet, net.minecraft.core.RegistryAccess)} instead ++ */ ++ @Deprecated public static PotionBrewing bootstrap(FeatureFlagSet p_341301_) { ++ return bootstrap(p_341301_, net.minecraft.core.RegistryAccess.EMPTY); ++ } ++ ++ public static PotionBrewing bootstrap(FeatureFlagSet p_341301_, net.minecraft.core.RegistryAccess registryAccess) { PotionBrewing.Builder potionbrewing$builder = new PotionBrewing.Builder(p_341301_); addVanillaMixes(potionbrewing$builder); -+ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent(potionbrewing$builder)); ++ net.neoforged.neoforge.common.NeoForge.EVENT_BUS.post(new net.neoforged.neoforge.event.brewing.RegisterBrewingRecipesEvent(potionbrewing$builder, registryAccess)); return potionbrewing$builder.build(); } diff --git a/src/main/java/net/neoforged/neoforge/common/VillagerTradingManager.java b/src/main/java/net/neoforged/neoforge/common/VillagerTradingManager.java index 92a0a16b4e..b36bbdb53b 100644 --- a/src/main/java/net/neoforged/neoforge/common/VillagerTradingManager.java +++ b/src/main/java/net/neoforged/neoforge/common/VillagerTradingManager.java @@ -12,6 +12,7 @@ import java.util.List; import java.util.Map; import net.minecraft.core.NonNullList; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerTrades; @@ -35,20 +36,20 @@ public class VillagerTradingManager { static void loadTrades(TagsUpdatedEvent e) { if (e.getUpdateCause() == TagsUpdatedEvent.UpdateCause.SERVER_DATA_LOAD) { - postWandererEvent(); - postVillagerEvents(); + postWandererEvent(e.getRegistryAccess()); + postVillagerEvents(e.getRegistryAccess()); } } /** * Posts the WandererTradesEvent. */ - private static void postWandererEvent() { + private static void postWandererEvent(RegistryAccess registryAccess) { List generic = NonNullList.create(); List rare = NonNullList.create(); Arrays.stream(WANDERER_TRADES.get(1)).forEach(generic::add); Arrays.stream(WANDERER_TRADES.get(2)).forEach(rare::add); - NeoForge.EVENT_BUS.post(new WandererTradesEvent(generic, rare)); + NeoForge.EVENT_BUS.post(new WandererTradesEvent(generic, rare, registryAccess)); VillagerTrades.WANDERING_TRADER_TRADES.put(1, generic.toArray(new ItemListing[0])); VillagerTrades.WANDERING_TRADER_TRADES.put(2, rare.toArray(new ItemListing[0])); } @@ -56,7 +57,7 @@ private static void postWandererEvent() { /** * Posts a VillagerTradesEvent for each registered profession. */ - private static void postVillagerEvents() { + private static void postVillagerEvents(RegistryAccess registryAccess) { for (VillagerProfession prof : BuiltInRegistries.VILLAGER_PROFESSION) { Int2ObjectMap trades = VANILLA_TRADES.getOrDefault(prof, new Int2ObjectOpenHashMap<>()); Int2ObjectMap> mutableTrades = new Int2ObjectOpenHashMap<>(); @@ -66,7 +67,7 @@ private static void postVillagerEvents() { trades.int2ObjectEntrySet().forEach(e -> { Arrays.stream(e.getValue()).forEach(mutableTrades.get(e.getIntKey())::add); }); - NeoForge.EVENT_BUS.post(new VillagerTradesEvent(mutableTrades, prof)); + NeoForge.EVENT_BUS.post(new VillagerTradesEvent(mutableTrades, prof, registryAccess)); Int2ObjectMap newTrades = new Int2ObjectOpenHashMap<>(); mutableTrades.int2ObjectEntrySet().forEach(e -> newTrades.put(e.getIntKey(), e.getValue().toArray(new ItemListing[0]))); VillagerTrades.TRADES.put(prof, newTrades); diff --git a/src/main/java/net/neoforged/neoforge/event/brewing/RegisterBrewingRecipesEvent.java b/src/main/java/net/neoforged/neoforge/event/brewing/RegisterBrewingRecipesEvent.java index 53ff0f6af2..669e61cedd 100644 --- a/src/main/java/net/neoforged/neoforge/event/brewing/RegisterBrewingRecipesEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/brewing/RegisterBrewingRecipesEvent.java @@ -5,6 +5,7 @@ package net.neoforged.neoforge.event.brewing; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.item.alchemy.PotionBrewing; import net.neoforged.bus.api.Event; import org.jetbrains.annotations.ApiStatus; @@ -16,13 +17,19 @@ */ public class RegisterBrewingRecipesEvent extends Event { private final PotionBrewing.Builder builder; + private final RegistryAccess registryAccess; @ApiStatus.Internal - public RegisterBrewingRecipesEvent(PotionBrewing.Builder builder) { + public RegisterBrewingRecipesEvent(PotionBrewing.Builder builder, RegistryAccess registryAccess) { this.builder = builder; + this.registryAccess = registryAccess; } public PotionBrewing.Builder getBuilder() { return builder; } + + public RegistryAccess getRegistryAccess() { + return registryAccess; + } } diff --git a/src/main/java/net/neoforged/neoforge/event/village/VillagerTradesEvent.java b/src/main/java/net/neoforged/neoforge/event/village/VillagerTradesEvent.java index 58adf8c425..4fb6c4c2fb 100644 --- a/src/main/java/net/neoforged/neoforge/event/village/VillagerTradesEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/village/VillagerTradesEvent.java @@ -7,6 +7,7 @@ import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import java.util.List; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.entity.npc.VillagerData; import net.minecraft.world.entity.npc.VillagerProfession; import net.minecraft.world.entity.npc.VillagerTrades.ItemListing; @@ -14,6 +15,7 @@ import net.neoforged.neoforge.common.BasicItemListing; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.TagsUpdatedEvent; +import org.jetbrains.annotations.ApiStatus; /** * VillagerTradesEvent is fired during reload by {@link TagsUpdatedEvent}. It is used to gather the trade lists for each profession. @@ -28,10 +30,21 @@ public class VillagerTradesEvent extends Event { protected Int2ObjectMap> trades; protected VillagerProfession type; + private final RegistryAccess registryAccess; + /** + * @deprecated Use {@link #VillagerTradesEvent(Int2ObjectMap, VillagerProfession, RegistryAccess)} instead + */ + @Deprecated(forRemoval = true, since = "1.21.1") public VillagerTradesEvent(Int2ObjectMap> trades, VillagerProfession type) { + this(trades, type, RegistryAccess.EMPTY); + } + + @ApiStatus.Internal + public VillagerTradesEvent(Int2ObjectMap> trades, VillagerProfession type, RegistryAccess registryAccess) { this.trades = trades; this.type = type; + this.registryAccess = registryAccess; } public Int2ObjectMap> getTrades() { @@ -41,4 +54,8 @@ public Int2ObjectMap> getTrades() { public VillagerProfession getType() { return type; } + + public RegistryAccess getRegistryAccess() { + return registryAccess; + } } diff --git a/src/main/java/net/neoforged/neoforge/event/village/WandererTradesEvent.java b/src/main/java/net/neoforged/neoforge/event/village/WandererTradesEvent.java index 4c9880952c..ba3766f6d9 100644 --- a/src/main/java/net/neoforged/neoforge/event/village/WandererTradesEvent.java +++ b/src/main/java/net/neoforged/neoforge/event/village/WandererTradesEvent.java @@ -6,11 +6,13 @@ package net.neoforged.neoforge.event.village; import java.util.List; +import net.minecraft.core.RegistryAccess; import net.minecraft.world.entity.npc.VillagerTrades.ItemListing; import net.neoforged.bus.api.Event; import net.neoforged.neoforge.common.BasicItemListing; import net.neoforged.neoforge.common.NeoForge; import net.neoforged.neoforge.event.TagsUpdatedEvent; +import org.jetbrains.annotations.ApiStatus; /** * WandererTradesEvent is fired during reload by {@link TagsUpdatedEvent}. It is used to gather the trade lists for the wandering merchant. @@ -21,10 +23,21 @@ public class WandererTradesEvent extends Event { protected List generic; protected List rare; + private final RegistryAccess registryAccess; + /** + * @deprecated Use {@link #WandererTradesEvent(List, List, RegistryAccess)} instead + */ + @Deprecated(forRemoval = true, since = "1.21.1") public WandererTradesEvent(List generic, List rare) { + this(generic, rare, RegistryAccess.EMPTY); + } + + @ApiStatus.Internal + public WandererTradesEvent(List generic, List rare, RegistryAccess registryAccess) { this.generic = generic; this.rare = rare; + this.registryAccess = registryAccess; } public List getGenericTrades() { @@ -34,4 +47,8 @@ public List getGenericTrades() { public List getRareTrades() { return rare; } + + public RegistryAccess getRegistryAccess() { + return registryAccess; + } }