implemented generic schematic ordering, close #1528

This commit is contained in:
SpaceToad 2014-03-29 18:34:17 +01:00
parent aa858467a1
commit 53b8f86db2
3 changed files with 57 additions and 50 deletions

View file

@ -18,7 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import buildcraft.core.utils.Utils;
public class SchematicBlock extends Schematic {
public class SchematicBlock extends Schematic implements Comparable<SchematicBlock> {
public Block block = null;
public int meta = 0;
@ -208,4 +208,15 @@ public class SchematicBlock extends Schematic {
storedRequirements = rqs.toArray(new ItemStack [rqs.size()]);
}
@Override
public int compareTo(SchematicBlock o) {
if (block.isOpaqueCube() == o.block.isOpaqueCube()) {
return 0;
} else if (block.isOpaqueCube()) {
return -1;
} else {
return 1;
}
}
}

View file

@ -31,11 +31,10 @@ import buildcraft.core.utils.BlockUtil;
public class BptBuilderBlueprint extends BptBuilderBase {
LinkedList<BuildingSlotBlock> clearList = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotBlock> primaryList = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotBlock> secondaryList = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
LinkedList<BuildingSlot> postProcessing = new LinkedList<BuildingSlot>();
private LinkedList<BuildingSlotBlock> clearList = new LinkedList<BuildingSlotBlock>();
private LinkedList<BuildingSlotBlock> blockList = new LinkedList<BuildingSlotBlock>();
private LinkedList<BuildingSlotEntity> entityList = new LinkedList<BuildingSlotEntity>();
private LinkedList<BuildingSlot> postProcessing = new LinkedList<BuildingSlot>();
public LinkedList <ItemStack> neededItems = new LinkedList <ItemStack> ();
@ -92,15 +91,13 @@ public class BptBuilderBlueprint extends BptBuilderBase {
b.z = zCoord;
b.mode = Mode.Build;
if (slot.block != null && slot.block.isOpaqueCube()) {
primaryList.add(b);
} else {
secondaryList.add(b);
}
blockList.add (b);
}
}
}
Collections.sort(blockList);
CoordTransformation transform = new CoordTransformation();
transform.x = x - blueprint.anchorX;
@ -121,8 +118,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
private void checkDone() {
recomputeNeededItems();
if (clearList.size() == 0 && primaryList.size() == 0
&& secondaryList.size() == 0 && entityList.size() == 0) {
if (clearList.size() == 0 && blockList.size() == 0
&& entityList.size() == 0) {
done = true;
} else {
done = false;
@ -140,17 +137,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
}
}
if (primaryList.size() != 0) {
BuildingSlot slot = internalGetNextBlock(world, inv, primaryList);
checkDone();
if (slot != null) {
return slot;
}
}
if (secondaryList.size() != 0) {
BuildingSlot slot = internalGetNextBlock(world, inv, secondaryList);
if (blockList.size() != 0) {
BuildingSlot slot = internalGetNextBlock(world, inv, blockList);
checkDone();
if (slot != null) {
@ -358,7 +346,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
HashMap <StackKey, Integer> computeStacks = new HashMap <StackKey, Integer> ();
for (BuildingSlot slot : primaryList) {
for (BuildingSlot slot : blockList) {
LinkedList<ItemStack> stacks = new LinkedList<ItemStack>();
try {
@ -388,28 +376,6 @@ public class BptBuilderBlueprint extends BptBuilderBase {
}
}
for (BuildingSlot slot : secondaryList) {
LinkedList<ItemStack> stacks = slot.getRequirements(context);
for (ItemStack stack : stacks) {
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
continue;
}
StackKey key = new StackKey(stack);
if (!computeStacks.containsKey(key)) {
computeStacks.put(key, stack.stackSize);
} else {
Integer num = computeStacks.get(key);
num += stack.stackSize;
computeStacks.put(key, num);
}
}
}
for (Entry<StackKey, Integer> e : computeStacks.entrySet()) {
ItemStack newStack = e.getKey().stack.copy();
newStack.stackSize = e.getValue();

View file

@ -10,13 +10,13 @@ package buildcraft.core.blueprints;
import java.util.LinkedList;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.blueprints.SchematicMask;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
public class BuildingSlotBlock extends BuildingSlot {
public class BuildingSlotBlock extends BuildingSlot implements Comparable<BuildingSlotBlock> {
public int x, y, z;
public Schematic schematic;
@ -66,4 +66,34 @@ public class BuildingSlotBlock extends BuildingSlot {
public LinkedList<ItemStack> getRequirements (IBuilderContext context) {
return getSchematic().getRequirements(context);
}
@Override
public int compareTo(BuildingSlotBlock o) {
if (o.schematic instanceof Comparable && schematic instanceof Comparable ) {
Comparable comp1 = (Comparable) schematic;
Comparable comp2 = (Comparable) o.schematic;
int cmp = comp1.compareTo(comp2);
if (cmp != 0) {
return cmp;
}
}
if (y < o.y) {
return -1;
} else if (y > o.y) {
return 1;
} else if (x < o.x) {
return -1;
} else if (x > o.x) {
return 1;
} else if (z < o.z) {
return -1;
} else if (z > o.z) {
return 1;
} else {
return 0;
}
}
}