/* * Decompiled with CFR 0.152. */ package net.minecraft.world.item.crafting; import net.minecraft.core.HolderLookup; import net.minecraft.core.NonNullList; import net.minecraft.core.component.DataComponents; import net.minecraft.world.item.BannerItem; import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.CraftingBookCategory; import net.minecraft.world.item.crafting.CraftingInput; import net.minecraft.world.item.crafting.CustomRecipe; import net.minecraft.world.item.crafting.RecipeSerializer; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.entity.BannerPatternLayers; public class BannerDuplicateRecipe extends CustomRecipe { public BannerDuplicateRecipe(CraftingBookCategory category) { super(category); } @Override public boolean matches(CraftingInput input, Level level) { if (input.ingredientCount() != 2) { return false; } DyeColor color = null; boolean hasTarget = false; boolean hasSource = false; for (int slot = 0; slot < input.size(); ++slot) { ItemStack itemStack = input.getItem(slot); if (itemStack.isEmpty()) continue; Item item = itemStack.getItem(); if (item instanceof BannerItem) { BannerItem banner = (BannerItem)item; if (color == null) { color = banner.getColor(); } else if (color != banner.getColor()) { return false; } } else { return false; } int patternCount = itemStack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY).layers().size(); if (patternCount > 6) { return false; } if (patternCount > 0) { if (hasSource) { return false; } hasSource = true; continue; } if (hasTarget) { return false; } hasTarget = true; } return hasSource && hasTarget; } @Override public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) { for (int slot = 0; slot < input.size(); ++slot) { int patternCount; ItemStack itemStack = input.getItem(slot); if (itemStack.isEmpty() || (patternCount = itemStack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY).layers().size()) <= 0 || patternCount > 6) continue; return itemStack.copyWithCount(1); } return ItemStack.EMPTY; } @Override public NonNullList getRemainingItems(CraftingInput input) { NonNullList result = NonNullList.withSize(input.size(), ItemStack.EMPTY); for (int slot = 0; slot < result.size(); ++slot) { ItemStack itemStack = input.getItem(slot); if (itemStack.isEmpty()) continue; ItemStack remainder = itemStack.getItem().getCraftingRemainder(); if (!remainder.isEmpty()) { result.set(slot, remainder); continue; } if (itemStack.getOrDefault(DataComponents.BANNER_PATTERNS, BannerPatternLayers.EMPTY).layers().isEmpty()) continue; result.set(slot, itemStack.copyWithCount(1)); } return result; } @Override public RecipeSerializer getSerializer() { return RecipeSerializer.BANNER_DUPLICATE; } }