Skip to content

Commit abde5ee

Browse files
authored
JEI Category Improvements (#34)
Various code cleanups and adjustments to JEI category displays to make them better. See #34 for full details and commit history.
1 parent f49d3f2 commit abde5ee

33 files changed

Lines changed: 332 additions & 201 deletions

src/main/java/gregtech/api/recipes/RecipeMap.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class RecipeMap<R extends RecipeBuilder<R>> implements SoundEmitter<Recip
6868
protected SoundEvent sound;
6969

7070
private final Map<FluidKey, Collection<Recipe>> recipeFluidMap = new HashMap<>();
71-
private final Collection<Recipe> recipeList = new ArrayList<>();
71+
private final List<Recipe> recipeList = new ArrayList<>();
7272

7373
public RecipeMap(String unlocalizedName,
7474
int minInputs, int maxInputs, int minOutputs, int maxOutputs,
@@ -528,4 +528,10 @@ public interface IChanceFunction {
528528
*/
529529
int chanceFor(int chance, int boostPerTier, int boostTier);
530530
}
531+
532+
// sort standard recipes by EU/t
533+
public static void sort() {
534+
for(var map : RECIPE_MAPS)
535+
map.recipeList.sort(Comparator.comparingInt(Recipe::getEUt));
536+
}
531537
}

src/main/java/gregtech/api/recipes/machines/FuelRecipeMap.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,10 @@ public FuelRecipeMap setSound(SoundEvent event) {
109109
this.sound = event;
110110
return this;
111111
}
112+
113+
// Sort fuels by energy density
114+
public static void sort() {
115+
for(var map : RECIPE_MAPS)
116+
map.recipeList.sort(Comparator.comparingDouble(FuelRecipe::getEnergyDensity));
117+
}
112118
}

src/main/java/gregtech/api/recipes/recipes/FuelRecipe.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ public class FuelRecipe {
1818
private final FluidStack recipeFluid;
1919
private final int duration;
2020
private final long minVoltage;
21+
private final double energyDensity;
2122

2223
public FuelRecipe(FluidStack recipeFluid, int duration, long minVoltage) {
2324
this.recipeFluid = recipeFluid.copy();
2425
this.duration = duration;
2526
this.minVoltage = minVoltage;
27+
this.energyDensity = (duration * minVoltage) / (double) recipeFluid.amount;
2628
}
2729

2830
@ZenMethod("create")
@@ -54,4 +56,9 @@ public boolean matches(long maxVoltage, FluidStack inputFluid) {
5456
public ILiquidStack ctGetFluid() {
5557
return new MCLiquidStack(getRecipeFluid());
5658
}
59+
60+
public double getEnergyDensity() {
61+
return energyDensity;
62+
}
63+
5764
}

src/main/java/gregtech/common/CommonProxy.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import gregtech.api.block.machines.MachineItemBlock;
66
import gregtech.api.enchants.EnchantmentEnderDamage;
77
import gregtech.api.items.metaitem.MetaItem;
8+
import gregtech.api.recipes.RecipeMap;
89
import gregtech.api.recipes.crafttweaker.MetaItemBracketHandler;
10+
import gregtech.api.recipes.machines.FuelRecipeMap;
911
import gregtech.api.recipes.recipeproperties.BlastTemperatureProperty;
1012
import gregtech.api.unification.material.type.DustMaterial;
1113
import gregtech.api.unification.material.type.Material;
@@ -265,6 +267,8 @@ public void onLoad() {
265267

266268
public void onPostLoad() {
267269
WoodMachineRecipes.postInit();
270+
RecipeMap.sort();
271+
FuelRecipeMap.sort();
268272
}
269273

270274
}

src/main/java/gregtech/integration/jei/GTOreCategory.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.minecraft.client.gui.FontRenderer;
1717
import net.minecraft.world.DimensionType;
1818
import net.minecraftforge.common.DimensionManager;
19+
import org.jetbrains.annotations.NotNull;
1920

2021
import java.util.*;
2122
import java.util.function.Supplier;
@@ -35,7 +36,7 @@ public class GTOreCategory extends PrimitiveRecipeCategory<GTOreInfo, GTOreInfo>
3536
protected List<Integer> dimensionIDs;
3637
protected final int FONT_HEIGHT = Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT;
3738
protected final Map<Integer, String> namedDimensions = WorldGenRegistry.getNamedDimensions();
38-
private Supplier<List<Integer>> dimension = this::getAllRegisteredDimensions;
39+
private final Supplier<List<Integer>> dimension = this::getAllRegisteredDimensions;
3940
private final int NUM_OF_SLOTS = 5;
4041
private final int SLOT_WIDTH = 18;
4142
private final int SLOT_HEIGHT = 18;
@@ -46,12 +47,13 @@ public GTOreCategory(IGuiHelper guiHelper) {
4647
guiHelper.createBlankDrawable(176, 166),
4748
guiHelper);
4849

49-
this.slot = guiHelper.createDrawable(GuiTextures.SLOT.imageLocation, 0, 0, 18, 18, 18, 18);
50+
this.slot = guiHelper.drawableBuilder(GuiTextures.SLOT.imageLocation, 0, 0, 18, 18)
51+
.setTextureSize(18, 18).build();
5052
}
5153

5254

5355
@Override
54-
public void setRecipe(IRecipeLayout recipeLayout, GTOreInfo recipeWrapper, IIngredients ingredients) {
56+
public void setRecipe(IRecipeLayout recipeLayout, GTOreInfo recipeWrapper, @NotNull IIngredients ingredients) {
5557

5658
IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
5759
int baseYPos = 19;
@@ -69,7 +71,7 @@ public void setRecipe(IRecipeLayout recipeLayout, GTOreInfo recipeWrapper, IIngr
6971
itemStackGroup.init(i + 2, false, xPos, yPos);
7072
}
7173

72-
itemStackGroup.addTooltipCallback(recipeWrapper::addTooltip);
74+
itemStackGroup.addTooltipCallback(recipeWrapper);
7375
itemStackGroup.set(ingredients);
7476
veinName = recipeWrapper.getVeinName();
7577
minHeight = recipeWrapper.getMinHeight();
@@ -80,12 +82,13 @@ public void setRecipe(IRecipeLayout recipeLayout, GTOreInfo recipeWrapper, IIngr
8082
}
8183

8284
@Override
83-
public IRecipeWrapper getRecipeWrapper(GTOreInfo recipe) {
85+
@NotNull
86+
public IRecipeWrapper getRecipeWrapper(@NotNull GTOreInfo recipe) {
8487
return recipe;
8588
}
8689

8790
@Override
88-
public void drawExtras(Minecraft minecraft) {
91+
public void drawExtras(@NotNull Minecraft minecraft) {
8992

9093
int baseXPos = 70;
9194
int baseYPos = 19;

src/main/java/gregtech/integration/jei/GTOreInfo.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
import gregtech.api.worldgen.populator.IVeinPopulator;
1010
import gregtech.api.worldgen.populator.SurfaceBlockPopulator;
1111
import gregtech.api.worldgen.populator.SurfaceRockPopulator;
12+
import mezz.jei.api.gui.ITooltipCallback;
1213
import mezz.jei.api.ingredients.IIngredients;
14+
import mezz.jei.api.ingredients.VanillaTypes;
1315
import mezz.jei.api.recipe.IRecipeWrapper;
1416
import net.minecraft.block.Block;
1517
import net.minecraft.block.state.IBlockState;
@@ -19,6 +21,7 @@
1921
import net.minecraft.world.biome.Biome;
2022
import net.minecraftforge.fluids.*;
2123
import org.apache.commons.lang3.tuple.Pair;
24+
import org.jetbrains.annotations.NotNull;
2225

2326
import java.nio.file.FileSystem;
2427
import java.nio.file.FileSystems;
@@ -28,7 +31,7 @@
2831

2932
import static gregtech.api.GTValues.*;
3033

31-
public class GTOreInfo implements IRecipeWrapper {
34+
public class GTOreInfo implements IRecipeWrapper, ITooltipCallback<ItemStack> {
3235

3336
private final OreDepositDefinition definition;
3437
private final int maxHeight;
@@ -38,8 +41,8 @@ public class GTOreInfo implements IRecipeWrapper {
3841
private final int weight;
3942
private final IVeinPopulator veinPopulator;
4043
private final BlockFiller blockFiller;
41-
private List<List<ItemStack>> groupedInputsAsItemStacks = new ArrayList<>();
42-
private List<List<ItemStack>> groupedOutputsAsItemStacks = new ArrayList<>();
44+
private final List<List<ItemStack>> groupedInputsAsItemStacks = new ArrayList<>();
45+
private final List<List<ItemStack>> groupedOutputsAsItemStacks;
4346
private final Function<Biome, Integer> biomeFunction;
4447

4548
public GTOreInfo(OreDepositDefinition definition) {
@@ -90,8 +93,8 @@ public GTOreInfo(OreDepositDefinition definition) {
9093

9194
@Override
9295
public void getIngredients(IIngredients ingredients) {
93-
ingredients.setInputLists(ItemStack.class, groupedInputsAsItemStacks);
94-
ingredients.setOutputLists(ItemStack.class, groupedOutputsAsItemStacks);
96+
ingredients.setInputLists(VanillaTypes.ITEM, groupedInputsAsItemStacks);
97+
ingredients.setOutputLists(VanillaTypes.ITEM, groupedOutputsAsItemStacks);
9598
}
9699

97100
//Finds the possible blocks from the Filler definition, and returns them as ItemStacks
@@ -136,14 +139,12 @@ public List<List<ItemStack>> findUniqueBlocksAsItemStack(List<ItemStack> itemLis
136139
List<List<ItemStack>> groupedItems = new ArrayList<>();
137140
int entries = itemList.size();
138141

139-
140142
//return early for Fluid Generation
141143
if(veinPopulator instanceof FluidSpringPopulator) {
142144
groupedItems.add(new ArrayList<>(itemList));
143145
return groupedItems;
144146
}
145147

146-
147148
ItemStack firstItem = itemList.get(0);
148149
List<ItemStack> oreList = new ArrayList<>();
149150
oreList.add(firstItem);
@@ -226,7 +227,7 @@ public String makePrettyName(String name) {
226227
}
227228

228229
//Creates a tooltip based on the specific slots
229-
public void addTooltip(int slotIndex, boolean input, Object ingredient, List<String> tooltip) {
230+
public void onTooltip(int slotIndex, boolean input, @NotNull ItemStack ingredient, @NotNull List<String> tooltip) {
230231

231232
//Only add the Biome Information to the selected Ore
232233
if(slotIndex == 0) {

src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoCategory.java

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@
1414
import mezz.jei.api.recipe.IRecipeCategory;
1515
import mezz.jei.gui.recipes.RecipeLayout;
1616
import net.minecraft.client.resources.I18n;
17+
import org.jetbrains.annotations.NotNull;
1718

18-
import java.util.HashMap;
19+
import java.util.LinkedHashMap;
1920
import java.util.Map;
2021

2122
public class MultiblockInfoCategory implements IRecipeCategory<MultiblockInfoRecipeWrapper> {
@@ -30,46 +31,52 @@ public MultiblockInfoCategory(IJeiHelpers helpers) {
3031
this.icon = guiHelper.drawableBuilder(GuiTextures.MULTIBLOCK_CATEGORY.imageLocation, 0, 0, 18, 18).setTextureSize(18, 18).build();
3132
}
3233

33-
public static final Map<String, MultiblockInfoRecipeWrapper> multiblockRecipes = new HashMap<String, MultiblockInfoRecipeWrapper>() {{
34-
put("primitive_blast_furnace", new MultiblockInfoRecipeWrapper(new PrimitiveBlastFurnaceInfo()));
35-
put("coke_oven", new MultiblockInfoRecipeWrapper(new CokeOvenInfo()));
36-
put("vacuum_freezer", new MultiblockInfoRecipeWrapper(new VacuumFreezerInfo()));
37-
put("implosion_compressor", new MultiblockInfoRecipeWrapper(new ImplosionCompressorInfo()));
38-
put("pyrolyze_oven", new MultiblockInfoRecipeWrapper(new PyrolyzeOvenInfo()));
39-
put("cracker_unit", new MultiblockInfoRecipeWrapper(new CrackerUnitInfo()));
40-
put("diesel_engine", new MultiblockInfoRecipeWrapper(new DieselEngineInfo()));
41-
put("distillation_tower", new MultiblockInfoRecipeWrapper(new DistillationTowerInfo()));
42-
put("electric_blast_furnace", new MultiblockInfoRecipeWrapper(new ElectricBlastFurnaceInfo()));
43-
put("multi_smelter", new MultiblockInfoRecipeWrapper(new MultiSmelterInfo()));
44-
put("large_bronze_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_BRONZE_BOILER)));
45-
put("large_steel_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_STEEL_BOILER)));
46-
put("large_titanium_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_TITANIUM_BOILER)));
47-
put("large_tungstensteel_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_TUNGSTENSTEEL_BOILER)));
48-
put("large_steam_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_STEAM_TURBINE)));
49-
put("large_gas_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_GAS_TURBINE)));
50-
put("large_plasma_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_PLASMA_TURBINE)));
51-
}};
34+
public static final Map<String, MultiblockInfoRecipeWrapper> multiblockRecipes = new LinkedHashMap<>();
35+
static {
36+
var map = multiblockRecipes;
37+
map.put("primitive_blast_furnace", new MultiblockInfoRecipeWrapper(new PrimitiveBlastFurnaceInfo()));
38+
map.put("coke_oven", new MultiblockInfoRecipeWrapper(new CokeOvenInfo()));
39+
map.put("vacuum_freezer", new MultiblockInfoRecipeWrapper(new VacuumFreezerInfo()));
40+
map.put("implosion_compressor", new MultiblockInfoRecipeWrapper(new ImplosionCompressorInfo()));
41+
map.put("pyrolyze_oven", new MultiblockInfoRecipeWrapper(new PyrolyzeOvenInfo()));
42+
map.put("cracker_unit", new MultiblockInfoRecipeWrapper(new CrackerUnitInfo()));
43+
map.put("diesel_engine", new MultiblockInfoRecipeWrapper(new DieselEngineInfo()));
44+
map.put("distillation_tower", new MultiblockInfoRecipeWrapper(new DistillationTowerInfo()));
45+
map.put("electric_blast_furnace", new MultiblockInfoRecipeWrapper(new ElectricBlastFurnaceInfo()));
46+
map.put("multi_smelter", new MultiblockInfoRecipeWrapper(new MultiSmelterInfo()));
47+
map.put("large_bronze_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_BRONZE_BOILER)));
48+
map.put("large_steel_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_STEEL_BOILER)));
49+
map.put("large_titanium_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_TITANIUM_BOILER)));
50+
map.put("large_tungstensteel_boiler", new MultiblockInfoRecipeWrapper(new LargeBoilerInfo(MetaTileEntities.LARGE_TUNGSTENSTEEL_BOILER)));
51+
map.put("large_steam_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_STEAM_TURBINE)));
52+
map.put("large_gas_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_GAS_TURBINE)));
53+
map.put("large_plasma_turbine", new MultiblockInfoRecipeWrapper(new LargeTurbineInfo(MetaTileEntities.LARGE_PLASMA_TURBINE)));
54+
}
5255

5356
public static void registerRecipes(IModRegistry registry) {
5457
registry.addRecipes(multiblockRecipes.values(), "gregtech:multiblock_info");
5558
}
5659

5760
@Override
61+
@NotNull
5862
public String getUid() {
5963
return "gregtech:multiblock_info";
6064
}
6165

6266
@Override
67+
@NotNull
6368
public String getTitle() {
6469
return I18n.format("gregtech.multiblock.title");
6570
}
6671

6772
@Override
73+
@NotNull
6874
public String getModName() {
6975
return GTValues.MODID;
7076
}
7177

7278
@Override
79+
@NotNull
7380
public IDrawable getBackground() {
7481
return background;
7582
}
@@ -80,10 +87,13 @@ public IDrawable getIcon() {
8087
}
8188

8289
@Override
83-
public void setRecipe(IRecipeLayout recipeLayout, MultiblockInfoRecipeWrapper recipeWrapper, IIngredients ingredients) {
90+
public void setRecipe(IRecipeLayout recipeLayout,
91+
MultiblockInfoRecipeWrapper recipeWrapper,
92+
@NotNull IIngredients ingredients)
93+
{
8494
recipeWrapper.setRecipeLayout((RecipeLayout) recipeLayout, this.guiHelper);
8595

8696
IGuiItemStackGroup itemStackGroup = recipeLayout.getItemStacks();
87-
itemStackGroup.addTooltipCallback(recipeWrapper::addBlockTooltips);
97+
itemStackGroup.addTooltipCallback(recipeWrapper);
8898
}
8999
}

src/main/java/gregtech/integration/jei/multiblock/MultiblockInfoPage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public abstract class MultiblockInfoPage {
2121

2222
private final Hash.Strategy<ItemStack> strategy = ItemStackHashStrategy.comparingAllButCount();
2323

24-
private Map<ItemStack, List<ITextComponent>> blockTooltips = new Object2ObjectOpenCustomHashMap<>(strategy);
24+
private final Map<ItemStack, List<ITextComponent>> blockTooltips = new Object2ObjectOpenCustomHashMap<>(strategy);
2525

2626
private static final ITextComponent defaultText = new TextComponentTranslation("gregtech.multiblock.preview.any_hatch").setStyle(new Style().setColor(TextFormatting.GREEN));
2727

0 commit comments

Comments
 (0)