Fixed multiple bugs related to transferring recipes into the Crafting Grid.

Cherry picked from e0fab68fd3957ee5081a0a709b7fb7c6f7c704a9
This commit is contained in:
Darkere
2021-12-30 14:24:06 +01:00
committed by raoulvdberge
parent 04187930c4
commit 6827b12f4a
4 changed files with 13 additions and 6 deletions

View File

@@ -7,6 +7,10 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [Unreleased] ## [Unreleased]
### Fixed
- Fixed multiple bugs related to transferring recipes into the Crafting Grid.
## [v1.10.0-beta.4] - 2021-12-28 ## [v1.10.0-beta.4] - 2021-12-28
### Fixed ### Fixed

View File

@@ -210,7 +210,7 @@ public class CraftingGridBehavior implements ICraftingGridBehavior {
// If we are connected, first try to get the possibilities from the network // If we are connected, first try to get the possibilities from the network
if (network != null && grid.isGridActive()) { if (network != null && grid.isGridActive()) {
for (ItemStack possibility : possibilities) { for (ItemStack possibility : possibilities) {
ItemStack took = network.extractItem(possibility, 1, IComparer.COMPARE_NBT, Action.PERFORM); ItemStack took = network.extractItem(possibility, possibility.getCount(), IComparer.COMPARE_NBT, Action.PERFORM);
if (!took.isEmpty()) { if (!took.isEmpty()) {
grid.getCraftingMatrix().setItem(i, took); grid.getCraftingMatrix().setItem(i, took);

View File

@@ -151,14 +151,15 @@ public class GridRecipeTransferHandler implements IRecipeTransferHandler<GridCon
if (gridContainer.getGrid().getGridType() == GridType.PATTERN && !(recipe instanceof CraftingRecipe)) { if (gridContainer.getGrid().getGridType() == GridType.PATTERN && !(recipe instanceof CraftingRecipe)) {
moveForProcessing(recipeLayout, tracker); moveForProcessing(recipeLayout, tracker);
} else { } else {
move(gridContainer, recipeLayout); move(gridContainer, recipeLayout, recipe);
} }
} }
private void move(GridContainerMenu gridContainer, IRecipeLayout recipeLayout) { private void move(GridContainerMenu gridContainer, IRecipeLayout recipeLayout, Object recipe) {
RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage( RS.NETWORK_HANDLER.sendToServer(new GridTransferMessage(
recipeLayout.getItemStacks().getGuiIngredients(), recipeLayout.getItemStacks().getGuiIngredients(),
gridContainer.slots.stream().filter(s -> s.container instanceof CraftingContainer).collect(Collectors.toList()) gridContainer.slots.stream().filter(s -> s.container instanceof CraftingContainer).collect(Collectors.toList()),
recipe instanceof CraftingRecipe
)); ));
} }

View File

@@ -20,13 +20,15 @@ public class GridTransferMessage {
private final ItemStack[][] recipe = new ItemStack[9][]; private final ItemStack[][] recipe = new ItemStack[9][];
private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs; private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs;
private List<Slot> slots; private List<Slot> slots;
boolean isCraftingRecipe;
public GridTransferMessage() { public GridTransferMessage() {
} }
public GridTransferMessage(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots) { public GridTransferMessage(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots, boolean isCraftingRecipe) {
this.inputs = inputs; this.inputs = inputs;
this.slots = slots; this.slots = slots;
this.isCraftingRecipe = isCraftingRecipe;
} }
public static GridTransferMessage decode(FriendlyByteBuf buf) { public static GridTransferMessage decode(FriendlyByteBuf buf) {
@@ -51,7 +53,7 @@ public class GridTransferMessage {
buf.writeInt(message.slots.size()); buf.writeInt(message.slots.size());
for (Slot slot : message.slots) { for (Slot slot : message.slots) {
IGuiIngredient<ItemStack> ingredient = message.inputs.get(slot.getSlotIndex() + 1); IGuiIngredient<ItemStack> ingredient = message.inputs.get(slot.getSlotIndex() + (message.isCraftingRecipe ? 1 : 0));
List<ItemStack> ingredients = new ArrayList<>(); List<ItemStack> ingredients = new ArrayList<>();