Skip to content

Commit

Permalink
#79 1 allow displaying fluids without capacity in the tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
mezz committed Dec 31, 2015
1 parent b8dda26 commit 0c47de7
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -3,4 +3,4 @@ forgeversion=11.14.4.1577

version_major=1
version_minor=13
version_patch=2
version_patch=3
18 changes: 18 additions & 0 deletions src/main/java/mezz/jei/api/gui/IGuiFluidStackGroup.java
Expand Up @@ -25,9 +25,27 @@ public interface IGuiFluidStackGroup extends IGuiIngredientGroup<FluidStack> {
* @param capacityMb maximum amount of fluid that this "tank" can hold in milli-buckets
* @param overlay optional overlay to display over the tank.
* Typically the overlay is fluid level lines, but it could also be a mask to shape the tank.
* @deprecated since JEI 1.13.3. Use the version that has showCapacity
*/
@Deprecated
void init(int slotIndex, boolean input, int xPosition, int yPosition, int width, int height, int capacityMb, @Nullable IDrawable overlay);

/**
* Sets up the fluid at slotIndex.
*
* @param slotIndex the slot index of this fluid
* @param input whether this slot is an input
* @param xPosition x position relative to the recipe background
* @param yPosition y position relative to the recipe background
* @param width width of this fluid
* @param height height of this fluid
* @param capacityMb maximum amount of fluid that this "tank" can hold in milli-buckets
* @param showCapacity show the capacity in the tooltip
* @param overlay optional overlay to display over the tank.
* Typically the overlay is fluid level lines, but it could also be a mask to shape the tank.
*/
void init(int slotIndex, boolean input, int xPosition, int yPosition, int width, int height, int capacityMb, boolean showCapacity, @Nullable IDrawable overlay);

@Override
void set(int slotIndex, @Nonnull Collection<FluidStack> fluidStacks);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/mezz/jei/api/package-info.java
@@ -1,4 +1,4 @@
@API(apiVersion = "1.3.0", owner = "JEI", provides = "JustEnoughItemsAPI")
@API(apiVersion = "1.4.0", owner = "JEI", provides = "JustEnoughItemsAPI")
package mezz.jei.api;

import net.minecraftforge.fml.common.API;
14 changes: 11 additions & 3 deletions src/main/java/mezz/jei/gui/ingredients/FluidStackRenderer.java
Expand Up @@ -21,20 +21,23 @@
import net.minecraftforge.fluids.FluidStack;

import mezz.jei.api.gui.IDrawable;
import mezz.jei.util.Translator;

public class FluidStackRenderer implements IIngredientRenderer<FluidStack> {
private static final int TEX_WIDTH = 16;
private static final int TEX_HEIGHT = 16;
private static final int MIN_FLUID_HEIGHT = 1; // ensure tiny amounts of fluid are still visible

private final int capacityMb;
private final boolean showCapacity;
private final int width;
private final int height;
@Nullable
private final IDrawable overlay;

public FluidStackRenderer(int capacityMb, int width, int height, @Nullable IDrawable overlay) {
public FluidStackRenderer(int capacityMb, boolean showCapacity, int width, int height, @Nullable IDrawable overlay) {
this.capacityMb = capacityMb;
this.showCapacity = showCapacity;
this.width = width;
this.height = height;
this.overlay = overlay;
Expand Down Expand Up @@ -159,8 +162,13 @@ public List<String> getTooltip(@Nonnull Minecraft minecraft, @Nonnull FluidStack
String fluidName = fluidType.getLocalizedName(fluidStack);
tooltip.add(fluidName);

String amount = String.format(Locale.ENGLISH, EnumChatFormatting.GRAY + "%,d / %,d", fluidStack.amount, capacityMb);
tooltip.add(amount);
String amount;
if (showCapacity) {
amount = Translator.translateToLocalFormatted("jei.tooltip.liquid.amount.with.capacity", fluidStack.amount, capacityMb);
} else {
amount = Translator.translateToLocalFormatted("jei.tooltip.liquid.amount", fluidStack.amount);
}
tooltip.add(EnumChatFormatting.GRAY + amount);

return tooltip;
}
Expand Down
Expand Up @@ -12,7 +12,12 @@ public class GuiFluidStackGroup extends GuiIngredientGroup<FluidStack, GuiIngred

@Override
public void init(int slotIndex, boolean input, int xPosition, int yPosition, int width, int height, int capacityMb, @Nullable IDrawable overlay) {
FluidStackRenderer renderer = new FluidStackRenderer(capacityMb, width, height, overlay);
init(slotIndex, input, xPosition, yPosition, width, height, capacityMb, true, overlay);
}

@Override
public void init(int slotIndex, boolean input, int xPosition, int yPosition, int width, int height, int capacityMb, boolean showCapacity, @Nullable IDrawable overlay) {
FluidStackRenderer renderer = new FluidStackRenderer(capacityMb, showCapacity, width, height, overlay);
GuiIngredient<FluidStack> guiIngredient = new GuiIngredient<>(renderer, helper, input, xPosition, yPosition, width, height, 0);
guiIngredients.put(slotIndex, guiIngredient);
}
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/mezz/jei/plugins/jei/debug/DebugRecipeCategory.java
Expand Up @@ -2,11 +2,15 @@

import javax.annotation.Nonnull;

import java.util.List;

import net.minecraft.client.Minecraft;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fluids.FluidStack;

import mezz.jei.api.IGuiHelper;
import mezz.jei.api.gui.IDrawable;
import mezz.jei.api.gui.IGuiFluidStackGroup;
Expand Down Expand Up @@ -74,12 +78,14 @@ public void setRecipe(@Nonnull IRecipeLayout recipeLayout, @Nonnull IRecipeWrapp
guiItemStacks.set(0, new ItemStack(Blocks.diamond_block));

IGuiFluidStackGroup guiFluidStacks = recipeLayout.getFluidStacks();
guiFluidStacks.init(0, true, 4, 4, 12, 47, 2000, tankOverlay);
guiFluidStacks.init(1, true, 24, 0, 12, 47, 16000, null);
guiFluidStacks.init(2, true, 50, 0, 24, 24, 2000, tankOverlay);
guiFluidStacks.init(3, true, 75, 0, 12, 47, 100, tankOverlay);
guiFluidStacks.set(0, recipeWrapper.getFluidInputs().get(0));
guiFluidStacks.set(1, recipeWrapper.getFluidInputs().get(1));
guiFluidStacks.set(3, recipeWrapper.getFluidInputs().get(0));
guiFluidStacks.init(0, true, 4, 4, 12, 47, 2000, true, tankOverlay);
guiFluidStacks.init(1, true, 24, 0, 12, 47, 16000, true, null);
guiFluidStacks.init(2, true, 50, 0, 24, 24, 2000, true, tankOverlay);
guiFluidStacks.init(3, true, 75, 0, 12, 47, 100, false, tankOverlay);

List<FluidStack> fluidInputs = recipeWrapper.getFluidInputs();
guiFluidStacks.set(0, fluidInputs.get(0));
guiFluidStacks.set(1, fluidInputs.get(1));
guiFluidStacks.set(3, fluidInputs.get(0));
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/jei/lang/en_US.lang
Expand Up @@ -2,6 +2,8 @@
jei.tooltip.config=Config
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

# Error Tooltips
jei.tooltip.error.recipe.transfer.missing=Missing Items
Expand Down

0 comments on commit 0c47de7

Please sign in to comment.