2021-02-14 21:15:30 +01:00
|
|
|
package com.minelittlepony.unicopia.item;
|
|
|
|
|
|
|
|
import net.minecraft.inventory.CraftingInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.recipe.SpecialCraftingRecipe;
|
2022-12-18 22:07:24 +01:00
|
|
|
import net.minecraft.recipe.book.CraftingRecipeCategory;
|
2021-02-14 21:15:30 +01:00
|
|
|
import net.minecraft.util.Identifier;
|
|
|
|
import net.minecraft.util.Pair;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
|
|
|
public abstract class ItemCombinationRecipe extends SpecialCraftingRecipe {
|
|
|
|
|
2022-12-18 22:07:24 +01:00
|
|
|
public ItemCombinationRecipe(Identifier id, CraftingRecipeCategory category) {
|
|
|
|
super(id, category);
|
2021-02-14 21:15:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean fits(int i, int j) {
|
|
|
|
return i * j >= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public final boolean matches(CraftingInventory inventory, World world) {
|
|
|
|
Pair<ItemStack, ItemStack> result = runMatch(inventory);
|
|
|
|
|
|
|
|
return !result.getLeft().isEmpty() && !result.getRight().isEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Pair<ItemStack, ItemStack> runMatch(CraftingInventory inventory) {
|
|
|
|
ItemStack bangle = ItemStack.EMPTY;
|
|
|
|
ItemStack dust = ItemStack.EMPTY;
|
|
|
|
|
|
|
|
for(int i = 0; i < inventory.size(); i++) {
|
|
|
|
ItemStack stack = inventory.getStack(i);
|
|
|
|
|
|
|
|
if (!stack.isEmpty()) {
|
|
|
|
if (isContainerItem(stack)) {
|
|
|
|
if (!bangle.isEmpty()) {
|
|
|
|
return new Pair<>(bangle, dust);
|
|
|
|
}
|
|
|
|
|
|
|
|
bangle = stack;
|
|
|
|
} else {
|
2021-02-21 19:51:51 +01:00
|
|
|
if (!dust.isEmpty() || !isInsertItem(stack)) {
|
2021-02-14 21:15:30 +01:00
|
|
|
return new Pair<>(bangle, dust);
|
|
|
|
}
|
|
|
|
|
|
|
|
dust = stack;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!bangle.isEmpty() && isCombinationInvalid(bangle, dust)) {
|
|
|
|
return new Pair<>(ItemStack.EMPTY, ItemStack.EMPTY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new Pair<>(bangle, dust);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected boolean isCombinationInvalid(ItemStack bangle, ItemStack dust) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract boolean isContainerItem(ItemStack stack);
|
|
|
|
|
|
|
|
protected abstract boolean isInsertItem(ItemStack stack);
|
|
|
|
}
|