80 lines
2.4 KiB
Java
80 lines
2.4 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*/
|
|
package net.minecraft.world.item.crafting;
|
|
|
|
import net.minecraft.core.HolderLookup;
|
|
import net.minecraft.core.component.DataComponents;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.item.Items;
|
|
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;
|
|
|
|
public class MapCloningRecipe
|
|
extends CustomRecipe {
|
|
public MapCloningRecipe(CraftingBookCategory category) {
|
|
super(category);
|
|
}
|
|
|
|
@Override
|
|
public boolean matches(CraftingInput input, Level level) {
|
|
if (input.ingredientCount() < 2) {
|
|
return false;
|
|
}
|
|
boolean hasEmptyMaps = false;
|
|
boolean hasSourceMap = false;
|
|
for (int slot = 0; slot < input.size(); ++slot) {
|
|
ItemStack itemStack = input.getItem(slot);
|
|
if (itemStack.isEmpty()) continue;
|
|
if (itemStack.has(DataComponents.MAP_ID)) {
|
|
if (hasSourceMap) {
|
|
return false;
|
|
}
|
|
hasSourceMap = true;
|
|
continue;
|
|
}
|
|
if (itemStack.is(Items.MAP)) {
|
|
hasEmptyMaps = true;
|
|
continue;
|
|
}
|
|
return false;
|
|
}
|
|
return hasSourceMap && hasEmptyMaps;
|
|
}
|
|
|
|
@Override
|
|
public ItemStack assemble(CraftingInput input, HolderLookup.Provider registries) {
|
|
int count = 0;
|
|
ItemStack source = ItemStack.EMPTY;
|
|
for (int slot = 0; slot < input.size(); ++slot) {
|
|
ItemStack itemStack = input.getItem(slot);
|
|
if (itemStack.isEmpty()) continue;
|
|
if (itemStack.has(DataComponents.MAP_ID)) {
|
|
if (!source.isEmpty()) {
|
|
return ItemStack.EMPTY;
|
|
}
|
|
source = itemStack;
|
|
continue;
|
|
}
|
|
if (itemStack.is(Items.MAP)) {
|
|
++count;
|
|
continue;
|
|
}
|
|
return ItemStack.EMPTY;
|
|
}
|
|
if (source.isEmpty() || count < 1) {
|
|
return ItemStack.EMPTY;
|
|
}
|
|
return source.copyWithCount(count + 1);
|
|
}
|
|
|
|
@Override
|
|
public RecipeSerializer<MapCloningRecipe> getSerializer() {
|
|
return RecipeSerializer.MAP_CLONING;
|
|
}
|
|
}
|
|
|