Skip to content

Commit

Permalink
Add the upgrade type to the tooltip of the upgrade recipe (JEI)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrbysco committed Sep 5, 2024
1 parent 88878c7 commit d14d761
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-08-21T23:30:13.887644198 Languages: en_us for mod: statues
e425fa5bdd0452b884c456886492ad8109fcf6ad assets/statues/lang/en_us.json
// 1.21.1 2024-09-05T19:45:11.278503 Languages: en_us for mod: statues
f24d78b394e3633c0e8f73f3b1578bf52d756460 assets/statues/lang/en_us.json
1 change: 1 addition & 0 deletions src/generated/resources/assets/statues/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@
"statues.upgrade.speed.name": "Speed",
"statues.upgrade.unglowing.name": "Unglowing",
"statues.upgrade.upgrade.name": "Upgrade",
"statues.upgrade.upgrade_type": "Upgrade Type",
"statues.villager.info": "WIP, Trades in the future.",
"tooltip.statues.player.info": "Player Username: ",
"tooltip.statues.player.info2": "Player UUID: ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,24 @@
import com.shynieke.statues.registry.StatueTags;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotRichTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocus;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.RegistryAccess;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

Expand Down Expand Up @@ -57,6 +62,7 @@ public IDrawable getIcon() {

@Override
public void setRecipe(IRecipeLayoutBuilder builder, UpgradeRecipe recipe, IFocusGroup focuses) {
UpgradeTooltipCallback callback = new UpgradeTooltipCallback(recipe);
Minecraft minecraft = Minecraft.getInstance();
ClientLevel level = minecraft.level;
if (level == null) {
Expand Down Expand Up @@ -94,9 +100,9 @@ public void setRecipe(IRecipeLayoutBuilder builder, UpgradeRecipe recipe, IFocus
} else {
setUpgradeSlots(outputStack, 1);
}
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(outputStack);
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(outputStack).addRichTooltipCallback(callback);
} else {
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(recipe.getResultItem(registryAccess));
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(recipe.getResultItem(registryAccess)).addRichTooltipCallback(callback);
}
} else {
List<ItemStack> centerList = new ArrayList<>();
Expand Down Expand Up @@ -132,9 +138,9 @@ public void setRecipe(IRecipeLayoutBuilder builder, UpgradeRecipe recipe, IFocus
}
stackList.add(stack);
}
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStacks(stackList);
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStacks(stackList).addRichTooltipCallback(callback);
} else {
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(recipe.getResultItem(registryAccess));
builder.addSlot(RecipeIngredientRole.OUTPUT, 127, 23).addItemStack(recipe.getResultItem(registryAccess)).addRichTooltipCallback(callback);
}
}

Expand Down Expand Up @@ -172,6 +178,19 @@ public void draw(UpgradeRecipe recipe, IRecipeSlotsView recipeSlotsView, GuiGrap
IRecipeCategory.super.draw(recipe, recipeSlotsView, guiGraphics, mouseX, mouseY);
}

public class UpgradeTooltipCallback implements IRecipeSlotRichTooltipCallback {
public final MutableComponent component;

public UpgradeTooltipCallback(UpgradeRecipe recipe) {
this.component = recipe.getUpgradeName();
}

@Override
public void onRichTooltip(IRecipeSlotView recipeSlotView, ITooltipBuilder tooltip) {
tooltip.add(component);
}
}

@Override
public Component getTitle() {
return localizedName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ protected void addTranslations() {
add("statues.info.kills", "Kills:");
add("statues.info.upgrade_slots", "Upgrade Slots:");

add("statues.upgrade.upgrade_type", "Upgrade Type");
add("statues.upgrade.upgrade.name", "Upgrade");
add("statues.upgrade.glowing.name", "Glowing");
add("statues.upgrade.unglowing.name", "Unglowing");
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/com/shynieke/statues/recipe/UpgradeRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
import com.shynieke.statues.items.StatueBlockItem;
import com.shynieke.statues.registry.StatueDataComponents;
import com.shynieke.statues.registry.StatueTags;
import net.minecraft.ChatFormatting;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.NonNullList;
import net.minecraft.network.RegistryFriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.codec.StreamCodec;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
Expand Down Expand Up @@ -80,6 +83,18 @@ public UpgradeType getUpgradeType() {
return upgradeType;
}

public MutableComponent getUpgradeName() {
String descriptionID = "statues.upgrade." + getUpgradeType().getSerializedName() + ".name";
MutableComponent component = Component.translatable("statues.upgrade.upgrade_type").withStyle(ChatFormatting.YELLOW);
component.append(" : ");
component = component.append(Component.translatable(descriptionID).withStyle(ChatFormatting.GRAY));

if (getTier() > 0) {
component.append(" ").append(Component.translatable("enchantment.level." + getTier()));
}
return component;
}

@Override
public boolean matches(RecipeInput recipeInput, Level level) {
ItemStack statueStack = recipeInput.getItem(0);
Expand Down

0 comments on commit d14d761

Please sign in to comment.