Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ configurations {
dependencies {
api jarJar("dev.technici4n:GrandPower:${project.grandpower_version}")

compileOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge:${project.jei_version}"
compileOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge-api:${project.jei_version}"
if (project.runtime_itemlist_mod == "jei") {
localRuntimeOnly "mezz.jei:jei-${project.jei_minecraft_version}-neoforge:${project.jei_version}"
}
Expand Down
7 changes: 4 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ emi_version=1.1.10
ftb_quests_version=2100.1.3
ftb_teams_version=2100.1.0
jade_file_id=5493270
jei_minecraft_version=1.21
jei_version=19.8.2.99
jei_version_range=[19.8.2.99,]
# JEI Versions https://github.com/mezz/JustEnoughItems#1211
jei_minecraft_version=1.21.1
jei_version=19.20.0.241
jei_version_range=[19.19.0,]
kubejs_version=2100.7.0-build.102
patchouli_version=1.21-87-NEOFORGE-SNAPSHOT
rei_version=16.0.729
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.compat.viewer.impl.jei;

import aztech.modern_industrialization.compat.viewer.abstraction.ViewerCategory;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.IGuiHelper;
import net.minecraft.client.gui.GuiGraphics;

public class DrawableIcon implements IDrawable {
private final ViewerCategory.Icon.Texture texture;

public static IDrawable create(IGuiHelper guiHelper, ViewerCategory.Icon icon) {
return switch (icon) {
case ViewerCategory.Icon.Stack stack -> guiHelper.createDrawableItemStack(stack.stack());
case ViewerCategory.Icon.Texture texture -> new DrawableIcon(texture);
case null -> throw new NullPointerException("Icon cannot be null");
};
}

public DrawableIcon(ViewerCategory.Icon.Texture texture) {
this.texture = texture;
}

@Override
public int getWidth() {
return 18;
}

@Override
public int getHeight() {
return 18;
}

@Override
public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) {
guiGraphics.blit(texture.loc(), xOffset - 1, yOffset - 1, 0, texture.u(), texture.v(), 18, 18, 256, 256);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
import mezz.jei.api.gui.builder.ITooltipBuilder;
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.gui.drawable.IDrawableStatic;
import mezz.jei.api.gui.ingredient.IRecipeSlotTooltipCallback;
import mezz.jei.api.gui.ingredient.IRecipeSlotView;
import mezz.jei.api.gui.ingredient.IRecipeSlotsView;
import mezz.jei.api.helpers.IJeiHelpers;
import mezz.jei.api.recipe.IFocusGroup;
import mezz.jei.api.recipe.RecipeIngredientRole;
import mezz.jei.api.recipe.RecipeType;
import mezz.jei.api.recipe.category.IRecipeCategory;
import mezz.jei.api.recipe.category.AbstractRecipeCategory;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
Expand All @@ -56,58 +54,26 @@
import net.neoforged.neoforge.fluids.FluidType;
import org.jetbrains.annotations.Nullable;

class ViewerCategoryJei<D> implements IRecipeCategory<D> {
class ViewerCategoryJei<D> extends AbstractRecipeCategory<D> {
private final IJeiHelpers helpers;
public final ViewerCategory<D> wrapped;
public final RecipeType<D> recipeType;
private final IDrawable background, icon, itemSlot, fluidSlot;
private final IDrawable fluidSlot;

public ViewerCategoryJei(IJeiHelpers helpers, ViewerCategory<D> wrapped) {
super(
RecipeType.create(wrapped.id.getNamespace(), wrapped.id.getPath(), wrapped.dataClass),
wrapped.title,
DrawableIcon.create(helpers.getGuiHelper(), wrapped.icon),
wrapped.width - 8,
wrapped.height - 8);

this.helpers = helpers;
this.wrapped = wrapped;
this.recipeType = RecipeType.create(wrapped.id.getNamespace(), wrapped.id.getPath(), wrapped.dataClass);

this.background = helpers.getGuiHelper().createBlankDrawable(wrapped.width - 8, wrapped.height - 8);
this.icon = wrapped.icon instanceof ViewerCategory.Icon.Stack stack ? helpers.getGuiHelper().createDrawableItemStack(stack.stack())
: new IDrawable() {
@Override
public int getWidth() {
return 18;
}

@Override
public int getHeight() {
return 18;
}

@Override
public void draw(GuiGraphics guiGraphics, int xOffset, int yOffset) {
var texture = (ViewerCategory.Icon.Texture) wrapped.icon;
guiGraphics.blit(texture.loc(), xOffset - 1, yOffset - 1, 0, texture.u(), texture.v(), 18, 18, 256, 256);
}
};
this.itemSlot = helpers.getGuiHelper().getSlotDrawable();
this.fluidSlot = helpers.getGuiHelper().createDrawable(MachineScreen.SLOT_ATLAS, 18, 0, 18, 18);
}

@Override
public RecipeType<D> getRecipeType() {
return recipeType;
}

@Override
public Component getTitle() {
return wrapped.title;
}

@Override
public IDrawable getBackground() {
return background;
}

@Override
public IDrawable getIcon() {
return icon;
var guiHelper = helpers.getGuiHelper();
this.fluidSlot = guiHelper.createDrawable(MachineScreen.SLOT_ATLAS, 18, 0, 18, 18);
}

@Override
Expand All @@ -130,8 +96,9 @@ public void invisibleOutput(ItemStack stack) {
}

private ViewerCategory.SlotBuilder slot(RecipeIngredientRole role, int x, int y) {
var slotBuilder = builder.addSlot(role, x - 4, y - 4);
slotBuilder.setBackground(itemSlot, -1, -1);
var slotBuilder = builder.addSlot(role, x - 4, y - 4)
.setStandardSlotBackground();

return new ViewerCategory.SlotBuilder() {
@Override
public ViewerCategory.SlotBuilder variant(TransferVariant<?> variant) {
Expand All @@ -150,23 +117,11 @@ public ViewerCategory.SlotBuilder variant(TransferVariant<?> variant) {
}

private static void addProbability(IRecipeSlotBuilder slot, float probability) {
slot.addTooltipCallback(new IRecipeSlotTooltipCallback() {
@Override
public void onTooltip(IRecipeSlotView recipeSlotView, List<Component> tooltip) {
var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT;
var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input);
if (probabilityLine != null) {
tooltip.add(probabilityLine);
}
}

@Override
public void onRichTooltip(IRecipeSlotView recipeSlotView, ITooltipBuilder tooltip) {
var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT;
var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input);
if (probabilityLine != null) {
tooltip.add(probabilityLine);
}
slot.addRichTooltipCallback((recipeSlotView, tooltip) -> {
var input = recipeSlotView.getRole() == RecipeIngredientRole.INPUT;
var probabilityLine = ViewerUtil.getProbabilityTooltip(probability, input);
if (probabilityLine != null) {
tooltip.add(probabilityLine);
}
});
}
Expand Down Expand Up @@ -218,6 +173,7 @@ public ViewerCategory.SlotBuilder markCatalyst() {

@Override
public void draw(D recipe, IRecipeSlotsView recipeSlotsView, GuiGraphics guiGraphics, double mouseX, double mouseY) {
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(-4, -4, 0);

wrapped.buildWidgets(recipe, new ViewerCategory.WidgetList() {
Expand Down Expand Up @@ -254,7 +210,7 @@ public void drawable(Consumer<GuiGraphics> widget) {
@Override
public void item(double x, double y, double w, double h, ItemLike item) {
guiGraphics.pose().pushPose();
var drawable = helpers.getGuiHelper().createDrawableItemStack(item.asItem().getDefaultInstance());
var drawable = helpers.getGuiHelper().createDrawableItemLike(item);
guiGraphics.pose().translate(x, y, 0);
guiGraphics.pose().scale((float) w / 16, (float) h / 16, 0);
drawable.draw(guiGraphics);
Expand All @@ -265,6 +221,8 @@ public void item(double x, double y, double w, double h, ItemLike item) {
public void tooltip(int x, int y, int w, int h, List<Component> tooltip) {
}
});

guiGraphics.pose().popPose();
}

@Override
Expand Down
Loading