Skip to content

Commit

Permalink
Fix #284 Improve recipe transfer error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Aug 11, 2016
1 parent c01bbf9 commit 7503b98
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 28 deletions.
Expand Up @@ -16,8 +16,8 @@
public interface IRecipeTransferError {
enum Type {
/**
* Errors where the Transfer handler is broken, or does not work, or the server is not present.
* These errors will hide the recipe transfer button, but do not display anything to the user.
* Errors where the Transfer handler is broken or does not work.
* These errors will hide the recipe transfer button, and do not display anything to the user.
*/
INTERNAL,

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/mezz/jei/config/Constants.java
Expand Up @@ -2,6 +2,8 @@

import java.util.Locale;

import mezz.jei.util.Translator;

public class Constants {
public static final String minecraftModName = "Minecraft";

Expand All @@ -16,6 +18,8 @@ public class Constants {

public static final int MAX_TOOLTIP_WIDTH = 125;

public static final String RECIPE_TRANSFER_TOOLTIP = Translator.translateToLocal("jei.tooltip.transfer");

private Constants() {

}
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/mezz/jei/gui/RecipeTransferButton.java
Expand Up @@ -3,20 +3,16 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.config.Constants;
import mezz.jei.transfer.RecipeTransferErrorInternal;
import mezz.jei.transfer.RecipeTransferUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;

import net.minecraftforge.fml.client.config.GuiButtonExt;

import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.transfer.RecipeTransferErrorInternal;
import mezz.jei.transfer.RecipeTransferUtil;
import mezz.jei.util.Translator;

public class RecipeTransferButton extends GuiButtonExt {
private static final String transferTooltip = Translator.translateToLocal("jei.tooltip.transfer");
private RecipeLayout recipeLayout;
private IRecipeTransferError recipeTransferError;

Expand All @@ -30,7 +26,7 @@ public void init(@Nullable Container container, @Nonnull RecipeLayout recipeLayo
if (container != null) {
this.recipeTransferError = RecipeTransferUtil.getTransferRecipeError(container, recipeLayout, player);
} else {
this.recipeTransferError = RecipeTransferErrorInternal.instance;
this.recipeTransferError = RecipeTransferErrorInternal.INSTANCE;
}

if (this.recipeTransferError == null) {
Expand All @@ -50,7 +46,7 @@ public void drawButton(Minecraft mc, int mouseX, int mouseY) {
if (recipeTransferError != null) {
recipeTransferError.showError(mc, mouseX, mouseY, recipeLayout, recipeLayout.getPosX(), recipeLayout.getPosY());
} else {
TooltipRenderer.drawHoveringText(mc, transferTooltip, mouseX, mouseY);
TooltipRenderer.drawHoveringText(mc, Constants.RECIPE_TRANSFER_TOOLTIP, mouseX, mouseY);
}
}
}
Expand Down
Expand Up @@ -55,7 +55,8 @@ public IRecipeTransferError transferRecipe(@Nonnull Container container, @Nonnul
StackHelper stackHelper = Internal.getStackHelper();

if (!SessionData.isJeiOnServer()) {
return handlerHelper.createInternalError();
String tooltipMessage = Translator.translateToLocal("jei.tooltip.error.recipe.transfer.no.server");
return handlerHelper.createUserErrorWithTooltip(tooltipMessage);
}

Map<Integer, Slot> inventorySlots = new HashMap<>();
Expand Down
Expand Up @@ -9,7 +9,7 @@
import mezz.jei.gui.RecipeLayout;

public class RecipeTransferErrorInternal implements IRecipeTransferError {
public static final RecipeTransferErrorInternal instance = new RecipeTransferErrorInternal();
public static final RecipeTransferErrorInternal INSTANCE = new RecipeTransferErrorInternal();

private RecipeTransferErrorInternal() {

Expand Down
13 changes: 8 additions & 5 deletions src/main/java/mezz/jei/transfer/RecipeTransferErrorTooltip.java
@@ -1,20 +1,23 @@
package mezz.jei.transfer;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

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

import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.gui.RecipeLayout;
import mezz.jei.config.Constants;
import mezz.jei.gui.TooltipRenderer;
import net.minecraft.client.Minecraft;
import net.minecraft.util.text.TextFormatting;

public class RecipeTransferErrorTooltip implements IRecipeTransferError {
@Nonnull
private final String message;
private final List<String> message = new ArrayList<>();

public RecipeTransferErrorTooltip(@Nonnull String message) {
this.message = message;
this.message.add(Constants.RECIPE_TRANSFER_TOOLTIP);
this.message.add(TextFormatting.RED + message);
}

@Nonnull
Expand Down
14 changes: 7 additions & 7 deletions src/main/java/mezz/jei/transfer/RecipeTransferHandlerHelper.java
Expand Up @@ -2,22 +2,24 @@

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

import mezz.jei.api.recipe.transfer.IRecipeTransferError;
import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper;
import mezz.jei.util.Log;
import mezz.jei.util.Translator;

public class RecipeTransferHandlerHelper implements IRecipeTransferHandlerHelper {
@Override
public IRecipeTransferError createInternalError() {
return RecipeTransferErrorInternal.instance;
return RecipeTransferErrorInternal.INSTANCE;
}

@Override
public IRecipeTransferError createUserErrorWithTooltip(@Nullable String tooltipMessage) {
if (tooltipMessage == null) {
Log.error("Null tooltipMessage", new NullPointerException());
return RecipeTransferErrorInternal.instance;
tooltipMessage = Translator.translateToLocal("jei.tooltip.error.recipe.transfer.unknown");
}
return new RecipeTransferErrorTooltip(tooltipMessage);
}
Expand All @@ -26,15 +28,13 @@ public IRecipeTransferError createUserErrorWithTooltip(@Nullable String tooltipM
public IRecipeTransferError createUserErrorForSlots(@Nullable String tooltipMessage, @Nullable Collection<Integer> missingItemSlots) {
if (tooltipMessage == null) {
Log.error("Null tooltipMessage", new NullPointerException());
return RecipeTransferErrorInternal.instance;
tooltipMessage = Translator.translateToLocal("jei.tooltip.error.recipe.transfer.unknown");
}
if (missingItemSlots == null) {
Log.error("Null missingItemSlots", new NullPointerException());
return RecipeTransferErrorInternal.instance;
}
if (missingItemSlots.isEmpty()) {
missingItemSlots = Collections.emptyList();
} else if (missingItemSlots.isEmpty()) {
Log.error("Empty missingItemSlots", new IllegalArgumentException());
return RecipeTransferErrorInternal.instance;
}

return new RecipeTransferErrorSlots(tooltipMessage, missingItemSlots);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/transfer/RecipeTransferUtil.java
Expand Up @@ -29,7 +29,7 @@ private static IRecipeTransferError transferRecipe(@Nonnull Container container,
if (doTransfer) {
Log.error("No Recipe Transfer handler for container {}", container.getClass());
}
return RecipeTransferErrorInternal.instance;
return RecipeTransferErrorInternal.INSTANCE;
}

return transferHandler.transferRecipe(container, recipeLayout, player, maxTransfer, doTransfer);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/jei/lang/en_US.lang
Expand Up @@ -5,7 +5,7 @@ jei.tooltip.show.all.recipes=Show All Recipes
jei.tooltip.delete.item=Click to Delete
jei.tooltip.liquid.amount.with.capacity=%,d / %,d mB
jei.tooltip.liquid.amount=%,d mB
jei.tooltip.transfer=Transfer Items
jei.tooltip.transfer=Move Items
jei.tooltip.recipe.ore.dict=Accepts any: %s
jei.tooltip.item.colors=Colors: %s
jei.tooltip.shapeless.recipe=Shapeless Recipe
Expand All @@ -14,6 +14,8 @@ jei.tooltip.cheat.mode=Cheat Mode
# Error Tooltips
jei.tooltip.error.recipe.transfer.missing=Missing Items
jei.tooltip.error.recipe.transfer.inventory.full=Inventory is too full
jei.tooltip.error.recipe.transfer.unknown=Unknown Error, see logs
jei.tooltip.error.recipe.transfer.no.server=The server must have JEI installed

# Error Messages
jei.chat.error.command.too.long=JEI must be on the server to handle this Chat Command, it is too long for Minecraft to send.
Expand Down

0 comments on commit 7503b98

Please sign in to comment.