DefaultCustomDisplay.java 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.plugin;
  6. import com.google.common.collect.Lists;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.recipe.Recipe;
  9. import net.minecraft.util.Identifier;
  10. import java.util.List;
  11. import java.util.Optional;
  12. public class DefaultCustomDisplay implements DefaultCraftingDisplay {
  13. private List<List<ItemStack>> input;
  14. private List<ItemStack> output;
  15. private Recipe possibleRecipe;
  16. private int width, height;
  17. public DefaultCustomDisplay(List<List<ItemStack>> input, List<ItemStack> output, Recipe possibleRecipe) {
  18. this.input = input;
  19. this.output = output;
  20. this.possibleRecipe = possibleRecipe;
  21. List<Boolean> row = Lists.newArrayList(false, false, false);
  22. List<Boolean> column = Lists.newArrayList(false, false, false);
  23. for(int i = 0; i < 9; i++)
  24. if (i < input.size()) {
  25. List<ItemStack> stacks = input.get(i);
  26. if (stacks.stream().filter(stack -> !stack.isEmpty()).count() > 0) {
  27. row.set((i - (i % 3)) / 3, true);
  28. column.set(i % 3, true);
  29. }
  30. }
  31. this.width = (int) column.stream().filter(Boolean::booleanValue).count();
  32. this.height = (int) row.stream().filter(Boolean::booleanValue).count();
  33. }
  34. public DefaultCustomDisplay(List<List<ItemStack>> input, List<ItemStack> output) {
  35. this(input, output, null);
  36. }
  37. public Recipe getPossibleRecipe() {
  38. return possibleRecipe;
  39. }
  40. @Override
  41. public Optional<Identifier> getRecipeLocation() {
  42. return Optional.ofNullable(possibleRecipe).map(Recipe::getId);
  43. }
  44. @Override
  45. public List<List<ItemStack>> getInput() {
  46. return input;
  47. }
  48. @Override
  49. public List<ItemStack> getOutput() {
  50. return output;
  51. }
  52. @Override
  53. public List<List<ItemStack>> getRequiredItems() {
  54. return input;
  55. }
  56. @Override
  57. public int getWidth() {
  58. return width;
  59. }
  60. @Override
  61. public int getHeight() {
  62. return height;
  63. }
  64. }