Still broken

This commit is contained in:
Raoul Van den Berge
2016-05-08 16:00:27 +02:00
parent 5051ae29a2
commit 59772fd303
6 changed files with 52 additions and 49 deletions

View File

@@ -138,7 +138,13 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
if (crafter.getStackInSlot(i) != null) {
ItemStack pattern = crafter.getStackInSlot(i);
newPatterns.add(new CraftingPattern(crafter, ItemPattern.isProcessing(pattern), ItemPattern.getInputs(pattern), ItemPattern.getOutputs(pattern)));
newPatterns.add(new CraftingPattern(
crafter.getPos().getX(),
crafter.getPos().getY(),
crafter.getPos().getZ(),
ItemPattern.isProcessing(pattern),
ItemPattern.getInputs(pattern),
ItemPattern.getOutputs(pattern)));
}
}
}
@@ -194,7 +200,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
while (craftingTaskIterator.hasNext()) {
ICraftingTask task = craftingTaskIterator.next();
if (ticks % task.getPattern().getCrafter().getSpeed() == 0 && task.update(this)) {
if (ticks % task.getPattern().getCrafter(worldObj).getSpeed() == 0 && task.update(this)) {
task.onDone(this);
craftingTaskIterator.remove();
@@ -289,7 +295,7 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
int amount = 0;
for (int i = 0; i < craftingTasks.size(); ++i) {
if (craftingTasks.get(i).getPattern().comparePattern(pattern, flags)) {
if (craftingTasks.get(i).getPattern().comparePattern(worldObj, pattern, flags)) {
amount++;
}
}
@@ -515,10 +521,10 @@ public class TileController extends TileBase implements IEnergyReceiver, INetwor
switch (taskTag.getInteger("Type")) {
case 0:
addCraftingTask(new BasicCraftingTask(worldObj, taskTag));
addCraftingTask(new BasicCraftingTask(taskTag));
break;
case 1:
addCraftingTask(new ProcessingCraftingTask(worldObj, taskTag));
addCraftingTask(new ProcessingCraftingTask(taskTag));
break;
}
}

View File

@@ -3,7 +3,6 @@ package refinedstorage.tile.autocrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants;
@@ -16,19 +15,27 @@ public class CraftingPattern {
public static final String NBT_CRAFTER_Y = "CrafterY";
public static final String NBT_CRAFTER_Z = "CrafterZ";
private int crafterX;
private int crafterY;
private int crafterZ;
private TileCrafter crafter;
private boolean processing;
private ItemStack[] inputs;
private ItemStack[] outputs;
public CraftingPattern(TileCrafter crafter, boolean processing, ItemStack[] inputs, ItemStack[] outputs) {
this.crafter = crafter;
public CraftingPattern(int crafterX, int crafterY, int crafterZ, boolean processing, ItemStack[] inputs, ItemStack[] outputs) {
this.crafterX = crafterX;
this.crafterY = crafterY;
this.crafterZ = crafterZ;
this.processing = processing;
this.inputs = inputs;
this.outputs = outputs;
}
public TileCrafter getCrafter() {
public TileCrafter getCrafter(World world) {
if (crafter == null) {
crafter = (TileCrafter) world.getTileEntity(new BlockPos(crafterX, crafterY, crafterZ));
}
return crafter;
}
@@ -44,7 +51,7 @@ public class CraftingPattern {
return outputs;
}
public boolean comparePattern(CraftingPattern otherPattern, int flags) {
public boolean comparePattern(World world, CraftingPattern otherPattern, int flags) {
if (otherPattern == this) {
return true;
}
@@ -52,7 +59,7 @@ public class CraftingPattern {
if (otherPattern.getInputs().length != inputs.length ||
otherPattern.getOutputs().length != outputs.length ||
otherPattern.isProcessing() != processing ||
!otherPattern.getCrafter().getPos().equals(crafter.getPos())) {
!otherPattern.getCrafter(world).getPos().equals(getCrafter(world).getPos())) {
return false;
}
@@ -91,14 +98,11 @@ public class CraftingPattern {
tag.setInteger(NBT_CRAFTER_Z, crafter.getPos().getZ());
}
public static CraftingPattern readFromNBT(World world, NBTTagCompound 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);
TileEntity crafter = world.getTileEntity(new BlockPos(cx, cy, cz));
if (crafter instanceof TileCrafter) {
boolean processing = tag.getBoolean(ItemPattern.NBT_PROCESSING);
NBTTagList inputsTag = tag.getTagList(ItemPattern.NBT_INPUTS, Constants.NBT.TAG_COMPOUND);
@@ -113,9 +117,6 @@ public class CraftingPattern {
outputs[i] = ItemStack.loadItemStackFromNBT(outputsTag.getCompoundTagAt(i));
}
return new CraftingPattern((TileCrafter) crafter, processing, inputs, outputs);
}
return null;
return new CraftingPattern(cx, cy, cz, processing, inputs, outputs);
}
}

View File

@@ -34,7 +34,7 @@ public class TileCrafter extends TileMachine implements IInventory {
@Override
public void onDisconnected() {
for (ICraftingTask task : controller.getCraftingTasks()) {
if (task.getPattern().getCrafter() == this) {
if (task.getPattern().getCrafter(worldObj) == this) {
controller.cancelCraftingTask(task);
}
}

View File

@@ -4,7 +4,6 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import refinedstorage.tile.TileController;
import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.util.NBTUtils;
@@ -33,8 +32,8 @@ public class BasicCraftingTask implements ICraftingTask {
this.childTasks = new boolean[pattern.getInputs().length];
}
public BasicCraftingTask(World world, NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(world, tag.getCompoundTag(CraftingPattern.NBT));
public BasicCraftingTask(NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
this.satisfied = NBTUtils.readBoolArray(tag, NBT_SATISFIED);
this.checked = NBTUtils.readBoolArray(tag, NBT_CHECKED);
this.childTasks = NBTUtils.readBoolArray(tag, NBT_CHILD_TASKS);

View File

@@ -6,7 +6,6 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import refinedstorage.tile.TileController;
import refinedstorage.tile.autocrafting.CraftingPattern;
import refinedstorage.tile.autocrafting.TileCrafter;
@@ -32,8 +31,8 @@ public class ProcessingCraftingTask implements ICraftingTask {
this.satisfied = new boolean[pattern.getOutputs().length];
}
public ProcessingCraftingTask(World world, NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(world, tag.getCompoundTag(CraftingPattern.NBT));
public ProcessingCraftingTask(NBTTagCompound tag) {
this.pattern = CraftingPattern.readFromNBT(tag.getCompoundTag(CraftingPattern.NBT));
this.inserted = NBTUtils.readBoolArray(tag, NBT_INSERTED);
this.missing = NBTUtils.readBoolArray(tag, NBT_MISSING);
this.satisfied = NBTUtils.readBoolArray(tag, NBT_SATISFIED);
@@ -46,7 +45,7 @@ public class ProcessingCraftingTask implements ICraftingTask {
@Override
public boolean update(TileController controller) {
TileCrafter crafter = pattern.getCrafter();
TileCrafter crafter = pattern.getCrafter(controller.getWorld());
TileEntity crafterFacing = crafter.getWorld().getTileEntity(crafter.getPos().offset(crafter.getDirection()));
if (crafterFacing instanceof IInventory) {

View File

@@ -1,28 +1,26 @@
package refinedstorage.util;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import net.minecraft.nbt.NBTTagIntArray;
public class NBTUtils {
public static void writeBoolArray(NBTTagCompound tag, String name, boolean[] arr) {
NBTTagList list = new NBTTagList();
int[] intArr = new int[arr.length];
for (int i = 0; i < arr.length; ++i) {
list.appendTag(new NBTTagByte(arr[i] ? (byte) 1 : (byte) 0));
for (int i = 0; i < intArr.length; ++i) {
intArr[i] = arr[i] ? 1 : 0;
}
tag.setTag(name, list);
tag.setTag(name, new NBTTagIntArray(intArr));
}
public static boolean[] readBoolArray(NBTTagCompound tag, String name) {
NBTTagList list = tag.getTagList(name, Constants.NBT.TAG_COMPOUND);
int[] intArr = tag.getIntArray(name);
boolean[] arr = new boolean[list.tagCount()];
boolean arr[] = new boolean[intArr.length];
for (int i = 0; i < arr.length; ++i) {
arr[i] = ((NBTTagByte) list.get(i)).getByte() == 1 ? true : false;
for (int i = 0; i < intArr.length; ++i) {
arr[i] = intArr[i] == 1 ? true : false;
}
return arr;