From e2dcd87c2c9e57667a223067923f3abaa8748eb6 Mon Sep 17 00:00:00 2001 From: Kli Kli Date: Mon, 30 Jan 2023 13:08:10 +0100 Subject: [PATCH] feat: re-enable jei now that it is available on 1.19.3 --- build.gradle | 9 +- gradle.properties | 12 +- .../occultism/integration/jei/JeiAccess.java | 15 +- .../occultism/integration/jei/JeiPlugin.java | 194 ++++----- .../integration/jei/JeiRecipeTypes.java | 23 +- ...torageControllerRecipeTransferHandler.java | 195 +++++---- .../jei/recipes/CrushingRecipeCategory.java | 129 +++--- .../jei/recipes/MinerRecipeCategory.java | 158 +++---- .../jei/recipes/RitualRecipeCategory.java | 406 +++++++++--------- .../jei/recipes/SpiritFireRecipeCategory.java | 130 +++--- 10 files changed, 633 insertions(+), 638 deletions(-) diff --git a/build.gradle b/build.gradle index 0cc5915a7..8e283824e 100644 --- a/build.gradle +++ b/build.gradle @@ -108,7 +108,7 @@ repositories { } maven { name = "Progwm16 maven - JEI" - url = 'https://dvs1.progwml6.com/files/maven' + url = 'https://maven.blamejared.com/' content { includeGroup "mezz.jei" } @@ -145,10 +145,9 @@ dependencies { minecraft "net.minecraftforge:forge:${forge_version}" //Jei - //TODO: reenable once updated -// compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-common-api:${jei_version}") -// compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge-api:${jei_version}") -// runtimeOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge:${jei_version}") + compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-common-api:${jei_version}") + compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge-api:${jei_version}") + runtimeOnly fg.deobf("mezz.jei:jei-${jei_mc_version}-forge:${jei_version}") //curios compileOnly fg.deobf("top.theillusivec4.curios:curios-forge:${curios_mc_version}-${curios_version}:api") diff --git a/gradle.properties b/gradle.properties index 262cdec86..138a8a7c9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,22 +5,22 @@ org.gradle.daemon=false mod_version=0.0.1 mc_version=1.19.3 -forge_version=1.19.3-44.0.41 +forge_version=1.19.3-44.1.8 mapping_channel=parchment #postfix is target mc version, optional prefix is source parchment mc version mapping_version=2022.12.18-1.19.3 -jei_mc_version=1.19.2 -jei_version=11.3.0.262 +jei_mc_version=1.19.3 +jei_version=12.1.1.13 curios_mc_version=1.19.3 curios_version=5.1.1.2 geckolib_mc_version=1.19.3 geckolib_version=4.0.2 -# SmartBrainLib v1.7.4 -smartbrainlib_file_id=4277541 -smartbrainlib_src_file_id=4277542 +# SmartBrainLib v1.8 +smartbrainlib_file_id=4312180 +smartbrainlib_src_file_id=4312182 modonomicon_mc_version=1.19.3 modonomicon_version=1.23.2 diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiAccess.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiAccess.java index 3f68cc244..78655484f 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiAccess.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiAccess.java @@ -23,20 +23,19 @@ package com.github.klikli_dev.occultism.integration.jei; import com.google.common.base.Strings; -//import mezz.jei.api.runtime.IJeiRuntime; +import mezz.jei.api.runtime.IJeiRuntime; public class JeiAccess { -//TODO: enable once jei is updated public static String getFilterText() { -// IJeiRuntime runtime = JeiPlugin.getJeiRuntime(); -// if (runtime != null) -// return runtime.getIngredientFilter().getFilterText(); + IJeiRuntime runtime = JeiPlugin.getJeiRuntime(); + if (runtime != null) + return runtime.getIngredientFilter().getFilterText(); return ""; } public static void setFilterText(String filter) { -// IJeiRuntime runtime = JeiPlugin.getJeiRuntime(); -// if (runtime != null) -// runtime.getIngredientFilter().setFilterText(Strings.nullToEmpty(filter)); + IJeiRuntime runtime = JeiPlugin.getJeiRuntime(); + if (runtime != null) + runtime.getIngredientFilter().setFilterText(Strings.nullToEmpty(filter)); } } diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiPlugin.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiPlugin.java index f6e61e342..392318c12 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiPlugin.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiPlugin.java @@ -30,22 +30,22 @@ import com.github.klikli_dev.occultism.crafting.recipe.MinerRecipe; import com.github.klikli_dev.occultism.crafting.recipe.RitualRecipe; import com.github.klikli_dev.occultism.crafting.recipe.SpiritFireRecipe; -//import com.github.klikli_dev.occultism.integration.jei.recipes.CrushingRecipeCategory; -//import com.github.klikli_dev.occultism.integration.jei.recipes.MinerRecipeCategory; -//import com.github.klikli_dev.occultism.integration.jei.recipes.RitualRecipeCategory; -//import com.github.klikli_dev.occultism.integration.jei.recipes.SpiritFireRecipeCategory; +import com.github.klikli_dev.occultism.integration.jei.recipes.CrushingRecipeCategory; +import com.github.klikli_dev.occultism.integration.jei.recipes.MinerRecipeCategory; +import com.github.klikli_dev.occultism.integration.jei.recipes.RitualRecipeCategory; +import com.github.klikli_dev.occultism.integration.jei.recipes.SpiritFireRecipeCategory; import com.github.klikli_dev.occultism.registry.OccultismBlocks; import com.github.klikli_dev.occultism.registry.OccultismItems; import com.github.klikli_dev.occultism.registry.OccultismRecipes; -//import mezz.jei.api.IModPlugin; -//import mezz.jei.api.constants.VanillaTypes; -//import mezz.jei.api.helpers.IStackHelper; -//import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; -//import mezz.jei.api.registration.IRecipeCatalystRegistration; -//import mezz.jei.api.registration.IRecipeCategoryRegistration; -//import mezz.jei.api.registration.IRecipeRegistration; -//import mezz.jei.api.registration.IRecipeTransferRegistration; -//import mezz.jei.api.runtime.IJeiRuntime; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.helpers.IStackHelper; +import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; +import mezz.jei.api.registration.IRecipeCatalystRegistration; +import mezz.jei.api.registration.IRecipeCategoryRegistration; +import mezz.jei.api.registration.IRecipeRegistration; +import mezz.jei.api.registration.IRecipeTransferRegistration; +import mezz.jei.api.runtime.IJeiRuntime; import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.network.chat.Component; @@ -56,87 +56,87 @@ import net.minecraftforge.registries.ForgeRegistries; import java.util.List; -//TODO: enable once jei is updated -//@mezz.jei.api.JeiPlugin -//public class JeiPlugin implements IModPlugin { -// -// protected static IJeiRuntime runtime; -// -// public static IJeiRuntime getJeiRuntime() { -// return runtime; -// } -// -// @Override -// public ResourceLocation getPluginUid() { -// return new ResourceLocation(Occultism.MODID, "jei"); -// } -// -// @Override -// public void registerCategories(IRecipeCategoryRegistration registration) { -// registration.addRecipeCategories(new SpiritFireRecipeCategory(registration.getJeiHelpers().getGuiHelper())); -// registration.addRecipeCategories(new CrushingRecipeCategory(registration.getJeiHelpers().getGuiHelper())); -// registration.addRecipeCategories(new MinerRecipeCategory(registration.getJeiHelpers().getGuiHelper())); -// registration.addRecipeCategories(new RitualRecipeCategory(registration.getJeiHelpers().getGuiHelper())); -// } -// -// @Override -// public void registerRecipes(IRecipeRegistration registration) { -// ClientLevel level = Minecraft.getInstance().level; -// RecipeManager recipeManager = level.getRecipeManager(); -// -// List spiritFireRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.SPIRIT_FIRE_TYPE.get()); -// registration.addRecipes(JeiRecipeTypes.SPIRIT_FIRE, spiritFireRecipes); -// -// List crushingRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.CRUSHING_TYPE.get()); -// registration.addRecipes(JeiRecipeTypes.CRUSHING, crushingRecipes); -// -// List minerRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.MINER_TYPE.get()); -// registration.addRecipes(JeiRecipeTypes.MINER, minerRecipes); -// -// List ritualRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.RITUAL_TYPE.get()); -// registration.addRecipes(JeiRecipeTypes.RITUAL, ritualRecipes); -// -// this.registerIngredientInfo(registration, OccultismItems.TALLOW.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.OTHERSTONE.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_LOG.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_LEAVES.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_SAPLING.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_SAPLING_NATURAL.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.IESNIUM_ORE.get()); -// this.registerIngredientInfo(registration, OccultismBlocks.SPIRIT_FIRE.get()); -// this.registerIngredientInfo(registration, OccultismItems.DATURA.get()); -// } -// -// @Override -// public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { -// IStackHelper stackHelper = registration.getJeiHelpers().getStackHelper(); -// IRecipeTransferHandlerHelper handlerHelper = registration.getTransferHelper(); -// registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( -// StorageControllerContainer.class, handlerHelper)); -// registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( -// StorageRemoteContainer.class, handlerHelper)); -// registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( -// StableWormholeContainer.class, handlerHelper)); -// } -// -// @Override -// public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { -// registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.SPIRIT_FIRE.get()), -// JeiRecipeTypes.SPIRIT_FIRE); -// registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.DIMENSIONAL_MINESHAFT.get()), -// JeiRecipeTypes.MINER); -// registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.GOLDEN_SACRIFICIAL_BOWL.get()), -// JeiRecipeTypes.RITUAL); -// } -// -// @Override -// public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { -// JeiPlugin.runtime = jeiRuntime; -// JeiSettings.setJeiLoaded(true); -// } -// -// public void registerIngredientInfo(IRecipeRegistration registration, ItemLike ingredient) { -// registration.addIngredientInfo(new ItemStack(ingredient.asItem()), VanillaTypes.ITEM_STACK, -// Component.translatable("jei." + Occultism.MODID + ".ingredient." + ForgeRegistries.ITEMS.getKey(ingredient.asItem()).getPath() + ".description")); -// } -//} + +@mezz.jei.api.JeiPlugin +public class JeiPlugin implements IModPlugin { + + protected static IJeiRuntime runtime; + + public static IJeiRuntime getJeiRuntime() { + return runtime; + } + + @Override + public ResourceLocation getPluginUid() { + return new ResourceLocation(Occultism.MODID, "jei"); + } + + @Override + public void registerCategories(IRecipeCategoryRegistration registration) { + registration.addRecipeCategories(new SpiritFireRecipeCategory(registration.getJeiHelpers().getGuiHelper())); + registration.addRecipeCategories(new CrushingRecipeCategory(registration.getJeiHelpers().getGuiHelper())); + registration.addRecipeCategories(new MinerRecipeCategory(registration.getJeiHelpers().getGuiHelper())); + registration.addRecipeCategories(new RitualRecipeCategory(registration.getJeiHelpers().getGuiHelper())); + } + + @Override + public void registerRecipes(IRecipeRegistration registration) { + ClientLevel level = Minecraft.getInstance().level; + RecipeManager recipeManager = level.getRecipeManager(); + + List spiritFireRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.SPIRIT_FIRE_TYPE.get()); + registration.addRecipes(JeiRecipeTypes.SPIRIT_FIRE, spiritFireRecipes); + + List crushingRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.CRUSHING_TYPE.get()); + registration.addRecipes(JeiRecipeTypes.CRUSHING, crushingRecipes); + + List minerRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.MINER_TYPE.get()); + registration.addRecipes(JeiRecipeTypes.MINER, minerRecipes); + + List ritualRecipes = recipeManager.getAllRecipesFor(OccultismRecipes.RITUAL_TYPE.get()); + registration.addRecipes(JeiRecipeTypes.RITUAL, ritualRecipes); + + this.registerIngredientInfo(registration, OccultismItems.TALLOW.get()); + this.registerIngredientInfo(registration, OccultismBlocks.OTHERSTONE.get()); + this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_LOG.get()); + this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_LEAVES.get()); + this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_SAPLING.get()); + this.registerIngredientInfo(registration, OccultismBlocks.OTHERWORLD_SAPLING_NATURAL.get()); + this.registerIngredientInfo(registration, OccultismBlocks.IESNIUM_ORE.get()); + this.registerIngredientInfo(registration, OccultismBlocks.SPIRIT_FIRE.get()); + this.registerIngredientInfo(registration, OccultismItems.DATURA.get()); + } + + @Override + public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { + IStackHelper stackHelper = registration.getJeiHelpers().getStackHelper(); + IRecipeTransferHandlerHelper handlerHelper = registration.getTransferHelper(); + registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( + StorageControllerContainer.class, handlerHelper)); + registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( + StorageRemoteContainer.class, handlerHelper)); + registration.addUniversalRecipeTransferHandler(new StorageControllerRecipeTransferHandler<>( + StableWormholeContainer.class, handlerHelper)); + } + + @Override + public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { + registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.SPIRIT_FIRE.get()), + JeiRecipeTypes.SPIRIT_FIRE); + registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.DIMENSIONAL_MINESHAFT.get()), + JeiRecipeTypes.MINER); + registration.addRecipeCatalyst(new ItemStack(OccultismBlocks.GOLDEN_SACRIFICIAL_BOWL.get()), + JeiRecipeTypes.RITUAL); + } + + @Override + public void onRuntimeAvailable(IJeiRuntime jeiRuntime) { + JeiPlugin.runtime = jeiRuntime; + JeiSettings.setJeiLoaded(true); + } + + public void registerIngredientInfo(IRecipeRegistration registration, ItemLike ingredient) { + registration.addIngredientInfo(new ItemStack(ingredient.asItem()), VanillaTypes.ITEM_STACK, + Component.translatable("jei." + Occultism.MODID + ".ingredient." + ForgeRegistries.ITEMS.getKey(ingredient.asItem()).getPath() + ".description")); + } +} diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiRecipeTypes.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiRecipeTypes.java index 052471baa..8849d94eb 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiRecipeTypes.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/JeiRecipeTypes.java @@ -24,18 +24,17 @@ import com.github.klikli_dev.occultism.Occultism; import com.github.klikli_dev.occultism.crafting.recipe.*; -//import mezz.jei.api.recipe.RecipeType; +import mezz.jei.api.recipe.RecipeType; public class JeiRecipeTypes { - //TODO: enable once jei is updated -// public static final RecipeType SPIRIT_TRADE = -// RecipeType.create(Occultism.MODID, "spirit_trade", SpiritTradeRecipe.class); -// public static final RecipeType SPIRIT_FIRE = -// RecipeType.create(Occultism.MODID, "spirit_fire", SpiritFireRecipe.class); -// public static final RecipeType CRUSHING = -// RecipeType.create(Occultism.MODID, "crushing", CrushingRecipe.class); -// public static final RecipeType MINER = -// RecipeType.create(Occultism.MODID, "miner", MinerRecipe.class); -// public static final RecipeType RITUAL = -// RecipeType.create(Occultism.MODID, "ritual", RitualRecipe.class); + public static final RecipeType SPIRIT_TRADE = + RecipeType.create(Occultism.MODID, "spirit_trade", SpiritTradeRecipe.class); + public static final RecipeType SPIRIT_FIRE = + RecipeType.create(Occultism.MODID, "spirit_fire", SpiritFireRecipe.class); + public static final RecipeType CRUSHING = + RecipeType.create(Occultism.MODID, "crushing", CrushingRecipe.class); + public static final RecipeType MINER = + RecipeType.create(Occultism.MODID, "miner", MinerRecipe.class); + public static final RecipeType RITUAL = + RecipeType.create(Occultism.MODID, "ritual", RitualRecipe.class); } diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/StorageControllerRecipeTransferHandler.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/StorageControllerRecipeTransferHandler.java index fe4094b83..820e7a4b9 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/StorageControllerRecipeTransferHandler.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/StorageControllerRecipeTransferHandler.java @@ -27,13 +27,13 @@ import com.github.klikli_dev.occultism.network.MessageSetRecipe; import com.github.klikli_dev.occultism.network.MessageSetRecipeByID; import com.github.klikli_dev.occultism.network.OccultismPackets; -//import mezz.jei.api.constants.RecipeTypes; -//import mezz.jei.api.constants.VanillaTypes; -//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -//import mezz.jei.api.recipe.RecipeType; -//import mezz.jei.api.recipe.transfer.IRecipeTransferError; -//import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; -//import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; +import mezz.jei.api.constants.RecipeTypes; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +import mezz.jei.api.recipe.RecipeType; +import mezz.jei.api.recipe.transfer.IRecipeTransferError; +import mezz.jei.api.recipe.transfer.IRecipeTransferHandler; +import mezz.jei.api.recipe.transfer.IRecipeTransferHandlerHelper; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.ListTag; import net.minecraft.network.chat.Component; @@ -48,98 +48,97 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -//TODO: enable once jei is updated /** * Based on https://github.com/Lothrazar/Storage-Network */ -//public class StorageControllerRecipeTransferHandler implements IRecipeTransferHandler { -// -// protected final Class containerClass; -// protected final IRecipeTransferHandlerHelper handlerHelper; -// -// public StorageControllerRecipeTransferHandler(Class containerClass, IRecipeTransferHandlerHelper handlerHelper) { -// this.handlerHelper = handlerHelper; -// this.containerClass = containerClass; -// } -// -// public CompoundTag recipeToNbt(AbstractContainerMenu container, IRecipeSlotsView recipeSlots) { -// CompoundTag nbt = new CompoundTag(); -// var slotsViewList = recipeSlots.getSlotViews(); -// -// for (Slot slot : container.slots) { -// if (slot.container instanceof CraftingContainer) { -// -// //get slot view corresponding to slot -// var slotView = slotsViewList.get(slot.getSlotIndex() + 1); -// if (slotView == null) { -// continue; -// } -// -// //gets all items matching ingredients. -// List possibleItems = slotView.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList()); -// if (possibleItems.isEmpty()) { -// continue; -// } -// -// ListTag invList = new ListTag(); -// for (int i = 0; i < possibleItems.size(); i++) { -// if (i >= 5) { -// break; //cap possible items at 5 to avoid mega-messages that hit network cap -// } -// -// //if stack is not empty, write to result -// ItemStack itemStack = possibleItems.get(i); -// if (!itemStack.isEmpty()) { -// invList.add(itemStack.serializeNBT()); -// } -// } -// nbt.put("s" + (slot.getSlotIndex()), invList); -// } -// } -// return nbt; -// } -// -// @Override -// public Class getContainerClass() { -// return this.containerClass; -// } -// -// @Override -// public Optional> getMenuType() { -// return Optional.empty(); -// } -// -// @Override -// public RecipeType getRecipeType() { -// return RecipeTypes.CRAFTING; -// } -// -// public IRecipeTransferError transferRecipe(T container, CraftingRecipe recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) { -// -// if (recipe.getId() == null) { -// return this.handlerHelper.createUserErrorWithTooltip(Component.translatable("jei." + Occultism.MODID + "error.missing_id")); -// } -// -// //sort out any modded recipes that don't fit 3x3 -// if (!recipe.canCraftInDimensions(3, 3)) { -// return this.handlerHelper.createUserErrorWithTooltip(Component.translatable("jei." + Occultism.MODID + "error.recipe_too_large")); -// } -// -// // can only send shaped/shapeless recipes to storage controller -// // disabled this -> not a good idea for custom recipes that fit in 3x3 such as botania -// // not needed either -> the 3x3 check handles anything that is invalid and still registers as crafting. -//// if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) { -//// return this.handlerHelper.createUserErrorWithTooltip(I18n.get("jei." + Occultism.MODID + "error.invalid_type")); -//// } -// -// //if recipe is in recipe manager send by id, otherwise fallback to ingredient list -// if (doTransfer) { -// if (player.getCommandSenderWorld().getRecipeManager().byKey(recipe.getId()).isPresent()) { -// OccultismPackets.sendToServer(new MessageSetRecipeByID(recipe.getId())); -// } else { -// OccultismPackets.sendToServer(new MessageSetRecipe(this.recipeToNbt(container, recipeSlots))); -// } +public class StorageControllerRecipeTransferHandler implements IRecipeTransferHandler { + + protected final Class containerClass; + protected final IRecipeTransferHandlerHelper handlerHelper; + + public StorageControllerRecipeTransferHandler(Class containerClass, IRecipeTransferHandlerHelper handlerHelper) { + this.handlerHelper = handlerHelper; + this.containerClass = containerClass; + } + + public CompoundTag recipeToNbt(AbstractContainerMenu container, IRecipeSlotsView recipeSlots) { + CompoundTag nbt = new CompoundTag(); + var slotsViewList = recipeSlots.getSlotViews(); + + for (Slot slot : container.slots) { + if (slot.container instanceof CraftingContainer) { + + //get slot view corresponding to slot + var slotView = slotsViewList.get(slot.getSlotIndex() + 1); + if (slotView == null) { + continue; + } + + //gets all items matching ingredients. + List possibleItems = slotView.getIngredients(VanillaTypes.ITEM_STACK).collect(Collectors.toList()); + if (possibleItems.isEmpty()) { + continue; + } + + ListTag invList = new ListTag(); + for (int i = 0; i < possibleItems.size(); i++) { + if (i >= 5) { + break; //cap possible items at 5 to avoid mega-messages that hit network cap + } + + //if stack is not empty, write to result + ItemStack itemStack = possibleItems.get(i); + if (!itemStack.isEmpty()) { + invList.add(itemStack.serializeNBT()); + } + } + nbt.put("s" + (slot.getSlotIndex()), invList); + } + } + return nbt; + } + + @Override + public Class getContainerClass() { + return this.containerClass; + } + + @Override + public Optional> getMenuType() { + return Optional.empty(); + } + + @Override + public RecipeType getRecipeType() { + return RecipeTypes.CRAFTING; + } + + public IRecipeTransferError transferRecipe(T container, CraftingRecipe recipe, IRecipeSlotsView recipeSlots, Player player, boolean maxTransfer, boolean doTransfer) { + + if (recipe.getId() == null) { + return this.handlerHelper.createUserErrorWithTooltip(Component.translatable("jei." + Occultism.MODID + "error.missing_id")); + } + + //sort out any modded recipes that don't fit 3x3 + if (!recipe.canCraftInDimensions(3, 3)) { + return this.handlerHelper.createUserErrorWithTooltip(Component.translatable("jei." + Occultism.MODID + "error.recipe_too_large")); + } + + // can only send shaped/shapeless recipes to storage controller + // disabled this -> not a good idea for custom recipes that fit in 3x3 such as botania + // not needed either -> the 3x3 check handles anything that is invalid and still registers as crafting. +// if (!(recipe instanceof ShapedRecipe) && !(recipe instanceof ShapelessRecipe)) { +// return this.handlerHelper.createUserErrorWithTooltip(I18n.get("jei." + Occultism.MODID + "error.invalid_type")); // } -// return null; -// } -//} + + //if recipe is in recipe manager send by id, otherwise fallback to ingredient list + if (doTransfer) { + if (player.getCommandSenderWorld().getRecipeManager().byKey(recipe.getId()).isPresent()) { + OccultismPackets.sendToServer(new MessageSetRecipeByID(recipe.getId())); + } else { + OccultismPackets.sendToServer(new MessageSetRecipe(this.recipeToNbt(container, recipeSlots))); + } + } + return null; + } +} diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/CrushingRecipeCategory.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/CrushingRecipeCategory.java index 445400b91..cd77968dc 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/CrushingRecipeCategory.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/CrushingRecipeCategory.java @@ -28,73 +28,72 @@ import com.github.klikli_dev.occultism.integration.jei.JeiRecipeTypes; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -//import mezz.jei.api.gui.drawable.IDrawable; -//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -//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 mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +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 mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; -//TODO: enable once jei is updated -//public class CrushingRecipeCategory implements IRecipeCategory { -// -// private final IDrawable background; -// private final Component localizedName; -// private final IDrawable overlay; -// -// public CrushingRecipeCategory(IGuiHelper guiHelper) { -// this.background = guiHelper.createBlankDrawable(168, 46); //64 -// this.localizedName = Component.translatable(Occultism.MODID + ".jei.crushing"); -// this.overlay = guiHelper.createDrawable( -// new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); -// } -// -// protected void drawStringCentered(PoseStack poseStack, Font fontRenderer, Component text, int x, int y) { -// fontRenderer.draw(poseStack, text, (x - fontRenderer.width(text) / 2.0f), y, 0); -// } -// -// @Override -// public RecipeType getRecipeType() { -// return JeiRecipeTypes.CRUSHING; -// } -// -// @Override -// public Component getTitle() { -// return this.localizedName; -// } -// -// @Override -// public IDrawable getBackground() { -// return this.background; -// } -// -// @Override -// public IDrawable getIcon() { -// return null; -// } -// -// @Override -// public void setRecipe(IRecipeLayoutBuilder builder, CrushingRecipe recipe, IFocusGroup focuses) { -// builder.addSlot(RecipeIngredientRole.INPUT, 56, 12) -// .addIngredients(recipe.getIngredients().get(0)); -// -// builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 12) -// .addItemStack(recipe.getResultItem()); -// } -// -// @Override -// public void draw(CrushingRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { -// RenderSystem.enableBlend(); -// this.overlay.draw(stack, 76, 14); //(center=84) - (width/16=8) = 76 -// this.drawStringCentered(stack, Minecraft.getInstance().font, this.getTitle(), 84, 0); -// if(recipe.getMinTier() >= 0){ -// this.drawStringCentered(stack, Minecraft.getInstance().font, Component.translatable(TranslationKeys.JEI_CRUSHING_RECIPE_TIER, recipe.getMinTier()), 84, 35); -// } -// } -//} +public class CrushingRecipeCategory implements IRecipeCategory { + + private final IDrawable background; + private final Component localizedName; + private final IDrawable overlay; + + public CrushingRecipeCategory(IGuiHelper guiHelper) { + this.background = guiHelper.createBlankDrawable(168, 46); //64 + this.localizedName = Component.translatable(Occultism.MODID + ".jei.crushing"); + this.overlay = guiHelper.createDrawable( + new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); + } + + protected void drawStringCentered(PoseStack poseStack, Font fontRenderer, Component text, int x, int y) { + fontRenderer.draw(poseStack, text, (x - fontRenderer.width(text) / 2.0f), y, 0); + } + + @Override + public RecipeType getRecipeType() { + return JeiRecipeTypes.CRUSHING; + } + + @Override + public Component getTitle() { + return this.localizedName; + } + + @Override + public IDrawable getBackground() { + return this.background; + } + + @Override + public IDrawable getIcon() { + return null; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder builder, CrushingRecipe recipe, IFocusGroup focuses) { + builder.addSlot(RecipeIngredientRole.INPUT, 56, 12) + .addIngredients(recipe.getIngredients().get(0)); + + builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 12) + .addItemStack(recipe.getResultItem()); + } + + @Override + public void draw(CrushingRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { + RenderSystem.enableBlend(); + this.overlay.draw(stack, 76, 14); //(center=84) - (width/16=8) = 76 + this.drawStringCentered(stack, Minecraft.getInstance().font, this.getTitle(), 84, 0); + if(recipe.getMinTier() >= 0){ + this.drawStringCentered(stack, Minecraft.getInstance().font, Component.translatable(TranslationKeys.JEI_CRUSHING_RECIPE_TIER, recipe.getMinTier()), 84, 35); + } + } +} diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/MinerRecipeCategory.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/MinerRecipeCategory.java index 214c2f1d2..aab236b8d 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/MinerRecipeCategory.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/MinerRecipeCategory.java @@ -29,14 +29,14 @@ import com.github.klikli_dev.occultism.registry.OccultismRecipes; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -//import mezz.jei.api.gui.drawable.IDrawable; -//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -//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 mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +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 mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; import net.minecraft.network.chat.Component; @@ -50,74 +50,74 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -//TODO: enable once jei is updated -//public class MinerRecipeCategory implements IRecipeCategory { -// -// private final IDrawable background; -// private final Component localizedName; -// private final IDrawable overlay; -// -// private final Map chances = new HashMap<>(); -// -// public MinerRecipeCategory(IGuiHelper guiHelper) { -// this.background = guiHelper.createBlankDrawable(168, 46); //64 -// this.localizedName = Component.translatable(Occultism.MODID + ".jei.miner"); -// this.overlay = guiHelper.createDrawable( -// new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); -// } -// -// protected void drawStringCentered(PoseStack poseStack, Font fontRenderer, Component text, int x, int y) { -// fontRenderer.draw(poseStack, text, (x - fontRenderer.width(text) / 2.0f), y, 0); -// } -// -// @Override -// public RecipeType getRecipeType() { -// return JeiRecipeTypes.MINER; -// } -// -// @Override -// public Component getTitle() { -// return this.localizedName; -// } -// -// @Override -// public IDrawable getBackground() { -// return this.background; -// } -// -// @Override -// public IDrawable getIcon() { -// return null; -// } -// -// @Override -// public void setRecipe(IRecipeLayoutBuilder builder, MinerRecipe recipe, IFocusGroup focuses) { -// //set up a simulated handler to get all possible results -// Level level = Minecraft.getInstance().level; -// ItemStackHandler simulatedHandler = new ItemStackHandler(1); -// simulatedHandler.setStackInSlot(0, recipe.getIngredients().get(0).getItems()[0]); -// List recipes = level.getRecipeManager() -// .getRecipesFor(OccultismRecipes.MINER_TYPE.get(), -// new RecipeWrapper(simulatedHandler), level); -// List possibleResults = recipes.stream().map(MinerRecipe::getWeightedOutput).collect(Collectors.toList()); -// -// float chance = (float) recipe.getWeightedOutput().getWeight().asInt() / (float) WeightedRandom.getTotalWeight(possibleResults) * 100.0F; -// //reduce to two decimals -// chance = Math.round(chance * 10) / 10.0f; -// this.chances.put(recipe, chance); -// -// builder.addSlot(RecipeIngredientRole.INPUT, 56, 12) -// .addIngredients(recipe.getIngredients().get(0)); -// -// builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 12) -// .addItemStack(recipe.getResultItem()); -// } -// -// @Override -// public void draw(MinerRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { -// RenderSystem.enableBlend(); -// this.overlay.draw(stack, 76, 14); //(center=84) - (width/16=8) = 76 -// this.drawStringCentered(stack, Minecraft.getInstance().font, -// Component.translatable(Occultism.MODID + ".jei.miner.chance", this.chances.get(recipe)), 84, 0); -// } -//} + +public class MinerRecipeCategory implements IRecipeCategory { + + private final IDrawable background; + private final Component localizedName; + private final IDrawable overlay; + + private final Map chances = new HashMap<>(); + + public MinerRecipeCategory(IGuiHelper guiHelper) { + this.background = guiHelper.createBlankDrawable(168, 46); //64 + this.localizedName = Component.translatable(Occultism.MODID + ".jei.miner"); + this.overlay = guiHelper.createDrawable( + new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); + } + + protected void drawStringCentered(PoseStack poseStack, Font fontRenderer, Component text, int x, int y) { + fontRenderer.draw(poseStack, text, (x - fontRenderer.width(text) / 2.0f), y, 0); + } + + @Override + public RecipeType getRecipeType() { + return JeiRecipeTypes.MINER; + } + + @Override + public Component getTitle() { + return this.localizedName; + } + + @Override + public IDrawable getBackground() { + return this.background; + } + + @Override + public IDrawable getIcon() { + return null; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder builder, MinerRecipe recipe, IFocusGroup focuses) { + //set up a simulated handler to get all possible results + Level level = Minecraft.getInstance().level; + ItemStackHandler simulatedHandler = new ItemStackHandler(1); + simulatedHandler.setStackInSlot(0, recipe.getIngredients().get(0).getItems()[0]); + List recipes = level.getRecipeManager() + .getRecipesFor(OccultismRecipes.MINER_TYPE.get(), + new RecipeWrapper(simulatedHandler), level); + List possibleResults = recipes.stream().map(MinerRecipe::getWeightedOutput).collect(Collectors.toList()); + + float chance = (float) recipe.getWeightedOutput().getWeight().asInt() / (float) WeightedRandom.getTotalWeight(possibleResults) * 100.0F; + //reduce to two decimals + chance = Math.round(chance * 10) / 10.0f; + this.chances.put(recipe, chance); + + builder.addSlot(RecipeIngredientRole.INPUT, 56, 12) + .addIngredients(recipe.getIngredients().get(0)); + + builder.addSlot(RecipeIngredientRole.OUTPUT, 94, 12) + .addItemStack(recipe.getResultItem()); + } + + @Override + public void draw(MinerRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { + RenderSystem.enableBlend(); + this.overlay.draw(stack, 76, 14); //(center=84) - (width/16=8) = 76 + this.drawStringCentered(stack, Minecraft.getInstance().font, + Component.translatable(Occultism.MODID + ".jei.miner.chance", this.chances.get(recipe)), 84, 0); + } +} diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/RitualRecipeCategory.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/RitualRecipeCategory.java index eb06e8e26..f54b774d1 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/RitualRecipeCategory.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/RitualRecipeCategory.java @@ -30,14 +30,14 @@ import com.klikli_dev.modonomicon.api.ModonomiconAPI; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -//import mezz.jei.api.gui.drawable.IDrawable; -//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -//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 mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +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 mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.Util; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Font; @@ -50,198 +50,198 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; -//TODO: enable once jei is updated -//public class RitualRecipeCategory implements IRecipeCategory { -// -// private final IDrawable background; -// private final IDrawable arrow; -// private final Component localizedName; -// private final String pentacle; -// private final ItemStack goldenSacrificialBowl = new ItemStack(OccultismBlocks.GOLDEN_SACRIFICIAL_BOWL.get()); -// private final ItemStack sacrificialBowl = new ItemStack(OccultismBlocks.SACRIFICIAL_BOWL.get()); -// private final int iconWidth = 16; -// private final int ritualCenterX; -// private final int ritualCenterY; -// private int recipeOutputOffsetX = 50; -// -// public RitualRecipeCategory(IGuiHelper guiHelper) { -// this.background = guiHelper.createBlankDrawable(168, 120); //64 -// this.ritualCenterX = this.background.getWidth() / 2 - this.iconWidth / 2 - 30; -// this.ritualCenterY = this.background.getHeight() / 2 - this.iconWidth / 2 + 20; -// this.localizedName = Component.translatable(Occultism.MODID + ".jei.ritual"); -// this.pentacle = I18n.get(Occultism.MODID + ".jei.pentacle"); -// this.goldenSacrificialBowl.getOrCreateTag().putBoolean("RenderFull", true); -// this.sacrificialBowl.getOrCreateTag().putBoolean("RenderFull", true); -// this.arrow = guiHelper.createDrawable( -// new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); -// } -// -// protected int getStringCenteredMaxX(Font font, Component text, int x, int y) { -// int width = font.width(text); -// int actualX = (int) (x - width / 2.0f); -// return actualX + width; -// } -// -// protected void drawStringCentered(PoseStack poseStack, Font font, Component text, int x, int y) { -// font.draw(poseStack, text, (x - font.width(text) / 2.0f), y, 0); -// } -// -// @Override -// public RecipeType getRecipeType() { -// return JeiRecipeTypes.RITUAL; -// } -// -// @Override -// public Component getTitle() { -// return this.localizedName; -// } -// -// @Override -// public IDrawable getBackground() { -// return this.background; -// } -// -// @Override -// public IDrawable getIcon() { -// return null; -// } -// -// @Override -// public void setRecipe(IRecipeLayoutBuilder builder, RitualRecipe recipe, IFocusGroup focuses) { -// this.recipeOutputOffsetX = 75; -// -// //draw activation item on top of bowl -// builder.addSlot(RecipeIngredientRole.INPUT, this.ritualCenterX, this.ritualCenterY - 5) -// .addIngredients(recipe.getActivationItem()); -// -// //draw the sacrificial bowl in the center -// builder.addSlot(RecipeIngredientRole.CATALYST, this.ritualCenterX, this.ritualCenterY) -// .addItemStack(this.goldenSacrificialBowl); -// -// int sacrificialCircleRadius = 30; -// int sacricialBowlPaddingVertical = 20; -// int sacricialBowlPaddingHorizontal = 15; -// List sacrificialBowlPosition = Stream.of( -// //first the 4 centers of each side -// new Vec3i(this.ritualCenterX, this.ritualCenterY - sacrificialCircleRadius, 0), -// new Vec3i(this.ritualCenterX + sacrificialCircleRadius, this.ritualCenterY, 0), -// new Vec3i(this.ritualCenterX, this.ritualCenterY + sacrificialCircleRadius, 0), -// new Vec3i(this.ritualCenterX - sacrificialCircleRadius, this.ritualCenterY, 0), -// -// //then clockwise of the enter the next 4 -// new Vec3i(this.ritualCenterX + sacricialBowlPaddingHorizontal, -// this.ritualCenterY - sacrificialCircleRadius, -// 0), -// new Vec3i(this.ritualCenterX + sacrificialCircleRadius, -// this.ritualCenterY - sacricialBowlPaddingVertical, 0), -// new Vec3i(this.ritualCenterX - sacricialBowlPaddingHorizontal, -// this.ritualCenterY + sacrificialCircleRadius, -// 0), -// new Vec3i(this.ritualCenterX - sacrificialCircleRadius, -// this.ritualCenterY + sacricialBowlPaddingVertical, 0), -// -// //then counterclockwise of the center the last 4 -// new Vec3i(this.ritualCenterX - sacricialBowlPaddingHorizontal, -// this.ritualCenterY - sacrificialCircleRadius, -// 0), -// new Vec3i(this.ritualCenterX + sacrificialCircleRadius, -// this.ritualCenterY + sacricialBowlPaddingVertical, 0), -// new Vec3i(this.ritualCenterX + sacricialBowlPaddingHorizontal, -// this.ritualCenterY + sacrificialCircleRadius, -// 0), -// new Vec3i(this.ritualCenterX - sacrificialCircleRadius, -// this.ritualCenterY - sacricialBowlPaddingVertical, 0) -// ).collect(Collectors.toList()); -// -// -// for (int i = 0; i < recipe.getIngredients().size(); i++) { -// Vec3i pos = sacrificialBowlPosition.get(i); -// -// builder.addSlot(RecipeIngredientRole.INPUT, pos.getX(), pos.getY() - 5) -// .addIngredients(recipe.getIngredients().get(i)); -// -// builder.addSlot(RecipeIngredientRole.RENDER_ONLY, pos.getX(), pos.getY()) -// .addItemStack(this.sacrificialBowl); -// } -// -// //ingredients: 0: recipe output, 1: ritual dummy item -// -// //draw recipe output on the left -// if (recipe.getResultItem().getItem() != OccultismItems.JEI_DUMMY_NONE.get()) { -// //if we have an item output -> render it -// builder.addSlot(RecipeIngredientRole.OUTPUT, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY - 5) -// .addItemStack(recipe.getResultItem()); -// } else { -// //if not, we instead render our ritual dummy item, just like in the corner -// builder.addSlot(RecipeIngredientRole.OUTPUT, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY - 5) -// .addItemStack(recipe.getRitualDummy()); -// } -// -// //draw output golden bowl -// builder.addSlot(RecipeIngredientRole.CATALYST, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY) -// .addItemStack(this.goldenSacrificialBowl); -// -// //draw ritual dummy item in upper left corner -// builder.addSlot(RecipeIngredientRole.OUTPUT, 0, 0) -// .addItemStack(recipe.getRitualDummy()); -// -// //draw item to use -// if (recipe.requiresItemUse()) { -// //first simulate the info rendering to get the right render position -// int infotextY = 0; -// if (recipe.requiresSacrifice()) { -// infotextY += 10; -// } -// -// infotextY += 10; -// int itemToUseY = infotextY - 5; -// int itemToUseX = this.getStringCenteredMaxX(Minecraft.getInstance().font, Component.translatable("jei.occultism.item_to_use"), 84, infotextY); -// -// builder.addSlot(RecipeIngredientRole.CATALYST, itemToUseX, itemToUseY) -// .addIngredients(recipe.getItemToUse()); -// } -// } -// -// @Override -// public void draw(RitualRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) { -// RenderSystem.enableBlend(); -// this.arrow.draw(poseStack, this.ritualCenterX + this.recipeOutputOffsetX - 20, this.ritualCenterY); -// RenderSystem.disableBlend(); -// -// var pentacle = ModonomiconAPI.get().getMultiblock(recipe.getPentacleId()); -// if (pentacle != null) { -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, -// Component.translatable(Util.makeDescriptionId("multiblock", pentacle.getId())), 84, 0); -// } else { -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, -// Component.translatable("jei.occultism.error.pentacle_not_loaded"), 84, 0); -// } -// -// int infotextY = 0; -// if (recipe.requiresSacrifice()) { -// infotextY += 10; -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, -// Component.translatable("jei.occultism.sacrifice", Component.translatable(recipe.getEntityToSacrificeDisplayName())), 84, infotextY); -// } -// -// if (recipe.requiresItemUse()) { -// infotextY += 10; -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, Component.translatable("jei.occultism.item_to_use"), 84, infotextY); -// } -// -// if (recipe.getEntityToSummon() != null) { -// infotextY += 10; -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, -// Component.translatable("jei.occultism.summon", Component.translatable(recipe.getEntityToSummon().getDescriptionId())), -// 84, infotextY); -// } -// -// if (recipe.getSpiritJobType() != null) { -// infotextY += 10; -// this.drawStringCentered(poseStack, Minecraft.getInstance().font, -// Component.translatable("jei.occultism.job", -// Component.translatable("job." + recipe.getSpiritJobType().toString().replace(":", "."))), -// 84, infotextY); -// } -// } -//} + +public class RitualRecipeCategory implements IRecipeCategory { + + private final IDrawable background; + private final IDrawable arrow; + private final Component localizedName; + private final String pentacle; + private final ItemStack goldenSacrificialBowl = new ItemStack(OccultismBlocks.GOLDEN_SACRIFICIAL_BOWL.get()); + private final ItemStack sacrificialBowl = new ItemStack(OccultismBlocks.SACRIFICIAL_BOWL.get()); + private final int iconWidth = 16; + private final int ritualCenterX; + private final int ritualCenterY; + private int recipeOutputOffsetX = 50; + + public RitualRecipeCategory(IGuiHelper guiHelper) { + this.background = guiHelper.createBlankDrawable(168, 120); //64 + this.ritualCenterX = this.background.getWidth() / 2 - this.iconWidth / 2 - 30; + this.ritualCenterY = this.background.getHeight() / 2 - this.iconWidth / 2 + 20; + this.localizedName = Component.translatable(Occultism.MODID + ".jei.ritual"); + this.pentacle = I18n.get(Occultism.MODID + ".jei.pentacle"); + this.goldenSacrificialBowl.getOrCreateTag().putBoolean("RenderFull", true); + this.sacrificialBowl.getOrCreateTag().putBoolean("RenderFull", true); + this.arrow = guiHelper.createDrawable( + new ResourceLocation(Occultism.MODID, "textures/gui/jei/arrow.png"), 0, 0, 64, 46); + } + + protected int getStringCenteredMaxX(Font font, Component text, int x, int y) { + int width = font.width(text); + int actualX = (int) (x - width / 2.0f); + return actualX + width; + } + + protected void drawStringCentered(PoseStack poseStack, Font font, Component text, int x, int y) { + font.draw(poseStack, text, (x - font.width(text) / 2.0f), y, 0); + } + + @Override + public RecipeType getRecipeType() { + return JeiRecipeTypes.RITUAL; + } + + @Override + public Component getTitle() { + return this.localizedName; + } + + @Override + public IDrawable getBackground() { + return this.background; + } + + @Override + public IDrawable getIcon() { + return null; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder builder, RitualRecipe recipe, IFocusGroup focuses) { + this.recipeOutputOffsetX = 75; + + //draw activation item on top of bowl + builder.addSlot(RecipeIngredientRole.INPUT, this.ritualCenterX, this.ritualCenterY - 5) + .addIngredients(recipe.getActivationItem()); + + //draw the sacrificial bowl in the center + builder.addSlot(RecipeIngredientRole.CATALYST, this.ritualCenterX, this.ritualCenterY) + .addItemStack(this.goldenSacrificialBowl); + + int sacrificialCircleRadius = 30; + int sacricialBowlPaddingVertical = 20; + int sacricialBowlPaddingHorizontal = 15; + List sacrificialBowlPosition = Stream.of( + //first the 4 centers of each side + new Vec3i(this.ritualCenterX, this.ritualCenterY - sacrificialCircleRadius, 0), + new Vec3i(this.ritualCenterX + sacrificialCircleRadius, this.ritualCenterY, 0), + new Vec3i(this.ritualCenterX, this.ritualCenterY + sacrificialCircleRadius, 0), + new Vec3i(this.ritualCenterX - sacrificialCircleRadius, this.ritualCenterY, 0), + + //then clockwise of the enter the next 4 + new Vec3i(this.ritualCenterX + sacricialBowlPaddingHorizontal, + this.ritualCenterY - sacrificialCircleRadius, + 0), + new Vec3i(this.ritualCenterX + sacrificialCircleRadius, + this.ritualCenterY - sacricialBowlPaddingVertical, 0), + new Vec3i(this.ritualCenterX - sacricialBowlPaddingHorizontal, + this.ritualCenterY + sacrificialCircleRadius, + 0), + new Vec3i(this.ritualCenterX - sacrificialCircleRadius, + this.ritualCenterY + sacricialBowlPaddingVertical, 0), + + //then counterclockwise of the center the last 4 + new Vec3i(this.ritualCenterX - sacricialBowlPaddingHorizontal, + this.ritualCenterY - sacrificialCircleRadius, + 0), + new Vec3i(this.ritualCenterX + sacrificialCircleRadius, + this.ritualCenterY + sacricialBowlPaddingVertical, 0), + new Vec3i(this.ritualCenterX + sacricialBowlPaddingHorizontal, + this.ritualCenterY + sacrificialCircleRadius, + 0), + new Vec3i(this.ritualCenterX - sacrificialCircleRadius, + this.ritualCenterY - sacricialBowlPaddingVertical, 0) + ).collect(Collectors.toList()); + + + for (int i = 0; i < recipe.getIngredients().size(); i++) { + Vec3i pos = sacrificialBowlPosition.get(i); + + builder.addSlot(RecipeIngredientRole.INPUT, pos.getX(), pos.getY() - 5) + .addIngredients(recipe.getIngredients().get(i)); + + builder.addSlot(RecipeIngredientRole.RENDER_ONLY, pos.getX(), pos.getY()) + .addItemStack(this.sacrificialBowl); + } + + //ingredients: 0: recipe output, 1: ritual dummy item + + //draw recipe output on the left + if (recipe.getResultItem().getItem() != OccultismItems.JEI_DUMMY_NONE.get()) { + //if we have an item output -> render it + builder.addSlot(RecipeIngredientRole.OUTPUT, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY - 5) + .addItemStack(recipe.getResultItem()); + } else { + //if not, we instead render our ritual dummy item, just like in the corner + builder.addSlot(RecipeIngredientRole.OUTPUT, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY - 5) + .addItemStack(recipe.getRitualDummy()); + } + + //draw output golden bowl + builder.addSlot(RecipeIngredientRole.CATALYST, this.ritualCenterX + this.recipeOutputOffsetX, this.ritualCenterY) + .addItemStack(this.goldenSacrificialBowl); + + //draw ritual dummy item in upper left corner + builder.addSlot(RecipeIngredientRole.OUTPUT, 0, 0) + .addItemStack(recipe.getRitualDummy()); + + //draw item to use + if (recipe.requiresItemUse()) { + //first simulate the info rendering to get the right render position + int infotextY = 0; + if (recipe.requiresSacrifice()) { + infotextY += 10; + } + + infotextY += 10; + int itemToUseY = infotextY - 5; + int itemToUseX = this.getStringCenteredMaxX(Minecraft.getInstance().font, Component.translatable("jei.occultism.item_to_use"), 84, infotextY); + + builder.addSlot(RecipeIngredientRole.CATALYST, itemToUseX, itemToUseY) + .addIngredients(recipe.getItemToUse()); + } + } + + @Override + public void draw(RitualRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack poseStack, double mouseX, double mouseY) { + RenderSystem.enableBlend(); + this.arrow.draw(poseStack, this.ritualCenterX + this.recipeOutputOffsetX - 20, this.ritualCenterY); + RenderSystem.disableBlend(); + + var pentacle = ModonomiconAPI.get().getMultiblock(recipe.getPentacleId()); + if (pentacle != null) { + this.drawStringCentered(poseStack, Minecraft.getInstance().font, + Component.translatable(Util.makeDescriptionId("multiblock", pentacle.getId())), 84, 0); + } else { + this.drawStringCentered(poseStack, Minecraft.getInstance().font, + Component.translatable("jei.occultism.error.pentacle_not_loaded"), 84, 0); + } + + int infotextY = 0; + if (recipe.requiresSacrifice()) { + infotextY += 10; + this.drawStringCentered(poseStack, Minecraft.getInstance().font, + Component.translatable("jei.occultism.sacrifice", Component.translatable(recipe.getEntityToSacrificeDisplayName())), 84, infotextY); + } + + if (recipe.requiresItemUse()) { + infotextY += 10; + this.drawStringCentered(poseStack, Minecraft.getInstance().font, Component.translatable("jei.occultism.item_to_use"), 84, infotextY); + } + + if (recipe.getEntityToSummon() != null) { + infotextY += 10; + this.drawStringCentered(poseStack, Minecraft.getInstance().font, + Component.translatable("jei.occultism.summon", Component.translatable(recipe.getEntityToSummon().getDescriptionId())), + 84, infotextY); + } + + if (recipe.getSpiritJobType() != null) { + infotextY += 10; + this.drawStringCentered(poseStack, Minecraft.getInstance().font, + Component.translatable("jei.occultism.job", + Component.translatable("job." + recipe.getSpiritJobType().toString().replace(":", "."))), + 84, infotextY); + } + } +} diff --git a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/SpiritFireRecipeCategory.java b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/SpiritFireRecipeCategory.java index 0834d93c2..b7779752b 100644 --- a/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/SpiritFireRecipeCategory.java +++ b/src/main/java/com/github/klikli_dev/occultism/integration/jei/recipes/SpiritFireRecipeCategory.java @@ -28,71 +28,71 @@ import com.github.klikli_dev.occultism.registry.OccultismItems; import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.vertex.PoseStack; -//import mezz.jei.api.constants.VanillaTypes; -//import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; -//import mezz.jei.api.gui.drawable.IDrawable; -//import mezz.jei.api.gui.ingredient.IRecipeSlotsView; -//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 mezz.jei.api.recipe.category.IRecipeCategory; +import mezz.jei.api.constants.VanillaTypes; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.ingredient.IRecipeSlotsView; +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 mezz.jei.api.recipe.category.IRecipeCategory; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; -//TODO: enable once jei is updated -//public class SpiritFireRecipeCategory implements IRecipeCategory { -// -// private final IDrawable background; -// private final Component localizedName; -// private final IDrawable overlay; -// private final IDrawable icon; -// private final ItemStack renderStack = new ItemStack(OccultismItems.SPIRIT_FIRE.get()); -// -// public SpiritFireRecipeCategory(IGuiHelper guiHelper) { -// this.background = guiHelper.createBlankDrawable(168, 46); //64 -// this.localizedName = Component.translatable(Occultism.MODID + ".jei.spirit_fire"); -// this.overlay = guiHelper.createDrawable( -// new ResourceLocation(Occultism.MODID, "textures/gui/jei/spirit_fire.png"), 0, 0, 64, 46); -// this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, this.renderStack); -// this.renderStack.getOrCreateTag().putBoolean("RenderFull", true); -// } -// -// @Override -// public RecipeType getRecipeType() { -// return JeiRecipeTypes.SPIRIT_FIRE; -// } -// -// @Override -// public Component getTitle() { -// return this.localizedName; -// } -// -// @Override -// public IDrawable getBackground() { -// return this.background; -// } -// -// @Override -// public IDrawable getIcon() { -// return this.icon; -// } -// -// @Override -// public void setRecipe(IRecipeLayoutBuilder builder, SpiritFireRecipe recipe, IFocusGroup focuses) { -// builder.addSlot(RecipeIngredientRole.INPUT, 40, 12) -// .addIngredients(recipe.getIngredients().get(0)); -// -// builder.addSlot(RecipeIngredientRole.CATALYST, 75, 12) -// .addItemStack(this.renderStack); -// -// builder.addSlot(RecipeIngredientRole.OUTPUT, 110, 12) -// .addItemStack(recipe.getResultItem()); -// } -// -// @Override -// public void draw(SpiritFireRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { -// RenderSystem.enableBlend(); -// this.overlay.draw(stack, 48, 0); -// } -//} + +public class SpiritFireRecipeCategory implements IRecipeCategory { + + private final IDrawable background; + private final Component localizedName; + private final IDrawable overlay; + private final IDrawable icon; + private final ItemStack renderStack = new ItemStack(OccultismItems.SPIRIT_FIRE.get()); + + public SpiritFireRecipeCategory(IGuiHelper guiHelper) { + this.background = guiHelper.createBlankDrawable(168, 46); //64 + this.localizedName = Component.translatable(Occultism.MODID + ".jei.spirit_fire"); + this.overlay = guiHelper.createDrawable( + new ResourceLocation(Occultism.MODID, "textures/gui/jei/spirit_fire.png"), 0, 0, 64, 46); + this.icon = guiHelper.createDrawableIngredient(VanillaTypes.ITEM_STACK, this.renderStack); + this.renderStack.getOrCreateTag().putBoolean("RenderFull", true); + } + + @Override + public RecipeType getRecipeType() { + return JeiRecipeTypes.SPIRIT_FIRE; + } + + @Override + public Component getTitle() { + return this.localizedName; + } + + @Override + public IDrawable getBackground() { + return this.background; + } + + @Override + public IDrawable getIcon() { + return this.icon; + } + + @Override + public void setRecipe(IRecipeLayoutBuilder builder, SpiritFireRecipe recipe, IFocusGroup focuses) { + builder.addSlot(RecipeIngredientRole.INPUT, 40, 12) + .addIngredients(recipe.getIngredients().get(0)); + + builder.addSlot(RecipeIngredientRole.CATALYST, 75, 12) + .addItemStack(this.renderStack); + + builder.addSlot(RecipeIngredientRole.OUTPUT, 110, 12) + .addItemStack(recipe.getResultItem()); + } + + @Override + public void draw(SpiritFireRecipe recipe, IRecipeSlotsView recipeSlotsView, PoseStack stack, double mouseX, double mouseY) { + RenderSystem.enableBlend(); + this.overlay.draw(stack, 48, 0); + } +}