From ec2836c91a189dbfc6ca715c11149cb25c31d8c8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 13 Jan 2019 00:25:30 +0800 Subject: Better Recipe Tooltips --- .../shedaniel/rei/gui/widget/ItemSlotWidget.java | 8 +++-- .../rei/mixin/MixinBrewingRecipeRegistry.java | 19 +++++------- .../me/shedaniel/rei/plugin/BrewingRecipe.java | 1 + .../rei/plugin/DefaultBlastingCategory.java | 7 ++++- .../rei/plugin/DefaultBrewingCategory.java | 35 ++++++++++++++++++---- .../rei/plugin/DefaultSmeltingCategory.java | 7 ++++- .../rei/plugin/DefaultSmokingCategory.java | 7 ++++- 7 files changed, 63 insertions(+), 21 deletions(-) (limited to 'src/main/java/me') diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java index bf3897c47..3aa94c8fc 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemSlotWidget.java @@ -1,7 +1,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; import me.shedaniel.rei.listeners.IMixinContainerGui; @@ -92,10 +91,15 @@ public class ItemSlotWidget extends Drawable implements HighlightableWidget { if (containerGui != null) toolTip = containerGui.getContainerGui().getStackTooltip(itemStack).stream().filter(s -> !s.equals(modString)).collect(Collectors.toList()); else toolTip.add(itemStack.getDisplayName().getFormattedText()); - toolTip.add("§9§o" + ClientHelper.getModFromItemStack(itemStack)); + toolTip.addAll(getExtraToolTips(itemStack)); + toolTip.add(modString); return toolTip; } + protected List getExtraToolTips(ItemStack stack) { + return Lists.newArrayList(); + } + protected String getItemCountOverlay(ItemStack currentStack) { return ""; } diff --git a/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java b/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java index 5813a42b3..15ea467dc 100644 --- a/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java +++ b/src/main/java/me/shedaniel/rei/mixin/MixinBrewingRecipeRegistry.java @@ -22,24 +22,21 @@ import java.util.List; @Mixin(BrewingRecipeRegistry.class) public class MixinBrewingRecipeRegistry { - private static final List ITEM_RECIPES = Lists.newArrayList(); + private static final List SELF_ITEM_RECIPES = Lists.newArrayList(); private static final List REGISTERED_POTION_TYPES = Lists.newArrayList(); - private static final List POTION_TYPES = Lists.newArrayList(); + private static final List SELF_POTION_TYPES = Lists.newArrayList(); @Inject(method = "method_8080", at = @At("RETURN")) private static void method_8080(Item item_1, CallbackInfo ci) { - if (!(item_1 instanceof PotionItem)) { - } else { - POTION_TYPES.add(Ingredient.ofItems(new ItemProvider[]{item_1})); + if (item_1 instanceof PotionItem) { + SELF_POTION_TYPES.add(Ingredient.ofItems(new ItemProvider[]{item_1})); } } @Inject(method = "method_8071", at = @At("RETURN")) private static void method_8071(Item item_1, Item item_2, Item item_3, CallbackInfo ci) { - if (!(item_1 instanceof PotionItem)) { - } else if (!(item_3 instanceof PotionItem)) { - } else { - ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.ofItems(new ItemProvider[]{item_2}), item_3)); + if (item_1 instanceof PotionItem && item_3 instanceof PotionItem) { + SELF_ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.ofItems(new ItemProvider[]{item_2}), item_3)); } } @@ -49,7 +46,7 @@ public class MixinBrewingRecipeRegistry { registerPotionType(potion_1); if (!REGISTERED_POTION_TYPES.contains(potion_2)) registerPotionType(potion_2); - POTION_TYPES.forEach(ingredient -> { + SELF_POTION_TYPES.forEach(ingredient -> { for(ItemStack stack : ingredient.getStackArray()) { DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(stack.copy(), potion_1), Ingredient.ofItems(new ItemProvider[]{item_1}), PotionUtil.setPotion(stack.copy(), potion_2))); @@ -59,7 +56,7 @@ public class MixinBrewingRecipeRegistry { private static void registerPotionType(Potion potion) { REGISTERED_POTION_TYPES.add(potion); - ITEM_RECIPES.forEach(recipe -> { + SELF_ITEM_RECIPES.forEach(recipe -> { DefaultPlugin.registerBrewingDisplay(new DefaultBrewingDisplay(PotionUtil.setPotion(recipe.input.getDefaultStack(), potion), recipe.ingredient, PotionUtil.setPotion(recipe.output.getDefaultStack(), potion))); }); diff --git a/src/main/java/me/shedaniel/rei/plugin/BrewingRecipe.java b/src/main/java/me/shedaniel/rei/plugin/BrewingRecipe.java index b4bcdb39a..0d501105f 100644 --- a/src/main/java/me/shedaniel/rei/plugin/BrewingRecipe.java +++ b/src/main/java/me/shedaniel/rei/plugin/BrewingRecipe.java @@ -14,4 +14,5 @@ public class BrewingRecipe { this.ingredient = ingredient_1; this.output = object_2; } + } \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java index 9e4855267..75c35407c 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultBlastingCategory.java @@ -57,7 +57,12 @@ public class DefaultBlastingCategory implements IRecipeCategory> input = recipeDisplay.getInput(); widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 1, input.get(0), true, true, containerGui, true)); - widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true)); + widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.smelting.fuel")); + } + }); widgets.add(new ItemSlotWidget(startPoint.x + 61, startPoint.y + 19, recipeDisplay.getOutput(), false, true, containerGui, true)); return widgets; } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java index 1f28e1ce1..41cfcab83 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultBrewingCategory.java @@ -55,11 +55,36 @@ public class DefaultBrewingCategory implements IRecipeCategory getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.brewing.input")); + } + }); + widgets.add(new ItemSlotWidget(startPoint.x + 40, startPoint.y + 1, recipeDisplay.getInput().get(1), false, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.brewing.reactant")); + } + }); + widgets.add(new ItemSlotWidget(startPoint.x + 40, startPoint.y + 35, recipeDisplay.getOutput(0), false, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.brewing.result")); + } + }); + widgets.add(new ItemSlotWidget(startPoint.x + 63, startPoint.y + 42, recipeDisplay.getOutput(1), false, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.brewing.result")); + } + }); + widgets.add(new ItemSlotWidget(startPoint.x + 86, startPoint.y + 35, recipeDisplay.getOutput(2), false, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.brewing.result")); + } + }); return widgets; } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java index 3bd10f472..63fbbd164 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultSmeltingCategory.java @@ -57,7 +57,12 @@ public class DefaultSmeltingCategory implements IRecipeCategory> input = recipeDisplay.getInput(); widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 1, input.get(0), true, true, containerGui, true)); - widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true)); + widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.smelting.fuel")); + } + }); widgets.add(new ItemSlotWidget(startPoint.x + 61, startPoint.y + 19, recipeDisplay.getOutput(), false, true, containerGui, true)); return widgets; } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java b/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java index dda60ba4b..eedce2977 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultSmokingCategory.java @@ -57,7 +57,12 @@ public class DefaultSmokingCategory implements IRecipeCategory> input = recipeDisplay.getInput(); widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 1, input.get(0), true, true, containerGui, true)); - widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true)); + widgets.add(new ItemSlotWidget(startPoint.x + 1, startPoint.y + 37, recipeDisplay.getFuel(), true, true, containerGui, true) { + @Override + protected List getExtraToolTips(ItemStack stack) { + return Arrays.asList(I18n.translate("category.rei.smelting.fuel")); + } + }); widgets.add(new ItemSlotWidget(startPoint.x + 61, startPoint.y + 19, recipeDisplay.getOutput(), false, true, containerGui, true)); return widgets; } -- cgit