Optimized blueprint memory footprint, for #1484
Air block generate null schematics x, y, z are not recorded in the schematic anymore
This commit is contained in:
parent
d38ab99d89
commit
add526d8f9
26 changed files with 170 additions and 132 deletions
|
@ -12,6 +12,7 @@ import java.lang.reflect.InvocationTargetException;
|
|||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
|
||||
public class BlueprintManager {
|
||||
|
||||
|
@ -32,6 +33,10 @@ public class BlueprintManager {
|
|||
}
|
||||
|
||||
public static Schematic newSchematic (Block block) {
|
||||
if (block == Blocks.air) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!schematicClasses.containsKey(block)) {
|
||||
registerSchematicClass(block, Schematic.class);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ import buildcraft.core.utils.Utils;
|
|||
public class Schematic {
|
||||
|
||||
public Block block = null;
|
||||
public int x, y, z, meta = 0;
|
||||
public int meta = 0;
|
||||
|
||||
/**
|
||||
* This field contains requirements for a given block when stored in the
|
||||
|
@ -64,25 +64,15 @@ public class Schematic {
|
|||
*/
|
||||
public NBTTagCompound cpt = new NBTTagCompound();
|
||||
|
||||
public enum Mode {
|
||||
ClearIfInvalid, Build
|
||||
};
|
||||
|
||||
public Mode mode = Mode.Build;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public Schematic clone() {
|
||||
Schematic obj = BlueprintManager.newSchematic(block);
|
||||
|
||||
obj.x = x;
|
||||
obj.y = y;
|
||||
obj.z = z;
|
||||
obj.block = block;
|
||||
obj.meta = meta;
|
||||
obj.cpt = (NBTTagCompound) cpt.copy();
|
||||
obj.storedRequirements = (ArrayList<ItemStack>) storedRequirements.clone();
|
||||
obj.mode = mode;
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -166,7 +156,7 @@ public class Schematic {
|
|||
* the blueprint at the location given by the slot. By default, this
|
||||
* subprogram is permissive and doesn't take into account metadata.
|
||||
*/
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z) && meta == context.world().getBlockMetadata(x, y, z);
|
||||
}
|
||||
|
||||
|
@ -180,7 +170,7 @@ public class Schematic {
|
|||
/**
|
||||
* Places the block in the world, at the location specified in the slot.
|
||||
*/
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
// Meta needs to be specified twice, depending on the block behavior
|
||||
context.world().setBlock(x, y, z, block, meta, 3);
|
||||
context.world().setBlockMetadataWithNotify(x, y, z, meta, 3);
|
||||
|
|
23
common/buildcraft/api/blueprints/SchematicToBuild.java
Executable file
23
common/buildcraft/api/blueprints/SchematicToBuild.java
Executable file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
|
||||
* http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.api.blueprints;
|
||||
|
||||
|
||||
public class SchematicToBuild {
|
||||
|
||||
public int x, y, z;
|
||||
public Schematic schematic;
|
||||
|
||||
public enum Mode {
|
||||
ClearIfInvalid, Build
|
||||
};
|
||||
|
||||
public Mode mode = Mode.Build;
|
||||
|
||||
}
|
|
@ -12,8 +12,8 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicBed extends Schematic {
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class SchematicBed extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
if ((meta & 8) != 0) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -13,8 +13,8 @@ import java.util.LinkedList;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicDirt extends Schematic {
|
||||
|
||||
|
@ -24,12 +24,12 @@ public class SchematicDirt extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
context.world().setBlock(x, y, z, Blocks.dirt, meta, 3);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
Block block = context.world().getBlock(x, y, z);
|
||||
|
||||
return block == Blocks.dirt || block == Blocks.grass || block == Blocks.farmland;
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicDoor extends Schematic {
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class SchematicDoor extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
context.world().setBlock(x, y, z, block, meta, 3);
|
||||
context.world().setBlock(x, y + 1, z, block, meta + 8, 3);
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicFluid extends Schematic {
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class SchematicFluid extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
if (meta == 0) {
|
||||
return block == context.world().getBlock(x, y, z) && context.world().getBlockMetadata(x, y, z) == 0;
|
||||
} else {
|
||||
|
@ -49,7 +49,7 @@ public class SchematicFluid extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
if (meta == 0) {
|
||||
context.world().setBlock(x, y, z, block, 0,1);
|
||||
}
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicIgnore extends Schematic {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SchematicIgnore extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicIgnoreMeta extends Schematic {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SchematicIgnoreMeta extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
package buildcraft.api.schematics;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicInventory extends Schematic {
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
super.writeToWorld(context);
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
super.writeToWorld(context, x, y, z);
|
||||
|
||||
IInventory inv = (IInventory) context.world().getTileEntity(x, y, z);
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ public class SchematicPiston extends SchematicRotateMeta {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
int localMeta = meta & 7;
|
||||
|
||||
context.world().setBlock(x, y, z, block, localMeta, 3);
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicPumpkin extends Schematic {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SchematicPumpkin extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class SchematicRotateInventory extends SchematicRotateMeta {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
super.writeToWorld(context);
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
super.writeToWorld(context, x, y, z);
|
||||
|
||||
IInventory inv = (IInventory) context.world().getTileEntity(x, y, z);
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicRotateMeta extends Schematic {
|
||||
|
||||
|
@ -43,7 +43,7 @@ public class SchematicRotateMeta extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,8 @@ package buildcraft.api.schematics;
|
|||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicStairs extends Schematic {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class SchematicStairs extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
return block == context.world().getBlock(x, y, z);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.SchematicToBuild;
|
||||
import buildcraft.api.gates.IAction;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
|
@ -637,10 +637,11 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory,
|
|||
|
||||
public void debugForceBlueprintCompletion () {
|
||||
if (bluePrintBuilder != null) {
|
||||
Schematic slot = bluePrintBuilder.getNextBlock(worldObj, this);
|
||||
SchematicToBuild slot = bluePrintBuilder.getNextBlock(worldObj, this);
|
||||
|
||||
if (slot != null) {
|
||||
slot.writeToWorld(bluePrintBuilder.context);
|
||||
slot.schematic.writeToWorld(bluePrintBuilder.context, slot.x,
|
||||
slot.y, slot.z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import buildcraft.api.blueprints.BlueprintManager;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.core.utils.BCLog;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
|
@ -33,9 +33,14 @@ public class Blueprint extends BlueprintBase {
|
|||
|
||||
Schematic slot = BlueprintManager.newSchematic(block);
|
||||
|
||||
slot.x = (int) (x - context.surroundingBox().pMin().x);
|
||||
slot.y = (int) (y - context.surroundingBox().pMin().y);
|
||||
slot.z = (int) (z - context.surroundingBox().pMin().z);
|
||||
if (slot == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int posX = (int) (x - context.surroundingBox().pMin().x);
|
||||
int posY = (int) (y - context.surroundingBox().pMin().y);
|
||||
int posZ = (int) (z - context.surroundingBox().pMin().z);
|
||||
|
||||
slot.block = block;
|
||||
slot.meta = anchorTile.getWorldObj().getBlockMetadata(x, y, z);
|
||||
|
||||
|
@ -45,7 +50,7 @@ public class Blueprint extends BlueprintBase {
|
|||
|
||||
try {
|
||||
slot.readFromWorld(context, x, y, z);
|
||||
contents[slot.x][slot.y][slot.z] = slot;
|
||||
contents[posX][posY][posZ] = slot;
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
|
@ -62,7 +67,11 @@ public class Blueprint extends BlueprintBase {
|
|||
for (int y = 0; y < sizeY; ++y) {
|
||||
for (int z = 0; z < sizeZ; ++z) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
contents[x][y][z].writeToNBT(cpt, mapping);
|
||||
|
||||
if (contents [x][y][z] != null) {
|
||||
contents[x][y][z].writeToNBT(cpt, mapping);
|
||||
}
|
||||
|
||||
nbtContents.appendTag(cpt);
|
||||
}
|
||||
}
|
||||
|
@ -90,10 +99,14 @@ public class Blueprint extends BlueprintBase {
|
|||
NBTTagCompound cpt = nbtContents.getCompoundTagAt(index);
|
||||
index++;
|
||||
|
||||
int blockId = cpt.getInteger("blockId");
|
||||
if (cpt.hasKey("blockId")) {
|
||||
int blockId = cpt.getInteger("blockId");
|
||||
|
||||
contents[x][y][z] = BlueprintManager.newSchematic(mapping.getBlockForId(blockId));
|
||||
contents[x][y][z].readFromNBT(cpt, mapping);
|
||||
contents[x][y][z] = BlueprintManager.newSchematic(mapping.getBlockForId(blockId));
|
||||
contents[x][y][z].readFromNBT(cpt, mapping);
|
||||
} else {
|
||||
contents[x][y][z] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -52,9 +52,6 @@ public abstract class BlueprintBase {
|
|||
public void setBlock(int x, int y, int z, Block block) {
|
||||
if (contents[x][y][z] == null) {
|
||||
contents[x][y][z] = BlueprintManager.newSchematic(block);
|
||||
contents[x][y][z].x = x;
|
||||
contents[x][y][z].y = y;
|
||||
contents[x][y][z].z = z;
|
||||
}
|
||||
|
||||
contents[x][y][z].block = block;
|
||||
|
|
|
@ -10,7 +10,7 @@ package buildcraft.core.blueprints;
|
|||
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.SchematicToBuild;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.IBuilderInventory;
|
||||
|
@ -35,7 +35,7 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
context = bluePrint.getContext(world, box);
|
||||
}
|
||||
|
||||
public abstract Schematic getNextBlock(World world, IBuilderInventory inv);
|
||||
public abstract SchematicToBuild getNextBlock(World world, IBuilderInventory inv);
|
||||
|
||||
@Override
|
||||
public int xMin() {
|
||||
|
|
|
@ -15,11 +15,13 @@ import java.util.LinkedList;
|
|||
import java.util.ListIterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings.GameType;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.Schematic.Mode;
|
||||
import buildcraft.api.blueprints.SchematicToBuild;
|
||||
import buildcraft.api.blueprints.SchematicToBuild.Mode;
|
||||
import buildcraft.api.core.StackKey;
|
||||
import buildcraft.core.IBuilderInventory;
|
||||
import buildcraft.core.utils.BCLog;
|
||||
|
@ -27,11 +29,11 @@ import buildcraft.core.utils.BlockUtil;
|
|||
|
||||
public class BptBuilderBlueprint extends BptBuilderBase {
|
||||
|
||||
LinkedList<Schematic> clearList = new LinkedList<Schematic>();
|
||||
LinkedList<Schematic> primaryList = new LinkedList<Schematic>();
|
||||
LinkedList<Schematic> secondaryList = new LinkedList<Schematic>();
|
||||
LinkedList<SchematicToBuild> clearList = new LinkedList<SchematicToBuild>();
|
||||
LinkedList<SchematicToBuild> primaryList = new LinkedList<SchematicToBuild>();
|
||||
LinkedList<SchematicToBuild> secondaryList = new LinkedList<SchematicToBuild>();
|
||||
|
||||
LinkedList<Schematic> postProcessingList = new LinkedList<Schematic>();
|
||||
LinkedList<SchematicToBuild> postProcessingList = new LinkedList<SchematicToBuild>();
|
||||
|
||||
public LinkedList <ItemStack> neededItems = new LinkedList <ItemStack> ();
|
||||
|
||||
|
@ -47,21 +49,20 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
Schematic slot = bluePrint.contents[i][j][k];
|
||||
|
||||
if (slot != null) {
|
||||
slot = slot.clone();
|
||||
} else {
|
||||
if (slot == null) {
|
||||
slot = new Schematic();
|
||||
slot.meta = 0;
|
||||
slot.block = null;
|
||||
slot.block = Blocks.air;
|
||||
}
|
||||
|
||||
slot.x = xCoord;
|
||||
slot.y = yCoord;
|
||||
slot.z = zCoord;
|
||||
SchematicToBuild b = new SchematicToBuild ();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.ClearIfInvalid;
|
||||
|
||||
slot.mode = Mode.ClearIfInvalid;
|
||||
|
||||
clearList.add(slot);
|
||||
clearList.add(b);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -76,28 +77,27 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
Schematic slot = bluePrint.contents[i][j][k];
|
||||
|
||||
if (slot != null) {
|
||||
slot = slot.clone();
|
||||
} else {
|
||||
if (slot == null) {
|
||||
slot = new Schematic();
|
||||
slot.meta = 0;
|
||||
slot.block = null;
|
||||
slot.block = Blocks.air;
|
||||
}
|
||||
|
||||
slot.x = xCoord;
|
||||
slot.y = yCoord;
|
||||
slot.z = zCoord;
|
||||
|
||||
slot.mode = Mode.Build;
|
||||
SchematicToBuild b = new SchematicToBuild ();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.Build;
|
||||
|
||||
if (slot.block != null && slot.block.isOpaqueCube()) {
|
||||
primaryList.add(slot);
|
||||
primaryList.add(b);
|
||||
} else {
|
||||
secondaryList.add(slot);
|
||||
secondaryList.add(b);
|
||||
}
|
||||
|
||||
if (slot.block != null) {
|
||||
postProcessingList.add(slot.clone());
|
||||
postProcessingList.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +117,9 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Schematic getNextBlock(World world, IBuilderInventory inv) {
|
||||
public SchematicToBuild getNextBlock(World world, IBuilderInventory inv) {
|
||||
if (clearList.size() != 0) {
|
||||
Schematic slot = internalGetNextBlock(world, inv, clearList);
|
||||
SchematicToBuild slot = internalGetNextBlock(world, inv, clearList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -128,7 +128,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
|
||||
if (primaryList.size() != 0) {
|
||||
Schematic slot = internalGetNextBlock(world, inv, primaryList);
|
||||
SchematicToBuild slot = internalGetNextBlock(world, inv, primaryList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -137,7 +137,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
|
||||
if (secondaryList.size() != 0) {
|
||||
Schematic slot = internalGetNextBlock(world, inv, secondaryList);
|
||||
SchematicToBuild slot = internalGetNextBlock(world, inv, secondaryList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -150,18 +150,19 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Schematic internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<Schematic> list) {
|
||||
LinkedList<Schematic> failSlots = new LinkedList<Schematic>();
|
||||
public SchematicToBuild internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<SchematicToBuild> list) {
|
||||
LinkedList<SchematicToBuild> failSlots = new LinkedList<SchematicToBuild>();
|
||||
|
||||
Schematic result = null;
|
||||
SchematicToBuild result = null;
|
||||
|
||||
while (list.size() > 0) {
|
||||
Schematic slot = list.removeFirst();
|
||||
SchematicToBuild slot = list.removeFirst();
|
||||
|
||||
boolean getNext = false;
|
||||
|
||||
try {
|
||||
getNext = !slot.isValid(context) && !slot.ignoreBuilding();
|
||||
getNext = !slot.schematic.isValid(context, slot.x, slot.y,
|
||||
slot.z) && !slot.schematic.ignoreBuilding();
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
|
@ -181,8 +182,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
result = slot;
|
||||
|
||||
break;
|
||||
} else if (checkRequirements(inv, slot)) {
|
||||
useRequirements(inv, slot);
|
||||
} else if (checkRequirements(inv, slot.schematic)) {
|
||||
useRequirements(inv, slot.schematic);
|
||||
|
||||
result = slot;
|
||||
break;
|
||||
|
@ -334,12 +335,12 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
HashMap <StackKey, Integer> computeStacks = new HashMap <StackKey, Integer> ();
|
||||
|
||||
for (Schematic slot : primaryList) {
|
||||
for (SchematicToBuild slot : primaryList) {
|
||||
|
||||
LinkedList<ItemStack> stacks = new LinkedList<ItemStack>();
|
||||
|
||||
try {
|
||||
stacks = slot.getRequirements(context);
|
||||
stacks = slot.schematic.getRequirements(context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
|
@ -365,8 +366,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
}
|
||||
}
|
||||
|
||||
for (Schematic slot : secondaryList) {
|
||||
LinkedList<ItemStack> stacks = slot.getRequirements(context);
|
||||
for (SchematicToBuild slot : secondaryList) {
|
||||
LinkedList<ItemStack> stacks = slot.schematic.getRequirements(context);
|
||||
|
||||
for (ItemStack stack : stacks) {
|
||||
if (stack == null || stack.getItem() == null || stack.stackSize == 0) {
|
||||
|
@ -414,9 +415,9 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
@Override
|
||||
public void postProcessing(World world) {
|
||||
for (Schematic s : postProcessingList) {
|
||||
for (SchematicToBuild s : postProcessingList) {
|
||||
try {
|
||||
s.postProcessing(context);
|
||||
s.schematic.postProcessing(context);
|
||||
} catch (Throwable t) {
|
||||
// Defensive code against errors in implementers
|
||||
t.printStackTrace();
|
||||
|
|
|
@ -12,13 +12,14 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.Schematic.Mode;
|
||||
import buildcraft.api.blueprints.SchematicToBuild;
|
||||
import buildcraft.api.blueprints.SchematicToBuild.Mode;
|
||||
import buildcraft.core.IBuilderInventory;
|
||||
|
||||
public class BptBuilderTemplate extends BptBuilderBase {
|
||||
|
||||
LinkedList<Schematic> clearList = new LinkedList<Schematic>();
|
||||
LinkedList<Schematic> buildList = new LinkedList<Schematic>();
|
||||
LinkedList<SchematicToBuild> clearList = new LinkedList<SchematicToBuild>();
|
||||
LinkedList<SchematicToBuild> buildList = new LinkedList<SchematicToBuild>();
|
||||
|
||||
public BptBuilderTemplate(BlueprintBase bluePrint, World world, int x, int y, int z) {
|
||||
super(bluePrint, world, x, y, z);
|
||||
|
@ -36,13 +37,17 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
slot = new Schematic();
|
||||
slot.meta = 0;
|
||||
slot.block = null;
|
||||
slot.x = xCoord;
|
||||
slot.y = yCoord;
|
||||
slot.z = zCoord;
|
||||
|
||||
slot.mode = Mode.ClearIfInvalid;
|
||||
|
||||
clearList.add(slot);
|
||||
SchematicToBuild b = new SchematicToBuild();
|
||||
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.ClearIfInvalid;
|
||||
|
||||
clearList.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -65,14 +70,17 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
slot.block = null;
|
||||
}
|
||||
|
||||
slot.x = xCoord;
|
||||
slot.y = yCoord;
|
||||
slot.z = zCoord;
|
||||
SchematicToBuild b = new SchematicToBuild();
|
||||
|
||||
slot.mode = Mode.Build;
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
|
||||
b.mode = Mode.Build;
|
||||
|
||||
if (slot.block != null) {
|
||||
buildList.add(slot);
|
||||
buildList.add(b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,9 +96,9 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Schematic getNextBlock(World world, IBuilderInventory inv) {
|
||||
public SchematicToBuild getNextBlock(World world, IBuilderInventory inv) {
|
||||
if (clearList.size() != 0) {
|
||||
Schematic slot = internalGetNextBlock(world, inv, clearList);
|
||||
SchematicToBuild slot = internalGetNextBlock(world, inv, clearList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -101,7 +109,7 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
}
|
||||
|
||||
if (buildList.size() != 0) {
|
||||
Schematic slot = internalGetNextBlock(world, inv, buildList);
|
||||
SchematicToBuild slot = internalGetNextBlock(world, inv, buildList);
|
||||
checkDone();
|
||||
|
||||
if (slot != null) {
|
||||
|
@ -116,11 +124,11 @@ public class BptBuilderTemplate extends BptBuilderBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public Schematic internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<Schematic> list) {
|
||||
Schematic result = null;
|
||||
public SchematicToBuild internalGetNextBlock(World world, IBuilderInventory inv, LinkedList<SchematicToBuild> list) {
|
||||
SchematicToBuild result = null;
|
||||
|
||||
while (list.size() > 0) {
|
||||
Schematic slot = list.getFirst();
|
||||
SchematicToBuild slot = list.getFirst();
|
||||
|
||||
// Note from CJ: I have no idea what this code is supposed to do, so I'm not touching it.
|
||||
/*if (slot.blockId == world.getBlockId(slot.x, slot.y, slot.z)) {
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
package buildcraft.energy;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicEngine extends Schematic {
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class SchematicEngine extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
context.world().setBlock(x, y, z, block, meta,1);
|
||||
|
||||
TileEngine engine = (TileEngine) context.world().getTileEntity(x, y, z);
|
||||
|
|
|
@ -12,9 +12,9 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.SchematicUtils;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
|
||||
public class SchematicAutoWorkbench extends Schematic {
|
||||
|
||||
|
@ -33,8 +33,8 @@ public class SchematicAutoWorkbench extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
super.writeToWorld(context);
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
super.writeToWorld(context, x, y, z);
|
||||
|
||||
IInventory inventory = (IInventory) context.world().getTileEntity(x, y, z);
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@
|
|||
package buildcraft.factory;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicRefinery extends Schematic {
|
||||
|
||||
|
@ -28,8 +28,8 @@ public class SchematicRefinery extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
super.writeToWorld(context);
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
super.writeToWorld(context, x, y, z);
|
||||
|
||||
TileRefinery refinery = (TileRefinery) context.world().getTileEntity(x, y, z);
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@
|
|||
*/
|
||||
package buildcraft.factory;
|
||||
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
|
||||
public class SchematicTank extends Schematic {
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class SchematicTank extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
context.world().setBlock(x, y, z, block, meta, 3);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,8 +13,8 @@ import java.util.LinkedList;
|
|||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.transport.BlockGenericPipe;
|
||||
import buildcraft.transport.Pipe;
|
||||
import buildcraft.transport.TileGenericPipe.SideProperties;
|
||||
|
@ -31,7 +31,7 @@ public class SchematicPipe extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid(IBuilderContext context) {
|
||||
public boolean isValid(IBuilderContext context, int x, int y, int z) {
|
||||
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
|
||||
|
||||
if (BlockGenericPipe.isValid(pipe)) {
|
||||
|
@ -58,7 +58,7 @@ public class SchematicPipe extends Schematic {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
public void writeToWorld(IBuilderContext context, int x, int y, int z) {
|
||||
cpt.setInteger("x", x);
|
||||
cpt.setInteger("y", y);
|
||||
cpt.setInteger("z", z);
|
||||
|
|
Loading…
Reference in a new issue