DefaultCookingDisplay.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright (c) 2018, 2019, 2020 shedaniel
  3. * Licensed under the MIT License (the "License").
  4. */
  5. package me.shedaniel.rei.plugin.cooking;
  6. import me.shedaniel.rei.api.EntryStack;
  7. import me.shedaniel.rei.api.TransferRecipeDisplay;
  8. import me.shedaniel.rei.server.ContainerInfo;
  9. import me.shedaniel.rei.utils.CollectionUtils;
  10. import net.minecraft.block.entity.FurnaceBlockEntity;
  11. import net.minecraft.client.resource.language.I18n;
  12. import net.minecraft.container.Container;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.recipe.AbstractCookingRecipe;
  16. import net.minecraft.util.Formatting;
  17. import net.minecraft.util.Identifier;
  18. import org.jetbrains.annotations.ApiStatus;
  19. import java.util.ArrayList;
  20. import java.util.Collections;
  21. import java.util.List;
  22. import java.util.Optional;
  23. import java.util.stream.Collectors;
  24. public abstract class DefaultCookingDisplay implements TransferRecipeDisplay {
  25. private static List<EntryStack> fuel;
  26. static {
  27. fuel = 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());
  28. }
  29. private AbstractCookingRecipe recipe;
  30. private List<List<EntryStack>> input;
  31. private List<EntryStack> output;
  32. private float xp;
  33. private double cookTime;
  34. public DefaultCookingDisplay(AbstractCookingRecipe recipe) {
  35. this.recipe = recipe;
  36. this.input = CollectionUtils.map(recipe.getPreviewInputs(), i -> CollectionUtils.map(i.getMatchingStacksClient(), EntryStack::create));
  37. this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
  38. this.xp = recipe.getExperience();
  39. this.cookTime = recipe.getCookTime();
  40. }
  41. @Override
  42. public Optional<Identifier> getRecipeLocation() {
  43. return Optional.ofNullable(recipe).map(AbstractCookingRecipe::getId);
  44. }
  45. @Override
  46. public List<List<EntryStack>> getInputEntries() {
  47. return input;
  48. }
  49. @Override
  50. public List<EntryStack> getOutputEntries() {
  51. return output;
  52. }
  53. @Override
  54. public List<List<EntryStack>> getRequiredEntries() {
  55. return input;
  56. }
  57. public float getXp() {
  58. return xp;
  59. }
  60. public double getCookingTime() {
  61. return cookTime;
  62. }
  63. public static List<EntryStack> getFuel() {
  64. return fuel;
  65. }
  66. @ApiStatus.Internal
  67. public Optional<AbstractCookingRecipe> getOptionalRecipe() {
  68. return Optional.ofNullable(recipe);
  69. }
  70. @Override
  71. public int getWidth() {
  72. return 1;
  73. }
  74. @Override
  75. public int getHeight() {
  76. return 1;
  77. }
  78. @Override
  79. public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<Container> containerInfo, Container container) {
  80. return input;
  81. }
  82. }