Fixed Grid not always using all combinations when using JEI autocompletion

This commit is contained in:
raoulvdberge
2018-04-06 11:31:46 +02:00
parent e3654fed56
commit 7fca77193f
3 changed files with 51 additions and 58 deletions

View File

@@ -367,7 +367,7 @@ public class NetworkNodeGrid extends NetworkNode implements IGridNetworkAware {
} }
} else if (grid.getType() == GridType.PATTERN) { } else if (grid.getType() == GridType.PATTERN) {
// If we are a pattern grid we can just set the slot // 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]);
} }
} }
} }

View File

@@ -14,14 +14,11 @@ import mezz.jei.api.recipe.transfer.IRecipeTransferHandler;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.stream.Collectors;
public class RecipeTransferHandlerGrid implements IRecipeTransferHandler { public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
@Override @Override
@@ -41,6 +38,7 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) { for (IGuiIngredient<ItemStack> guiIngredient : recipeLayout.getItemStacks().getGuiIngredients().values()) {
if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) { if (guiIngredient != null && guiIngredient.getDisplayedIngredient() != null) {
ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy(); ItemStack ingredient = guiIngredient.getDisplayedIngredient().copy();
if (guiIngredient.isInput()) { if (guiIngredient.isInput()) {
inputs.add(ingredient); inputs.add(ingredient);
} else { } else {
@@ -51,35 +49,7 @@ public class RecipeTransferHandlerGrid implements IRecipeTransferHandler {
RS.INSTANCE.network.sendToServer(new MessageGridProcessingTransfer(inputs, outputs)); RS.INSTANCE.network.sendToServer(new MessageGridProcessingTransfer(inputs, outputs));
} else { } else {
Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs = recipeLayout.getItemStacks().getGuiIngredients(); RS.INSTANCE.network.sendToServer(new MessageGridTransfer(recipeLayout.getItemStacks().getGuiIngredients(), container.inventorySlots.stream().filter(s -> s.inventory instanceof InventoryCrafting).collect(Collectors.toList())));
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));
} }
} }

View File

@@ -3,33 +3,70 @@ package com.raoulvdberge.refinedstorage.network;
import com.raoulvdberge.refinedstorage.api.network.grid.GridType; import com.raoulvdberge.refinedstorage.api.network.grid.GridType;
import com.raoulvdberge.refinedstorage.api.network.grid.IGrid; import com.raoulvdberge.refinedstorage.api.network.grid.IGrid;
import com.raoulvdberge.refinedstorage.container.ContainerGrid; import com.raoulvdberge.refinedstorage.container.ContainerGrid;
import com.raoulvdberge.refinedstorage.util.StackUtils;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import mezz.jei.api.gui.IGuiIngredient;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; 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 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 { 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() {
} }
public MessageGridTransfer(NBTTagCompound recipe) { public MessageGridTransfer(Map<Integer, ? extends IGuiIngredient<ItemStack>> inputs, List<Slot> slots) {
this.recipe = recipe; this.inputs = inputs;
this.slots = slots;
} }
@Override @Override
public void fromBytes(ByteBuf buf) { 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 @Override
public void toBytes(ByteBuf buf) { 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 @Override
@@ -38,21 +75,7 @@ public class MessageGridTransfer extends MessageHandlerPlayerToServer<MessageGri
IGrid grid = ((ContainerGrid) player.openContainer).getGrid(); IGrid grid = ((ContainerGrid) player.openContainer).getGrid();
if (grid.getType() == GridType.CRAFTING || grid.getType() == GridType.PATTERN) { if (grid.getType() == GridType.CRAFTING || grid.getType() == GridType.PATTERN) {
ItemStack[][] actualRecipe = new ItemStack[9][]; grid.onRecipeTransfer(player, message.recipe);
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);
} }
} }
} }