DefaultCookingDisplay.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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.block.entity.FurnaceBlockEntity;
  30. import net.minecraft.container.Container;
  31. import net.minecraft.item.Item;
  32. import net.minecraft.recipe.AbstractCookingRecipe;
  33. import net.minecraft.text.TranslatableText;
  34. import net.minecraft.util.Formatting;
  35. import net.minecraft.util.Identifier;
  36. import org.jetbrains.annotations.ApiStatus;
  37. import java.util.Collections;
  38. import java.util.List;
  39. import java.util.Optional;
  40. import java.util.stream.Collectors;
  41. @Environment(EnvType.CLIENT)
  42. public abstract class DefaultCookingDisplay implements TransferRecipeDisplay {
  43. private static List<EntryStack> fuel;
  44. static {
  45. fuel = FurnaceBlockEntity.createFuelTimeMap().keySet().stream().map(Item::getStackForRender).map(EntryStack::create).map(e -> e.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableText("category.rei.smelting.fuel").formatted(Formatting.YELLOW)))).collect(Collectors.toList());
  46. }
  47. private AbstractCookingRecipe recipe;
  48. private List<List<EntryStack>> input;
  49. private List<EntryStack> output;
  50. private float xp;
  51. private double cookTime;
  52. public DefaultCookingDisplay(AbstractCookingRecipe recipe) {
  53. this.recipe = recipe;
  54. this.input = EntryStack.ofIngredients(recipe.getPreviewInputs());
  55. this.output = Collections.singletonList(EntryStack.create(recipe.getOutput()));
  56. this.xp = recipe.getExperience();
  57. this.cookTime = recipe.getCookTime();
  58. }
  59. public static List<EntryStack> getFuel() {
  60. return fuel;
  61. }
  62. @Override
  63. public Optional<Identifier> getRecipeLocation() {
  64. return Optional.ofNullable(recipe).map(AbstractCookingRecipe::getId);
  65. }
  66. @Override
  67. public List<List<EntryStack>> getInputEntries() {
  68. return input;
  69. }
  70. @Override
  71. public List<EntryStack> getOutputEntries() {
  72. return output;
  73. }
  74. @Override
  75. public List<List<EntryStack>> getRequiredEntries() {
  76. return input;
  77. }
  78. public float getXp() {
  79. return xp;
  80. }
  81. public double getCookingTime() {
  82. return cookTime;
  83. }
  84. @ApiStatus.Internal
  85. public Optional<AbstractCookingRecipe> getOptionalRecipe() {
  86. return Optional.ofNullable(recipe);
  87. }
  88. @Override
  89. public int getWidth() {
  90. return 1;
  91. }
  92. @Override
  93. public int getHeight() {
  94. return 1;
  95. }
  96. @Override
  97. public List<List<EntryStack>> getOrganisedInputEntries(ContainerInfo<Container> containerInfo, Container container) {
  98. return input;
  99. }
  100. }