reduced memory footprint of bpt requirements, #1484
This commit is contained in:
parent
b775c045fc
commit
896dce5b65
4 changed files with 26 additions and 18 deletions
|
@ -48,7 +48,9 @@ public class BlueprintManager {
|
|||
|
||||
try {
|
||||
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) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -16,6 +16,9 @@ import net.minecraft.item.Item;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
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
|
||||
* Schematic.
|
||||
*/
|
||||
public ArrayList<ItemStack> storedRequirements = new ArrayList<ItemStack>();
|
||||
public ItemStack [] storedRequirements = new ItemStack [0];
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
|
@ -60,7 +63,7 @@ public class Schematic {
|
|||
|
||||
obj.block = block;
|
||||
obj.meta = meta;
|
||||
obj.storedRequirements = (ArrayList<ItemStack>) storedRequirements.clone();
|
||||
obj.storedRequirements = ArrayUtils.clone(storedRequirements);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -81,8 +84,10 @@ public class Schematic {
|
|||
*/
|
||||
public void addRequirements(IBuilderContext context, LinkedList<ItemStack> requirements) {
|
||||
if (block != null) {
|
||||
if (storedRequirements.size() != 0) {
|
||||
requirements.addAll(storedRequirements);
|
||||
if (storedRequirements.length != 0) {
|
||||
for (ItemStack s : storedRequirements) {
|
||||
requirements.add(s);
|
||||
}
|
||||
} else {
|
||||
requirements.add(new ItemStack(block, 1, meta));
|
||||
}
|
||||
|
@ -187,7 +192,8 @@ public class Schematic {
|
|||
y, z, context.world().getBlockMetadata(x, y, z), 0);
|
||||
|
||||
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");
|
||||
|
||||
NBTTagList rq = nbt.getTagList("rq", Utils.NBTTag_Types.NBTTagList.ordinal());
|
||||
storedRequirements = new ItemStack[rq.tagCount()];
|
||||
|
||||
for (int i = 0; i < rq.tagCount(); ++i) {
|
||||
NBTTagCompound sub = rq.getCompoundTagAt(i);
|
||||
|
@ -231,7 +238,7 @@ public class Schematic {
|
|||
sub.setInteger("id", Item.itemRegistry.getIDForObject(registry
|
||||
.getItemForId(sub.getInteger("id"))));
|
||||
|
||||
storedRequirements.add(ItemStack.loadItemStackFromNBT(sub));
|
||||
storedRequirements [i] = ItemStack.loadItemStackFromNBT(sub);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -643,6 +643,10 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
|
|||
slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x,
|
||||
slot.y, slot.z);
|
||||
}
|
||||
|
||||
if (bluePrintBuilder instanceof BptBuilderBlueprint) {
|
||||
((BptBuilderBlueprint) bluePrintBuilder).recomputeNeededItems();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
*/
|
||||
package buildcraft.transport.blueprints;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
@ -21,15 +21,6 @@ import buildcraft.transport.TileGenericPipe.SideProperties;
|
|||
|
||||
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
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int 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);
|
||||
|
||||
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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue