Skip to content

Commit b52c634

Browse files
committed
Fix #1109: Optimize CrafterComponent#takeItemInputs a little
1 parent deb878f commit b52c634

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/main/java/aztech/modern_industrialization/machines/components/CrafterComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ protected boolean takeItemInputs(MachineRecipe recipe, boolean simulate) {
444444
}
445445
int remainingAmount = input.amount();
446446
for (ConfigurableItemStack stack : stacks) {
447-
if (stack.getAmount() > 0 && input.matches(stack.getResource().toStack())) { // TODO: ItemStack creation slow?
447+
if (stack.getAmount() > 0 && stack.getResource().test(input.ingredient())) {
448448
int taken = Math.min((int) stack.getAmount(), remainingAmount);
449449
if (taken > 0 && !simulate) {
450450
behavior.getStatsOrDummy().addUsedItems(stack.getResource().getItem(), taken);

src/main/java/aztech/modern_industrialization/thirdparty/fabrictransfer/api/item/ItemVariant.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import aztech.modern_industrialization.thirdparty.fabrictransfer.impl.item.ItemVariantImpl;
2929
import com.mojang.serialization.Codec;
3030
import java.util.Optional;
31+
import java.util.function.Predicate;
3132
import net.minecraft.core.HolderLookup;
3233
import net.minecraft.nbt.CompoundTag;
3334
import net.minecraft.nbt.NbtOps;
@@ -80,6 +81,14 @@ static ItemVariant of(ItemLike item) {
8081
*/
8182
boolean matches(ItemStack stack);
8283

84+
/**
85+
* Tests an {@link ItemStack} predicate with the inner stack.
86+
*
87+
* @param predicate Predicate to perform the test with
88+
* @return {@code true} if the test passed
89+
*/
90+
boolean test(Predicate<ItemStack> predicate);
91+
8392
/**
8493
* Return the item of this variant.
8594
*/

src/main/java/aztech/modern_industrialization/thirdparty/fabrictransfer/impl/item/ItemVariantImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Map;
2828
import java.util.Objects;
2929
import java.util.concurrent.ConcurrentHashMap;
30+
import java.util.function.Predicate;
3031
import net.minecraft.core.component.DataComponentPatch;
3132
import net.minecraft.world.item.Item;
3233
import net.minecraft.world.item.ItemStack;
@@ -78,6 +79,11 @@ public boolean matches(ItemStack stack) {
7879
return ItemStack.isSameItemSameComponents(this.stack, stack);
7980
}
8081

82+
@Override
83+
public boolean test(Predicate<ItemStack> predicate) {
84+
return predicate.test(this.stack);
85+
}
86+
8187
@Override
8288
public ItemStack toStack(int count) {
8389
return this.stack.copyWithCount(count);

0 commit comments

Comments
 (0)