reduced memory footprint of bpt requirements, #1484

This commit is contained in:
SpaceToad 2014-03-09 11:55:09 +01:00
parent b775c045fc
commit 896dce5b65
4 changed files with 26 additions and 18 deletions

View file

@ -48,7 +48,9 @@ public class BlueprintManager {
try { try {
SchematicConstructor c = schematicClasses.get(block); SchematicConstructor c = schematicClasses.get(block);
return (Schematic) c.clas.getConstructors() [0].newInstance(c.params); Schematic s = (Schematic) c.clas.getConstructors() [0].newInstance(c.params);
s.block = block;
return s;
} catch (InstantiationException e) { } catch (InstantiationException e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();

View file

@ -16,6 +16,9 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import org.apache.commons.lang3.ArrayUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
/** /**
@ -51,7 +54,7 @@ public class Schematic {
* blueprint. Modders can either rely on this list or compute their own int * blueprint. Modders can either rely on this list or compute their own int
* Schematic. * Schematic.
*/ */
public ArrayList<ItemStack> storedRequirements = new ArrayList<ItemStack>(); public ItemStack [] storedRequirements = new ItemStack [0];
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@ -60,7 +63,7 @@ public class Schematic {
obj.block = block; obj.block = block;
obj.meta = meta; obj.meta = meta;
obj.storedRequirements = (ArrayList<ItemStack>) storedRequirements.clone(); obj.storedRequirements = ArrayUtils.clone(storedRequirements);
return obj; return obj;
} }
@ -81,8 +84,10 @@ public class Schematic {
*/ */
public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) { public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) {
if (block != null) { if (block != null) {
if (storedRequirements.size() != 0) { if (storedRequirements.length != 0) {
requirements.addAll(storedRequirements); for (ItemStack s : storedRequirements) {
requirements.add(s);
}
} else { } else {
requirements.add(new ItemStack(block, 1, meta)); requirements.add(new ItemStack(block, 1, meta));
} }
@ -187,7 +192,8 @@ public class Schematic {
y, z, context.world().getBlockMetadata(x, y, z), 0); y, z, context.world().getBlockMetadata(x, y, z), 0);
if (req != null) { if (req != null) {
storedRequirements.addAll(req); storedRequirements = new ItemStack [req.size()];
req.toArray(storedRequirements);
} }
} }
} }
@ -223,6 +229,7 @@ public class Schematic {
meta = nbt.getInteger("blockMeta"); meta = nbt.getInteger("blockMeta");
NBTTagList rq = nbt.getTagList("rq", Utils.NBTTag_Types.NBTTagList.ordinal()); NBTTagList rq = nbt.getTagList("rq", Utils.NBTTag_Types.NBTTagList.ordinal());
storedRequirements = new ItemStack[rq.tagCount()];
for (int i = 0; i < rq.tagCount(); ++i) { for (int i = 0; i < rq.tagCount(); ++i) {
NBTTagCompound sub = rq.getCompoundTagAt(i); NBTTagCompound sub = rq.getCompoundTagAt(i);
@ -231,7 +238,7 @@ public class Schematic {
sub.setInteger("id", Item.itemRegistry.getIDForObject(registry sub.setInteger("id", Item.itemRegistry.getIDForObject(registry
.getItemForId(sub.getInteger("id")))); .getItemForId(sub.getInteger("id"))));
storedRequirements.add(ItemStack.loadItemStackFromNBT(sub)); storedRequirements [i] = ItemStack.loadItemStackFromNBT(sub);
} }
} }
} }

View file

@ -643,6 +643,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x, slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x,
slot.y, slot.z); slot.y, slot.z);
} }
if (bluePrintBuilder instanceof BptBuilderBlueprint) {
((BptBuilderBlueprint) bluePrintBuilder).recomputeNeededItems();
}
} }
} }

View file

@ -8,7 +8,7 @@
*/ */
package buildcraft.transport.blueprints; package buildcraft.transport.blueprints;
import java.util.LinkedList; import java.util.ArrayList;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -21,15 +21,6 @@ import buildcraft.transport.TileGenericPipe.SideProperties;
public class SchematicPipe extends SchematicTile { public class SchematicPipe extends SchematicTile {
@Override
public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) {
Item pipeItem = context.getMappingRegistry().getItemForId (cpt.getInteger("pipeId"));
requirements.add(new ItemStack(pipeItem));
requirements.addAll(storedRequirements);
}
@Override @Override
public boolean isValid(IBuilderContext context, int x, int y, int z) { public boolean isValid(IBuilderContext context, int x, int y, int z) {
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z); Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
@ -79,7 +70,11 @@ public class SchematicPipe extends SchematicTile {
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z); Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
if (BlockGenericPipe.isValid(pipe)) { if (BlockGenericPipe.isValid(pipe)) {
storedRequirements.addAll(pipe.computeItemDrop ()); ArrayList <ItemStack> items = pipe.computeItemDrop ();
storedRequirements = new ItemStack [items.size() + 1];
items.toArray(storedRequirements);
storedRequirements[storedRequirements.length - 1] = new ItemStack(
pipe.item);
tile.writeToNBT(cpt); tile.writeToNBT(cpt);