aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/plugin/cooking
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/shedaniel/rei/plugin/cooking')
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java96
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java84
2 files changed, 180 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java
new file mode 100644
index 000000000..9588a239b
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingCategory.java
@@ -0,0 +1,96 @@
+/*
+ * Roughly Enough Items by Danielshe.
+ * Licensed under the MIT License.
+ */
+
+package me.shedaniel.rei.plugin.cooking;
+
+import it.unimi.dsi.fastutil.ints.IntList;
+import me.shedaniel.math.api.Point;
+import me.shedaniel.math.api.Rectangle;
+import me.shedaniel.math.compat.RenderHelper;
+import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.api.Renderer;
+import me.shedaniel.rei.api.TransferRecipeCategory;
+import me.shedaniel.rei.gui.renderers.RecipeRenderer;
+import me.shedaniel.rei.gui.widget.EntryWidget;
+import me.shedaniel.rei.gui.widget.RecipeArrowWidget;
+import me.shedaniel.rei.gui.widget.RecipeBaseWidget;
+import me.shedaniel.rei.gui.widget.Widget;
+import me.shedaniel.rei.plugin.DefaultPlugin;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.DrawableHelper;
+import net.minecraft.client.render.GuiLighting;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.util.Identifier;
+import net.minecraft.util.math.MathHelper;
+
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.function.Supplier;
+
+public class DefaultCookingCategory implements TransferRecipeCategory<DefaultCookingDisplay> {
+ private Identifier identifier;
+ private EntryStack logo;
+ private String categoryName;
+
+ public DefaultCookingCategory(Identifier identifier, EntryStack logo, String categoryName) {
+ this.identifier = identifier;
+ this.logo = logo;
+ this.categoryName = categoryName;
+ }
+
+ @Override
+ public void renderRedSlots(List<Widget> widgets, Rectangle bounds, DefaultCookingDisplay display, IntList redSlots) {
+ Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 27);
+ RenderHelper.translatef(0, 0, 400);
+ if (redSlots.contains(0)) {
+ DrawableHelper.fill(startPoint.x + 1, startPoint.y + 1, startPoint.x + 1 + 16, startPoint.y + 1 + 16, 822018048);
+ }
+ RenderHelper.translatef(0, 0, -400);
+ }
+
+ @Override
+ public List<Widget> setupDisplay(Supplier<DefaultCookingDisplay> recipeDisplaySupplier, Rectangle bounds) {
+ Point startPoint = new Point(bounds.getCenterX() - 41, bounds.getCenterY() - 27);
+ List<Widget> widgets = new LinkedList<>(Arrays.asList(new RecipeBaseWidget(bounds) {
+ @Override
+ public void render(int mouseX, int mouseY, float delta) {
+ super.render(mouseX, mouseY, delta);
+ RenderHelper.color4f(1.0F, 1.0F, 1.0F, 1.0F);
+ GuiLighting.disable();
+ MinecraftClient.getInstance().getTextureManager().bindTexture(DefaultPlugin.getDisplayTexture());
+ blit(startPoint.x, startPoint.y, 0, 54, 82, 54);
+ int height = MathHelper.ceil((System.currentTimeMillis() / 250 % 14d) / 1f);
+ blit(startPoint.x + 2, startPoint.y + 21 + (14 - height), 82, 77 + (14 - height), 14, height);
+ }
+ }));
+ widgets.add(new RecipeArrowWidget(startPoint.x + 24, startPoint.y + 18, true));
+ List<List<EntryStack>> input = recipeDisplaySupplier.get().getInputEntries();
+ widgets.add(EntryWidget.create(startPoint.x + 1, startPoint.y + 1).entries(input.get(0)));
+ widgets.add(EntryWidget.create(startPoint.x + 1, startPoint.y + 37).entries(input.get(1)));
+ widgets.add(EntryWidget.create(startPoint.x + 61, startPoint.y + 19).entries(recipeDisplaySupplier.get().getOutputEntries()).noBackground());
+ return widgets;
+ }
+
+ @Override
+ public RecipeRenderer getSimpleRenderer(DefaultCookingDisplay recipe) {
+ return Renderer.fromRecipeEntries(() -> Arrays.asList(recipe.getInputEntries().get(0)), recipe::getOutputEntries);
+ }
+
+ @Override
+ public Identifier getIdentifier() {
+ return identifier;
+ }
+
+ @Override
+ public EntryStack getLogo() {
+ return logo;
+ }
+
+ @Override
+ public String getCategoryName() {
+ return I18n.translate(categoryName);
+ }
+}
diff --git a/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java
new file mode 100644
index 000000000..6de7700a1
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/plugin/cooking/DefaultCookingDisplay.java
@@ -0,0 +1,84 @@
+/*
+ * Roughly Enough Items by Danielshe.
+ * Licensed under the MIT License.
+ */
+
+package me.shedaniel.rei.plugin.cooking;
+
+import me.shedaniel.rei.api.EntryStack;
+import me.shedaniel.rei.api.TransferRecipeDisplay;
+import me.shedaniel.rei.server.ContainerInfo;
+import net.minecraft.block.entity.FurnaceBlockEntity;
+import net.minecraft.client.resource.language.I18n;
+import net.minecraft.container.Container;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.recipe.AbstractCookingRecipe;
+import net.minecraft.util.Formatting;
+import net.minecraft.util.Identifier;
+
+import java.util.*;
+import java.util.stream.Collectors;
+
+public abstract class DefaultCookingDisplay implements TransferRecipeDisplay {
+ private AbstractCookingRecipe recipe;
+ private List<List<EntryStack>> input;
+ private List<EntryStack> output;
+
+ public DefaultCookingDisplay(AbstractCookingRecipe recipe) {
+ this.recipe = recipe;
+ this.input = recipe.getPreviewInputs().stream().map(i -> {
+ List<EntryStack> entries = new ArrayList<>();
+ for (ItemStack stack : i.getStackArray()) {
+ entries.add(EntryStack.create(stack));
+ }
+ return entries;
+ }).collect(Collectors.toList());
+ this.input.add(FurnaceBlockEntity.createFuelTimeMap().keySet().stream().map(Item::getStackForRender).map(EntryStack::create).map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("category.rei.smelting.fuel")))).collect(Collectors.toList()));
+ this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
+ }
+
+ @Override
+ public Optional<Identifier> getRecipeLocation() {
+ return Optional.ofNullable(recipe).map(AbstractCookingRecipe::getId);
+ }
+
+ @Override
+ public List<List<EntryStack>> getInputEntries() {
+ return input;
+ }
+
+ @Override
+ public List<EntryStack> getOutputEntries() {
+ return output;
+ }
+
+ public List<EntryStack> getFuel() {
+ return input.get(1);
+ }
+
+ @Override
+ public List<List<EntryStack>> getRequiredEntries() {
+ return input;
+ }
+
+ @Deprecated
+ public Optional<AbstractCookingRecipe> getOptionalRecipe() {
+ return Optional.ofNullable(recipe);
+ }
+
+ @Override
+ public int getWidth() {
+ return 1;
+ }
+
+ @Override
+ public int getHeight() {
+ return 1;
+ }
+
+ @Override
+ public List<List<ItemStack>> getOrganisedInput(ContainerInfo<Container> containerInfo, Container container) {
+ return recipe.getPreviewInputs().stream().map(i -> Arrays.asList(i.getStackArray())).collect(Collectors.toList());
+ }
+}