Refactor. Processing patterns are broken.
This commit is contained in:
@@ -1,38 +1,37 @@
|
|||||||
package refinedstorage.api.autocrafting;
|
package refinedstorage.api.autocrafting;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraft.world.World;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a crafting pattern.
|
* Represents a crafting pattern.
|
||||||
*/
|
*/
|
||||||
public interface ICraftingPattern {
|
public interface ICraftingPattern {
|
||||||
/**
|
/**
|
||||||
* @param world The world
|
|
||||||
* @return The container where the pattern is in
|
* @return The container where the pattern is in
|
||||||
*/
|
*/
|
||||||
ICraftingPatternContainer getContainer(World world);
|
ICraftingPatternContainer getContainer();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The crafting pattern stack
|
* @return The crafting pattern stack
|
||||||
*/
|
*/
|
||||||
ItemStack getStack();
|
ItemStack getStack();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Whether the crafting pattern is valid
|
||||||
|
*/
|
||||||
|
boolean isValid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The inputs
|
* @return The inputs
|
||||||
*/
|
*/
|
||||||
ItemStack[] getInputs();
|
List<ItemStack> getInputs();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The outputs
|
* @return The outputs
|
||||||
*/
|
*/
|
||||||
ItemStack[] getOutputs();
|
List<ItemStack> getOutputs();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The byproducts
|
|
||||||
*/
|
|
||||||
ItemStack[] getByproducts();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The id of the crafting task, as defined in the registry
|
* @return The id of the crafting task, as defined in the registry
|
||||||
@@ -44,12 +43,4 @@ public interface ICraftingPattern {
|
|||||||
* @return The quantity returned per request
|
* @return The quantity returned per request
|
||||||
*/
|
*/
|
||||||
int getQuantityPerRequest(ItemStack requested);
|
int getQuantityPerRequest(ItemStack requested);
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes this pattern to NBT.
|
|
||||||
*
|
|
||||||
* @param tag The NBT tag to write to
|
|
||||||
* @return The written NBT tag
|
|
||||||
*/
|
|
||||||
NBTTagCompound writeToNBT(NBTTagCompound tag);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package refinedstorage.api.autocrafting;
|
package refinedstorage.api.autocrafting;
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implement this interface on pattern items.
|
* Implement this interface on pattern items.
|
||||||
@@ -12,18 +11,10 @@ public interface ICraftingPatternProvider {
|
|||||||
/**
|
/**
|
||||||
* Creates a crafting pattern.
|
* Creates a crafting pattern.
|
||||||
*
|
*
|
||||||
|
* @param world The world
|
||||||
* @param stack The pattern stack
|
* @param stack The pattern stack
|
||||||
* @param container The container where the pattern is in
|
* @param container The container where the pattern is in
|
||||||
* @return The crafting pattern
|
* @return The crafting pattern
|
||||||
*/
|
*/
|
||||||
ICraftingPattern create(ItemStack stack, ICraftingPatternContainer container);
|
ICraftingPattern create(World world, ItemStack stack, ICraftingPatternContainer container);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a crafting pattern from the pattern item stack.
|
|
||||||
*
|
|
||||||
* @param stack The item stack
|
|
||||||
* @return The crafting pattern, or null if the read failed
|
|
||||||
*/
|
|
||||||
@Nullable
|
|
||||||
ICraftingPattern create(ItemStack stack);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package refinedstorage.api.autocrafting.registry;
|
package refinedstorage.api.autocrafting.registry;
|
||||||
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
|
|
||||||
@@ -15,9 +16,10 @@ public interface ICraftingTaskFactory {
|
|||||||
* Returns a crafting task for a given NBT tag and pattern.
|
* Returns a crafting task for a given NBT tag and pattern.
|
||||||
*
|
*
|
||||||
* @param tag The NBT tag. If this is null it isn't reading from disk but is used for making a task on demand
|
* @param tag The NBT tag. If this is null it isn't reading from disk but is used for making a task on demand
|
||||||
|
* @param world The world
|
||||||
* @param pattern The pattern
|
* @param pattern The pattern
|
||||||
* @return The crafting task
|
* @return The crafting task
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern);
|
ICraftingTask create(@Nullable NBTTagCompound tag, World world, ICraftingPattern pattern);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cofh.api.energy.EnergyStorage;
|
|||||||
import net.minecraft.entity.player.EntityPlayerMP;
|
import net.minecraft.entity.player.EntityPlayerMP;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
@@ -83,14 +84,6 @@ public interface INetworkMaster {
|
|||||||
*/
|
*/
|
||||||
void addCraftingTask(@Nonnull ICraftingTask task);
|
void addCraftingTask(@Nonnull ICraftingTask task);
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a crafting task from a {@link ICraftingPattern}.
|
|
||||||
*
|
|
||||||
* @param pattern The pattern to create a task for
|
|
||||||
* @return A task
|
|
||||||
*/
|
|
||||||
ICraftingTask createCraftingTask(@Nonnull ICraftingPattern pattern);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancels a crafting task.
|
* Cancels a crafting task.
|
||||||
*
|
*
|
||||||
@@ -209,4 +202,9 @@ public interface INetworkMaster {
|
|||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags);
|
FluidStack extractFluid(@Nonnull FluidStack stack, int size, int flags);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The world where this node is in
|
||||||
|
*/
|
||||||
|
World getNetworkWorld();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraftforge.fluids.FluidRegistry;
|
import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||||
|
import refinedstorage.api.RefinedStorageAPI;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
@@ -26,6 +27,10 @@ public final class NetworkUtils {
|
|||||||
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
return network.getPattern(stack, CompareUtils.COMPARE_DAMAGE | CompareUtils.COMPARE_NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ICraftingTask createCraftingTask(INetworkMaster network, ICraftingPattern pattern) {
|
||||||
|
return RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(pattern.getId()).create(null, network.getNetworkWorld(), pattern);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
public static boolean hasPattern(INetworkMaster network, ItemStack stack) {
|
||||||
return getPattern(network, stack) != null;
|
return getPattern(network, stack) != null;
|
||||||
}
|
}
|
||||||
@@ -57,7 +62,7 @@ public final class NetworkUtils {
|
|||||||
ICraftingPattern pattern = network.getPattern(stack, compare);
|
ICraftingPattern pattern = network.getPattern(stack, compare);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
network.addCraftingTask(network.createCraftingTask(pattern));
|
network.addCraftingTask(createCraftingTask(network, pattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,62 @@
|
|||||||
package refinedstorage.apiimpl.autocrafting;
|
package refinedstorage.apiimpl.autocrafting;
|
||||||
|
|
||||||
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
|
import net.minecraft.inventory.Container;
|
||||||
|
import net.minecraft.inventory.InventoryCrafting;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.item.crafting.CraftingManager;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
import net.minecraftforge.items.ItemHandlerHelper;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
|
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryNormal;
|
||||||
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryProcessing;
|
import refinedstorage.apiimpl.autocrafting.registry.CraftingTaskFactoryProcessing;
|
||||||
import refinedstorage.item.ItemPattern;
|
import refinedstorage.item.ItemPattern;
|
||||||
import refinedstorage.tile.TileCrafter;
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CraftingPattern implements ICraftingPattern {
|
public class CraftingPattern implements ICraftingPattern {
|
||||||
public static final String NBT_CRAFTER_X = "CrafterX";
|
private ICraftingPatternContainer container;
|
||||||
public static final String NBT_CRAFTER_Y = "CrafterY";
|
|
||||||
public static final String NBT_CRAFTER_Z = "CrafterZ";
|
|
||||||
|
|
||||||
private ItemStack stack;
|
private ItemStack stack;
|
||||||
private BlockPos crafterPos;
|
private List<ItemStack> inputs = new ArrayList<>();
|
||||||
private TileCrafter crafter;
|
private List<ItemStack> outputs = new ArrayList<>();
|
||||||
private boolean processing;
|
private boolean processing = false;
|
||||||
private ItemStack[] inputs;
|
|
||||||
private ItemStack[] outputs;
|
|
||||||
private ItemStack[] byproducts;
|
|
||||||
|
|
||||||
public CraftingPattern(ItemStack stack, BlockPos crafterPos, boolean processing, ItemStack[] inputs, ItemStack[] outputs, ItemStack[] byproducts) {
|
public CraftingPattern(World world, ICraftingPatternContainer container, ItemStack stack) {
|
||||||
|
this.container = container;
|
||||||
this.stack = stack;
|
this.stack = stack;
|
||||||
this.crafterPos = crafterPos;
|
|
||||||
this.processing = processing;
|
InventoryCrafting dummyInventory = new InventoryCrafting(new Container() {
|
||||||
this.inputs = inputs;
|
@Override
|
||||||
this.outputs = outputs;
|
public boolean canInteractWith(EntityPlayer player) {
|
||||||
this.byproducts = byproducts;
|
return false;
|
||||||
|
}
|
||||||
|
}, 3, 3);
|
||||||
|
|
||||||
|
for (int i = 0; i < 9; ++i) {
|
||||||
|
ItemStack slot = ItemPattern.getSlot(stack, i);
|
||||||
|
|
||||||
|
if (slot != null) {
|
||||||
|
for (int j = 0; j < slot.stackSize; ++j) {
|
||||||
|
inputs.add(ItemHandlerHelper.copyStackWithSize(slot, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
dummyInventory.setInventorySlotContents(i, slot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemStack output = CraftingManager.getInstance().findMatchingRecipe(dummyInventory, world);
|
||||||
|
|
||||||
|
if (output != null) {
|
||||||
|
outputs.add(output);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICraftingPatternContainer getContainer(World world) {
|
public ICraftingPatternContainer getContainer() {
|
||||||
if (crafter == null) {
|
return container;
|
||||||
crafter = (TileCrafter) world.getTileEntity(crafterPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
return crafter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -50,20 +65,20 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack[] getInputs() {
|
public boolean isValid() {
|
||||||
|
return !inputs.isEmpty() && !outputs.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ItemStack> getInputs() {
|
||||||
return inputs;
|
return inputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack[] getOutputs() {
|
public List<ItemStack> getOutputs() {
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ItemStack[] getByproducts() {
|
|
||||||
return byproducts;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return processing ? CraftingTaskFactoryProcessing.ID : CraftingTaskFactoryNormal.ID;
|
return processing ? CraftingTaskFactoryProcessing.ID : CraftingTaskFactoryNormal.ID;
|
||||||
@@ -85,41 +100,4 @@ public class CraftingPattern implements ICraftingPattern {
|
|||||||
|
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
|
||||||
tag.setBoolean(ItemPattern.NBT_PROCESSING, processing);
|
|
||||||
|
|
||||||
NBTTagList inputsTag = new NBTTagList();
|
|
||||||
|
|
||||||
for (ItemStack input : inputs) {
|
|
||||||
inputsTag.appendTag(input.serializeNBT());
|
|
||||||
}
|
|
||||||
|
|
||||||
tag.setTag(ItemPattern.NBT_INPUTS, inputsTag);
|
|
||||||
|
|
||||||
NBTTagList outputsTag = new NBTTagList();
|
|
||||||
|
|
||||||
for (ItemStack output : outputs) {
|
|
||||||
outputsTag.appendTag(output.serializeNBT());
|
|
||||||
}
|
|
||||||
|
|
||||||
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, crafterPos.getX());
|
|
||||||
tag.setInteger(NBT_CRAFTER_Y, crafterPos.getY());
|
|
||||||
tag.setInteger(NBT_CRAFTER_Z, crafterPos.getZ());
|
|
||||||
|
|
||||||
return tag;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package refinedstorage.apiimpl.autocrafting.registry;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||||
@@ -20,7 +21,7 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) {
|
public ICraftingTask create(@Nullable NBTTagCompound tag, World world, ICraftingPattern pattern) {
|
||||||
CraftingTaskNormal task = new CraftingTaskNormal(pattern);
|
CraftingTaskNormal task = new CraftingTaskNormal(pattern);
|
||||||
|
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
@@ -42,7 +43,7 @@ public class CraftingTaskFactoryNormal implements ICraftingTaskFactory {
|
|||||||
|
|
||||||
task.setTook(took);
|
task.setTook(took);
|
||||||
|
|
||||||
task.readChildNBT(tag);
|
task.readChildNBT(world, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package refinedstorage.apiimpl.autocrafting.registry;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
import refinedstorage.api.autocrafting.registry.ICraftingTaskFactory;
|
||||||
@@ -20,7 +21,7 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ICraftingTask create(@Nullable NBTTagCompound tag, ICraftingPattern pattern) {
|
public ICraftingTask create(@Nullable NBTTagCompound tag, World world, ICraftingPattern pattern) {
|
||||||
CraftingTaskProcessing task = new CraftingTaskProcessing(pattern);
|
CraftingTaskProcessing task = new CraftingTaskProcessing(pattern);
|
||||||
|
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
@@ -43,7 +44,7 @@ public class CraftingTaskFactoryProcessing implements ICraftingTaskFactory {
|
|||||||
|
|
||||||
task.setTook(took);
|
task.setTook(took);
|
||||||
|
|
||||||
task.readChildNBT(tag);
|
task.readChildNBT(world, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
return task;
|
return task;
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagIntArray;
|
import net.minecraft.nbt.NBTTagIntArray;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
import refinedstorage.api.network.INetworkMaster;
|
import refinedstorage.api.network.INetworkMaster;
|
||||||
@@ -27,7 +28,7 @@ public abstract class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
public CraftingTask(ICraftingPattern pattern) {
|
public CraftingTask(ICraftingPattern pattern) {
|
||||||
this.pattern = pattern;
|
this.pattern = pattern;
|
||||||
this.childrenCreated = new boolean[pattern.getInputs().length];
|
this.childrenCreated = new boolean[pattern.getInputs().size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -45,10 +46,10 @@ public abstract class CraftingTask implements ICraftingTask {
|
|||||||
|
|
||||||
protected void tryCreateChild(INetworkMaster network, int i) {
|
protected void tryCreateChild(INetworkMaster network, int i) {
|
||||||
if (!childrenCreated[i]) {
|
if (!childrenCreated[i]) {
|
||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, this.pattern.getInputs()[i]);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, this.pattern.getInputs().get(i));
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
child = network.createCraftingTask(pattern);
|
child = NetworkUtils.createCraftingTask(network, pattern);
|
||||||
|
|
||||||
childrenCreated[i] = true;
|
childrenCreated[i] = true;
|
||||||
|
|
||||||
@@ -99,9 +100,9 @@ public abstract class CraftingTask implements ICraftingTask {
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readChildNBT(NBTTagCompound tag) {
|
public void readChildNBT(World world, NBTTagCompound tag) {
|
||||||
if (tag.hasKey(NBT_CHILD)) {
|
if (tag.hasKey(NBT_CHILD)) {
|
||||||
child = TileController.readCraftingTask(tag.getCompoundTag(NBT_CHILD));
|
child = TileController.readCraftingTask(world, tag.getCompoundTag(NBT_CHILD));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,8 +17,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
public CraftingTaskNormal(ICraftingPattern pattern) {
|
public CraftingTaskNormal(ICraftingPattern pattern) {
|
||||||
super(pattern);
|
super(pattern);
|
||||||
|
|
||||||
this.satisfied = new boolean[pattern.getInputs().length];
|
this.satisfied = new boolean[pattern.getInputs().size()];
|
||||||
this.checked = new boolean[pattern.getInputs().length];
|
this.checked = new boolean[pattern.getInputs().size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSatisfied(boolean[] satisfied) {
|
public void setSatisfied(boolean[] satisfied) {
|
||||||
@@ -31,10 +31,10 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(World world, INetworkMaster network) {
|
public boolean update(World world, INetworkMaster network) {
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
checked[i] = true;
|
checked[i] = true;
|
||||||
|
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i]) {
|
if (!satisfied[i]) {
|
||||||
ItemStack received = NetworkUtils.extractItem(network, input, input.stackSize);
|
ItemStack received = NetworkUtils.extractItem(network, input, input.stackSize);
|
||||||
@@ -64,13 +64,6 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
network.insertItem(output, output.stackSize, false);
|
network.insertItem(output, output.stackSize, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pattern.getByproducts() != null) {
|
|
||||||
for (ItemStack byproduct : pattern.getByproducts()) {
|
|
||||||
// @TODO: Handle remainder
|
|
||||||
network.insertItem(byproduct, byproduct.stackSize, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,8 +83,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
|
|
||||||
boolean missingItems = false;
|
boolean missingItems = false;
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i] && !childrenCreated[i] && checked[i]) {
|
if (!satisfied[i] && !childrenCreated[i] && checked[i]) {
|
||||||
if (!missingItems) {
|
if (!missingItems) {
|
||||||
@@ -106,8 +99,8 @@ public class CraftingTaskNormal extends CraftingTask {
|
|||||||
|
|
||||||
boolean itemsCrafting = false;
|
boolean itemsCrafting = false;
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i] && childrenCreated[i] && checked[i]) {
|
if (!satisfied[i] && childrenCreated[i] && checked[i]) {
|
||||||
if (!itemsCrafting) {
|
if (!itemsCrafting) {
|
||||||
|
|||||||
@@ -22,9 +22,9 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
public CraftingTaskProcessing(ICraftingPattern pattern) {
|
public CraftingTaskProcessing(ICraftingPattern pattern) {
|
||||||
super(pattern);
|
super(pattern);
|
||||||
|
|
||||||
this.satisfied = new boolean[pattern.getInputs().length];
|
this.satisfied = new boolean[pattern.getInputs().size()];
|
||||||
this.satisfiedInsertion = new boolean[pattern.getInputs().length];
|
this.satisfiedInsertion = new boolean[pattern.getInputs().size()];
|
||||||
this.checked = new boolean[pattern.getInputs().length];
|
this.checked = new boolean[pattern.getInputs().size()];
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSatisfied(boolean[] satisfied) {
|
public void setSatisfied(boolean[] satisfied) {
|
||||||
@@ -41,10 +41,10 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean update(World world, INetworkMaster network) {
|
public boolean update(World world, INetworkMaster network) {
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
checked[i] = true;
|
checked[i] = true;
|
||||||
|
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i]) {
|
if (!satisfied[i]) {
|
||||||
ItemStack received = NetworkUtils.extractItem(network, input, input.stackSize);
|
ItemStack received = NetworkUtils.extractItem(network, input, input.stackSize);
|
||||||
@@ -68,7 +68,7 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!took.isEmpty()) {
|
if (!took.isEmpty()) {
|
||||||
ICraftingPatternContainer container = pattern.getContainer(world);
|
ICraftingPatternContainer container = pattern.getContainer();
|
||||||
|
|
||||||
ItemStack toInsert = took.get(0);
|
ItemStack toInsert = took.get(0);
|
||||||
|
|
||||||
@@ -97,8 +97,8 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getOutputs().length; ++i) {
|
for (int i = 0; i < pattern.getOutputs().size(); ++i) {
|
||||||
ItemStack output = pattern.getOutputs()[i];
|
ItemStack output = pattern.getOutputs().get(i);
|
||||||
|
|
||||||
if (!satisfiedInsertion[i]) {
|
if (!satisfiedInsertion[i]) {
|
||||||
if (CompareUtils.compareStackNoQuantity(output, stack)) {
|
if (CompareUtils.compareStackNoQuantity(output, stack)) {
|
||||||
@@ -139,8 +139,8 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
|
|
||||||
boolean missingItems = false;
|
boolean missingItems = false;
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i] && !childrenCreated[i]) {
|
if (!satisfied[i] && !childrenCreated[i]) {
|
||||||
if (!missingItems) {
|
if (!missingItems) {
|
||||||
@@ -155,8 +155,8 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
|
|
||||||
boolean itemsCrafting = false;
|
boolean itemsCrafting = false;
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
ItemStack input = pattern.getInputs()[i];
|
ItemStack input = pattern.getInputs().get(i);
|
||||||
|
|
||||||
if (!satisfied[i] && childrenCreated[i]) {
|
if (!satisfied[i] && childrenCreated[i]) {
|
||||||
if (!itemsCrafting) {
|
if (!itemsCrafting) {
|
||||||
@@ -172,8 +172,8 @@ public class CraftingTaskProcessing extends CraftingTask {
|
|||||||
if (isReadyToInsert()) {
|
if (isReadyToInsert()) {
|
||||||
builder.append("I=gui.refinedstorage:crafting_monitor.items_processing\n");
|
builder.append("I=gui.refinedstorage:crafting_monitor.items_processing\n");
|
||||||
|
|
||||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
for (int i = 0; i < pattern.getInputs().size(); ++i) {
|
||||||
builder.append("T=").append(pattern.getInputs()[i].getUnlocalizedName()).append(".name\n");
|
builder.append("T=").append(pattern.getInputs().get(i).getUnlocalizedName()).append(".name\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -134,7 +134,7 @@ public class ItemGridHandler implements IItemGridHandler {
|
|||||||
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
int quantityPerRequest = pattern.getQuantityPerRequest(stack);
|
||||||
|
|
||||||
while (quantity > 0) {
|
while (quantity > 0) {
|
||||||
network.addCraftingTask(network.createCraftingTask(pattern));
|
network.addCraftingTask(NetworkUtils.createCraftingTask(network, pattern));
|
||||||
|
|
||||||
quantity -= quantityPerRequest;
|
quantity -= quantityPerRequest;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public final class FluidUtils {
|
|||||||
ICraftingPattern pattern = NetworkUtils.getPattern(network, EMPTY_BUCKET);
|
ICraftingPattern pattern = NetworkUtils.getPattern(network, EMPTY_BUCKET);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
network.addCraftingTask(network.createCraftingTask(pattern));
|
network.addCraftingTask(NetworkUtils.createCraftingTask(network, pattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,13 @@
|
|||||||
package refinedstorage.item;
|
package refinedstorage.item;
|
||||||
|
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
|
||||||
import net.minecraft.client.resources.I18n;
|
|
||||||
import net.minecraft.entity.player.EntityPlayer;
|
import net.minecraft.entity.player.EntityPlayer;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
|
||||||
import net.minecraft.util.ActionResult;
|
import net.minecraft.util.ActionResult;
|
||||||
import net.minecraft.util.EnumActionResult;
|
import net.minecraft.util.EnumActionResult;
|
||||||
import net.minecraft.util.EnumHand;
|
import net.minecraft.util.EnumHand;
|
||||||
import net.minecraft.util.math.BlockPos;
|
|
||||||
import net.minecraft.util.text.TextFormatting;
|
import net.minecraft.util.text.TextFormatting;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.util.Constants;
|
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPattern;
|
import refinedstorage.api.autocrafting.ICraftingPattern;
|
||||||
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
|
||||||
@@ -20,16 +15,12 @@ import refinedstorage.api.autocrafting.ICraftingPatternProvider;
|
|||||||
import refinedstorage.api.storage.CompareUtils;
|
import refinedstorage.api.storage.CompareUtils;
|
||||||
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
import refinedstorage.apiimpl.autocrafting.CraftingPattern;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
||||||
public static final String NBT_INPUTS = "Inputs";
|
private static final String NBT_SLOT = "Slot_%d";
|
||||||
public static final String NBT_OUTPUTS = "Outputs";
|
|
||||||
public static final String NBT_BYPRODUCTS = "Byproducts";
|
|
||||||
public static final String NBT_PROCESSING = "Processing";
|
|
||||||
|
|
||||||
public ItemPattern() {
|
public ItemPattern() {
|
||||||
super("pattern");
|
super("pattern");
|
||||||
@@ -37,7 +28,7 @@ public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addInformation(ItemStack pattern, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
public void addInformation(ItemStack pattern, EntityPlayer player, List<String> tooltip, boolean advanced) {
|
||||||
if (isValid(pattern)) {
|
/* @todo CraftingPattern
|
||||||
if (GuiScreen.isShiftKeyDown() || isProcessing(pattern)) {
|
if (GuiScreen.isShiftKeyDown() || isProcessing(pattern)) {
|
||||||
tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.inputs") + TextFormatting.RESET);
|
tooltip.add(TextFormatting.YELLOW + I18n.format("misc.refinedstorage:pattern.inputs") + TextFormatting.RESET);
|
||||||
|
|
||||||
@@ -47,7 +38,25 @@ public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
combineItems(tooltip, true, getOutputs(pattern));
|
combineItems(tooltip, true, getOutputs(pattern));
|
||||||
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setSlot(ItemStack pattern, int slot, ItemStack stack) {
|
||||||
|
if (!pattern.hasTagCompound()) {
|
||||||
|
pattern.setTagCompound(new NBTTagCompound());
|
||||||
|
}
|
||||||
|
|
||||||
|
pattern.getTagCompound().setTag(String.format(NBT_SLOT, slot), stack.serializeNBT());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ItemStack getSlot(ItemStack pattern, int slot) {
|
||||||
|
String id = String.format(NBT_SLOT, slot);
|
||||||
|
|
||||||
|
if (!pattern.hasTagCompound() || !pattern.getTagCompound().hasKey(id)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ItemStack.loadItemStackFromNBT(pattern.getTagCompound().getCompoundTag(id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void combineItems(List<String> tooltip, boolean displayAmount, ItemStack... stacks) {
|
public static void combineItems(List<String> tooltip, boolean displayAmount, ItemStack... stacks) {
|
||||||
@@ -83,157 +92,8 @@ public class ItemPattern extends ItemBase implements ICraftingPatternProvider {
|
|||||||
return new ActionResult<>(EnumActionResult.PASS, stack);
|
return new ActionResult<>(EnumActionResult.PASS, stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addInput(ItemStack pattern, ItemStack stack) {
|
|
||||||
add(pattern, stack, NBT_INPUTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addOutput(ItemStack pattern, ItemStack stack) {
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pattern.getTagCompound().hasKey(type)) {
|
|
||||||
pattern.getTagCompound().setTag(type, new NBTTagList());
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern.getTagCompound().getTagList(type, Constants.NBT.TAG_COMPOUND).appendTag(stack.serializeNBT());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack[] getInputs(ItemStack pattern) {
|
|
||||||
return get(pattern, NBT_INPUTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ItemStack[] getOutputs(ItemStack pattern) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
NBTTagList stacksList = pattern.getTagCompound().getTagList(type, Constants.NBT.TAG_COMPOUND);
|
|
||||||
|
|
||||||
ItemStack[] stacks = new ItemStack[stacksList.tagCount()];
|
|
||||||
|
|
||||||
for (int i = 0; i < stacksList.tagCount(); ++i) {
|
|
||||||
stacks[i] = ItemStack.loadItemStackFromNBT(stacksList.getCompoundTagAt(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
return stacks;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isValid(ItemStack pattern) {
|
|
||||||
if (pattern.getTagCompound() == null || (!pattern.getTagCompound().hasKey(NBT_INPUTS) || !pattern.getTagCompound().hasKey(NBT_OUTPUTS) || !pattern.getTagCompound().hasKey(NBT_PROCESSING))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemStack input : getInputs(pattern)) {
|
|
||||||
if (input == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ItemStack output : getOutputs(pattern)) {
|
|
||||||
if (output == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack[] byproducts = getByproducts(pattern);
|
|
||||||
if (byproducts != null) {
|
|
||||||
for (ItemStack byproduct : byproducts) {
|
|
||||||
if (byproduct == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setProcessing(ItemStack pattern, boolean processing) {
|
|
||||||
if (pattern.getTagCompound() == null) {
|
|
||||||
pattern.setTagCompound(new NBTTagCompound());
|
|
||||||
}
|
|
||||||
|
|
||||||
pattern.getTagCompound().setBoolean(NBT_PROCESSING, processing);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isProcessing(ItemStack pattern) {
|
|
||||||
if (!pattern.hasTagCompound() || !pattern.getTagCompound().hasKey(NBT_PROCESSING)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return pattern.getTagCompound().getBoolean(NBT_PROCESSING);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ICraftingPattern create(ItemStack stack, ICraftingPatternContainer container) {
|
public ICraftingPattern create(World world, ItemStack stack, ICraftingPatternContainer container) {
|
||||||
return new CraftingPattern(stack, container.getPosition(), isProcessing(stack), getInputs(stack), getOutputs(stack), getByproducts(stack));
|
return new CraftingPattern(world, container, stack);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Nullable
|
|
||||||
public ICraftingPattern create(ItemStack stack) {
|
|
||||||
NBTTagCompound tag = stack.getTagCompound();
|
|
||||||
|
|
||||||
BlockPos crafterPos = new BlockPos(tag.getInteger(CraftingPattern.NBT_CRAFTER_X), tag.getInteger(CraftingPattern.NBT_CRAFTER_Y), tag.getInteger(CraftingPattern.NBT_CRAFTER_Z));
|
|
||||||
|
|
||||||
boolean processing = tag.getBoolean(NBT_PROCESSING);
|
|
||||||
|
|
||||||
NBTTagList inputsTag = tag.getTagList(NBT_INPUTS, Constants.NBT.TAG_COMPOUND);
|
|
||||||
|
|
||||||
ItemStack inputs[] = new ItemStack[inputsTag.tagCount()];
|
|
||||||
|
|
||||||
for (int i = 0; i < inputsTag.tagCount(); ++i) {
|
|
||||||
inputs[i] = ItemStack.loadItemStackFromNBT(inputsTag.getCompoundTagAt(i));
|
|
||||||
|
|
||||||
if (inputs[i] == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NBTTagList outputsTag = tag.getTagList(NBT_OUTPUTS, Constants.NBT.TAG_COMPOUND);
|
|
||||||
|
|
||||||
ItemStack outputs[] = new ItemStack[outputsTag.tagCount()];
|
|
||||||
|
|
||||||
for (int i = 0; i < outputsTag.tagCount(); ++i) {
|
|
||||||
outputs[i] = ItemStack.loadItemStackFromNBT(outputsTag.getCompoundTagAt(i));
|
|
||||||
|
|
||||||
if (outputs[i] == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ItemStack byproducts[] = new ItemStack[0];
|
|
||||||
|
|
||||||
if (tag.hasKey(ItemPattern.NBT_BYPRODUCTS)) {
|
|
||||||
NBTTagList byproductsTag = tag.getTagList(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(stack, crafterPos, processing, inputs, outputs, byproducts);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package refinedstorage.tile;
|
|||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
import refinedstorage.api.autocrafting.task.ICraftingTask;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ClientCraftingTask {
|
public class ClientCraftingTask {
|
||||||
private ItemStack output;
|
private ItemStack output;
|
||||||
private int id;
|
private int id;
|
||||||
@@ -11,7 +13,7 @@ public class ClientCraftingTask {
|
|||||||
private int progress;
|
private int progress;
|
||||||
|
|
||||||
// Used server-side while sending
|
// Used server-side while sending
|
||||||
private ItemStack[] outputs;
|
private List<ItemStack> outputs;
|
||||||
private ClientCraftingTask child;
|
private ClientCraftingTask child;
|
||||||
|
|
||||||
public ClientCraftingTask(ItemStack output, int id, String status, int depth, int progress) {
|
public ClientCraftingTask(ItemStack output, int id, String status, int depth, int progress) {
|
||||||
@@ -22,7 +24,7 @@ public class ClientCraftingTask {
|
|||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientCraftingTask(String status, ItemStack[] outputs, int progress, ICraftingTask child) {
|
public ClientCraftingTask(String status, List<ItemStack> outputs, int progress, ICraftingTask child) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.outputs = outputs;
|
this.outputs = outputs;
|
||||||
this.progress = progress;
|
this.progress = progress;
|
||||||
@@ -33,7 +35,7 @@ public class ClientCraftingTask {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ItemStack[] getOutputs() {
|
public List<ItemStack> getOutputs() {
|
||||||
return outputs;
|
return outputs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
import net.minecraft.nbt.NBTTagList;
|
import net.minecraft.nbt.NBTTagList;
|
||||||
import net.minecraft.network.datasync.DataSerializers;
|
import net.minecraft.network.datasync.DataSerializers;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.EnumFacing;
|
import net.minecraft.util.EnumFacing;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.world.World;
|
||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.common.util.Constants;
|
import net.minecraftforge.common.util.Constants;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
@@ -132,6 +134,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
private static final String NBT_CRAFTING_TASKS = "CraftingTasks";
|
private static final String NBT_CRAFTING_TASKS = "CraftingTasks";
|
||||||
private static final String NBT_CRAFTING_TASK_PATTERN = "Pattern";
|
private static final String NBT_CRAFTING_TASK_PATTERN = "Pattern";
|
||||||
private static final String NBT_CRAFTING_TASK_TYPE = "Type";
|
private static final String NBT_CRAFTING_TASK_TYPE = "Type";
|
||||||
|
private static final String NBT_CRAFTING_TASK_CONTAINER = "Container";
|
||||||
|
|
||||||
private static final Comparator<IItemStorage> ITEM_SIZE_COMPARATOR = (left, right) -> {
|
private static final Comparator<IItemStorage> ITEM_SIZE_COMPARATOR = (left, right) -> {
|
||||||
if (left.getStored() == right.getStored()) {
|
if (left.getStored() == right.getStored()) {
|
||||||
@@ -181,6 +184,8 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<>();
|
private List<ICraftingTask> craftingTasksToAdd = new ArrayList<>();
|
||||||
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<>();
|
private List<ICraftingTask> craftingTasksToCancel = new ArrayList<>();
|
||||||
|
|
||||||
|
private List<NBTTagCompound> craftingTasksToRead = new ArrayList<>();
|
||||||
|
|
||||||
private EnergyStorage energy = new EnergyStorage(RefinedStorage.INSTANCE.controllerCapacity);
|
private EnergyStorage energy = new EnergyStorage(RefinedStorage.INSTANCE.controllerCapacity);
|
||||||
private IControllerEnergyIC2 energyEU;
|
private IControllerEnergyIC2 energyEU;
|
||||||
private ControllerEnergyTesla energyTesla;
|
private ControllerEnergyTesla energyTesla;
|
||||||
@@ -237,6 +242,18 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
if (!worldObj.isRemote) {
|
if (!worldObj.isRemote) {
|
||||||
energyEU.update();
|
energyEU.update();
|
||||||
|
|
||||||
|
if (!craftingTasksToRead.isEmpty()) {
|
||||||
|
for (NBTTagCompound tag : craftingTasksToRead) {
|
||||||
|
ICraftingTask task = readCraftingTask(worldObj, tag);
|
||||||
|
|
||||||
|
if (task != null) {
|
||||||
|
addCraftingTask(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
craftingTasksToRead.clear();
|
||||||
|
}
|
||||||
|
|
||||||
if (canRun()) {
|
if (canRun()) {
|
||||||
Collections.sort(itemStorage.getStorages(), ITEM_SIZE_COMPARATOR);
|
Collections.sort(itemStorage.getStorages(), ITEM_SIZE_COMPARATOR);
|
||||||
Collections.sort(itemStorage.getStorages(), ITEM_PRIORITY_COMPARATOR);
|
Collections.sort(itemStorage.getStorages(), ITEM_PRIORITY_COMPARATOR);
|
||||||
@@ -325,7 +342,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean updateCraftingTask(ICraftingTask task) {
|
private boolean updateCraftingTask(ICraftingTask task) {
|
||||||
ICraftingPatternContainer container = task.getPattern().getContainer(worldObj);
|
ICraftingPatternContainer container = task.getPattern().getContainer();
|
||||||
|
|
||||||
return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
|
return container != null && ticks % container.getSpeed() == 0 && task.update(worldObj, this);
|
||||||
}
|
}
|
||||||
@@ -395,11 +412,6 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
markDirty();
|
markDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ICraftingTask createCraftingTask(ICraftingPattern pattern) {
|
|
||||||
return RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(pattern.getId()).create(null, pattern);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void cancelCraftingTask(ICraftingTask task) {
|
public void cancelCraftingTask(ICraftingTask task) {
|
||||||
craftingTasksToCancel.add(task);
|
craftingTasksToCancel.add(task);
|
||||||
@@ -470,7 +482,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
ItemStack stack = container.getPatterns().getStackInSlot(i);
|
ItemStack stack = container.getPatterns().getStackInSlot(i);
|
||||||
|
|
||||||
if (stack != null) {
|
if (stack != null) {
|
||||||
patterns.add(((ICraftingPatternProvider) stack.getItem()).create(stack, container));
|
ICraftingPattern pattern = ((ICraftingPatternProvider) stack.getItem()).create(worldObj, stack, container);
|
||||||
|
|
||||||
|
if (pattern.isValid()) {
|
||||||
|
patterns.add(pattern);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -687,6 +703,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
return newStack;
|
return newStack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public World getNetworkWorld() {
|
||||||
|
return worldObj;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readFromNBT(NBTTagCompound tag) {
|
public void readFromNBT(NBTTagCompound tag) {
|
||||||
super.readFromNBT(tag);
|
super.readFromNBT(tag);
|
||||||
@@ -701,26 +722,25 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND);
|
NBTTagList taskList = tag.getTagList(NBT_CRAFTING_TASKS, Constants.NBT.TAG_COMPOUND);
|
||||||
|
|
||||||
for (int i = 0; i < taskList.tagCount(); ++i) {
|
for (int i = 0; i < taskList.tagCount(); ++i) {
|
||||||
ICraftingTask task = readCraftingTask(taskList.getCompoundTagAt(i));
|
craftingTasksToRead.add(taskList.getCompoundTagAt(i));
|
||||||
|
|
||||||
if (task != null) {
|
|
||||||
addCraftingTask(task);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ICraftingTask readCraftingTask(NBTTagCompound tag) {
|
public static ICraftingTask readCraftingTask(World world, NBTTagCompound tag) {
|
||||||
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_CRAFTING_TASK_PATTERN));
|
ItemStack stack = ItemStack.loadItemStackFromNBT(tag.getCompoundTag(NBT_CRAFTING_TASK_PATTERN));
|
||||||
|
|
||||||
if (stack != null && stack.getItem() instanceof ICraftingPatternProvider) {
|
if (stack != null && stack.getItem() instanceof ICraftingPatternProvider) {
|
||||||
ICraftingPattern pattern = ((ICraftingPatternProvider) stack.getItem()).create(stack);
|
TileEntity container = world.getTileEntity(BlockPos.fromLong(tag.getLong(NBT_CRAFTING_TASK_CONTAINER)));
|
||||||
|
|
||||||
|
if (container instanceof ICraftingPatternContainer) {
|
||||||
|
ICraftingPattern pattern = ((ICraftingPatternProvider) stack.getItem()).create(world, stack, (ICraftingPatternContainer) container);
|
||||||
|
|
||||||
if (pattern != null) {
|
if (pattern != null) {
|
||||||
ICraftingTaskFactory factory = RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(tag.getString(NBT_CRAFTING_TASK_TYPE));
|
ICraftingTaskFactory factory = RefinedStorageAPI.CRAFTING_TASK_REGISTRY.getFactory(tag.getString(NBT_CRAFTING_TASK_TYPE));
|
||||||
|
|
||||||
if (factory != null) {
|
if (factory != null) {
|
||||||
ICraftingTask task = factory.create(tag, pattern);
|
ICraftingTask task = factory.create(tag, world, pattern);
|
||||||
|
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
return task;
|
return task;
|
||||||
@@ -728,6 +748,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -749,6 +770,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
|
|||||||
|
|
||||||
taskTag.setString(NBT_CRAFTING_TASK_TYPE, task.getPattern().getId());
|
taskTag.setString(NBT_CRAFTING_TASK_TYPE, task.getPattern().getId());
|
||||||
taskTag.setTag(NBT_CRAFTING_TASK_PATTERN, task.getPattern().getStack().serializeNBT());
|
taskTag.setTag(NBT_CRAFTING_TASK_PATTERN, task.getPattern().getStack().serializeNBT());
|
||||||
|
taskTag.setLong(NBT_CRAFTING_TASK_CONTAINER, task.getPattern().getContainer().getPosition().toLong());
|
||||||
|
|
||||||
list.appendTag(taskTag);
|
list.appendTag(taskTag);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
|
|||||||
public void onConnectionChange(INetworkMaster network, boolean state) {
|
public void onConnectionChange(INetworkMaster network, boolean state) {
|
||||||
if (!state) {
|
if (!state) {
|
||||||
network.getCraftingTasks().stream()
|
network.getCraftingTasks().stream()
|
||||||
.filter(task -> task.getPattern().getContainer(worldObj).getPosition().equals(pos))
|
.filter(task -> task.getPattern().getContainer().getPosition().equals(pos))
|
||||||
.forEach(network::cancelCraftingTask);
|
.forEach(network::cancelCraftingTask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,9 @@ import net.minecraft.util.EnumFacing;
|
|||||||
import net.minecraftforge.common.capabilities.Capability;
|
import net.minecraftforge.common.capabilities.Capability;
|
||||||
import net.minecraftforge.items.CapabilityItemHandler;
|
import net.minecraftforge.items.CapabilityItemHandler;
|
||||||
import net.minecraftforge.items.IItemHandler;
|
import net.minecraftforge.items.IItemHandler;
|
||||||
import net.minecraftforge.items.ItemHandlerHelper;
|
|
||||||
import refinedstorage.RefinedStorageItems;
|
import refinedstorage.RefinedStorageItems;
|
||||||
import refinedstorage.inventory.ItemHandlerBasic;
|
import refinedstorage.inventory.ItemHandlerBasic;
|
||||||
import refinedstorage.inventory.ItemValidatorBasic;
|
import refinedstorage.inventory.ItemValidatorBasic;
|
||||||
import refinedstorage.item.ItemPattern;
|
|
||||||
|
|
||||||
public class TileProcessingPatternEncoder extends TileBase {
|
public class TileProcessingPatternEncoder extends TileBase {
|
||||||
private ItemHandlerBasic patterns = new ItemHandlerBasic(2, this, new ItemValidatorBasic(RefinedStorageItems.PATTERN));
|
private ItemHandlerBasic patterns = new ItemHandlerBasic(2, this, new ItemValidatorBasic(RefinedStorageItems.PATTERN));
|
||||||
@@ -38,7 +36,8 @@ public class TileProcessingPatternEncoder extends TileBase {
|
|||||||
if (canCreatePattern()) {
|
if (canCreatePattern()) {
|
||||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
||||||
|
|
||||||
ItemPattern.setProcessing(pattern, true);
|
// @todo
|
||||||
|
/*ItemPattern.setProcessing(pattern, true);
|
||||||
|
|
||||||
for (int i = 0; i < 18; ++i) {
|
for (int i = 0; i < 18; ++i) {
|
||||||
if (configuration.getStackInSlot(i) != null) {
|
if (configuration.getStackInSlot(i) != null) {
|
||||||
@@ -50,7 +49,7 @@ public class TileProcessingPatternEncoder extends TileBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
patterns.extractItem(0, 1, false);
|
patterns.extractItem(0, 1, false);
|
||||||
patterns.setStackInSlot(1, pattern);
|
patterns.setStackInSlot(1, pattern);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ public final class RefinedStorageSerializers {
|
|||||||
|
|
||||||
buf.writeInt(task.getProgress());
|
buf.writeInt(task.getProgress());
|
||||||
|
|
||||||
buf.writeInt(task.getOutputs().length);
|
buf.writeInt(task.getOutputs().size());
|
||||||
|
|
||||||
for (ItemStack output : task.getOutputs()) {
|
for (ItemStack output : task.getOutputs()) {
|
||||||
ByteBufUtils.writeItemStack(buf, output);
|
ByteBufUtils.writeItemStack(buf, output);
|
||||||
|
|||||||
@@ -308,21 +308,11 @@ public class TileGrid extends TileNode implements IGrid {
|
|||||||
|
|
||||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
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);
|
|
||||||
|
|
||||||
for (int i = 0; i < 9; ++i) {
|
for (int i = 0; i < 9; ++i) {
|
||||||
ItemStack ingredient = matrix.getStackInSlot(i);
|
ItemStack ingredient = matrix.getStackInSlot(i);
|
||||||
|
|
||||||
if (ingredient != null) {
|
if (ingredient != null) {
|
||||||
ItemPattern.addInput(pattern, ingredient);
|
ItemPattern.setSlot(pattern, i, ingredient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user