Skip to content

Commit

Permalink
Use default methods for the API where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Jun 11, 2017
1 parent 2746a1c commit 5952da1
Show file tree
Hide file tree
Showing 37 changed files with 100 additions and 153 deletions.
30 changes: 2 additions & 28 deletions src/api/java/mezz/jei/api/BlankModPlugin.java
@@ -1,35 +1,9 @@
package mezz.jei.api;

import mezz.jei.api.ingredients.IModIngredientRegistration;
import mezz.jei.api.recipe.IRecipeCategoryRegistration;

/**
* An {@link IModPlugin} that does nothing, inherit from this to avoid implementing methods you don't need.
* IModPlugin implementations must have the {@link JEIPlugin} annotation to get loaded by JEI.
* @deprecated since JEI 4.6.0. This was replaced by default methods in {@link IModPlugin}.
*/
@Deprecated
public abstract class BlankModPlugin implements IModPlugin {
@Override
public void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {
// override to register item subtypes
}

@Override
public void registerCategories(IRecipeCategoryRegistration registry) {
// override to register recipe categories
}

@Override
public void registerIngredients(IModIngredientRegistration ingredientRegistry) {
// override to register ingredients
}

@Override
public void register(IModRegistry registry) {
// override to register recipes
}

@Override
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
// override to use the JEI runtime
}
}
22 changes: 15 additions & 7 deletions src/api/java/mezz/jei/api/IModPlugin.java
Expand Up @@ -6,8 +6,6 @@
/**
* The main class to implement to create a JEI plugin. Everything communicated between a mod and JEI is through this class.
* IModPlugins must have the {@link JEIPlugin} annotation to get loaded by JEI.
*
* @see BlankModPlugin
*/
public interface IModPlugin {

Expand All @@ -16,32 +14,42 @@ public interface IModPlugin {
*
* @since JEI 3.12.1
*/
void registerItemSubtypes(ISubtypeRegistry subtypeRegistry);
default void registerItemSubtypes(ISubtypeRegistry subtypeRegistry) {

}

/**
* Register special ingredients, beyond the basic ItemStack and FluidStack.
*
* @since JEI 3.11.0
*/
void registerIngredients(IModIngredientRegistration registry);
default void registerIngredients(IModIngredientRegistration registry) {

}

/**
* Register the categories handled by this plugin.
* These are registered before recipes so they can be checked for validity.
*
* @since JEI 4.5.0
*/
void registerCategories(IRecipeCategoryRegistration registry);
default void registerCategories(IRecipeCategoryRegistration registry) {

}

/**
* Register this mod plugin with the mod registry.
*/
void register(IModRegistry registry);
default void register(IModRegistry registry) {

}

/**
* Called when jei's runtime features are available, after all mods have registered.
*
* @since JEI 2.23.0
*/
void onRuntimeAvailable(IJeiRuntime jeiRuntime);
default void onRuntimeAvailable(IJeiRuntime jeiRuntime) {

}
}
18 changes: 4 additions & 14 deletions src/api/java/mezz/jei/api/gui/BlankAdvancedGuiHandler.java
@@ -1,21 +1,11 @@
package mezz.jei.api.gui;

import javax.annotation.Nullable;
import java.awt.Rectangle;
import java.util.List;

import net.minecraft.client.gui.inventory.GuiContainer;

/**
* @deprecated since JEI 4.6.0. This was replaced by default methods in {@link IAdvancedGuiHandler}.
*/
@Deprecated
public abstract class BlankAdvancedGuiHandler<T extends GuiContainer> implements IAdvancedGuiHandler<T> {
@Nullable
@Override
public List<Rectangle> getGuiExtraAreas(T guiContainer) {
return null;
}

@Nullable
@Override
public Object getIngredientUnderMouse(T guiContainer, int mouseX, int mouseY) {
return null;
}
}
10 changes: 6 additions & 4 deletions src/api/java/mezz/jei/api/gui/IAdvancedGuiHandler.java
Expand Up @@ -11,8 +11,6 @@
/**
* Allows plugins to change how JEI is displayed next to their mod's guis.
* Register your implementation with {@link IModRegistry#addAdvancedGuiHandlers(IAdvancedGuiHandler[])}.
*
* @see BlankAdvancedGuiHandler
*/
public interface IAdvancedGuiHandler<T extends GuiContainer> {
/**
Expand All @@ -27,7 +25,9 @@ public interface IAdvancedGuiHandler<T extends GuiContainer> {
* @return the space that the gui takes up besides the normal rectangle defined by GuiContainer.
*/
@Nullable
List<Rectangle> getGuiExtraAreas(T guiContainer);
default List<Rectangle> getGuiExtraAreas(T guiContainer) {
return null;
}

/**
* Return anything under the mouse that JEI could not normally detect, used for JEI recipe lookups.
Expand All @@ -42,5 +42,7 @@ public interface IAdvancedGuiHandler<T extends GuiContainer> {
* @since JEI 3.13.2
*/
@Nullable
Object getIngredientUnderMouse(T guiContainer, int mouseX, int mouseY);
default Object getIngredientUnderMouse(T guiContainer, int mouseX, int mouseY) {
return null;
}
}
4 changes: 3 additions & 1 deletion src/api/java/mezz/jei/api/gui/IDrawable.java
Expand Up @@ -19,7 +19,9 @@ public interface IDrawable {

int getHeight();

void draw(Minecraft minecraft);
default void draw(Minecraft minecraft) {
draw(minecraft, 0, 0);
}

void draw(Minecraft minecraft, int xOffset, int yOffset);

Expand Down
@@ -1,10 +1,16 @@
package mezz.jei.api.ingredients;

import java.util.List;

import mezz.jei.api.IJeiHelpers;
import net.minecraftforge.oredict.OreDictionary;

/**
* The Ingredient Blacklist allows mods to hide ingredients from JEI's ingredient list.
*
* Ingredients can only be blacklisted during the loading phase.
* To get rid of ingredients at runtime, use {@link IIngredientRegistry#removeIngredientsAtRuntime(Class, List)}
*
* Get the instance from {@link IJeiHelpers#getIngredientBlacklist()}.
*
* @since JEI 4.2.1
Expand Down
4 changes: 3 additions & 1 deletion src/api/java/mezz/jei/api/ingredients/IIngredientHelper.java
Expand Up @@ -79,7 +79,9 @@ public interface IIngredientHelper<V> {
* @return an ItemStack for JEI to give the player, or an empty stack if this method handles it manually.
* @since JEI 4.2.9
*/
ItemStack cheatIngredient(V ingredient, boolean fullStack);
default ItemStack cheatIngredient(V ingredient, boolean fullStack) {
return ItemStack.EMPTY;
}

/**
* Makes a copy of the given ingredient.
Expand Down
Expand Up @@ -39,6 +39,7 @@ public interface IIngredientRenderer<T> {
* @since JEI 4.6.0
*/
default List<String> getTooltip(Minecraft minecraft, T ingredient, ITooltipFlag tooltipFlag) {
// you should override this method. this default method is to keep old JEI plugins from crashing.
return getTooltip(minecraft, ingredient, tooltipFlag == ITooltipFlag.TooltipFlags.ADVANCED);
}

Expand Down
24 changes: 2 additions & 22 deletions src/api/java/mezz/jei/api/recipe/BlankRecipeCategory.java
@@ -1,29 +1,9 @@
package mezz.jei.api.recipe;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

import mezz.jei.api.gui.IDrawable;
import net.minecraft.client.Minecraft;

/**
* An {@link IRecipeCategory} that does nothing, inherit from this to avoid implementing methods you don't need.
* @deprecated since JEI 4.6.0. This was replaced by default methods in {@link IRecipeCategory}.
*/
@Deprecated
public abstract class BlankRecipeCategory<T extends IRecipeWrapper> implements IRecipeCategory<T> {
@Nullable
@Override
public IDrawable getIcon() {
return null;
}

@Override
public void drawExtras(Minecraft minecraft) {

}

@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.emptyList();
}
}
20 changes: 1 addition & 19 deletions src/api/java/mezz/jei/api/recipe/BlankRecipeWrapper.java
@@ -1,26 +1,8 @@
package mezz.jei.api.recipe;

import java.util.Collections;
import java.util.List;

import net.minecraft.client.Minecraft;

/**
* An {@link IRecipeWrapper} that does nothing, inherit from this to avoid implementing methods you don't need.
* @deprecated since JEI 4.6.0. This was replaced by default methods in {@link IRecipeWrapper}.
*/
public abstract class BlankRecipeWrapper implements IRecipeWrapper {
@Override
public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
// override to draw extra info about the recipe
}

@Override
public List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.emptyList();
}

@Override
public boolean handleClick(Minecraft minecraft, int mouseX, int mouseY, int mouseButton) {
return false;
}
}
15 changes: 10 additions & 5 deletions src/api/java/mezz/jei/api/recipe/IRecipeCategory.java
@@ -1,6 +1,7 @@
package mezz.jei.api.recipe;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;

import mezz.jei.api.IGuiHelper;
Expand All @@ -16,8 +17,6 @@
* Defines a category of recipe, (i.e. Crafting Table Recipe, Furnace Recipe).
* Handles setting up the GUI for its recipe category in {@link #setRecipe(IRecipeLayout, IRecipeWrapper, IIngredients)}.
* Also draws elements that are common to all recipes in the category like the background.
*
* @see BlankRecipeCategory
*/
public interface IRecipeCategory<T extends IRecipeWrapper> {

Expand Down Expand Up @@ -59,15 +58,19 @@ public interface IRecipeCategory<T extends IRecipeWrapper> {
* @since 3.13.1
*/
@Nullable
IDrawable getIcon();
default IDrawable getIcon() {
return null;
}

/**
* Draw any extra elements that might be necessary, icons or extra slots.
*
* @see IDrawable for a simple class for drawing things.
* @see IGuiHelper for useful functions.
*/
void drawExtras(Minecraft minecraft);
default void drawExtras(Minecraft minecraft) {

}

/**
* Set the {@link IRecipeLayout} properties from the {@link IRecipeWrapper} and {@link IIngredients}.
Expand All @@ -91,5 +94,7 @@ public interface IRecipeCategory<T extends IRecipeWrapper> {
* @return tooltip strings. If there is no tooltip at this position, return an empty list.
* @since JEI 4.2.5
*/
List<String> getTooltipStrings(int mouseX, int mouseY);
default List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.emptyList();
}
}
15 changes: 10 additions & 5 deletions src/api/java/mezz/jei/api/recipe/IRecipeWrapper.java
@@ -1,5 +1,6 @@
package mezz.jei.api.recipe;

import java.util.Collections;
import java.util.List;

import mezz.jei.api.IGuiHelper;
Expand All @@ -12,8 +13,6 @@
/**
* A wrapper around a normal recipe with methods that allow JEI can make sense of it.
* Plugins implement these to wrap each type of recipe they have.
*
* @see BlankRecipeWrapper
*/
public interface IRecipeWrapper {

Expand All @@ -35,7 +34,9 @@ public interface IRecipeWrapper {
* @see IGuiHelper for useful functions.
* @since JEI 2.19.0
*/
void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY);
default void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {

}

/**
* Get the tooltip for whatever's under the mouse.
Expand All @@ -48,7 +49,9 @@ public interface IRecipeWrapper {
* @param mouseY the Y position of the mouse, relative to the recipe.
* @return tooltip strings. If there is no tooltip at this position, return an empty list.
*/
List<String> getTooltipStrings(int mouseX, int mouseY);
default List<String> getTooltipStrings(int mouseX, int mouseY) {
return Collections.emptyList();
}

/**
* Called when a player clicks the recipe.
Expand All @@ -60,5 +63,7 @@ public interface IRecipeWrapper {
* @return true if the click was handled, false otherwise
* @since JEI 2.19.0
*/
boolean handleClick(Minecraft minecraft, int mouseX, int mouseY, int mouseButton);
default boolean handleClick(Minecraft minecraft, int mouseX, int mouseY, int mouseButton) {
return false;
}
}
5 changes: 0 additions & 5 deletions src/main/java/mezz/jei/gui/elements/DrawableAnimated.java
Expand Up @@ -26,11 +26,6 @@ public int getHeight() {
return drawable.getHeight();
}

@Override
public void draw(Minecraft minecraft) {
draw(minecraft, 0, 0);
}

@Override
public void draw(Minecraft minecraft, int xOffset, int yOffset) {
int maskLeft = 0;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/mezz/jei/gui/elements/DrawableBlank.java
Expand Up @@ -28,11 +28,6 @@ public void draw(Minecraft minecraft, int xOffset, int yOffset, int maskTop, int
// draws nothing
}

@Override
public void draw(Minecraft minecraft) {
// draws nothing
}

@Override
public void draw(Minecraft minecraft, int xOffset, int yOffset) {
// draws nothing
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/mezz/jei/gui/elements/DrawableResource.java
Expand Up @@ -46,11 +46,6 @@ public int getHeight() {
return height + paddingTop + paddingBottom;
}

@Override
public void draw(Minecraft minecraft) {
draw(minecraft, 0, 0);
}

@Override
public void draw(Minecraft minecraft, int xOffset, int yOffset) {
draw(minecraft, xOffset, yOffset, 0, 0, 0, 0);
Expand Down

0 comments on commit 5952da1

Please sign in to comment.