Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ protected boolean takeItemInputs(MachineRecipe recipe, boolean simulate) {
}
int remainingAmount = input.amount();
for (ConfigurableItemStack stack : stacks) {
if (stack.getAmount() > 0 && input.matches(stack.getResource().toStack())) { // TODO: ItemStack creation slow?
if (stack.getAmount() > 0 && stack.getResource().test(input.ingredient())) {
int taken = Math.min((int) stack.getAmount(), remainingAmount);
if (taken > 0 && !simulate) {
behavior.getStatsOrDummy().addUsedItems(stack.getResource().getItem(), taken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import aztech.modern_industrialization.thirdparty.fabrictransfer.impl.item.ItemVariantImpl;
import com.mojang.serialization.Codec;
import java.util.Optional;
import java.util.function.Predicate;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
Expand Down Expand Up @@ -80,6 +81,14 @@ static ItemVariant of(ItemLike item) {
*/
boolean matches(ItemStack stack);

/**
* Tests an {@link ItemStack} predicate with the inner stack.
*
* @param predicate Predicate to perform the test with
* @return {@code true} if the test passed
*/
boolean test(Predicate<ItemStack> predicate);

/**
* Return the item of this variant.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Predicate;
import net.minecraft.core.component.DataComponentPatch;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -78,6 +79,11 @@ public boolean matches(ItemStack stack) {
return ItemStack.isSameItemSameComponents(this.stack, stack);
}

@Override
public boolean test(Predicate<ItemStack> predicate) {
return predicate.test(this.stack);
}

@Override
public ItemStack toStack(int count) {
return this.stack.copyWithCount(count);
Expand Down
Loading