Fix processing patterns
This commit is contained in:
@@ -22,7 +22,6 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
private ItemStack stack;
|
||||
private List<ItemStack> inputs = new ArrayList<>();
|
||||
private List<ItemStack> outputs = new ArrayList<>();
|
||||
private boolean processing = false;
|
||||
|
||||
public CraftingPattern(World world, ICraftingPatternContainer container, ItemStack stack) {
|
||||
this.container = container;
|
||||
@@ -47,10 +46,20 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
}
|
||||
}
|
||||
|
||||
ItemStack output = CraftingManager.getInstance().findMatchingRecipe(dummyInventory, world);
|
||||
if (!ItemPattern.isProcessing(stack)) {
|
||||
ItemStack output = CraftingManager.getInstance().findMatchingRecipe(dummyInventory, world);
|
||||
|
||||
if (output != null) {
|
||||
outputs.add(output);
|
||||
if (output != null) {
|
||||
outputs.add(output.copy());
|
||||
}
|
||||
|
||||
for (ItemStack remaining : CraftingManager.getInstance().getRemainingItems(dummyInventory, world)) {
|
||||
if (remaining != null) {
|
||||
outputs.add(remaining.copy());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
outputs = ItemPattern.getOutputs(stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +90,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return processing ? CraftingTaskFactoryProcessing.ID : CraftingTaskFactoryNormal.ID;
|
||||
return ItemPattern.isProcessing(stack) ? CraftingTaskFactoryProcessing.ID : CraftingTaskFactoryNormal.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,7 +101,7 @@ public class CraftingPattern implements ICraftingPattern {
|
||||
if (CompareUtils.compareStackNoQuantity(requested, output)) {
|
||||
quantity += output.stackSize;
|
||||
|
||||
if (!processing) {
|
||||
if (!ItemPattern.isProcessing(stack)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,18 @@
|
||||
package refinedstorage.item;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||
@@ -15,30 +20,36 @@ import refinedstorage.api.autocrafting.ICraftingPatternProvider;
|
||||
import refinedstorage.api.storage.CompareUtils;
|
||||
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
||||
private static final String NBT_SLOT = "Slot_%d";
|
||||
private static final String NBT_OUTPUTS = "Outputs";
|
||||
|
||||
public ItemPattern() {
|
||||
super("pattern");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack pattern, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
/* @todo CraftingPattern
|
||||
if (GuiScreen.isShiftKeyDown() || isProcessing(pattern)) {
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||
ICraftingPattern pattern = create(player.worldObj, stack, null);
|
||||
|
||||
if (pattern.isValid()) {
|
||||
if (GuiScreen.isShiftKeyDown() || isProcessing(stack)) {
|
||||
tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.inputs") + TextFormatting.RESET);
|
||||
|
||||
combineItems(tooltip, true, getInputs(pattern));
|
||||
combineItems(tooltip, true, Iterables.toArray(pattern.getInputs(), ItemStack.class));
|
||||
|
||||
tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.outputs") + TextFormatting.RESET);
|
||||
}
|
||||
|
||||
combineItems(tooltip, true, getOutputs(pattern));
|
||||
}*/
|
||||
combineItems(tooltip, true, Iterables.toArray(pattern.getOutputs(), ItemStack.class));
|
||||
} else {
|
||||
tooltip.add(TextFormatting.RED + "Invalid pattern, please re-make!");
|
||||
}
|
||||
}
|
||||
|
||||
public static void setSlot(ItemStack pattern, int slot, ItemStack stack) {
|
||||
@@ -59,6 +70,47 @@ public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
||||
return ItemStack.loadItemStackFromNBT(pattern.getTagCompound().getCompoundTag(id));
|
||||
}
|
||||
|
||||
public static void addOutput(ItemStack pattern, ItemStack output) {
|
||||
if (!pattern.hasTagCompound()) {
|
||||
pattern.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagList outputs;
|
||||
if (!pattern.getTagCompound().hasKey(NBT_OUTPUTS)) {
|
||||
outputs = new NBTTagList();
|
||||
} else {
|
||||
outputs = pattern.getTagCompound().getTagList(NBT_OUTPUTS, Constants.NBT.TAG_COMPOUND);
|
||||
}
|
||||
|
||||
outputs.appendTag(output.serializeNBT());
|
||||
|
||||
pattern.getTagCompound().setTag(NBT_OUTPUTS, outputs);
|
||||
}
|
||||
|
||||
public static List<ItemStack> getOutputs(ItemStack pattern) {
|
||||
if (!isProcessing(pattern)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ArrayList<ItemStack> outputs = new ArrayList<>();
|
||||
|
||||
NBTTagList outputsTag = pattern.getTagCompound().getTagList(NBT_OUTPUTS, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < outputsTag.tagCount(); ++i) {
|
||||
ItemStack stack = ItemStack.loadItemStackFromNBT(outputsTag.getCompoundTagAt(i));
|
||||
|
||||
if (stack != null) {
|
||||
outputs.add(stack);
|
||||
}
|
||||
}
|
||||
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public static boolean isProcessing(ItemStack pattern) {
|
||||
return pattern.hasTagCompound() && pattern.getTagCompound().hasKey(NBT_OUTPUTS);
|
||||
}
|
||||
|
||||
public static void combineItems(List<String> tooltip, boolean displayAmount, ItemStack... stacks) {
|
||||
Set<Integer> combinedIndices = new HashSet<>();
|
||||
|
||||
|
||||
@@ -6,9 +6,11 @@ import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.items.CapabilityItemHandler;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.inventory.ItemHandlerBasic;
|
||||
import refinedstorage.inventory.ItemValidatorBasic;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
|
||||
public class TileProcessingPatternEncoder extends TileBase {
|
||||
private ItemHandlerBasic patterns = new ItemHandlerBasic(2, this, new ItemValidatorBasic(RefinedStorageItems.PATTERN));
|
||||
@@ -36,20 +38,17 @@ public class TileProcessingPatternEncoder extends TileBase {
|
||||
if (canCreatePattern()) {
|
||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
||||
|
||||
// @todo
|
||||
/*ItemPattern.setProcessing(pattern, true);
|
||||
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
if (configuration.getStackInSlot(i) != null) {
|
||||
for (int j = 0; j < configuration.getStackInSlot(i).stackSize; ++j) {
|
||||
if (i >= 9) {
|
||||
if (i >= 9) {
|
||||
for (int j = 0; j < configuration.getStackInSlot(i).stackSize; ++j) {
|
||||
ItemPattern.addOutput(pattern, ItemHandlerHelper.copyStackWithSize(configuration.getStackInSlot(i), 1));
|
||||
} else {
|
||||
ItemPattern.addInput(pattern, ItemHandlerHelper.copyStackWithSize(configuration.getStackInSlot(i), 1));
|
||||
}
|
||||
} else {
|
||||
ItemPattern.setSlot(pattern, i, configuration.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
patterns.extractItem(0, 1, false);
|
||||
patterns.setStackInSlot(1, pattern);
|
||||
|
||||
Reference in New Issue
Block a user