Skip to content

Commit

Permalink
Fixed using non Registry registries for holders
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredlll08 committed Apr 3, 2022
1 parent 4d0e822 commit 8b6c05f
Showing 1 changed file with 9 additions and 3 deletions.
@@ -1,5 +1,6 @@
package com.blamejared.crafttweaker.platform.services;

import com.blamejared.crafttweaker.api.CraftTweakerAPI;
import com.blamejared.crafttweaker.api.CraftTweakerConstants;
import com.blamejared.crafttweaker.api.ingredient.IIngredient;
import com.blamejared.crafttweaker.api.ingredient.condition.serializer.IIngredientConditionSerializer;
Expand All @@ -14,6 +15,7 @@
import com.blamejared.crafttweaker.api.recipe.serializer.ICTShapelessRecipeBaseSerializer;
import com.blamejared.crafttweaker.api.recipe.type.CTShapedRecipeBase;
import com.blamejared.crafttweaker.api.recipe.type.CTShapelessRecipeBase;
import com.blamejared.crafttweaker.api.util.GenericUtil;
import com.blamejared.crafttweaker.platform.registry.RegistryWrapper;
import com.blamejared.crafttweaker.platform.registry.VanillaRegistryWrapper;
import com.mojang.datafixers.util.Either;
Expand Down Expand Up @@ -272,16 +274,20 @@ default <T> Holder<T> makeHolder(ResourceKey<?> resourceKey, Either<T, ResourceL
}

default <T> Holder<T> makeHolder(ResourceKey<?> resourceKey, T object) {

Registry<T> registry = (Registry<T>) Registry.REGISTRY.get(resourceKey.location());

Registry<T> registry = CraftTweakerAPI.getAccessibleElementsProvider()
.registryAccess()
.registryOrThrow(GenericUtil.uncheck(resourceKey));
return registry.getResourceKey(object)
.flatMap(registry::getHolder)
.orElseThrow(() -> new RuntimeException("Unable to make holder for registry: " + registry + " and object: " + object));
}

default <T> Holder<T> makeHolder(ResourceKey<?> resourceKey, ResourceLocation key) {

Registry<T> registry = (Registry<T>) Registry.REGISTRY.get(resourceKey.location());
Registry<T> registry = CraftTweakerAPI.getAccessibleElementsProvider()
.registryAccess()
.registryOrThrow(GenericUtil.uncheck(resourceKey));

if(!registry.containsKey(key)) {
throw new IllegalArgumentException("Registry does not contain key: '" + key + "'");
Expand Down

0 comments on commit 8b6c05f

Please sign in to comment.