Skip to content

Commit

Permalink
Add a jei category for alchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
cubebotfan committed Feb 23, 2025
1 parent 72c5aa9 commit 9489de2
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 5 deletions.
18 changes: 18 additions & 0 deletions kubejs/client_scripts/jei_categories/_jei_category_helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// priority: 100

//Java imports
//Mysterious Conversion recipe type
const ConversionRecipe = Java.loadClass('com.simibubi.create.compat.jei.ConversionRecipe')
//Used for creating Drawable graphics for JEI
const ResourceLocation = Java.loadClass('net.minecraft.resources.ResourceLocation');
const JEIIDrawableAnimated = Java.loadClass('mezz.jei.api.gui.drawable.IDrawableAnimated');
//Used to make the FE energy tooltip when hovering over the energy bar
const ThermalStringHelper = Java.loadClass('cofh.lib.util.helpers.StringHelper');
//Used for to draw block models in jei categories
const Boolean = Java.loadClass('java.lang.Boolean');
const Axis = Java.loadClass('com.mojang.math.Axis');
const BlockStateProperties = Java.loadClass('net.minecraft.world.level.block.state.properties.BlockStateProperties');
const AnimatedKinetics = Java.loadClass('com.simibubi.create.compat.jei.category.animations.AnimatedKinetics');

//initialize globals
if (!global.jeiCategories) global.jeiCategories = {}
103 changes: 103 additions & 0 deletions kubejs/client_scripts/jei_categories/alchemy/alchemy_handlers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
if (!global.jeiCategories.alchemy) global.jeiCategories.alchemy = {
recipeType: null,
resources: {
energyEmpty: null,
energyFull: null,
alchemyArrow: null
},
handlers: {
verifyRecipe: undefined,
setRecipe: undefined,
draw: undefined,
tooltips: undefined
},
loadResources: undefined
};

global.jeiCategories.alchemy.loadResources = function(guiHelper) {
this.resources.energyEmpty = guiHelper.createDrawable(
new ResourceLocation("cabin:textures/gui/jei/widgets.png"),
0,
0,
14,
18
);
this.resources.energyFull = guiHelper.createAnimatedDrawable(
guiHelper.createDrawable(new ResourceLocation("cabin:textures/gui/jei/widgets.png"), 14, 0, 14, 18),
40,
JEIIDrawableAnimated.StartDirection.BOTTOM,
false
);
this.resources.alchemyArrow = guiHelper.createDrawable(
new ResourceLocation("cabin:textures/gui/jei/widgets.png"),
28,
0,
42,
18
);
}

global.jeiCategories.alchemy.handlers.verifyRecipe = (jeiHelpers, recipe) => {
// IMPORTANT: Always return true or false. If you do not, it could crash the game or cause JEI to not work properly.
if (!recipe) return false;
if (!recipe.data) return false;
if (!recipe.data.input) return false;
if (!recipe.data.output) return false;

return true;
}

global.jeiCategories.alchemy.handlers.setRecipe = (jeiHelpers, builder, recipe, focuses) => {
let guiHelper = jeiHelpers.getGuiHelper()
let inputItems = recipe.data.input;

for(let i=0;i<inputItems.length;++i) {
builder.addSlot("INPUT", 20+(20*i), 45)
.addItemStack(Item.of(inputItems[i]))
.setStandardSlotBackground()
.setBackground(guiHelper.getSlotDrawable(), -1, -1);
}
builder.addSlot("CATALYST", 75, 45)
.addItemStack(Item.of('minecraft:hopper_minecart'));

builder.addSlot("OUTPUT", 114, 45)
.addItemStack(Item.of(recipe.data.output))
.setOutputSlotBackground()
.setBackground(guiHelper.getOutputSlot(), -1, -1);

}

global.jeiCategories.alchemy.handlers.draw = (jeiHelpers, recipe, recipeSlotsView, guiGraphics, mouseX, mouseY) => {
global.jeiCategories.alchemy.resources.energyEmpty.draw(guiGraphics, 5, 44);
global.jeiCategories.alchemy.resources.energyFull.draw(guiGraphics, 5, 44);
global.jeiCategories.alchemy.resources.alchemyArrow.draw(guiGraphics, 60, 44);

//I don't fully understand this matrix stuff, most of it is copied from Create
let matrixStack = guiGraphics.pose();
matrixStack.pushPose();
matrixStack.translate(2, 22, 200);
matrixStack.translate(75, 5, 0);
matrixStack.mulPose(Axis.XP.rotationDegrees(-15.5));
matrixStack.mulPose(Axis.YP.rotationDegrees(22.5 + 90));

AnimatedKinetics.defaultBlockElement(Block.getBlock('thermal:machine_frame').defaultBlockState())
.rotateBlock(0, 0, 0)
.scale(20)
.render(guiGraphics);

matrixStack.translate(0, 20, 0);

AnimatedKinetics.defaultBlockElement(Block.getBlock('createdeco:green_industrial_iron_lamp').defaultBlockState().setValue(BlockStateProperties.FACING, Direction.DOWN).setValue(BlockStateProperties.LIT, new Boolean(true)))
.rotateBlock(0, 0, 0)
.scale(20)
.render(guiGraphics);

matrixStack.popPose();
}

global.jeiCategories.alchemy.handlers.tooltips = (jeiHelpers, recipe, recipeSlotsView, mouseX, mouseY) => {
if (mouseX>5&&mouseX<18&&mouseY>44&&mouseY<61) {
return [ThermalStringHelper.getTextComponent("info.cofh.energy").append(": " + ThermalStringHelper.format(recipe.data.energy) + " " + ThermalStringHelper.localize("info.cofh.unit_rf"))];
}
return [];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
JEIAddedEvents.registerCategories((event) => {
event.custom("kubejs:alchemy", (category) => {
let guiHelper = category.jeiHelpers.getGuiHelper();
global.jeiCategories.alchemy.recipeType = category.recipeType;
global.jeiCategories.alchemy.loadResources(guiHelper);

category.title("Alchemical Laser")
.background(guiHelper.createBlankDrawable(146, 70))
.icon(guiHelper.createDrawableItemStack(Item.of('kubejs:alchemical_laser')))
.setIsRecipeHandledByCategory((recipe) => {
return global.jeiCategories.alchemy.handlers["verifyRecipe"](category.jeiHelpers, recipe);
})
.setSetRecipeHandler((builder, recipe, focuses) => {
global.jeiCategories.alchemy.handlers["setRecipe"](category.jeiHelpers, builder, recipe, focuses);
})
.setDrawHandler((recipe, recipeSlotsView, guiGraphics, mouseX, mouseY) => {
global.jeiCategories.alchemy.handlers["draw"](category.jeiHelpers, recipe, recipeSlotsView, guiGraphics, mouseX, mouseY);
})
.setTooltipHandler((recipe, recipeSlotsView, mouseX, mouseY) => {
return global.jeiCategories.alchemy.handlers["tooltips"](category.jeiHelpers, recipe, recipeSlotsView, mouseX, mouseY);
})
});
});

JEIAddedEvents.registerRecipeCatalysts(event => {
let addRecipeCatalyst = function(ingredient, recipeTypes) {
return event.data["addRecipeCatalyst(net.minecraft.world.item.ItemStack,mezz.jei.api.recipe.RecipeType[])"](ingredient, recipeTypes);
}
addRecipeCatalyst(Item.of('thermal:machine_frame'), [global.jeiCategories.alchemy.recipeType]);
addRecipeCatalyst(Item.of('kubejs:alchemical_laser'), [global.jeiCategories.alchemy.recipeType]);
addRecipeCatalyst(Item.of('minecraft:hopper_minecart'), [global.jeiCategories.alchemy.recipeType]);
})

JEIAddedEvents.registerRecipes((event) => {
event.custom("kubejs:alchemy")
.add({input: ["thermal:flux_magnet", "minecraft:basalt"], output: "thermal:basalz_rod", energy: 80})
.add({input: ["ae2:entropy_manipulator", "minecraft:snowball"], output: "thermal:blizz_rod", energy: 160});
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
// let MysteriousItemConversionCategory = Java.loadClass('com.simibubi.create.compat.jei.category.MysteriousItemConversionCategory')
const ConversionRecipe = Java.loadClass('com.simibubi.create.compat.jei.ConversionRecipe')

//We have to brute force things since the kubejs create guide doesn't work at all
JEIEvents.removeRecipes(event => {
const mysteryConversion = global.jeiRuntime.jeiHelpers.getRecipeType('create:mystery_conversion').get()
global.jeiRuntime.recipeManager.addRecipes(mysteryConversion, [
//Chapter 3 singularity recipe
new ConversionRecipe.create('ae2:singularity', 'ae2:quantum_entangled_singularity'),
//Refined radiance mysterious conversion
new ConversionRecipe.create('create:chromatic_compound', 'create:refined_radiance'),
new ConversionRecipe.create('create:chromatic_compound', 'create:shadow_steel')
Expand Down
5 changes: 5 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,11 @@
"projectID": 238086,
"required": true
},
{
"fileID": 5817338,
"projectID": 594387,
"required": true
},
{
"fileID": 5404565,
"projectID": 570630,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9489de2

Please sign in to comment.