DefaultCookingDisplay.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * This file is licensed under the MIT License, part of Roughly Enough Items.
  3. * Copyright (c) 2018, 2019, 2020 shedaniel
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package me.shedaniel.rei.plugin.cooking;
  24. import me.shedaniel.rei.api.EntryStack;
  25. import me.shedaniel.rei.api.TransferRecipeDisplay;
  26. import me.shedaniel.rei.server.ContainerInfo;
  27. import net.fabricmc.api.EnvType;
  28. import net.fabricmc.api.Environment;
  29. import net.minecraft.ChatFormatting;
  30. import net.minecraft.network.chat.TranslatableComponent;
  31. import net.minecraft.resources.ResourceLocation;
  32. import net.minecraft.world.inventory.AbstractContainerMenu;
  33. import net.minecraft.world.item.Item;
  34. import net.minecraft.world.item.crafting.AbstractCookingRecipe;
  35. import net.minecraft.world.level.block.entity.FurnaceBlockEntity;
  36. import org.jetbrains.annotations.ApiStatus;
  37. import org.jetbrains.annotations.NotNull;
  38. import java.util.Collections;
  39. import java.util.List;
  40. import java.util.Optional;
  41. import java.util.stream.Collectors;
  42. @Environment(EnvType.CLIENT)
  43. public abstract class DefaultCookingDisplay implements TransferRecipeDisplay {
  44. private static List<EntryStack> fuel;
  45. static {
  46. fuel = FurnaceBlockEntity.getFuel().keySet().stream().map(Item::getDefaultInstance).map(EntryStack::create).map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableComponent("category.rei.smelting.fuel").withStyle(ChatFormatting.YELLOW)))).collect(Collectors.toList());
  47. }
  48. private AbstractCookingRecipe recipe;
  49. private List<List<EntryStack>> input;
  50. private List<EntryStack> output;
  51. private float xp;
  52. private double cookTime;
  53. public DefaultCookingDisplay(AbstractCookingRecipe recipe) {
  54. this.recipe = recipe;
  55. this.input = EntryStack.ofIngredients(recipe.getIngredients());
  56. this.output = Collections.singletonList(EntryStack.create(recipe.getResultItem()));
  57. this.xp = recipe.getExperience();
  58. this.cookTime = recipe.getCookingTime();
  59. }
  60. public static List<EntryStack> getFuel() {
  61. return fuel;
  62. }
  63. @Override
  64. public @NotNull Optional<ResourceLocation> getRecipeLocation() {
  65. return Optional.ofNullable(recipe).map(AbstractCookingRecipe::getId);
  66. }
  67. @Override
  68. public @NotNull List<List<EntryStack>> getInputEntries() {
  69. return input;
  70. }
  71. @Override
  72. public @NotNull List<List<EntryStack>> getResultingEntries() {
  73. return Collections.singletonList(output);
  74. }
  75. @Override
  76. public @NotNull List<List<EntryStack>> getRequiredEntries() {
  77. return input;
  78. }
  79. public float getXp() {
  80. return xp;
  81. }
  82. public double getCookingTime() {
  83. return cookTime;
  84. }
  85. @ApiStatus.Internal
  86. public Optional<AbstractCookingRecipe> getOptionalRecipe() {
  87. return Optional.ofNullable(recipe);
  88. }
  89. @Override
  90. public int getWidth() {
  91. return 1;
  92. }
  93. @Override
  94. public int getHeight() {
  95. return 1;
  96. }
  97. @Override
  98. public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<AbstractContainerMenu> containerInfo, AbstractContainerMenu container) {
  99. return input;
  100. }
  101. }