Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JEI text-button to see JEI Recipes ran at higher tiers #2468

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7ce98eb
yeah i forgot to commit again
vrejhead May 2, 2024
0f5ee03
cool (spotless)
vrejhead May 2, 2024
ceb906e
don't allow tiers below min tier
vrejhead May 3, 2024
1012b2e
allow recipemaps to disable the overclock button
vrejhead May 3, 2024
700133c
yeah should have used long
vrejhead May 3, 2024
c7bd95e
correct comments and stuff
vrejhead May 3, 2024
f940598
spotless jumpscare
vrejhead May 3, 2024
12e842f
make initExtras logic not trash
vrejhead May 3, 2024
3617e38
mb this actually makes it not trash
vrejhead May 3, 2024
3a4e6c1
hopefully no more outdated comments
vrejhead May 3, 2024
e457c01
left and right clicks and long eut and custom fusion overclocks
vrejhead May 3, 2024
05169b7
add !!!COLOR!!!
vrejhead May 4, 2024
a98ca75
thanks spotless
vrejhead May 4, 2024
d2877d1
pass state instead of current text
vrejhead May 4, 2024
28f73cc
move to bottom right, add tooltip
vrejhead May 4, 2024
9cc66cb
manual LCR override
vrejhead May 4, 2024
d2f4754
spotless + dedicate logic into seperate method
vrejhead May 4, 2024
83f07da
yeah recipeHeight isnt always 120
vrejhead May 4, 2024
6ff20df
improve logic
vrejhead May 4, 2024
5d98bf8
Add the base chance + tier boosted chance to output items in recipe t…
Zorbatron Aug 5, 2024
ca8fdbd
Do the same for the ore processing pages
Zorbatron Aug 5, 2024
b614312
Reset the voltage to the recipe if middle clicked
Zorbatron Aug 9, 2024
c6fe2f6
Merge branch 'master' into jei-overclocks
Zorbatron Nov 17, 2024
ff93f2c
Make middle clicking reset the ore page too.
Zorbatron Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/main/java/gregtech/api/recipes/RecipeMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public class RecipeMap<R extends RecipeBuilder<R>> {
public ChanceBoostFunction chanceFunction = DEFAULT_CHANCE_FUNCTION;

public final String unlocalizedName;

private boolean jeiOverclockButton = true;
private final R recipeBuilderSample;
private int maxInputs;
private int maxOutputs;
Expand Down Expand Up @@ -365,6 +365,15 @@ public RecipeMap<? extends RecipeBuilder<?>> getSmallRecipeMap() {
return smallRecipeMap;
}

public RecipeMap<R> disableJeiOverclockButton() {
this.jeiOverclockButton = false;
return this;
}

public boolean jeiOverclockButtonEnabled() {
return this.jeiOverclockButton;
}

/**
* Internal usage <strong>only</strong>, use {@link RecipeBuilder#buildAndRegister()}
*
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/gregtech/api/recipes/RecipeMapBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class RecipeMapBuilder<B extends RecipeBuilder<B>> {
private boolean modifyFluidInputs = true;
private int fluidOutputs;
private boolean modifyFluidOutputs = true;
private boolean jeiOverclockButton = true;

private boolean isGenerator;

Expand Down Expand Up @@ -265,6 +266,11 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
return this;
}

public @NotNull RecipeMapBuilder<B> disableJeiOverclockButton() {
this.jeiOverclockButton = false;
return this;
}

/**
* Add a recipe build action to be performed upon this RecipeMap's builder's recipe registration.
*
Expand Down Expand Up @@ -297,6 +303,9 @@ public RecipeMapBuilder(@NotNull String unlocalizedName, @NotNull B defaultRecip
if (buildActions != null) {
recipeMap.onRecipeBuild(buildActions);
}
if (!jeiOverclockButton) {
recipeMap.disableJeiOverclockButton();
}
return recipeMap;
}
}
9 changes: 8 additions & 1 deletion src/main/java/gregtech/api/recipes/RecipeMaps.java
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ public final class RecipeMaps {
.fluidOutputs(1)
.ui(CokeOvenUI::new)
.sound(GTSoundEvents.FIRE)
.disableJeiOverclockButton()
.build();

/**
Expand Down Expand Up @@ -1289,6 +1290,7 @@ public final class RecipeMaps {
.modifyFluidInputs(false)
.modifyFluidOutputs(false)
.sound(GTSoundEvents.FIRE)
.disableJeiOverclockButton()
.build();

/**
Expand Down Expand Up @@ -1338,7 +1340,7 @@ public final class RecipeMaps {

@ZenProperty
public static final RecipeMap<ComputationRecipeBuilder> RESEARCH_STATION_RECIPES = new RecipeMapResearchStation<>(
"research_station", new ComputationRecipeBuilder(), ResearchStationUI::new);
"research_station", new ComputationRecipeBuilder(), ResearchStationUI::new).disableJeiOverclockButton();

@ZenProperty
public static final RecipeMap<SimpleRecipeBuilder> ROCK_BREAKER_RECIPES = new RecipeMapBuilder<>("rock_breaker",
Expand Down Expand Up @@ -1486,6 +1488,7 @@ public final class RecipeMaps {
.sound(GTSoundEvents.COMBUSTION)
.allowEmptyOutputs()
.generator()
.disableJeiOverclockButton()
.build();

@ZenProperty
Expand All @@ -1497,6 +1500,7 @@ public final class RecipeMaps {
.sound(GTSoundEvents.TURBINE)
.allowEmptyOutputs()
.generator()
.disableJeiOverclockButton()
.build();

@ZenProperty
Expand All @@ -1509,6 +1513,7 @@ public final class RecipeMaps {
.sound(GTSoundEvents.TURBINE)
.allowEmptyOutputs()
.generator()
.disableJeiOverclockButton()
.build();

@ZenProperty
Expand All @@ -1520,6 +1525,7 @@ public final class RecipeMaps {
.sound(GTSoundEvents.COMBUSTION)
.allowEmptyOutputs()
.generator()
.disableJeiOverclockButton()
.build();

@ZenProperty
Expand All @@ -1532,6 +1538,7 @@ public final class RecipeMaps {
.sound(GTSoundEvents.TURBINE)
.allowEmptyOutputs()
.generator()
.disableJeiOverclockButton()
.build();

private RecipeMaps() {}
Expand Down
79 changes: 79 additions & 0 deletions src/main/java/gregtech/integration/jei/basic/OreByProduct.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package gregtech.integration.jei.basic;

import gregtech.api.GTValues;
import gregtech.api.GregTechAPI;
import gregtech.api.recipes.chance.output.impl.ChancedItemOutput;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
Expand All @@ -10,12 +12,18 @@
import gregtech.api.unification.ore.OrePrefix;
import gregtech.client.utils.TooltipHelper;
import gregtech.common.metatileentities.MetaTileEntities;
import gregtech.integration.jei.utils.JeiInteractableText;

import net.minecraft.client.Minecraft;
import net.minecraft.client.audio.PositionedSoundRecord;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.resources.I18n;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fml.client.config.GuiUtils;
import net.minecraftforge.oredict.OreDictionary;

import com.google.common.collect.ImmutableList;
Expand All @@ -25,6 +33,7 @@
import mezz.jei.api.ingredients.VanillaTypes;
import mezz.jei.api.recipe.IRecipeWrapper;
import org.apache.commons.lang3.tuple.Pair;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -37,6 +46,8 @@ public class OreByProduct implements IRecipeWrapper {

private static final int NUM_INPUTS = 21;

public final List<JeiInteractableText> jeiTexts = new ArrayList<>();

public static void addOreByProductPrefix(OrePrefix orePrefix) {
if (!ORES.contains(orePrefix)) {
ORES.add(orePrefix);
Expand Down Expand Up @@ -275,6 +286,33 @@ public OreByProduct(Material material) {
} else {
addEmptyOutputs(6);
}

// just here because if highTier is disabled, if a recipe is (incorrectly) registering
// UIV+ recipes, this allows it to go up to the recipe tier for that recipe only
int maxTier = GregTechAPI.isHighTier() ? GTValues.UIV : GTValues.MAX_TRUE;
// scuffed positioning because we can't have good ui(until mui soontm)
jeiTexts.add(
new JeiInteractableText(0, 160, GTValues.VOCNF[GTValues.LV], 0x111111, GTValues.LV, true)
.setTooltipBuilder((state, tooltip) -> {
tooltip.add(I18n.format("gregtech.jei.overclock_button", GTValues.VOCNF[state]));
tooltip.add(TooltipHelper.BLINKING_CYAN + I18n.format("gregtech.jei.overclock_warn"));
})
.setClickAction((minecraft, text, mouseX, mouseY, mouseButton) -> {
int state = text.getState();
if (mouseButton == 0) {
// increment tier if left click
if (++state > maxTier) state = GTValues.LV;
} else if (mouseButton == 1) {
// decrement tier if right click
if (--state < GTValues.LV) state = maxTier;
} else if (mouseButton == 2) {
// reset tier if middle click
state = GTValues.LV;
} else return false;
text.setCurrentText(GTValues.VOCNF[state]);
text.setState(state);
return true;
}));
}

@Override
Expand All @@ -290,6 +328,18 @@ public void addTooltip(int slotIndex, boolean input, Object ingredient, List<Str
double chance = entry.getChance() / 100.0;
double boost = entry.getChanceBoost() / 100.0;
tooltip.add(TooltipHelper.BLINKING_CYAN + I18n.format("gregtech.recipe.chance", chance, boost));

// This kinda assumes that all ore processing recipes are ULV or LV, but I'm not sure how I would
// get the original recipe's EU/t here instead of just the map of chances

// Add the total chance to the tooltip
int tier = jeiTexts.get(0).getState();
int tierDifference = tier - GTValues.LV;

// The total chance may or may not max out at 100%.
// TODO possibly change in the future.
double totalChance = Math.min(chance + boost * tierDifference, 100);
tooltip.add(I18n.format("gregtech.recipe.chance_total", GTValues.VOCNF[tier], totalChance));
}
}

Expand Down Expand Up @@ -352,4 +402,33 @@ private void addGemChance(int baseLow, int tierLow, int baseHigh, int tierHigh,
addChance(baseLow, tierLow);
}
}

@Override
public void drawInfo(@NotNull Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY) {
for (JeiInteractableText text : jeiTexts) {
text.render(minecraft, recipeWidth, recipeHeight, mouseX, mouseY);
if (text.isHovering(mouseX, mouseY)) {
List<String> tooltip = new ArrayList<>();
text.buildTooltip(tooltip);
if (tooltip.isEmpty()) continue;
int width = (int) (minecraft.displayWidth / 2f + recipeWidth / 2f);
GuiUtils.drawHoveringText(tooltip, mouseX, mouseY, width, minecraft.displayHeight,
Math.min(150, width - mouseX - 5), minecraft.fontRenderer);
GlStateManager.disableLighting();
}
}
}

@Override
public boolean handleClick(@NotNull Minecraft minecraft, int mouseX, int mouseY, int mouseButton) {
for (JeiInteractableText text : jeiTexts) {
if (text.isHovering(mouseX, mouseY) &&
text.getTextClickAction().click(minecraft, text, mouseX, mouseY, mouseButton)) {
Minecraft.getMinecraft().getSoundHandler()
.playSound(PositionedSoundRecord.getMasterRecord(SoundEvents.UI_BUTTON_CLICK, 1.0F));
return true;
}
}
return false;
}
}
Loading