diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/jei/AnvilCraftJeiPlugin.java b/src/main/java/dev/dubhe/anvilcraft/integration/jei/AnvilCraftJeiPlugin.java index c5a8455b9..8b75d512a 100644 --- a/src/main/java/dev/dubhe/anvilcraft/integration/jei/AnvilCraftJeiPlugin.java +++ b/src/main/java/dev/dubhe/anvilcraft/integration/jei/AnvilCraftJeiPlugin.java @@ -4,6 +4,7 @@ import dev.dubhe.anvilcraft.client.gui.screen.JewelCraftingScreen; import dev.dubhe.anvilcraft.init.ModBlocks; import dev.dubhe.anvilcraft.init.ModItems; +import dev.dubhe.anvilcraft.integration.jei.category.BeaconConversionCategory; import dev.dubhe.anvilcraft.integration.jei.category.EndPortalConversionCategory; import dev.dubhe.anvilcraft.integration.jei.category.JewelCraftingCategory; import dev.dubhe.anvilcraft.integration.jei.category.anvil.BlockCompressCategory; @@ -22,6 +23,7 @@ import dev.dubhe.anvilcraft.integration.jei.category.anvil.SuperHeatingCategory; import dev.dubhe.anvilcraft.integration.jei.category.anvil.TimeWarpCategory; import dev.dubhe.anvilcraft.integration.jei.category.multiblock.MultiBlockCraftingCategory; +import dev.dubhe.anvilcraft.integration.jei.recipe.BeaconConversionRecipe; import dev.dubhe.anvilcraft.integration.jei.recipe.CementStainingRecipe; import dev.dubhe.anvilcraft.integration.jei.recipe.ColoredConcreteRecipe; import dev.dubhe.anvilcraft.integration.jei.recipe.EndPortalConversionRecipe; @@ -73,6 +75,8 @@ public class AnvilCraftJeiPlugin implements IModPlugin { createRecipeType("colored_concrete", ColoredConcreteRecipe.class); public static final RecipeType END_PORTAL_CONVERSION = createRecipeType("end_portal_conversion", EndPortalConversionRecipe.class); + public static final RecipeType BEACON_CONVERSION = + createRecipeType("beacon_conversion", BeaconConversionRecipe.class); public static final RecipeType> BLOCK_COMPRESS = createRecipeHolderType("block_compress"); @@ -119,6 +123,7 @@ public void registerRecipes(IRecipeRegistration registration) { MultiBlockCraftingCategory.registerRecipes(registration); JewelCraftingCategory.registerRecipes(registration); EndPortalConversionCategory.registerRecipes(registration); + BeaconConversionCategory.registerRecipes(registration); registration.addItemStackInfo( new ItemStack(ModItems.GEODE.get()), @@ -161,6 +166,7 @@ public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { MultiBlockCraftingCategory.registerRecipeCatalysts(registration); JewelCraftingCategory.registerRecipeCatalysts(registration); EndPortalConversionCategory.registerRecipeCatalysts(registration); + BeaconConversionCategory.registerRecipeCatalysts(registration); registration.addRecipeCatalyst(new ItemStack(ModBlocks.BATCH_CRAFTER), RecipeTypes.CRAFTING); @@ -196,6 +202,7 @@ public void registerCategories(IRecipeCategoryRegistration registration) { registration.addRecipeCategories(new MultiBlockCraftingCategory(guiHelper)); registration.addRecipeCategories(new JewelCraftingCategory(guiHelper)); registration.addRecipeCategories(new EndPortalConversionCategory(guiHelper)); + registration.addRecipeCategories(new BeaconConversionCategory(guiHelper)); } @Override diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/BeaconConversionCategory.java b/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/BeaconConversionCategory.java new file mode 100644 index 000000000..2e075d064 --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/BeaconConversionCategory.java @@ -0,0 +1,161 @@ +package dev.dubhe.anvilcraft.integration.jei.category; + +import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.init.ModItems; +import dev.dubhe.anvilcraft.integration.jei.AnvilCraftJeiPlugin; +import dev.dubhe.anvilcraft.integration.jei.drawable.DrawableBlockStateIcon; +import dev.dubhe.anvilcraft.integration.jei.recipe.BeaconConversionRecipe; +import dev.dubhe.anvilcraft.integration.jei.util.JeiRecipeUtil; +import dev.dubhe.anvilcraft.integration.jei.util.TextureConstants; +import dev.dubhe.anvilcraft.util.LevelLike; +import dev.dubhe.anvilcraft.util.RenderHelper; +import mezz.jei.api.gui.builder.IRecipeLayoutBuilder; +import mezz.jei.api.gui.builder.IRecipeSlotBuilder; +import mezz.jei.api.gui.builder.ITooltipBuilder; +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.registration.IRecipeCatalystRegistration; +import mezz.jei.api.registration.IRecipeRegistration; +import net.minecraft.MethodsReturnNonnullByDefault; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; +import net.minecraft.world.level.block.Blocks; +import net.neoforged.neoforge.common.util.Lazy; +import org.jetbrains.annotations.Nullable; + +import javax.annotation.ParametersAreNonnullByDefault; +import java.util.HashMap; +import java.util.Map; + +@MethodsReturnNonnullByDefault +@ParametersAreNonnullByDefault +public class BeaconConversionCategory implements IRecipeCategory { + public static final int WIDTH = 162; + public static final int HEIGHT = 128; + + private final Lazy background; + private final IDrawable slot; + private final IDrawable progressArrow; + private final Component title; + private final IDrawable arrowIn; + + private final Map cache = new HashMap<>(); + + public BeaconConversionCategory(IGuiHelper helper) { + background = Lazy.of(() -> helper.createBlankDrawable(WIDTH, HEIGHT)); + slot = helper.getSlotDrawable(); + title = Component.translatable("gui.anvilcraft.category.beacon_conversion"); + progressArrow = helper.drawableBuilder(TextureConstants.PROGRESS, 0, 0, 24, 16) + .setTextureSize(24, 16) + .build(); + arrowIn = helper.createDrawable(TextureConstants.ANVIL_CRAFT_SPRITES, 0, 31, 16, 8); + } + + @Override + public RecipeType getRecipeType() { + return AnvilCraftJeiPlugin.BEACON_CONVERSION; + } + + @Override + public Component getTitle() { + return title; + } + + @Override + public IDrawable getBackground() { + return background.get(); + } + + @Override + public @Nullable IDrawable getIcon() { + return new DrawableBlockStateIcon( + Blocks.BEACON.defaultBlockState(), + ModBlocks.CURSED_GOLD_BLOCK.getDefaultState() + ); + } + + @Override + public void setRecipe( + IRecipeLayoutBuilder builder, BeaconConversionRecipe recipe, IFocusGroup focuses) { + builder.addSlot(RecipeIngredientRole.INPUT, 10, 12) + .addItemStack(ModItems.CURSED_GOLD_INGOT.asStack()); + builder.addSlot(RecipeIngredientRole.CATALYST, 10, 32) + .addItemStack(ModBlocks.CURSED_GOLD_BLOCK.asStack(recipe.cursedGoldBlockCount)); + builder.addSlot(RecipeIngredientRole.INPUT, 10, 96) + .addItemStack(Blocks.BEACON.asItem().getDefaultInstance()); + IRecipeSlotBuilder slot = builder.addSlot(RecipeIngredientRole.OUTPUT, 130, 96) + .addItemStack(ModBlocks.CORRUPTED_BEACON.asStack()); + JeiRecipeUtil.addTooltips(slot, recipe.corruptedBeaconOutput.getAmount()); + if (recipe.chance < 1.0f) { + slot = builder.addSlot(RecipeIngredientRole.OUTPUT, 112, 96) + .addItemStack(Blocks.BEACON.asItem().getDefaultInstance()); + JeiRecipeUtil.addTooltips(slot, recipe.beaconOutput.getAmount()); + } + } + + @Override + public void draw( + BeaconConversionRecipe recipe, + IRecipeSlotsView recipeSlotsView, + GuiGraphics guiGraphics, + double mouseX, + double mouseY) { + LevelLike level = cache.get(recipe); + if (level == null) { + LevelLike beaconBase = new LevelLike(Minecraft.getInstance().level); + int layers = recipe.cursedGoldBlockLayers; + for (int i = 0; i < layers; i++) { + for (int j = i; j <= 2 * layers - i; j++) { + for (int k = i; k <= 2 * layers - i; k++) { + beaconBase.setBlockState(new BlockPos(j, i, k), ModBlocks.CURSED_GOLD_BLOCK.getDefaultState()); + } + } + } + beaconBase.setBlockState(new BlockPos(layers, layers, layers), Blocks.BEACON.defaultBlockState()); + cache.put(recipe, beaconBase); + level = beaconBase; + } + + RenderHelper.renderLevelLike(level, guiGraphics, 100, 50, 80); + + slot.draw(guiGraphics, 9, 11); + slot.draw(guiGraphics, 9, 31); + slot.draw(guiGraphics, 9, 95); + if (recipe.chance < 1.0f) slot.draw(guiGraphics, 111, 95); + slot.draw(guiGraphics, 129, 95); + + arrowIn.draw(guiGraphics, 30, 18); + progressArrow.draw(guiGraphics, 60, 96); + } + + @Override + public void getTooltip( + ITooltipBuilder tooltip, + BeaconConversionRecipe recipe, + IRecipeSlotsView recipeSlotsView, + double mouseX, + double mouseY) { +// if (mouseX >= 57 && mouseX <= 107) { +// if (mouseY >= 35 && mouseY <= 66) { +// tooltip.add(Component.translatable("gui.anvilcraft.category.end_portal_conversion.fall_through")); +// } +// } + } + + public static void registerRecipes(IRecipeRegistration registration) { + registration.addRecipes( + AnvilCraftJeiPlugin.BEACON_CONVERSION, + BeaconConversionRecipe.getAllRecipes()); + } + + public static void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { + registration.addRecipeCatalyst(ModBlocks.CURSED_GOLD_BLOCK.asStack(), AnvilCraftJeiPlugin.BEACON_CONVERSION); + } +} diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/EndPortalConversionCategory.java b/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/EndPortalConversionCategory.java index c6fa34e01..7647abdc1 100644 --- a/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/EndPortalConversionCategory.java +++ b/src/main/java/dev/dubhe/anvilcraft/integration/jei/category/EndPortalConversionCategory.java @@ -96,6 +96,7 @@ public void draw( JeiSlotUtil.drawOutputSlots(guiGraphics, slot, recipe.results.size()); } + @Override public void getTooltip( ITooltipBuilder tooltip, EndPortalConversionRecipe recipe, diff --git a/src/main/java/dev/dubhe/anvilcraft/integration/jei/recipe/BeaconConversionRecipe.java b/src/main/java/dev/dubhe/anvilcraft/integration/jei/recipe/BeaconConversionRecipe.java new file mode 100644 index 000000000..c3d99793a --- /dev/null +++ b/src/main/java/dev/dubhe/anvilcraft/integration/jei/recipe/BeaconConversionRecipe.java @@ -0,0 +1,35 @@ +package dev.dubhe.anvilcraft.integration.jei.recipe; + +import com.google.common.collect.ImmutableList; +import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.recipe.ChanceItemStack; +import net.minecraft.world.level.block.Blocks; + +public class BeaconConversionRecipe { + public final int cursedGoldBlockLayers; + public final int cursedGoldBlockCount; + public final float chance; + public final ChanceItemStack corruptedBeaconOutput; + public final ChanceItemStack beaconOutput; + + public BeaconConversionRecipe(int cursedGoldBlockLayers, float chance){ + this.cursedGoldBlockLayers = cursedGoldBlockLayers; + this.chance = chance; + int count = 0; + for (int i = 0; i < cursedGoldBlockLayers; i++) { + count += (2 * i + 3) * (2 * i + 3); + } + this.cursedGoldBlockCount = count; + this.corruptedBeaconOutput = ChanceItemStack.of(ModBlocks.CORRUPTED_BEACON.asStack()).withChance(chance); + this.beaconOutput = ChanceItemStack.of(Blocks.BEACON.asItem().getDefaultInstance()).withChance(1.0f - chance); + } + + public static ImmutableList getAllRecipes() { + ImmutableList.Builder builder = ImmutableList.builder(); + builder.add(new BeaconConversionRecipe(1, 0.02f)); + builder.add(new BeaconConversionRecipe(2, 0.05f)); + builder.add(new BeaconConversionRecipe(3, 0.2f)); + builder.add(new BeaconConversionRecipe(4, 1.0f)); + return builder.build(); + } +}