Skip to content

Commit

Permalink
add holder lookup provider to adavncement and loot table provider (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lcy0x1 authored Sep 12, 2024
1 parent bb545bc commit 2e08feb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.tterrag.registrate.AbstractRegistrate;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;

import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementHolder;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.fml.LogicalSide;
import net.neoforged.neoforge.common.conditions.ICondition;
Expand All @@ -37,13 +40,19 @@ public class RegistrateAdvancementProvider implements RegistrateProvider, Consum
private final PackOutput packOutput;
private final CompletableFuture<HolderLookup.Provider> registriesLookup;
private final List<CompletableFuture<?>> advancementsToSave = Lists.newArrayList();
@Getter
private HolderLookup.Provider provider;

public RegistrateAdvancementProvider(AbstractRegistrate<?> owner, PackOutput packOutputIn, CompletableFuture<HolderLookup.Provider> registriesLookupIn) {
this.owner = owner;
this.packOutput = packOutputIn;
this.registriesLookup = registriesLookupIn;
}

public <T> Holder<T> resolve(ResourceKey<T> key) {
return provider.lookupOrThrow(key.registryKey()).getOrThrow(key);
}

@Override
public LogicalSide getSide() {
return LogicalSide.SERVER;
Expand All @@ -63,6 +72,7 @@ public MutableComponent desc(String category, String name, String desc) {
@Override
public CompletableFuture<?> run(CachedOutput cache) {
return registriesLookup.thenCompose(lookup -> {
this.provider = lookup;
advancementsToSave.clear();

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import com.tterrag.registrate.util.nullness.NonNullBiFunction;
import com.tterrag.registrate.util.nullness.NonNullConsumer;

import lombok.Getter;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.WritableRegistry;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.PackOutput;
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.data.loot.LootTableSubProvider;
Expand Down Expand Up @@ -69,9 +72,20 @@ public LootContextParamSet getLootSet() {
private final Multimap<LootContextParamSet, Consumer<BiConsumer<ResourceKey<LootTable>, LootTable.Builder>>> lootActions = HashMultimap.create();
private final Set<RegistrateLootTables> currentLootCreators = new HashSet<>();

private CompletableFuture<HolderLookup.Provider> provider;

public RegistrateLootTableProvider(AbstractRegistrate<?> parent, PackOutput packOutput, CompletableFuture<HolderLookup.Provider> provider) {
super(packOutput, Set.of(), VanillaLootTableProvider.create(packOutput, provider).getTables(), provider);
this.parent = parent;
this.provider = provider;
}

public HolderLookup.Provider getProvider(){
return provider.getNow(null);
}

public <T> Holder<T> resolve(ResourceKey<T> key) {
return getProvider().lookupOrThrow(key.registryKey()).getOrThrow(key);
}

@Override
Expand Down

0 comments on commit 2e08feb

Please sign in to comment.