Skip to content

Commit

Permalink
Ensure all IDs produced by IRecipeHelper are in your own namespace
Browse files Browse the repository at this point in the history
Tinkers used this to simplify some datagen key creation on Minecraft objects. We never want to generate a recipe for another domain.
  • Loading branch information
KnightMiner committed Mar 14, 2024
1 parent 0d1e557 commit b2f8009
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/main/java/slimeknights/mantle/recipe/data/IRecipeHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraftforge.common.crafting.conditions.NotCondition;
import net.minecraftforge.common.crafting.conditions.TagEmptyCondition;
import net.minecraftforge.registries.RegistryObject;
import org.jetbrains.annotations.ApiStatus;
import slimeknights.mantle.util.IdExtender.LocationExtender;

import java.util.Objects;
import java.util.function.Consumer;

/**
Expand All @@ -25,13 +27,20 @@ public interface IRecipeHelper extends LocationExtender {
/** Gets the ID of the mod adding recipes */
String getModId();

/** Use {@link #location(String)}, this method just exists to simplify implementation. */
@ApiStatus.Internal
@Override
default ResourceLocation location(String namespace, String path) {
return location(path);
}

/**
* Gets a resource location for the mod
* @param name Location path
* @return Location for the mod
*/
default ResourceLocation location(String name) {
return location(getModId(), name);
return new ResourceLocation(getModId(), name);
}

/**
Expand All @@ -46,10 +55,21 @@ default String prefix(String id) {
/**
* Gets a registry ID for the given item
* @param item Item to fetch ID
* @return ID for the item
* @return ID for the item put in your namespace
*/
@SuppressWarnings("deprecation") // won't be for long
default ResourceLocation id(ItemLike item) {
return Registry.ITEM.getKey(item.asItem());
return location(Registry.ITEM.getKey(item.asItem()).getPath());
}

/**
* Gets a registry ID for the given item
* @param registry Registry to fetch IDs
* @param value Registry value
* @return ID for the item put in your namespace
*/
default <T> ResourceLocation id(Registry<T> registry, T value) {
return location(Objects.requireNonNull(registry.getKey(value)).getPath());
}


Expand Down

0 comments on commit b2f8009

Please sign in to comment.