Skip to content

Commit

Permalink
Fix foundry ore rates affecting byproducts in JEI (#5018)
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed Nov 24, 2022
1 parent 1723c8d commit 50a9b96
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import slimeknights.mantle.recipe.helper.LoggingRecipeSerializer;
import slimeknights.mantle.recipe.helper.RecipeHelper;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer.OreRateType;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;

Expand Down Expand Up @@ -92,12 +93,17 @@ public void handleByproducts(IMeltingContainer inv, IFluidHandler handler) {
}
}

/** Gets the recipe output for display in JEI */
/** Gets the recipe output for foundry display in JEI */
public List<List<FluidStack>> getOutputWithByproducts() {
if (outputWithByproducts == null) {
outputWithByproducts = Stream.concat(Stream.of(output), byproducts.stream())
.map(Collections::singletonList)
.collect(Collectors.toList());
outputWithByproducts = Stream.concat(Stream.of(output).map(output -> {
// boost for foundry rate, this method is used for the foundry only
OreRateType rate = getOreType();
if (rate != null) {
return new FluidStack(output, Config.COMMON.foundryOreRate.applyOreBoost(rate, output.getAmount()));
}
return output;
}), byproducts.stream()).map(Collections::singletonList).collect(Collectors.toList());
}
return outputWithByproducts;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
package slimeknights.tconstruct.plugin.jei.melting;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.forge.ForgeTypes;
import mezz.jei.api.gui.builder.IRecipeLayoutBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.helpers.IGuiHelper;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.mantle.fluid.tooltip.FluidTooltipHandler;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.common.config.Config;
import slimeknights.tconstruct.library.recipe.FluidValues;
import slimeknights.tconstruct.library.recipe.melting.IMeltingContainer.OreRateType;
import slimeknights.tconstruct.library.recipe.melting.MeltingRecipe;
import slimeknights.tconstruct.plugin.jei.AlloyRecipeCategory;
import slimeknights.tconstruct.plugin.jei.TConstructJEIConstants;
import slimeknights.tconstruct.smeltery.TinkerSmeltery;

import java.util.List;

/** Extension of melting for byproducts, but ditchs solid fuels */
public class FoundryCategory extends AbstractMeltingCategory {
private static final Component TITLE = TConstruct.makeTranslation("jei", "foundry.title");

/** Tooltip callback for fluids */
private static final IRecipeSlotTooltipCallback METAL_ORE_TOOLTIP = new MeltingFluidCallback(OreRateType.METAL);
private static final IRecipeSlotTooltipCallback GEM_ORE_TOOLTIP = new MeltingFluidCallback(OreRateType.GEM);
@Getter
private final IDrawable icon;

Expand Down Expand Up @@ -64,33 +53,12 @@ public void setRecipe(IRecipeLayoutBuilder builder, MeltingRecipe recipe, IFocus
builder.addSlot(RecipeIngredientRole.INPUT, 24, 18).addIngredients(recipe.getInput());

// output fluid
OreRateType oreType = recipe.getOreType();
IRecipeSlotTooltipCallback tooltip;
if (oreType == OreRateType.METAL) {
tooltip = METAL_ORE_TOOLTIP;
} else if (oreType == OreRateType.GEM) {
tooltip = GEM_ORE_TOOLTIP;
} else {
tooltip = MeltingFluidCallback.INSTANCE;
}
AlloyRecipeCategory.drawVariableFluids(builder, RecipeIngredientRole.OUTPUT, 96, 4, 32, 32, recipe.getOutputWithByproducts(), FluidValues.METAL_BLOCK, tooltip);
AlloyRecipeCategory.drawVariableFluids(builder, RecipeIngredientRole.OUTPUT, 96, 4, 32, 32, recipe.getOutputWithByproducts(), FluidValues.METAL_BLOCK, MeltingFluidCallback.INSTANCE);

// fuel
builder.addSlot(RecipeIngredientRole.RENDER_ONLY, 4, 4)
.addTooltipCallback(FUEL_TOOLTIP)
.setFluidRenderer(1, false, 12, 32)
.addIngredients(ForgeTypes.FLUID_STACK, MeltingFuelHandler.getUsableFuels(recipe.getTemperature()));
}

/** Adds amounts to outputs and temperatures to fuels */
@RequiredArgsConstructor
private static class MeltingFluidCallback extends AbstractMeltingCategory.MeltingFluidCallback {
@Getter
private final OreRateType oreRate;

@Override
protected boolean appendMaterial(FluidStack stack, List<Component> list) {
return FluidTooltipHandler.appendMaterialNoShift(stack.getFluid(), Config.COMMON.foundryOreRate.applyOreBoost(oreRate, stack.getAmount()), list);
}
}
}

0 comments on commit 50a9b96

Please sign in to comment.