DefaultShapelessDisplay.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.plugin.crafting;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.recipe.Recipe;
  8. import net.minecraft.recipe.ShapelessRecipe;
  9. import net.minecraft.util.Identifier;
  10. import java.util.Arrays;
  11. import java.util.Collections;
  12. import java.util.List;
  13. import java.util.Optional;
  14. import java.util.stream.Collectors;
  15. public class DefaultShapelessDisplay implements DefaultCraftingDisplay {
  16. private ShapelessRecipe display;
  17. private List<List<ItemStack>> input;
  18. private List<ItemStack> output;
  19. public DefaultShapelessDisplay(ShapelessRecipe recipe) {
  20. this.display = recipe;
  21. this.input = recipe.getPreviewInputs().stream().map(i -> Arrays.asList(i.getMatchingStacksClient())).collect(Collectors.toList());
  22. this.output = Collections.singletonList(recipe.getOutput());
  23. }
  24. @Override
  25. public Optional<Recipe<?>> getOptionalRecipe() {
  26. return Optional.ofNullable(display);
  27. }
  28. @Override
  29. public Optional<Identifier> getRecipeLocation() {
  30. return Optional.ofNullable(display).map(ShapelessRecipe::getId);
  31. }
  32. @Override
  33. public List<List<ItemStack>> getInput() {
  34. return input;
  35. }
  36. @Override
  37. public List<ItemStack> getOutput() {
  38. return output;
  39. }
  40. @Override
  41. public List<List<ItemStack>> getRequiredItems() {
  42. return input;
  43. }
  44. @Override
  45. public int getWidth() {
  46. if (display.getPreviewInputs().size() > 4)
  47. return 3;
  48. return 2;
  49. }
  50. @Override
  51. public int getHeight() {
  52. if (display.getPreviewInputs().size() > 4)
  53. return 3;
  54. return 2;
  55. }
  56. }