Skip to content

Commit

Permalink
Fix some minor Deprecation issues (#2428)
Browse files Browse the repository at this point in the history
  • Loading branch information
pupnewfster committed Aug 3, 2021
1 parent f6bd6ea commit 6113e26
Show file tree
Hide file tree
Showing 10 changed files with 92 additions and 12 deletions.
Expand Up @@ -2,7 +2,10 @@

import java.util.List;

import net.minecraft.item.crafting.BlastingRecipe;
import net.minecraft.item.crafting.CampfireCookingRecipe;
import net.minecraft.item.crafting.SmithingRecipe;
import net.minecraft.item.crafting.SmokingRecipe;
import net.minecraft.item.crafting.StonecuttingRecipe;
import net.minecraftforge.common.brewing.BrewingRecipeRegistry;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -47,21 +50,21 @@ public final class VanillaRecipeCategoryUid {
/**
* The smoking recipe category.
*
* Automatically includes every {@link FurnaceRecipe}
* Automatically includes every {@link SmokingRecipe}
*/
public static final ResourceLocation SMOKING = new ResourceLocation(ModIds.MINECRAFT_ID, "smoking");

/**
* The blasting recipe category.
*
* Automatically includes every {@link FurnaceRecipe}
* Automatically includes every {@link BlastingRecipe}
*/
public static final ResourceLocation BLASTING = new ResourceLocation(ModIds.MINECRAFT_ID, "blasting");

/**
* The campfire furnace recipe category.
*
* Automatically includes every {@link FurnaceRecipe}
* Automatically includes every {@link CampfireCookingRecipe}
*/
public static final ResourceLocation CAMPFIRE = new ResourceLocation(ModIds.MINECRAFT_ID, "campfire");

Expand Down
Expand Up @@ -76,7 +76,7 @@ default String getUniqueId(V ingredient, UidContext context) {
/**
* Wildcard ID for use in comparing, blacklisting, and looking up ingredients.
* For an example, ItemStack's wildcardId does not include NBT.
* For ingredients like FluidStacks which do not have a wildcardId, just return the uniqueId here.
* For ingredients which do not have a wildcardId, just return the uniqueId here.
*/
default String getWildcardId(V ingredient) {
return getUniqueId(ingredient);
Expand Down
2 changes: 2 additions & 0 deletions src/api/java/mezz/jei/api/recipe/IRecipeManager.java
Expand Up @@ -165,6 +165,7 @@ default IRecipeCategory<?> getRecipeCategory(ResourceLocation recipeCategoryUid)
* Returns a list of recipes in recipeCategory.
* @deprecated since JEI 7.7.1. Use {@link #getRecipes(IRecipeCategory, IFocus, boolean)}
*/
@Deprecated
default <T> List<T> getRecipes(IRecipeCategory<T> recipeCategory) {
return getRecipes(recipeCategory, null, false);
}
Expand All @@ -174,6 +175,7 @@ default <T> List<T> getRecipes(IRecipeCategory<T> recipeCategory) {
*
* @deprecated since JEI 7.7.1. Use {@link #getRecipes(IRecipeCategory, IFocus, boolean)}
*/
@Deprecated
default <T, V> List<T> getRecipes(IRecipeCategory<T> recipeCategory, IFocus<V> focus) {
return getRecipes(recipeCategory, focus, false);
}
Expand Down
Expand Up @@ -10,7 +10,7 @@
* A reason that a recipe transfer couldn't happen.
*
* Recipe transfer errors can be created with {@link IRecipeTransferHandlerHelper} or you can implement your own.
* These errors are returned from {@link IRecipeTransferHandler#transferRecipe(Container, IRecipeLayout, PlayerEntity, boolean, boolean)}.
* These errors are returned from {@link IRecipeTransferHandler#transferRecipe(Container, Object, IRecipeLayout, PlayerEntity, boolean, boolean)}.
*/
public interface IRecipeTransferError {
enum Type {
Expand Down
Expand Up @@ -2,6 +2,7 @@

import javax.annotation.Nullable;

import mezz.jei.api.ingredients.subtypes.UidContext;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.player.ClientPlayerEntity;
import net.minecraft.item.ItemStack;
Expand All @@ -12,12 +13,23 @@
import mezz.jei.util.CommandUtilServer;

public class DebugIngredientHelper implements IIngredientHelper<DebugIngredient> {
@Override
@Nullable
@Deprecated
public DebugIngredient getMatch(Iterable<DebugIngredient> ingredients, DebugIngredient toMatch) {
return getMatch(ingredients, toMatch, UidContext.Ingredient);
}

@Nullable
@Override
public DebugIngredient getMatch(Iterable<DebugIngredient> ingredients, DebugIngredient ingredientToMatch) {
public DebugIngredient getMatch(Iterable<DebugIngredient> ingredients, DebugIngredient ingredientToMatch, UidContext context) {
for (DebugIngredient debugIngredient : ingredients) {
if (debugIngredient.getNumber() == ingredientToMatch.getNumber()) {
return debugIngredient;
String keyLhs = getUniqueId(ingredientToMatch, context);
String keyRhs = getUniqueId(debugIngredient, context);
if (keyLhs.equals(keyRhs)) {
return debugIngredient;
}
}
}
return null;
Expand Down
Expand Up @@ -6,6 +6,7 @@

import mezz.jei.api.ingredients.subtypes.ISubtypeManager;
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.util.ErrorUtil;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraftforge.fluids.FluidAttributes;
import net.minecraftforge.fluids.FluidStack;
Expand All @@ -31,13 +32,23 @@ public FluidStackHelper(ISubtypeManager subtypeManager, IColorHelper colorHelper
this.colorHelper = colorHelper;
}


@Override
@Nullable
@Deprecated
public FluidStack getMatch(Iterable<FluidStack> ingredients, FluidStack toMatch) {
return getMatch(ingredients, toMatch, UidContext.Ingredient);
}

@Override
@Nullable
public FluidStack getMatch(Iterable<FluidStack> ingredients, FluidStack toMatch, UidContext context) {
for (FluidStack fluidStack : ingredients) {
if (toMatch.getFluid() == fluidStack.getFluid()) {
return fluidStack;
String keyLhs = getUniqueId(toMatch, context);
String keyRhs = getUniqueId(fluidStack, context);
if (keyLhs.equals(keyRhs)) {
return fluidStack;
}
}
}
return null;
Expand Down Expand Up @@ -69,6 +80,14 @@ public String getUniqueId(FluidStack ingredient, UidContext context) {
return result.toString();
}

@Override
public String getWildcardId(FluidStack ingredient) {
ErrorUtil.checkNotEmpty(ingredient);
Fluid fluid = ingredient.getFluid();
ResourceLocation registryName = fluid.getRegistryName();
return "fluid:" + registryName;
}

@Override
public String getModId(FluidStack ingredient) {
Fluid fluid = ingredient.getFluid();
Expand Down
Expand Up @@ -54,6 +54,7 @@ public IFocus<?> translateFocus(IFocus<ItemStack> focus, IFocusFactory focusFact

@Override
@Nullable
@Deprecated
public ItemStack getMatch(Iterable<ItemStack> ingredients, ItemStack toMatch) {
return getMatch(ingredients, toMatch, UidContext.Ingredient);
}
Expand Down
Expand Up @@ -52,7 +52,7 @@ public Class<PlayerContainer> getContainerClass() {

@Nullable
@Override
public IRecipeTransferError transferRecipe(PlayerContainer container, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
public IRecipeTransferError transferRecipe(PlayerContainer container, Object recipe, IRecipeLayout recipeLayout, PlayerEntity player, boolean maxTransfer, boolean doTransfer) {
if (!ServerInfo.isJeiOnServer()) {
ITextComponent tooltipMessage = new TranslationTextComponent("jei.tooltip.error.recipe.transfer.no.server");
return handlerHelper.createUserErrorWithTooltip(tooltipMessage);
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/mezz/jei/util/ErrorUtil.java
Expand Up @@ -8,6 +8,8 @@
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.config.ClientConfig;
import mezz.jei.ingredients.IngredientsForType;
import net.minecraft.fluid.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -176,6 +178,26 @@ public static String getItemStackInfo(@Nullable ItemStack itemStack) {
return itemStack + " " + itemName;
}

public static String getFluidStackInfo(@Nullable FluidStack fluidStack) {
if (fluidStack == null) {
return "null";
}
Fluid fluid = fluidStack.getFluid();
final String fluidName;
ResourceLocation registryName = fluid.getRegistryName();
if (registryName != null) {
fluidName = registryName.toString();
} else {
fluidName = fluid.getClass().getName();
}

CompoundNBT nbt = fluidStack.getTag();
if (nbt != null) {
return fluidStack + " " + fluidName + " nbt:" + nbt;
}
return fluidStack + " " + fluidName;
}

public static void checkNotEmpty(@Nullable ItemStack itemStack) {
if (itemStack == null) {
throw new NullPointerException("ItemStack must not be null.");
Expand All @@ -194,6 +216,15 @@ public static void checkNotEmpty(@Nullable ItemStack itemStack, String name) {
}
}

public static void checkNotEmpty(@Nullable FluidStack fluidStack) {
if (fluidStack == null) {
throw new NullPointerException("FluidStack must not be null.");
} else if (fluidStack.isEmpty()) {
String info = getFluidStackInfo(fluidStack);
throw new IllegalArgumentException("FluidStack value must not be empty. " + info);
}
}

public static <T> void checkNotEmpty(@Nullable T[] values, String name) {
if (values == null) {
throw new NullPointerException(name + " must not be null.");
Expand Down
16 changes: 14 additions & 2 deletions src/test/java/mezz/jei/test/lib/TestIngredientHelper.java
Expand Up @@ -4,14 +4,26 @@
import java.util.Collections;

import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.ingredients.subtypes.UidContext;

public class TestIngredientHelper implements IIngredientHelper<TestIngredient> {
@Override
@Nullable
@Deprecated
public TestIngredient getMatch(Iterable<TestIngredient> ingredients, TestIngredient toMatch) {
return getMatch(ingredients, toMatch, UidContext.Ingredient);
}

@Nullable
@Override
public TestIngredient getMatch(Iterable<TestIngredient> ingredients, TestIngredient ingredientToMatch) {
public TestIngredient getMatch(Iterable<TestIngredient> ingredients, TestIngredient ingredientToMatch, UidContext context) {
for (TestIngredient ingredient : ingredients) {
if (ingredient.getNumber() == ingredientToMatch.getNumber()) {
return ingredient;
String keyLhs = getUniqueId(ingredientToMatch, context);
String keyRhs = getUniqueId(ingredient, context);
if (keyLhs.equals(keyRhs)) {
return ingredient;
}
}
}
return null;
Expand Down

0 comments on commit 6113e26

Please sign in to comment.