Fixed Grid not always using all combinations when using JEI autocompletion
This commit is contained in:
@@ -367,7 +367,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
|
||||
}
|
||||
} else if (grid.getType() == GridType.PATTERN) {
|
||||
// If we are a pattern grid we can just set the slot
|
||||
grid.getCraftingMatrix().setInventorySlotContents(i, possibilities[0]);
|
||||
grid.getCraftingMatrix().setInventorySlotContents(i, possibilities.length == 0 ? ItemStack.EMPTY : possibilities[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,14 +14,11 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
@Override
|
||||
@@ -41,6 +38,7 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
|
||||
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
|
||||
ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy();
|
||||
|
||||
if (guiIngredient.isInput()) {
|
||||
inputs.add(ingredient);
|
||||
} else {
|
||||
@@ -51,35 +49,7 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
|
||||
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridProcessingTransfer(inputs, outputs));
|
||||
} else {
|
||||
Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs = recipeLayout.getItemStacks().getGuiIngredients();
|
||||
|
||||
NBTTagCompound recipe = new NBTTagCompound();
|
||||
|
||||
for (Slot slot : container.inventorySlots) {
|
||||
if (slot.inventory instanceof InventoryCrafting) {
|
||||
IGuiIngredient<ItemStack> ingredient = inputs.get(slot.getSlotIndex() + 1);
|
||||
|
||||
if (ingredient != null) {
|
||||
NBTTagList tags = new NBTTagList();
|
||||
|
||||
for (ItemStack possibleItem : ingredient.getAllIngredients()) {
|
||||
if (possibleItem != null) {
|
||||
possibleItem = possibleItem.copy();
|
||||
possibleItem.setTagCompound(possibleItem.getItem().getNBTShareTag(possibleItem));
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
possibleItem.writeToNBT(tag);
|
||||
|
||||
tags.appendTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
recipe.setTag("#" + slot.getSlotIndex(), tags);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridTransfer(recipe));
|
||||
RS.INSTANCE.network.sendToServer(new MessageGridTransfer(recipeLayout.getItemStacks().getGuiIngredients(), container.inventorySlots.stream().filter(s -> s.inventory instanceof InventoryCrafting).collect(Collectors.toList())));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,33 +3,70 @@ package com.raoulvdberge.refinedstorage.network;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
|
||||
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
|
||||
import com.raoulvdberge.refinedstorage.container.ContainerGrid;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import mezz.jei.api.gui.IGuiIngredient;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class MessageGridTransfer extends MessageHandlerPlayerToServer<MessageGridTransfer> implements IMessage {
|
||||
private NBTTagCompound recipe;
|
||||
private Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs;
|
||||
private List<Slot> slots;
|
||||
|
||||
private ItemStack[][] recipe = new ItemStack[9][];
|
||||
|
||||
public MessageGridTransfer() {
|
||||
}
|
||||
|
||||
public MessageGridTransfer(NBTTagCompound recipe) {
|
||||
this.recipe = recipe;
|
||||
public MessageGridTransfer(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots) {
|
||||
this.inputs = inputs;
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
recipe = ByteBufUtils.readTag(buf);
|
||||
int slots = buf.readInt();
|
||||
|
||||
for (int i = 0; i < slots; ++i) {
|
||||
int ingredients = buf.readInt();
|
||||
|
||||
recipe[i] = new ItemStack[ingredients];
|
||||
|
||||
for (int j = 0; j < ingredients; ++j) {
|
||||
recipe[i][j] = StackUtils.readItemStack(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
ByteBufUtils.writeTag(buf, recipe);
|
||||
buf.writeInt(slots.size());
|
||||
|
||||
for (Slot slot : slots) {
|
||||
IGuiIngredient<ItemStack> ingredient = inputs.get(slot.getSlotIndex() + 1);
|
||||
|
||||
List<ItemStack> ingredients = new ArrayList<>();
|
||||
|
||||
if (ingredient != null) {
|
||||
for (ItemStack possibleStack : ingredient.getAllIngredients()) {
|
||||
if (possibleStack != null) {
|
||||
ingredients.add(possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
buf.writeInt(ingredients.size());
|
||||
|
||||
for (ItemStack possibleStack : ingredients) {
|
||||
StackUtils.writeItemStack(buf, possibleStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,21 +75,7 @@ public class MessageGridTransfer extends MessageHandlerPlayerToServer<MessageGri
|
||||
IGrid grid = ((ContainerGrid) player.openContainer).getGrid();
|
||||
|
||||
if (grid.getType() == GridType.CRAFTING || grid.getType() == GridType.PATTERN) {
|
||||
ItemStack[][] actualRecipe = new ItemStack[9][];
|
||||
|
||||
for (int x = 0; x < actualRecipe.length; x++) {
|
||||
NBTTagList list = message.recipe.getTagList("#" + x, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
if (list.tagCount() > 0) {
|
||||
actualRecipe[x] = new ItemStack[list.tagCount()];
|
||||
|
||||
for (int y = 0; y < list.tagCount(); y++) {
|
||||
actualRecipe[x][y] = new ItemStack(list.getCompoundTagAt(y));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
grid.onRecipeTransfer(player, actualRecipe);
|
||||
grid.onRecipeTransfer(player, message.recipe);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user