Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing RegistryAccess to more Events! #1529

Merged
merged 11 commits into from
Sep 28, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions patches/net/minecraft/server/MinecraftServer.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@
Optional<Holder<Potion>> optional = p_43531_.getOrDefault(DataComponents.POTION_CONTENTS, PotionContents.EMPTY).potion();
if (optional.isEmpty()) {
return p_43531_;
@@ -127,6 +_,7 @@
public static PotionBrewing bootstrap(FeatureFlagSet p_341301_) {
@@ -124,9 +_,10 @@
}
}

- public static PotionBrewing bootstrap(FeatureFlagSet p_341301_) {
+ public static PotionBrewing bootstrap(FeatureFlagSet p_341301_, net.minecraft.core.RegistryAccess registryAccess) {
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,28 +36,28 @@ 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<ItemListing> generic = NonNullList.create();
List<ItemListing> 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]));
}

/**
* Posts a VillagerTradesEvent for each registered profession.
*/
private static void postVillagerEvents() {
private static void postVillagerEvents(RegistryAccess registryAccess) {
for (VillagerProfession prof : BuiltInRegistries.VILLAGER_PROFESSION) {
Int2ObjectMap<ItemListing[]> trades = VANILLA_TRADES.getOrDefault(prof, new Int2ObjectOpenHashMap<>());
Int2ObjectMap<List<ItemListing>> mutableTrades = new Int2ObjectOpenHashMap<>();
Expand All @@ -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<ItemListing[]> newTrades = new Int2ObjectOpenHashMap<>();
mutableTrades.int2ObjectEntrySet().forEach(e -> newTrades.put(e.getIntKey(), e.getValue().toArray(new ItemListing[0])));
VillagerTrades.TRADES.put(prof, newTrades);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,10 +29,12 @@
public class VillagerTradesEvent extends Event {
protected Int2ObjectMap<List<ItemListing>> trades;
protected VillagerProfession type;
protected RegistryAccess registryAccess;
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved

public VillagerTradesEvent(Int2ObjectMap<List<ItemListing>> trades, VillagerProfession type) {
public VillagerTradesEvent(Int2ObjectMap<List<ItemListing>> trades, VillagerProfession type, RegistryAccess registryAccess) {
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved
this.trades = trades;
this.type = type;
this.registryAccess = registryAccess;
}

public Int2ObjectMap<List<ItemListing>> getTrades() {
Expand All @@ -41,4 +44,8 @@ public Int2ObjectMap<List<ItemListing>> getTrades() {
public VillagerProfession getType() {
return type;
}

public RegistryAccess getRegistryAccess() {
return registryAccess;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand All @@ -21,10 +22,12 @@
public class WandererTradesEvent extends Event {
protected List<ItemListing> generic;
protected List<ItemListing> rare;
protected RegistryAccess registryAccess;

public WandererTradesEvent(List<ItemListing> generic, List<ItemListing> rare) {
public WandererTradesEvent(List<ItemListing> generic, List<ItemListing> rare, RegistryAccess registryAccess) {
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved
ZestyBlaze marked this conversation as resolved.
Show resolved Hide resolved
this.generic = generic;
this.rare = rare;
this.registryAccess = registryAccess;
}

public List<ItemListing> getGenericTrades() {
Expand All @@ -34,4 +37,8 @@ public List<ItemListing> getGenericTrades() {
public List<ItemListing> getRareTrades() {
return rare;
}

public RegistryAccess getRegistryAccess() {
return registryAccess;
}
}