Extremely buggy processing automation
This commit is contained in:
@@ -10,7 +10,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import refinedstorage.RefinedStorage;
|
||||
import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.tile.TileCrafter;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
|
||||
public class BlockCrafter extends BlockMachine {
|
||||
public BlockCrafter() {
|
||||
|
||||
@@ -8,7 +8,7 @@ import refinedstorage.container.slot.IItemValidator;
|
||||
import refinedstorage.container.slot.SlotFiltered;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.item.ItemUpgrade;
|
||||
import refinedstorage.tile.TileCrafter;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
|
||||
public class ContainerCrafter extends ContainerStorage {
|
||||
public ContainerCrafter(EntityPlayer player, TileCrafter crafter) {
|
||||
@@ -18,7 +18,7 @@ public class ContainerCrafter extends ContainerStorage {
|
||||
addSlotToContainer(new SlotFiltered(crafter, i, 8, 19 + (i * 18), new IItemValidator() {
|
||||
@Override
|
||||
public boolean isValid(ItemStack stack) {
|
||||
return stack.getItem() == RefinedStorageItems.PATTERN && ItemPattern.hasResult(stack);
|
||||
return stack.getItem() == RefinedStorageItems.PATTERN && ItemPattern.isValid(stack);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.container.ContainerCrafter;
|
||||
import refinedstorage.gui.sidebutton.SideButtonRedstoneMode;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.tile.TileCrafter;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
|
||||
public class GuiCrafter extends GuiBase {
|
||||
private TileCrafter crafter;
|
||||
@@ -50,15 +50,23 @@ public class GuiCrafter extends GuiBase {
|
||||
int y = 19 + (i * 18);
|
||||
|
||||
if (crafter.getStackInSlot(i) != null) {
|
||||
ItemStack result = ItemPattern.getResult(crafter.getStackInSlot(i));
|
||||
ItemStack pattern = crafter.getStackInSlot(i);
|
||||
|
||||
drawItem(x, y, result);
|
||||
String text = "Processing";
|
||||
|
||||
if (!ItemPattern.isProcessing(pattern)) {
|
||||
ItemStack result = ItemPattern.getOutputs(pattern)[0];
|
||||
|
||||
drawItem(x, y, result);
|
||||
|
||||
text = result.getDisplayName();
|
||||
}
|
||||
|
||||
GlStateManager.pushMatrix();
|
||||
|
||||
float scale = 0.5f;
|
||||
GlStateManager.scale(scale, scale, 1);
|
||||
drawString(calculateOffsetOnScale(x + 20, scale), calculateOffsetOnScale(y + 6, scale), result.getDisplayName());
|
||||
drawString(calculateOffsetOnScale(x + (ItemPattern.isProcessing(pattern) ? 0 : 20), scale), calculateOffsetOnScale(y + 6, scale), text);
|
||||
|
||||
GlStateManager.popMatrix();
|
||||
}
|
||||
|
||||
@@ -155,16 +155,12 @@ public class GuiGrid extends GuiBase {
|
||||
|
||||
public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) {
|
||||
if (grid.getType() == EnumGridType.PATTERN) {
|
||||
return inBounds(152, 124, 16, 16, mouseX, mouseY) && isCreatePatternEnabled();
|
||||
return inBounds(152, 124, 16, 16, mouseX, mouseY) && ((TileGrid) grid).canCreatePattern();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isCreatePatternEnabled() {
|
||||
return ((TileGrid) grid).getCraftingResultInventory().getStackInSlot(0) != null && ((TileGrid) grid).getPatternsInventory().getStackInSlot(0) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBackground(int x, int y, int mouseX, int mouseY) {
|
||||
if (grid.getType() == EnumGridType.CRAFTING) {
|
||||
@@ -184,7 +180,7 @@ public class GuiGrid extends GuiBase {
|
||||
ty = 1;
|
||||
}
|
||||
|
||||
if (!isCreatePatternEnabled()) {
|
||||
if (!((TileGrid) grid).canCreatePattern()) {
|
||||
ty = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import refinedstorage.RefinedStorageGui;
|
||||
import refinedstorage.container.*;
|
||||
import refinedstorage.storage.IStorageGui;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
import refinedstorage.tile.autocrafting.TileCraftingMonitor;
|
||||
import refinedstorage.tile.autocrafting.TileProcessingPatternEncoder;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
@@ -33,25 +33,7 @@ public class GuiProcessingPatternEncoder extends GuiBase {
|
||||
}
|
||||
|
||||
public boolean isHoveringOverCreatePattern(int mouseX, int mouseY) {
|
||||
return inBounds(152, 38, 16, 16, mouseX, mouseY) && isCreatePatternEnabled();
|
||||
}
|
||||
|
||||
public boolean isCreatePatternEnabled() {
|
||||
int inputsFilled = 0, outputsFilled = 0;
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (ppEncoder.getInputsOutputsInventory().getStackInSlot(i) != null) {
|
||||
inputsFilled++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 9; i < 18; ++i) {
|
||||
if (ppEncoder.getInputsOutputsInventory().getStackInSlot(i) != null) {
|
||||
outputsFilled++;
|
||||
}
|
||||
}
|
||||
|
||||
return inputsFilled > 0 && outputsFilled > 0 && ppEncoder.getStackInSlot(0) != null;
|
||||
return inBounds(152, 38, 16, 16, mouseX, mouseY) && ppEncoder.canCreatePattern();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +48,7 @@ public class GuiProcessingPatternEncoder extends GuiBase {
|
||||
ty = 1;
|
||||
}
|
||||
|
||||
if (!isCreatePatternEnabled()) {
|
||||
if (!ppEncoder.canCreatePattern()) {
|
||||
ty = 2;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ import net.minecraftforge.common.util.Constants;
|
||||
import java.util.List;
|
||||
|
||||
public class ItemPattern extends ItemBase {
|
||||
public static final String NBT_RESULT = "Result";
|
||||
public static final String NBT_INGREDIENTS = "Ingredients";
|
||||
public static final String NBT_INPUTS = "Inputs";
|
||||
public static final String NBT_OUTPUTS = "Outputs";
|
||||
public static final String NBT_PROCESSING = "Processing";
|
||||
|
||||
public ItemPattern() {
|
||||
@@ -21,8 +21,10 @@ public class ItemPattern extends ItemBase {
|
||||
|
||||
@Override
|
||||
public void addInformation(ItemStack pattern, EntityPlayer player, List list, boolean b) {
|
||||
if (hasResult(pattern)) {
|
||||
list.add(getResult(pattern).getDisplayName());
|
||||
if (isValid(pattern)) {
|
||||
for (ItemStack output : getOutputs(pattern)) {
|
||||
list.add(output.getDisplayName());
|
||||
}
|
||||
|
||||
if (isProcessing(pattern)) {
|
||||
list.add(TextFormatting.ITALIC + I18n.translateToLocal("misc.refinedstorage:processing") + TextFormatting.RESET);
|
||||
@@ -30,47 +32,55 @@ public class ItemPattern extends ItemBase {
|
||||
}
|
||||
}
|
||||
|
||||
public static void addIngredient(ItemStack pattern, ItemStack 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);
|
||||
}
|
||||
|
||||
private static void add(ItemStack pattern, ItemStack stack, String type) {
|
||||
if (pattern.getTagCompound() == null) {
|
||||
pattern.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
if (!pattern.getTagCompound().hasKey(NBT_INGREDIENTS)) {
|
||||
pattern.getTagCompound().setTag(NBT_INGREDIENTS, new NBTTagList());
|
||||
if (!pattern.getTagCompound().hasKey(type)) {
|
||||
pattern.getTagCompound().setTag(type, new NBTTagList());
|
||||
}
|
||||
|
||||
pattern.getTagCompound().getTagList(NBT_INGREDIENTS, Constants.NBT.TAG_COMPOUND).appendTag(stack.serializeNBT());
|
||||
pattern.getTagCompound().getTagList(type, Constants.NBT.TAG_COMPOUND).appendTag(stack.serializeNBT());
|
||||
}
|
||||
|
||||
public static ItemStack[] getIngredients(ItemStack pattern) {
|
||||
if (pattern.getTagCompound() == null) {
|
||||
public static ItemStack[] getInputs(ItemStack pattern) {
|
||||
return get(pattern, NBT_INPUTS);
|
||||
}
|
||||
|
||||
public static ItemStack[] getOutputs(ItemStack pattern) {
|
||||
return get(pattern, NBT_OUTPUTS);
|
||||
}
|
||||
|
||||
private static ItemStack[] get(ItemStack pattern, String type) {
|
||||
if (!isValid(pattern)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!pattern.getTagCompound().hasKey(NBT_INGREDIENTS)) {
|
||||
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));
|
||||
}
|
||||
|
||||
NBTTagList ingredients = pattern.getTagCompound().getTagList(NBT_INGREDIENTS, Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
ItemStack[] ingredientsArray = new ItemStack[ingredients.tagCount()];
|
||||
|
||||
for (int i = 0; i < ingredients.tagCount(); ++i) {
|
||||
ingredientsArray[i] = ItemStack.loadItemStackFromNBT(ingredients.getCompoundTagAt(i));
|
||||
}
|
||||
|
||||
return ingredientsArray;
|
||||
return stacks;
|
||||
}
|
||||
|
||||
public static void setResult(ItemStack pattern, ItemStack stack) {
|
||||
if (pattern.getTagCompound() == null) {
|
||||
pattern.setTagCompound(new NBTTagCompound());
|
||||
}
|
||||
|
||||
NBTTagCompound stackTag = new NBTTagCompound();
|
||||
stack.writeToNBT(stackTag);
|
||||
|
||||
pattern.getTagCompound().setTag(NBT_RESULT, stackTag);
|
||||
public static boolean isValid(ItemStack pattern) {
|
||||
return pattern.getTagCompound() != null &&
|
||||
pattern.getTagCompound().hasKey(NBT_INPUTS) &&
|
||||
pattern.getTagCompound().hasKey(NBT_OUTPUTS) &&
|
||||
pattern.getTagCompound().hasKey(NBT_PROCESSING);
|
||||
}
|
||||
|
||||
public static void setProcessing(ItemStack pattern, boolean processing) {
|
||||
@@ -88,20 +98,4 @@ public class ItemPattern extends ItemBase {
|
||||
|
||||
return pattern.getTagCompound().getBoolean(NBT_PROCESSING);
|
||||
}
|
||||
|
||||
public static boolean hasResult(ItemStack pattern) {
|
||||
if (pattern.getTagCompound() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pattern.getTagCompound().hasKey(NBT_RESULT);
|
||||
}
|
||||
|
||||
public static ItemStack getResult(ItemStack pattern) {
|
||||
if (!hasResult(pattern)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return ItemStack.loadItemStackFromNBT(pattern.getTagCompound().getCompoundTag(NBT_RESULT));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import refinedstorage.item.*;
|
||||
import refinedstorage.network.*;
|
||||
import refinedstorage.storage.NBTStorage;
|
||||
import refinedstorage.tile.*;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
import refinedstorage.tile.autocrafting.TileCraftingMonitor;
|
||||
import refinedstorage.tile.autocrafting.TileProcessingPatternEncoder;
|
||||
import refinedstorage.tile.grid.TileGrid;
|
||||
|
||||
@@ -28,9 +28,10 @@ import refinedstorage.network.MessageWirelessGridItems;
|
||||
import refinedstorage.storage.IStorage;
|
||||
import refinedstorage.storage.IStorageProvider;
|
||||
import refinedstorage.storage.ItemGroup;
|
||||
import refinedstorage.tile.autocrafting.CraftingPattern;
|
||||
import refinedstorage.tile.autocrafting.BasicCraftingTask;
|
||||
import refinedstorage.tile.autocrafting.ICraftingTask;
|
||||
import refinedstorage.tile.autocrafting.*;
|
||||
import refinedstorage.tile.autocrafting.task.BasicCraftingTask;
|
||||
import refinedstorage.tile.autocrafting.task.ICraftingTask;
|
||||
import refinedstorage.tile.autocrafting.task.ProcessingCraftingTask;
|
||||
import refinedstorage.tile.config.IRedstoneModeConfig;
|
||||
import refinedstorage.tile.config.RedstoneMode;
|
||||
import refinedstorage.tile.grid.WirelessGridConsumer;
|
||||
@@ -130,7 +131,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
if (crafter.getStackInSlot(i) != null) {
|
||||
ItemStack pattern = crafter.getStackInSlot(i);
|
||||
|
||||
newPatterns.add(new CraftingPattern(ItemPattern.getResult(pattern), ItemPattern.getIngredients(pattern), 20 - (crafter.getUpgrades() * 4)));
|
||||
newPatterns.add(new CraftingPattern(crafter, ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,8 +175,8 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
if (craftingTasks.size() > 0) {
|
||||
ICraftingTask task = craftingTasks.peek();
|
||||
|
||||
if (ticks % task.getPattern().getSpeed() == 0 && task.update(this)) {
|
||||
push(task.getPattern().getResult());
|
||||
if (ticks % task.getPattern().getCrafter().getSpeed() == 0 && task.update(this)) {
|
||||
task.onDone(this);
|
||||
|
||||
craftingTasks.pop();
|
||||
}
|
||||
@@ -259,8 +260,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
public CraftingPattern getPatternForItem(ItemStack stack) {
|
||||
for (CraftingPattern pattern : getPatterns()) {
|
||||
if (InventoryUtils.compareStackNoQuantity(pattern.getResult(), stack)) {
|
||||
return pattern;
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (InventoryUtils.compareStackNoQuantity(output, stack)) {
|
||||
return pattern;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,9 +278,11 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
}
|
||||
|
||||
for (CraftingPattern pattern : patterns) {
|
||||
ItemGroup patternGroup = new ItemGroup(pattern.getResult());
|
||||
patternGroup.setQuantity(0);
|
||||
itemGroups.add(patternGroup);
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
ItemGroup patternGroup = new ItemGroup(output);
|
||||
patternGroup.setQuantity(0);
|
||||
itemGroups.add(patternGroup);
|
||||
}
|
||||
}
|
||||
|
||||
combineItems();
|
||||
@@ -341,6 +346,12 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
syncItems();
|
||||
|
||||
for (ICraftingTask task : craftingTasks) {
|
||||
if (task instanceof ProcessingCraftingTask) {
|
||||
((ProcessingCraftingTask) task).onInserted(stack);
|
||||
}
|
||||
}
|
||||
|
||||
markDirty();
|
||||
|
||||
return true;
|
||||
@@ -673,13 +684,26 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
|
||||
|
||||
public void onCraftingRequested(int id, int quantity) {
|
||||
if (id >= 0 && id < itemGroups.size() && quantity > 0) {
|
||||
ItemStack requested = itemGroups.get(id).toItemStack();
|
||||
int quantityPerRequest = 0;
|
||||
CraftingPattern pattern = getPatternForItem(requested);
|
||||
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
if (InventoryUtils.compareStackNoQuantity(requested, output)) {
|
||||
quantityPerRequest = output.stackSize;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (quantity > 0) {
|
||||
CraftingPattern pattern = getPatternForItem(itemGroups.get(id).toItemStack());
|
||||
|
||||
if (pattern != null) {
|
||||
addCraftingTask(new BasicCraftingTask(pattern));
|
||||
if (pattern.isProcessing()) {
|
||||
addCraftingTask(new ProcessingCraftingTask(pattern));
|
||||
} else {
|
||||
addCraftingTask(new BasicCraftingTask(pattern));
|
||||
}
|
||||
|
||||
quantity -= pattern.getResult().stackSize;
|
||||
quantity -= quantityPerRequest;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -3,25 +3,31 @@ package refinedstorage.tile.autocrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class CraftingPattern {
|
||||
private ItemStack result;
|
||||
private ItemStack[] ingredients;
|
||||
private int speed;
|
||||
private TileCrafter crafter;
|
||||
private boolean processing;
|
||||
private ItemStack[] inputs;
|
||||
private ItemStack[] outputs;
|
||||
|
||||
public CraftingPattern(ItemStack result, ItemStack[] ingredients, int speed) {
|
||||
this.result = result;
|
||||
this.ingredients = ingredients;
|
||||
this.speed = speed;
|
||||
public CraftingPattern(TileCrafter crafter, boolean processing, ItemStack[] inputs, ItemStack[] outputs) {
|
||||
this.crafter = crafter;
|
||||
this.processing = processing;
|
||||
this.inputs = inputs;
|
||||
this.outputs = outputs;
|
||||
}
|
||||
|
||||
public ItemStack getResult() {
|
||||
return result;
|
||||
public TileCrafter getCrafter() {
|
||||
return crafter;
|
||||
}
|
||||
|
||||
public ItemStack[] getIngredients() {
|
||||
return ingredients;
|
||||
public boolean isProcessing() {
|
||||
return processing;
|
||||
}
|
||||
|
||||
public int getSpeed() {
|
||||
return speed;
|
||||
public ItemStack[] getInputs() {
|
||||
return inputs;
|
||||
}
|
||||
|
||||
public ItemStack[] getOutputs() {
|
||||
return outputs;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
package refinedstorage.tile.autocrafting;
|
||||
|
||||
import refinedstorage.tile.TileController;
|
||||
|
||||
public class ProcessingCraftingTask implements ICraftingTask {
|
||||
private CraftingPattern pattern;
|
||||
|
||||
public ProcessingCraftingTask(CraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(TileController controller) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package refinedstorage.tile;
|
||||
package refinedstorage.tile.autocrafting;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import refinedstorage.container.ContainerCrafter;
|
||||
import refinedstorage.inventory.InventorySimple;
|
||||
import refinedstorage.tile.TileMachine;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
public class TileCrafter extends TileMachine implements IInventory {
|
||||
@@ -43,7 +44,11 @@ public class TileCrafter extends TileMachine implements IInventory {
|
||||
InventoryUtils.saveInventory(inventory, 0, nbt);
|
||||
}
|
||||
|
||||
public int getUpgrades() {
|
||||
public int getSpeed() {
|
||||
return 20 - (getUpgrades() * 4);
|
||||
}
|
||||
|
||||
private int getUpgrades() {
|
||||
int upgrades = 0;
|
||||
|
||||
for (int i = PATTERN_SLOTS; i < PATTERN_SLOTS + 4; ++i) {
|
||||
@@ -6,6 +6,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fml.common.network.ByteBufUtils;
|
||||
import refinedstorage.container.ContainerCraftingMonitor;
|
||||
import refinedstorage.tile.TileMachine;
|
||||
import refinedstorage.tile.autocrafting.task.ICraftingTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -30,7 +31,11 @@ public class TileCraftingMonitor extends TileMachine {
|
||||
buf.writeInt(controller.getCraftingTasks().size());
|
||||
|
||||
for (ICraftingTask task : controller.getCraftingTasks()) {
|
||||
ByteBufUtils.writeItemStack(buf, task.getPattern().getResult());
|
||||
buf.writeInt(task.getPattern().getOutputs().length);
|
||||
|
||||
for (ItemStack output : task.getPattern().getOutputs()) {
|
||||
ByteBufUtils.writeItemStack(buf, output);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
buf.writeInt(0);
|
||||
@@ -46,7 +51,11 @@ public class TileCraftingMonitor extends TileMachine {
|
||||
int size = buf.readInt();
|
||||
|
||||
for (int i = 0; i < size; ++i) {
|
||||
newTasks.add(ByteBufUtils.readItemStack(buf));
|
||||
int outputSize = buf.readInt();
|
||||
|
||||
for (int j = 0; j < outputSize; ++j) {
|
||||
newTasks.add(ByteBufUtils.readItemStack(buf));
|
||||
}
|
||||
}
|
||||
|
||||
tasks = newTasks;
|
||||
|
||||
@@ -7,7 +7,9 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import refinedstorage.RefinedStorageItems;
|
||||
import refinedstorage.inventory.InventorySimple;
|
||||
import refinedstorage.item.ItemPattern;
|
||||
import refinedstorage.tile.TileBase;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
@@ -148,6 +150,40 @@ public class TileProcessingPatternEncoder extends TileBase implements ISidedInve
|
||||
}
|
||||
|
||||
public void onCreatePattern() {
|
||||
System.out.println("Create pattern!!");
|
||||
if (canCreatePattern()) {
|
||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
||||
|
||||
ItemPattern.setProcessing(pattern, true);
|
||||
|
||||
for (int i = 0; i < 18; ++i) {
|
||||
if (inputsOutputsInventory.getStackInSlot(i) != null) {
|
||||
if (i >= 9) {
|
||||
ItemPattern.addOutput(pattern, inputsOutputsInventory.getStackInSlot(i));
|
||||
} else {
|
||||
ItemPattern.addInput(pattern, inputsOutputsInventory.getStackInSlot(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setInventorySlotContents(1, pattern);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCreatePattern() {
|
||||
int inputsFilled = 0, outputsFilled = 0;
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
if (inputsOutputsInventory.getStackInSlot(i) != null) {
|
||||
inputsFilled++;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 9; i < 18; ++i) {
|
||||
if (inputsOutputsInventory.getStackInSlot(i) != null) {
|
||||
outputsFilled++;
|
||||
}
|
||||
}
|
||||
|
||||
return inputsFilled > 0 && outputsFilled > 0 && getStackInSlot(0) != null && getStackInSlot(1) == null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package refinedstorage.tile.autocrafting;
|
||||
package refinedstorage.tile.autocrafting.task;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.autocrafting.CraftingPattern;
|
||||
|
||||
public class BasicCraftingTask implements ICraftingTask {
|
||||
private CraftingPattern pattern;
|
||||
@@ -10,8 +11,8 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
|
||||
public BasicCraftingTask(CraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.satisfied = new boolean[pattern.getIngredients().length];
|
||||
this.childTasks = new boolean[pattern.getIngredients().length];
|
||||
this.satisfied = new boolean[pattern.getInputs().length];
|
||||
this.childTasks = new boolean[pattern.getInputs().length];
|
||||
}
|
||||
|
||||
public CraftingPattern getPattern() {
|
||||
@@ -21,18 +22,18 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
public boolean update(TileController controller) {
|
||||
boolean done = true;
|
||||
|
||||
for (int i = 0; i < pattern.getIngredients().length; ++i) {
|
||||
ItemStack ingredient = pattern.getIngredients()[i];
|
||||
for (int i = 0; i < pattern.getInputs().length; ++i) {
|
||||
ItemStack input = pattern.getInputs()[i];
|
||||
|
||||
if (!satisfied[i]) {
|
||||
done = false;
|
||||
|
||||
ItemStack took = controller.take(ingredient.copy());
|
||||
ItemStack took = controller.take(input.copy());
|
||||
|
||||
if (took != null) {
|
||||
satisfied[i] = true;
|
||||
} else if (!childTasks[i]) {
|
||||
CraftingPattern pattern = controller.getPatternForItem(ingredient);
|
||||
CraftingPattern pattern = controller.getPatternForItem(input);
|
||||
|
||||
if (pattern != null) {
|
||||
controller.addCraftingTask(new BasicCraftingTask(pattern));
|
||||
@@ -49,4 +50,11 @@ public class BasicCraftingTask implements ICraftingTask {
|
||||
|
||||
return done;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone(TileController controller) {
|
||||
for (ItemStack output : pattern.getOutputs()) {
|
||||
controller.push(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,12 @@
|
||||
package refinedstorage.tile.autocrafting;
|
||||
package refinedstorage.tile.autocrafting.task;
|
||||
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.autocrafting.CraftingPattern;
|
||||
|
||||
public interface ICraftingTask {
|
||||
CraftingPattern getPattern();
|
||||
|
||||
boolean update(TileController controller);
|
||||
|
||||
void onDone(TileController controller);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package refinedstorage.tile.autocrafting.task;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntityHopper;
|
||||
import refinedstorage.tile.TileController;
|
||||
import refinedstorage.tile.autocrafting.CraftingPattern;
|
||||
import refinedstorage.tile.autocrafting.TileCrafter;
|
||||
import refinedstorage.util.InventoryUtils;
|
||||
|
||||
public class ProcessingCraftingTask implements ICraftingTask {
|
||||
private CraftingPattern pattern;
|
||||
private boolean inserted;
|
||||
private boolean satisfied[];
|
||||
|
||||
public ProcessingCraftingTask(CraftingPattern pattern) {
|
||||
this.pattern = pattern;
|
||||
this.satisfied = new boolean[pattern.getOutputs().length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingPattern getPattern() {
|
||||
return pattern;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(TileController controller) {
|
||||
if (!inserted) {
|
||||
for (ItemStack input : pattern.getInputs()) {
|
||||
ItemStack take = controller.take(input);
|
||||
|
||||
if (take != null) {
|
||||
TileCrafter crafter = pattern.getCrafter();
|
||||
|
||||
TileEntityHopper.putStackInInventoryAllSlots((IInventory) crafter.getWorld().getTileEntity(crafter.getPos().offset(crafter.getDirection())), take, crafter.getDirection().getOpposite());
|
||||
}
|
||||
}
|
||||
|
||||
inserted = true;
|
||||
}
|
||||
|
||||
for (int i = 0; i < satisfied.length; ++i) {
|
||||
if (!satisfied[i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onInserted(ItemStack in) {
|
||||
for (int i = 0; i < pattern.getOutputs().length; ++i) {
|
||||
if (!satisfied[i] && InventoryUtils.compareStack(in, pattern.getOutputs()[i])) {
|
||||
satisfied[i] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDone(TileController controller) {
|
||||
// NO OP
|
||||
}
|
||||
}
|
||||
@@ -166,21 +166,20 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
}
|
||||
|
||||
public void onCreatePattern() {
|
||||
ItemStack crafted = craftingResultInventory.getStackInSlot(0);
|
||||
|
||||
if (patternsInventory.getStackInSlot(1) == null && patternsInventory.getStackInSlot(0) != null && patternsInventory.getStackInSlot(0).stackSize > 0) {
|
||||
if (canCreatePattern()) {
|
||||
patternsInventory.decrStackSize(0, 1);
|
||||
|
||||
ItemStack pattern = new ItemStack(RefinedStorageItems.PATTERN);
|
||||
|
||||
ItemPattern.setResult(pattern, crafted);
|
||||
ItemPattern.addOutput(pattern, craftingResultInventory.getStackInSlot(0));
|
||||
|
||||
ItemPattern.setProcessing(pattern, false);
|
||||
|
||||
for (int i = 0; i < 9; ++i) {
|
||||
ItemStack ingredient = craftingInventory.getStackInSlot(i);
|
||||
|
||||
if (ingredient != null) {
|
||||
ItemPattern.addIngredient(pattern, ingredient);
|
||||
ItemPattern.addInput(pattern, ingredient);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,6 +187,10 @@ public class TileGrid extends TileMachine implements IGrid {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canCreatePattern() {
|
||||
return craftingResultInventory.getStackInSlot(0) != null && patternsInventory.getStackInSlot(1) == null && patternsInventory.getStackInSlot(0) != null;
|
||||
}
|
||||
|
||||
public void onRecipeTransfer(ItemStack[][] recipe) {
|
||||
if (isConnected()) {
|
||||
for (int i = 0; i < craftingInventory.getSizeInventory(); ++i) {
|
||||
|
||||
Reference in New Issue
Block a user