Fixed crafting tasks not saving properly, fixes #171

This commit is contained in:
Raoul Van den Berge
2016-07-09 02:50:15 +02:00
parent 3611f8f542
commit f443d43300
5 changed files with 27 additions and 20 deletions

View File

@@ -6,6 +6,7 @@
- Fixed External Storage not updating correctly
- Fixed wireless signal starting from Controller instead of per Wireless Transmitter individually
- Fixed Controller's redstone state not saving
- Fixed crafting tasks not saving properly
- Huge performance improvements to large storage networks
**Features**

View File

@@ -2,6 +2,7 @@ package refinedstorage.api.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
/**
@@ -14,6 +15,11 @@ public interface ICraftingPattern {
*/
ICraftingPatternContainer getContainer(World world);
/**
* @return The position of the container where the pattern is in
*/
BlockPos getContainerPosition();
/**
* @return If this pattern is a processing pattern
*/

View File

@@ -17,19 +17,15 @@ public class CraftingPattern implements ICraftingPattern {
private static final String NBT_CRAFTER_Y = "CrafterY";
private static final String NBT_CRAFTER_Z = "CrafterZ";
private int crafterX;
private int crafterY;
private int crafterZ;
private BlockPos crafterPos;
private TileCrafter crafter;
private boolean processing;
private ItemStack[] inputs;
private ItemStack[] outputs;
private ItemStack[] byproducts;
public CraftingPattern(int crafterX, int crafterY, int crafterZ, boolean processing, ItemStack[] inputs, ItemStack[] outputs, ItemStack[] byproducts) {
this.crafterX = crafterX;
this.crafterY = crafterY;
this.crafterZ = crafterZ;
public CraftingPattern(BlockPos crafterPos, boolean processing, ItemStack[] inputs, ItemStack[] outputs, ItemStack[] byproducts) {
this.crafterPos = crafterPos;
this.processing = processing;
this.inputs = inputs;
this.outputs = outputs;
@@ -39,12 +35,17 @@ public class CraftingPattern implements ICraftingPattern {
@Override
public ICraftingPatternContainer getContainer(World world) {
if (crafter == null) {
crafter = (TileCrafter) world.getTileEntity(new BlockPos(crafterX, crafterY, crafterZ));
crafter = (TileCrafter) world.getTileEntity(crafterPos);
}
return crafter;
}
@Override
public BlockPos getContainerPosition() {
return crafterPos;
}
@Override
public boolean isProcessing() {
return processing;
@@ -88,17 +89,15 @@ public class CraftingPattern implements ICraftingPattern {
tag.setTag(ItemPattern.NBT_BYPRODUCTS, byproductsTag);
}
tag.setInteger(NBT_CRAFTER_X, crafter.getPos().getX());
tag.setInteger(NBT_CRAFTER_Y, crafter.getPos().getY());
tag.setInteger(NBT_CRAFTER_Z, crafter.getPos().getZ());
tag.setInteger(NBT_CRAFTER_X, crafterPos.getX());
tag.setInteger(NBT_CRAFTER_Y, crafterPos.getY());
tag.setInteger(NBT_CRAFTER_Z, crafterPos.getZ());
return tag;
}
public static CraftingPattern readFromNBT(NBTTagCompound tag) {
int cx = tag.getInteger(NBT_CRAFTER_X);
int cy = tag.getInteger(NBT_CRAFTER_Y);
int cz = tag.getInteger(NBT_CRAFTER_Z);
BlockPos crafterPos = new BlockPos(tag.getInteger(NBT_CRAFTER_X), tag.getInteger(NBT_CRAFTER_Y), tag.getInteger(NBT_CRAFTER_Z));
boolean processing = tag.getBoolean(ItemPattern.NBT_PROCESSING);
@@ -139,6 +138,6 @@ public class CraftingPattern implements ICraftingPattern {
}
}
return new CraftingPattern(cx, cy, cz, processing, inputs, outputs, byproducts);
return new CraftingPattern(crafterPos, processing, inputs, outputs, byproducts);
}
}

View File

@@ -66,7 +66,7 @@ public class TileCrafter extends TileNode implements ICraftingPatternContainer {
public void onConnectionChange(INetworkMaster network, boolean state) {
if (!state) {
for (ICraftingTask task : network.getCraftingTasks()) {
if (task.getPattern().getContainer(worldObj) == this) {
if (task.getPattern().getContainerPosition().equals(pos)) {
network.cancelCraftingTask(task);
}
}

View File

@@ -25,6 +25,7 @@ import refinedstorage.RefinedStorage;
import refinedstorage.RefinedStorageBlocks;
import refinedstorage.RefinedStorageUtils;
import refinedstorage.api.autocrafting.ICraftingPattern;
import refinedstorage.api.autocrafting.ICraftingPatternContainer;
import refinedstorage.api.autocrafting.ICraftingTask;
import refinedstorage.api.network.IGridHandler;
import refinedstorage.api.network.INetworkMaster;
@@ -172,7 +173,9 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
ICraftingTask top = craftingTasks.peek();
if (ticks % top.getPattern().getContainer(worldObj).getSpeed() == 0 && top.update(worldObj, this)) {
ICraftingPatternContainer container = top.getPattern().getContainer(worldObj);
if (container != null && (ticks % container.getSpeed()) == 0 && top.update(worldObj, this)) {
top.onDone(this);
craftingTasks.pop();
@@ -365,9 +368,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
if (pattern != null && ItemPattern.isValid(pattern)) {
patterns.add(new CraftingPattern(
crafter.getPos().getX(),
crafter.getPos().getY(),
crafter.getPos().getZ(),
crafter.getPos(),
ItemPattern.isProcessing(pattern),
ItemPattern.getInputs(pattern),
ItemPattern.getOutputs(pattern),