Skip to content

Commit

Permalink
Update to Minecraft 1.20.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Sep 24, 2023
1 parent eecef8a commit e78fd19
Show file tree
Hide file tree
Showing 70 changed files with 700 additions and 560 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import mezz.jei.common.config.IClientToggleState;
import net.minecraft.ChatFormatting;
import net.minecraft.client.player.LocalPlayer;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -20,17 +21,7 @@ public static void handleHasCheatPermission(ClientPacketContext context, boolean
LocalPlayer player = context.player();
ChatUtil.writeChatMessage(player, "jei.chat.error.no.cheat.permission.1", ChatFormatting.RED);

IServerConfig serverConfig = context.serverConfig();
List<String> allowedCheatingMethods = new ArrayList<>();
if (serverConfig.isCheatModeEnabledForOp()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.op");
}
if (serverConfig.isCheatModeEnabledForCreative()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.creative");
}
if (serverConfig.isCheatModeEnabledForGive()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.give");
}
List<String> allowedCheatingMethods = getAllowedCheatingMethods(context);

if (allowedCheatingMethods.isEmpty()) {
ChatUtil.writeChatMessage(player, "jei.chat.error.no.cheat.permission.disabled", ChatFormatting.RED);
Expand All @@ -46,4 +37,20 @@ public static void handleHasCheatPermission(ClientPacketContext context, boolean
player.closeContainer();
}
}

@NotNull
private static List<String> getAllowedCheatingMethods(ClientPacketContext context) {
IServerConfig serverConfig = context.serverConfig();
List<String> allowedCheatingMethods = new ArrayList<>();
if (serverConfig.isCheatModeEnabledForOp()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.op");
}
if (serverConfig.isCheatModeEnabledForCreative()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.creative");
}
if (serverConfig.isCheatModeEnabledForGive()) {
allowedCheatingMethods.add("jei.chat.error.no.cheat.permission.give");
}
return allowedCheatingMethods;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
import mezz.jei.api.recipe.vanilla.IJeiBrewingRecipe;
import mezz.jei.api.recipe.vanilla.IVanillaRecipeFactory;
import mezz.jei.api.runtime.IIngredientManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.SmithingRecipe;

import java.util.List;
import java.util.Optional;

public interface IPlatformRecipeHelper {
<T extends CraftingRecipe> int getWidth(T recipe);
Expand All @@ -21,7 +18,5 @@ public interface IPlatformRecipeHelper {
Ingredient getTemplate(SmithingRecipe recipe);
boolean isHandled(SmithingRecipe recipe);

Optional<ResourceLocation> getRegistryNameForRecipe(Recipe<?> recipe);

List<IJeiBrewingRecipe> getBrewingRecipes(IIngredientManager ingredientManager, IVanillaRecipeFactory vanillaRecipeFactory);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public interface IPlatformRenderHelper {
Optional<NativeImage> getMainImage(TextureAtlasSprite sprite);

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
void renderTooltip(Screen screen, GuiGraphics guiGraphics, List<Component> textComponents, Optional<TooltipComponent> tooltipComponent, int x, int y, @Nullable Font font, ItemStack stack);
void renderTooltip(Screen screen, GuiGraphics guiGraphics, List<Component> textComponents, Optional<TooltipComponent> tooltipComponent, int x, int y, Font font, ItemStack stack);
}
10 changes: 10 additions & 0 deletions Common/src/main/java/mezz/jei/common/util/ErrorUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mezz.jei.api.ingredients.IIngredientHelper;
import mezz.jei.api.ingredients.IIngredientType;
import mezz.jei.api.ingredients.subtypes.UidContext;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.runtime.IIngredientManager;
import mezz.jei.common.platform.IPlatformModHelper;
import mezz.jei.common.platform.IPlatformRegistry;
Expand Down Expand Up @@ -178,4 +179,13 @@ public static <T> ReportedException createRenderIngredientException(Throwable th

throw new ReportedException(crashreport);
}

public static <T> void validateRecipes(RecipeType<T> recipeType, Iterable<? extends T> recipes) {
Class<?> recipeClass = recipeType.getRecipeClass();
for (T recipe : recipes) {
if (!recipeClass.isInstance(recipe)) {
throw new IllegalArgumentException(recipeType.getUid() + " recipes must be an instance of " + recipeClass + ". Instead got: " + recipe.getClass());
}
}
}
}
31 changes: 15 additions & 16 deletions CommonApi/src/main/java/mezz/jei/api/constants/RecipeTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.world.item.crafting.BlastingRecipe;
import net.minecraft.world.item.crafting.CampfireCookingRecipe;
import net.minecraft.world.item.crafting.CraftingRecipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import net.minecraft.world.item.crafting.SmeltingRecipe;
import net.minecraft.world.item.crafting.SmithingRecipe;
import net.minecraft.world.item.crafting.SmokingRecipe;
Expand All @@ -30,8 +31,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<CraftingRecipe> CRAFTING =
RecipeType.create(ModIds.MINECRAFT_ID, "crafting", CraftingRecipe.class);
public static final RecipeType<RecipeHolder<CraftingRecipe>> CRAFTING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.CRAFTING);

/**
* The stonecutting recipe type.
Expand All @@ -40,8 +41,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<StonecutterRecipe> STONECUTTING =
RecipeType.create(ModIds.MINECRAFT_ID, "stonecutting", StonecutterRecipe.class);
public static final RecipeType<RecipeHolder<StonecutterRecipe>> STONECUTTING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.STONECUTTING);

/**
* The smelting recipe type.
Expand All @@ -50,8 +51,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<SmeltingRecipe> SMELTING =
RecipeType.create(ModIds.MINECRAFT_ID, "furnace", SmeltingRecipe.class);
public static final RecipeType<RecipeHolder<SmeltingRecipe>> SMELTING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.SMELTING);

/**
* The smoking recipe type.
Expand All @@ -60,8 +61,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<SmokingRecipe> SMOKING =
RecipeType.create(ModIds.MINECRAFT_ID, "smoking", SmokingRecipe.class);
public static final RecipeType<RecipeHolder<SmokingRecipe>> SMOKING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.SMOKING);

/**
* The blasting recipe type.
Expand All @@ -70,8 +71,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<BlastingRecipe> BLASTING =
RecipeType.create(ModIds.MINECRAFT_ID, "blasting", BlastingRecipe.class);
public static final RecipeType<RecipeHolder<BlastingRecipe>> BLASTING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.BLASTING);

/**
* The campfire cooking recipe type.
Expand All @@ -80,8 +81,8 @@ public final class RecipeTypes {
*
* @since 9.5.0
*/
public static final RecipeType<CampfireCookingRecipe> CAMPFIRE_COOKING =
RecipeType.create(ModIds.MINECRAFT_ID, "campfire", CampfireCookingRecipe.class);
public static final RecipeType<RecipeHolder<CampfireCookingRecipe>> CAMPFIRE_COOKING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.CAMPFIRE_COOKING);

/**
* The fueling recipe type.
Expand Down Expand Up @@ -119,15 +120,13 @@ public final class RecipeTypes {
/**
* The smithing recipe type.
* Automatically includes every
* {@link net.minecraft.world.item.crafting.LegacyUpgradeRecipe}
* {@link net.minecraft.world.item.crafting.SmithingTrimRecipe}
* {@link net.minecraft.world.item.crafting.SmithingTransformRecipe}
*
* @since 9.5.0
*/
@SuppressWarnings("removal")
public static final RecipeType<SmithingRecipe> SMITHING =
RecipeType.create(ModIds.MINECRAFT_ID, "smithing", SmithingRecipe.class);
public static final RecipeType<RecipeHolder<SmithingRecipe>> SMITHING =
RecipeType.createFromVanilla(net.minecraft.world.item.crafting.RecipeType.SMITHING);

/**
* The composting recipe type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.client.gui.GuiGraphics;

/**
* An animated {@link IDrawable}, useful for showing a gui animation like furnace flames or progress arrows.
*
* Useful for drawing miscellaneous things in
* {@link IRecipeCategory#draw(Object, IRecipeSlotsView, guiGraphics, double, double)}.
* {@link IRecipeCategory#draw(Object, IRecipeSlotsView, GuiGraphics, double, double)}.
*
* To create an instance, call
* {@link IGuiHelper#createAnimatedDrawable(IDrawableStatic, int, StartDirection, boolean)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICraftingCategoryExtension;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.jetbrains.annotations.Nullable;

/**
* Helps set crafting-grid-style layouts.
* This places smaller recipes in the grid in a consistent way.
*
* This is passed to plugins that implement
* {@link ICraftingCategoryExtension#setRecipe(IRecipeLayoutBuilder, ICraftingGridHelper, IFocusGroup)}
* {@link ICraftingCategoryExtension#setRecipe(RecipeHolder, IRecipeLayoutBuilder, ICraftingGridHelper, IFocusGroup)}
* to help them override the default behavior.
*/
public interface ICraftingGridHelper {
Expand Down
28 changes: 28 additions & 0 deletions CommonApi/src/main/java/mezz/jei/api/recipe/RecipeType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

import mezz.jei.api.constants.RecipeTypes;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;

/**
* Identifies a type of recipe, (i.e. Crafting Table Recipe, Furnace Recipe).
* Each {@link IRecipeCategory} can be uniquely identified by its {@link RecipeType}.
*
* Unfortunately, the vanilla RecipeType only works for recipes that extend the vanilla {@link Recipe} class,
* so this more general version is needed for modded recipes in JEI.
*
* @see RecipeTypes for all the built-in recipe types that are added by JEI.
*
* @since 9.5.0
Expand All @@ -18,10 +24,32 @@ public static <T> RecipeType<T> create(String nameSpace, String path, Class<? ex
return new RecipeType<>(uid, recipeClass);
}

/**
* Create a JEI RecipeType from a Vanilla RecipeType.
* Returns a RecipeType that uses {@link RecipeHolder} to hold recipes.
* @since 16.0.0
*/
public static <R extends Recipe<?>> RecipeType<RecipeHolder<R>> createFromVanilla(net.minecraft.world.item.crafting.RecipeType<R> vanillaRecipeType) {
ResourceLocation uid = BuiltInRegistries.RECIPE_TYPE.getKey(vanillaRecipeType);
if (uid == null) {
throw new IllegalArgumentException("Vanilla Recipe Type must be registered before using it here. %s".formatted(vanillaRecipeType));
}
@SuppressWarnings({"unchecked", "RedundantCast"})
Class<? extends RecipeHolder<R>> holderClass = (Class<? extends RecipeHolder<R>>) (Object) RecipeHolder.class;
return new RecipeType<>(uid, holderClass);
}

private final ResourceLocation uid;
private final Class<? extends T> recipeClass;

@SuppressWarnings("ConstantValue")
public RecipeType(ResourceLocation uid, Class<? extends T> recipeClass) {
if (uid == null) {
throw new NullPointerException("uid must not be null.");
}
if (recipeClass == null) {
throw new NullPointerException("recipeClass must not be null.");
}
this.uid = uid;
this.recipeClass = recipeClass;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.crafting.Recipe;
import net.minecraft.world.item.crafting.RecipeHolder;
import org.jetbrains.annotations.Nullable;

import java.util.List;
Expand Down Expand Up @@ -156,8 +156,8 @@ default boolean isHandled(T recipe) {
*/
@Nullable
default ResourceLocation getRegistryName(T recipe) {
if (recipe instanceof Recipe<?> vanillaRecipe) {
return vanillaRecipe.getId();
if (recipe instanceof RecipeHolder<?> recipeHolder) {
return recipeHolder.id();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,36 @@
import java.util.function.Predicate;

import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICraftingCategoryExtension;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.IExtendableCraftingRecipeCategory;

public interface IExtendableRecipeCategory<T, W extends IRecipeCategoryExtension> extends IRecipeCategory<T> {
/**
* @deprecated breaking change: replaced by a simpler interface {@link IExtendableCraftingRecipeCategory} to support RecipeHolder
*/
@Deprecated(since = "16.0.0", forRemoval = true)
public interface IExtendableRecipeCategory<T, W extends IRecipeCategoryExtension<T>> extends IRecipeCategory<T> {
/**
* Add an extension that handles a subset of the recipes in the recipe category.
*
* @param recipeClass the class of recipes to handle
* @param extensionFactory a factory that can turn recipes into recipe extensions
* @deprecated extensions can be singletons now, use {@link IExtendableCraftingRecipeCategory#addExtension(Class, ICraftingCategoryExtension)}
*/
@Deprecated(since = "16.0.0", forRemoval = true)
<R extends T> void addCategoryExtension(Class<? extends R> recipeClass, Function<R, ? extends W> extensionFactory);

/**
* Add an extension that handles a subset of the recipes in the recipe category.
*
* @param recipeClass the class of recipes to handle
* @param extensionFilter a filter that returns true for instances of the recipe that can be handled by the extensionFactory
* @param extensionFactory a factory that can turn recipes into recipe extensions
* @since 7.2.0
*
* @deprecated extensions can be singletons now,
* use {@link IExtendableCraftingRecipeCategory#addExtension(Class, ICraftingCategoryExtension)}
* and {@link IRecipeCategoryExtension#isHandled(Object)}
*/
@Deprecated(since = "16.0.0", forRemoval = true)
<R extends T> void addCategoryExtension(Class<? extends R> recipeClass, Predicate<R> extensionFilter, Function<R, ? extends W> extensionFactory);
}
Loading

0 comments on commit e78fd19

Please sign in to comment.