Skip to content

Commit e62f219

Browse files
committed
add RecipePlaceTest
1 parent 1d935e2 commit e62f219

File tree

2 files changed

+450
-13
lines changed

2 files changed

+450
-13
lines changed

src/mixins/java/org/spongepowered/common/mixin/core/recipebook/ServerPlaceRecipeMixin.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
import net.minecraft.world.item.Item;
3636
import net.minecraft.world.item.ItemStack;
3737
import net.minecraft.world.item.crafting.RecipeHolder;
38+
import org.checkerframework.checker.nullness.qual.Nullable;
3839
import org.spongepowered.asm.mixin.Mixin;
3940
import org.spongepowered.asm.mixin.injection.At;
4041
import org.spongepowered.common.bridge.world.item.crafting.PlacementInfoBridge;
4142
import org.spongepowered.common.item.recipe.crafting.SpongeStackedItemContents;
4243

4344
import java.util.ArrayDeque;
4445
import java.util.Deque;
45-
import java.util.List;
4646

4747
/**
4848
* Makes recipe placing to work with sponge custom ingredients.
@@ -52,6 +52,8 @@
5252
public abstract class ServerPlaceRecipeMixin {
5353

5454
private Deque<ItemStack> impl$stackList = new ArrayDeque<>();
55+
private @Nullable Slot impl$lastSlot;
56+
private @Nullable ItemStack impl$lastStack;
5557

5658
@WrapOperation(
5759
method = "placeRecipe(Lnet/minecraft/recipebook/ServerPlaceRecipe$CraftingMenuAccess;IILjava/util/List;Ljava/util/List;Lnet/minecraft/world/entity/player/Inventory;Lnet/minecraft/world/item/crafting/RecipeHolder;ZZ)Lnet/minecraft/world/inventory/RecipeBookMenu$PostPlaceAction;",
@@ -62,11 +64,7 @@ public abstract class ServerPlaceRecipeMixin {
6264
)
6365
private static StackedItemContents impl$useCustomStackedItemContents(
6466
final Operation<StackedItemContents> original,
65-
final ServerPlaceRecipe.CraftingMenuAccess<?> menu,
66-
final int gridWidth, final int gridHeight,
67-
final List<Slot> inputGridSlots, final List<Slot> slotsToClear,
68-
final Inventory inventory, final RecipeHolder<?> recipe,
69-
final boolean useMaxItems, final boolean isCreative,
67+
final @Local(argsOnly = true) RecipeHolder<?> recipe,
7068
final @Local ServerPlaceRecipe<?> placeRecipe
7169
) {
7270
final ServerPlaceRecipeMixin mixed = (ServerPlaceRecipeMixin) (Object) placeRecipe;
@@ -84,16 +82,23 @@ public abstract class ServerPlaceRecipeMixin {
8482
)
8583
private int impl$adjustMatchingSlotFinder(
8684
final Inventory instance, final Holder<Item> exemplaryItem, final ItemStack craftInputStack,
87-
final Operation<Integer> original
85+
final Operation<Integer> original,
86+
final @Local(argsOnly = true) Slot craftInputSlot
8887
) {
88+
if (this.impl$lastSlot == craftInputSlot) {
89+
return original.call(instance, exemplaryItem, this.impl$lastStack);
90+
}
91+
8992
if (this.impl$stackList.isEmpty()) {
9093
return original.call(instance, exemplaryItem, craftInputStack);
91-
} else {
92-
final ItemStack input = this.impl$stackList.poll();
93-
if (!craftInputStack.isEmpty() && !ItemStack.isSameItemSameComponents(craftInputStack, input)) {
94-
return -1;
95-
}
96-
return original.call(instance, exemplaryItem, input);
9794
}
95+
96+
if (!craftInputStack.isEmpty() && !ItemStack.isSameItemSameComponents(craftInputStack, this.impl$stackList.peek())) {
97+
return -1;
98+
}
99+
100+
this.impl$lastSlot = craftInputSlot;
101+
this.impl$lastStack = this.impl$stackList.poll();
102+
return original.call(instance, exemplaryItem, this.impl$lastStack);
98103
}
99104
}

0 commit comments

Comments
 (0)