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