|
| 1 | +package juuxel.adorn.compat.emi; |
| 2 | + |
| 3 | +import dev.emi.emi.api.recipe.EmiRecipe; |
| 4 | +import dev.emi.emi.api.recipe.EmiRecipeCategory; |
| 5 | +import dev.emi.emi.api.stack.EmiIngredient; |
| 6 | +import dev.emi.emi.api.stack.EmiStack; |
| 7 | +import dev.emi.emi.api.widget.TankWidget; |
| 8 | +import dev.emi.emi.api.widget.WidgetHolder; |
| 9 | +import juuxel.adorn.AdornCommon; |
| 10 | +import juuxel.adorn.block.entity.BrewerBlockEntity; |
| 11 | +import juuxel.adorn.client.gui.screen.BrewerScreen; |
| 12 | +import juuxel.adorn.item.AdornItems; |
| 13 | +import juuxel.adorn.platform.FluidBridge; |
| 14 | +import juuxel.adorn.recipe.FluidBrewingRecipe; |
| 15 | +import juuxel.adorn.recipe.ItemBrewingRecipe; |
| 16 | +import net.minecraft.util.Identifier; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | + |
| 20 | +public record BrewingEmiRecipe( |
| 21 | + Identifier id, |
| 22 | + EmiIngredient inputItem, |
| 23 | + EmiIngredient firstItemIngredient, |
| 24 | + EmiIngredient secondItemIngredient, |
| 25 | + EmiIngredient fluidIngredient, |
| 26 | + EmiStack result |
| 27 | +) implements EmiRecipe { |
| 28 | + private static final int PADDING = 0; |
| 29 | + private static final int FLUID_SCALE_Z_OFFSET = 100; |
| 30 | + private static final Identifier TEXTURE = AdornCommon.id("textures/gui/recipe_viewer/brewer_light.png"); |
| 31 | + |
| 32 | + public BrewingEmiRecipe(Identifier id, ItemBrewingRecipe recipe) { |
| 33 | + this( |
| 34 | + id, |
| 35 | + EmiStack.of(AdornItems.INSTANCE.getMUG()), |
| 36 | + EmiUtil.withRemainders(EmiIngredient.of(recipe.firstIngredient())), |
| 37 | + EmiUtil.withRemainders(EmiIngredient.of(recipe.secondIngredient())), |
| 38 | + EmiStack.EMPTY, |
| 39 | + EmiStack.of(recipe.result()) |
| 40 | + ); |
| 41 | + } |
| 42 | + |
| 43 | + public BrewingEmiRecipe(Identifier id, FluidBrewingRecipe recipe) { |
| 44 | + this( |
| 45 | + id, |
| 46 | + EmiStack.of(AdornItems.INSTANCE.getMUG()), |
| 47 | + EmiUtil.withRemainders(EmiIngredient.of(recipe.firstIngredient())), |
| 48 | + EmiUtil.withRemainders(EmiIngredient.of(recipe.secondIngredient())), |
| 49 | + EmiUtil.emiIngredientOf(recipe.fluid()), |
| 50 | + EmiStack.of(recipe.result()) |
| 51 | + ); |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public EmiRecipeCategory getCategory() { |
| 56 | + return AdornEmiPlugin.BREWER_CATEGORY; |
| 57 | + } |
| 58 | + |
| 59 | + @Override |
| 60 | + public Identifier getId() { |
| 61 | + return id; |
| 62 | + } |
| 63 | + |
| 64 | + @Override |
| 65 | + public List<EmiIngredient> getInputs() { |
| 66 | + return List.of(inputItem, firstItemIngredient, secondItemIngredient, fluidIngredient); |
| 67 | + } |
| 68 | + |
| 69 | + @Override |
| 70 | + public List<EmiStack> getOutputs() { |
| 71 | + return List.of(result); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public int getDisplayWidth() { |
| 76 | + return 78 + 27 + 2 * PADDING; |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public int getDisplayHeight() { |
| 81 | + return 61 + 2 * PADDING; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public void addWidgets(WidgetHolder widgets) { |
| 86 | + int leftX = PADDING; |
| 87 | + int topY = PADDING; |
| 88 | + widgets.addTexture(TEXTURE, leftX, topY, 105, 61, 49, 16); |
| 89 | + widgets.addSlot(firstItemIngredient, leftX, topY).drawBack(false); |
| 90 | + widgets.addSlot(secondItemIngredient, leftX + 60, topY).drawBack(false); |
| 91 | + widgets.addSlot(result, leftX + 26, topY + 35).drawBack(false).recipeContext(this).large(true); |
| 92 | + var capacity = BrewerBlockEntity.FLUID_CAPACITY_IN_BUCKETS * FluidBridge.get().getFluidUnit().getBucketVolume(); |
| 93 | + widgets.add(new TankWidget(fluidIngredient, leftX + 87, topY, 18, BrewerScreen.FLUID_AREA_HEIGHT + 2, capacity).drawBack(false)); |
| 94 | + |
| 95 | + // Empty mug |
| 96 | + widgets.addSlot(inputItem, leftX + 3, topY + 38).drawBack(false); |
| 97 | + |
| 98 | + // Fluid scale |
| 99 | + widgets.addDrawable(leftX + 88, topY + 1, 16, BrewerScreen.FLUID_AREA_HEIGHT, (context, mouseX, mouseY, tickDelta) -> { |
| 100 | + context.drawTexture(TEXTURE, 0, 0, FLUID_SCALE_Z_OFFSET, 154f, 17f, 16, BrewerScreen.FLUID_AREA_HEIGHT, 256, 256); |
| 101 | + }); |
| 102 | + |
| 103 | + // Progress arrow |
| 104 | + widgets.addDrawable(leftX + 35, topY + 8, 8, BrewerScreen.FLUID_AREA_HEIGHT, (context, mouseX, mouseY, tickDelta) -> { |
| 105 | + float progressFraction = (System.currentTimeMillis() % 4000) / 4000f; |
| 106 | + int height = Math.round(progressFraction * 25); |
| 107 | + context.drawTexture(TEXTURE, 0, 0, 1, 176f, 0f, 8, height, 256, 256); |
| 108 | + }); |
| 109 | + } |
| 110 | +} |
0 commit comments