Fixes issue #77 "Crafter Does not Give Byproducts Back"
This commit is contained in:
@@ -6,11 +6,13 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemPattern extends ItemBase {
|
||||
public static final String NBT_INPUTS = "Inputs";
|
||||
public static final String NBT_OUTPUTS = "Outputs";
|
||||
public static final String NBT_BYPRODUCTS = "Byproducts";
|
||||
public static final String NBT_PROCESSING = "Processing";
|
||||
|
||||
public ItemPattern() {
|
||||
@@ -44,6 +46,10 @@ public class ItemPattern extends ItemBase {
|
||||
add(pattern, stack, NBT_OUTPUTS);
|
||||
}
|
||||
|
||||
public static void addByproduct(ItemStack pattern, ItemStack stack) {
|
||||
add(pattern, stack, NBT_BYPRODUCTS);
|
||||
}
|
||||
|
||||
private static void add(ItemStack pattern, ItemStack stack, String type) {
|
||||
if (pattern.getTagCompound() == null) {
|
||||
pattern.setTagCompound(new NBTTagCompound());
|
||||
@@ -64,6 +70,10 @@ public class ItemPattern extends ItemBase {
|
||||
return get(pattern, NBT_OUTPUTS);
|
||||
}
|
||||
|
||||
public static ItemStack[] getByproducts(ItemStack pattern) {
|
||||
return get(pattern, NBT_BYPRODUCTS);
|
||||
}
|
||||
|
||||
private static ItemStack[] get(ItemStack pattern, String type) {
|
||||
if (!pattern.hasTagCompound() || !pattern.getTagCompound().hasKey(type)) {
|
||||
return null;
|
||||
|
||||
@@ -3,8 +3,11 @@ package refinedstorage.proxy;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -31,6 +34,8 @@ import refinedstorage.tile.controller.TileController;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
import refinedstorage.tile.solderer.*;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static refinedstorage.RefinedStorage.ID;
|
||||
|
||||
public class CommonProxy {
|
||||
|
||||
@@ -21,14 +21,16 @@ public class CraftingPattern {
|
||||
private boolean processing;
|
||||
private ItemStack[] inputs;
|
||||
private ItemStack[] outputs;
|
||||
private ItemStack[] byproducts;
|
||||
|
||||
public CraftingPattern(int crafterX, int crafterY, int crafterZ, boolean processing, ItemStack[] inputs, ItemStack[] outputs) {
|
||||
public CraftingPattern(int crafterX, int crafterY, int crafterZ, boolean processing, ItemStack[] inputs, ItemStack[] outputs, ItemStack[] byproducts) {
|
||||
this.crafterX = crafterX;
|
||||
this.crafterY = crafterY;
|
||||
this.crafterZ = crafterZ;
|
||||
this.processing = processing;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
this.byproducts = byproducts;
|
||||
}
|
||||
|
||||
public TileCrafter getCrafter(World world) {
|
||||
@@ -51,6 +53,10 @@ public class CraftingPattern {
|
||||
return outputs;
|
||||
}
|
||||
|
||||
public ItemStack[] getByproducts() {
|
||||
return byproducts;
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
tag.setBoolean(ItemPattern.NBT_PROCESSING, processing);
|
||||
|
||||
@@ -66,6 +72,14 @@ public class CraftingPattern {
|
||||
}
|
||||
tag.setTag(ItemPattern.NBT_OUTPUTS, outputsTag);
|
||||
|
||||
if (byproducts != null) {
|
||||
NBTTagList byproductsTag = new NBTTagList();
|
||||
for (ItemStack byproduct : byproducts) {
|
||||
byproductsTag.appendTag(byproduct.serializeNBT());
|
||||
}
|
||||
tag.setTag(ItemPattern.NBT_BYPRODUCTS, byproductsTag);
|
||||
}
|
||||
|
||||
tag.setInteger(NBT_CRAFTER_X, crafter.getPos().getX());
|
||||
tag.setInteger(NBT_CRAFTER_Y, crafter.getPos().getY());
|
||||
tag.setInteger(NBT_CRAFTER_Z, crafter.getPos().getZ());
|
||||
@@ -100,6 +114,21 @@ public class CraftingPattern {
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftingPattern(cx, cy, cz, processing, inputs, outputs);
|
||||
ItemStack byproducts[] = new ItemStack[0];
|
||||
|
||||
if (tag.hasKey(ItemPattern.NBT_BYPRODUCTS)) {
|
||||
NBTTagList byproductsTag = tag.getTagList(ItemPattern.NBT_BYPRODUCTS, Constants.NBT.TAG_COMPOUND);
|
||||
byproducts = new ItemStack[byproductsTag.tagCount()];
|
||||
|
||||
for (int i = 0; i < byproductsTag.tagCount(); ++i) {
|
||||
byproducts[i] = ItemStack.loadItemStackFromNBT(byproductsTag.getCompoundTagAt(i));
|
||||
|
||||
if (byproducts[i] == null) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new CraftingPattern(cx, cy, cz, processing, inputs, outputs, byproducts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,12 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
controller.push(output);
|
||||
}
|
||||
|
||||
if (pattern.getByproducts() != null) {
|
||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
||||
controller.push(byproduct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -279,7 +279,7 @@ public class TileController extends TileBase implements IEnergyReceiver, ISynchr
|
||||
ItemStack pattern = crafter.getPatterns().getStackInSlot(i);
|
||||
|
||||
if (pattern != null && ItemPattern.isValid(pattern)) {
|
||||
patterns.add(new CraftingPattern(crafter.getPos().getX(), crafter.getPos().getY(), crafter.getPos().getZ(), ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
|
||||
patterns.add(new CraftingPattern(crafter.getPos().getX(), crafter.getPos().getY(), crafter.getPos().getZ(), ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern), ItemPattern.getByproducts(pattern)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,12 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
|
||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
||||
|
||||
for (ItemStack byproduct : CraftingManager.getInstance().getRemainingItems(matrix, worldObj)) {
|
||||
if (byproduct != null) {
|
||||
ItemPattern.addByproduct(pattern, byproduct);
|
||||
}
|
||||
}
|
||||
|
||||
ItemPattern.addOutput(pattern, result.getStackInSlot(0));
|
||||
|
||||
ItemPattern.setProcessing(pattern, false);
|
||||
|
||||
Reference in New Issue
Block a user