Skip to content

Commit

Permalink
Expose HLA and extract correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
Matyrobbrt committed Nov 9, 2024
1 parent ffca39b commit 8618c04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
--- a/net/minecraft/server/ReloadableServerRegistries.java
+++ b/net/minecraft/server/ReloadableServerRegistries.java
@@ -61,8 +_,16 @@
@@ -59,10 +_,19 @@
) {
return CompletableFuture.supplyAsync(
() -> {
+ var provider = net.neoforged.neoforge.common.CommonHooks.extractLookupProvider(p_336173_);
WritableRegistry<T> writableregistry = new MappedRegistry<>(p_335741_.registryKey(), Lifecycle.experimental());
Map<ResourceLocation, T> map = new HashMap<>();
+ Map<ResourceLocation, Optional<T>> optionalMap = new HashMap<>();
Expand All @@ -11,7 +14,7 @@
+ optionalMap.forEach((rl, optionalEntry) -> {
+ optionalEntry.ifPresent(entry -> p_335741_.idSetter().accept(entry, rl));
+ T value = optionalEntry.orElse(p_335741_.defaultValue());
+ if (value instanceof LootTable lootTable) value = (T) net.neoforged.neoforge.event.EventHooks.loadLootTable(rl, lootTable, (HolderLookup.Provider) p_336173_.lookupProvider);
+ if (value instanceof LootTable lootTable) value = (T) net.neoforged.neoforge.event.EventHooks.loadLootTable(rl, lootTable, provider);
+ if (value != null)
+ map.put(rl, value);
+ });
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/net/neoforged/neoforge/common/CommonHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket;
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
import net.minecraft.network.syncher.EntityDataSerializer;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
Expand Down Expand Up @@ -1524,6 +1525,18 @@ public static <T> RegistryLookup<T> resolveLookup(ResourceKey<? extends Registry
return null;
}

/**
* Extracts a {@link HolderLookup.Provider} from the given {@code ops}, if possible.
*
* @throws IllegalArgumentException if the ops were not created using a {@linkplain HolderLookup.Provider}
*/
public static HolderLookup.Provider extractLookupProvider(RegistryOps<?> ops) {
if (ops.lookupProvider instanceof RegistryOps.HolderLookupAdapter hla) {
return hla.lookupProvider;
}
throw new IllegalArgumentException("Registry ops has lookup provider " + ops.lookupProvider + " which is not a HolderLookupAdapter");
}

/**
* Creates a {@link UseOnContext} for {@link net.minecraft.core.dispenser.DispenseItemBehavior dispense behavior}.
*
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ public net.minecraft.gametest.framework.GameTestInfo sequences # sequences
public net.minecraft.gametest.framework.GameTestSequence <init>(Lnet/minecraft/gametest/framework/GameTestInfo;)V # <init>
protected net.minecraft.resources.RegistryOps <init>(Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/resources/RegistryOps$RegistryInfoLookup;)V # constructor
public net.minecraft.resources.RegistryOps lookupProvider
public net.minecraft.resources.RegistryOps$HolderLookupAdapter
public net.minecraft.resources.RegistryOps$HolderLookupAdapter lookupProvider
public net.minecraft.resources.ResourceLocation validNamespaceChar(C)Z # validNamespaceChar
protected net.minecraft.server.MinecraftServer nextTickTimeNanos # nextTickTimeNanos
public net.minecraft.server.MinecraftServer$ReloadableResources
Expand Down

0 comments on commit 8618c04

Please sign in to comment.