Skip to content

Commit

Permalink
add progress bar animation to JEI
Browse files Browse the repository at this point in the history
  • Loading branch information
DStrand1 committed Jul 18, 2021
1 parent d206ba0 commit 0a3929f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,14 @@ private Recipe findByInputs(long voltage, List<ItemStack> inputs, List<FluidStac
}

public ModularUI.Builder createJeiUITemplate(IItemHandlerModifiable importItems, IItemHandlerModifiable exportItems, FluidTankList importFluids, FluidTankList exportFluids) {
return createUITemplate(() -> 0.0, importItems, exportItems, importFluids, exportFluids);
return createUITemplate(this::jeiProgressBar, importItems, exportItems, importFluids, exportFluids);
}

private double timer = 0;
private double jeiProgressBar() {
timer += 0.0005;
if (timer > 1.0) timer = 0.0;
return timer;
}

//this DOES NOT include machine control widgets or binds player inventory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import gregtech.api.gui.IRenderContext;
import gregtech.api.gui.ModularUI;
import gregtech.api.gui.Widget;
import gregtech.api.gui.widgets.ProgressWidget;
import gregtech.api.gui.widgets.SlotWidget;
import gregtech.api.gui.widgets.TankWidget;
import gregtech.api.recipes.RecipeMap;
Expand All @@ -15,21 +16,23 @@
import mezz.jei.api.gui.IGuiItemStackGroup;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.items.ItemStackHandler;
import net.minecraftforge.items.SlotItemHandler;

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

public class RecipeMapCategory implements IRecipeCategory<GTRecipeWrapper> {

private final RecipeMap<?> recipeMap;
private final ModularUI modularUI;
private ItemStackHandler importItems, exportItems;
private FluidTankList importFluids, exportFluids;
private final ItemStackHandler importItems, exportItems;
private final FluidTankList importFluids, exportFluids;
private final IDrawable backgroundDrawable;

public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
Expand All @@ -51,27 +54,31 @@ public RecipeMapCategory(RecipeMap<?> recipeMap, IGuiHelper guiHelper) {
}

@Override
@Nonnull
public String getUid() {
return GTValues.MODID + ":" + recipeMap.unlocalizedName;
}

@Override
@Nonnull
public String getTitle() {
return recipeMap.getLocalizedName();
}

@Override
@Nonnull
public String getModName() {
return GTValues.MODID;
}

@Override
@Nonnull
public IDrawable getBackground() {
return backgroundDrawable;
}

@Override
public void setRecipe(IRecipeLayout recipeLayout, GTRecipeWrapper recipeWrapper, IIngredients ingredients) {
public void setRecipe(IRecipeLayout recipeLayout, @Nonnull GTRecipeWrapper recipeWrapper, @Nonnull IIngredients ingredients) {
IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
IGuiFluidStackGroup fluidStackGroup = recipeLayout.getFluidStacks();
for (Widget uiWidget : modularUI.guiWidgets.values()) {
Expand All @@ -97,7 +104,7 @@ public void setRecipe(IRecipeLayout recipeLayout, GTRecipeWrapper recipeWrapper,
TankWidget tankWidget = (TankWidget) uiWidget;
if (importFluids.getFluidTanks().contains(tankWidget.fluidTank)) {
int importIndex = importFluids.getFluidTanks().indexOf(tankWidget.fluidTank);
List<List<FluidStack>> inputsList = ingredients.getInputs(FluidStack.class);
List<List<FluidStack>> inputsList = ingredients.getInputs(VanillaTypes.FLUID);
int fluidAmount = 0;
if (inputsList.size() > importIndex && !inputsList.get(importIndex).isEmpty())
fluidAmount = inputsList.get(importIndex).get(0).amount;
Expand All @@ -111,7 +118,7 @@ public void setRecipe(IRecipeLayout recipeLayout, GTRecipeWrapper recipeWrapper,

} else if (exportFluids.getFluidTanks().contains(tankWidget.fluidTank)) {
int exportIndex = exportFluids.getFluidTanks().indexOf(tankWidget.fluidTank);
List<List<FluidStack>> inputsList = ingredients.getOutputs(FluidStack.class);
List<List<FluidStack>> inputsList = ingredients.getOutputs(VanillaTypes.FLUID);
int fluidAmount = 0;
if (inputsList.size() > exportIndex && !inputsList.get(exportIndex).isEmpty())
fluidAmount = inputsList.get(exportIndex).get(0).amount;
Expand All @@ -133,8 +140,9 @@ public void setRecipe(IRecipeLayout recipeLayout, GTRecipeWrapper recipeWrapper,
}

@Override
public void drawExtras(Minecraft minecraft) {
public void drawExtras(@Nonnull Minecraft minecraft) {
for (Widget widget : modularUI.guiWidgets.values()) {
if (widget instanceof ProgressWidget) widget.detectAndSendChanges();
widget.drawInBackground(0, 0, new IRenderContext() {
});
widget.drawInForeground(0, 0);
Expand Down

0 comments on commit 0a3929f

Please sign in to comment.