diff --git a/common/buildcraft/BuildCraftCore.java b/common/buildcraft/BuildCraftCore.java index 87241370..cc0048d5 100644 --- a/common/buildcraft/BuildCraftCore.java +++ b/common/buildcraft/BuildCraftCore.java @@ -8,7 +8,7 @@ package buildcraft; -import buildcraft.builders.BlueprintDatabase; +import buildcraft.builders.blueprints.BlueprintDatabase; import java.io.File; import java.util.TreeMap; import java.util.logging.Logger; diff --git a/common/buildcraft/api/builder/BlockHandler.java b/common/buildcraft/api/builder/BlockHandler.java index eb3b37ba..db91ce58 100644 --- a/common/buildcraft/api/builder/BlockHandler.java +++ b/common/buildcraft/api/builder/BlockHandler.java @@ -7,6 +7,8 @@ import java.util.Map; import net.minecraft.block.Block; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; @@ -20,24 +22,44 @@ import net.minecraftforge.common.ForgeDirection; */ public class BlockHandler { - private static final Map handlers = new HashMap(); - private final Block block; + private static final Map handlers = new HashMap(); + private final int id; + + public static BlockHandler get(Item item) { + if (item == null) + return null; + return get(item.itemID); + } public static BlockHandler get(Block block) { - BlockHandler handler = handlers.get(block); + if (block == null) + return null; + return get(block.blockID); + } + + public static BlockHandler get(int id) { + BlockHandler handler = handlers.get(id); if (handler == null) { - handler = new BlockHandler(block); - registerHandler(block, handler); + handler = new BlockHandler(id); + registerHandler(id, handler); } return handler; } public static void registerHandler(Block block, BlockHandler handler) { - handlers.put(block, handler); + handlers.put(block.blockID, handler); } - public BlockHandler(Block block) { - this.block = block; + public static void registerHandler(Item item, BlockHandler handler) { + handlers.put(item.itemID, handler); + } + + public static void registerHandler(int id, BlockHandler handler) { + handlers.put(id, handler); + } + + public BlockHandler(int id) { + this.id = id; } /** @@ -45,12 +67,19 @@ public class BlockHandler { * * We will also skip any blocks that drop actual items like Ore blocks. */ - public boolean canSaveBlockToSchematic(World world, int x, int y, int z) { + public boolean canSaveToSchematic(World world, int x, int y, int z) { + if (!(Item.itemsList[id] instanceof ItemBlock)) + return false; + + Block block = Block.blocksList[id]; + if (block == null) + return false; + int meta = world.getBlockMetadata(x, y, z); try { - if (block.idDropped(meta, null, 0) != block.blockID) { + if (block.idDropped(meta, null, 0) != id) return false; - } + } catch (NullPointerException ex) { return false; } @@ -58,12 +87,32 @@ public class BlockHandler { } /** - * It is assumed that Blueprints always face North on save. + * By default we will ignore all blocks with Tile Entities. * - * Store any info you need to reproduce the block in the data tag. + * We will also ignore anything that's not a ItemBlock. + * + * We will also skip any blocks that drop actual items like Ore blocks. */ - public void saveToSchematic(World world, int x, int y, int z, NBTTagCompound blockData) { - blockData.setByte("blockMeta", (byte) world.getBlockMetadata(x, y, z)); + public boolean canSaveToSchematic(ItemStack stack) { + if (stack == null) + return false; + if (!(stack.getItem() instanceof ItemBlock)) + return false; + + if (id > Block.blocksList.length) + return false; + + Block block = Block.blocksList[id]; + if (block == null) + return false; + + try { + if (block.idDropped(stack.getItemDamage(), null, 0) != id) + return false; + } catch (NullPointerException ex) { + return false; + } + return !block.hasTileEntity(stack.getItemDamage()); } /** @@ -71,9 +120,19 @@ public class BlockHandler { * * Store any info you need to reproduce the block in the data tag. */ - public void saveToSchematic(ItemStack stack, NBTTagCompound blockData) { + public void saveToSchematic(World world, int x, int y, int z, NBTTagCompound data) { + data.setByte("blockMeta", (byte) world.getBlockMetadata(x, y, z)); + } + + /** + * It is assumed that Blueprints always face North on save. + * + * Store any info you need to reproduce the block from this ItemStack in the + * data tag. + */ + public void saveToSchematic(ItemStack stack, NBTTagCompound data) { if (stack.getHasSubtypes()) - blockData.setByte("blockMeta", (byte) stack.getItemDamage()); + data.setByte("blockMeta", (byte) stack.getItemDamage()); } /** @@ -87,9 +146,10 @@ public class BlockHandler { * entities and will in fact break on Ore blocks as well. Which is why those * blocks can't be saved by default. */ - public List getCostForSchematic(NBTTagCompound blockData) { + public List getCostForSchematic(NBTTagCompound data) { List cost = new ArrayList(); - cost.add(new ItemStack(block.idDropped(blockData.getByte("blockMeta"), BlueprintHelpers.RANDOM, 0), 1, block.damageDropped(blockData.getByte("blockMeta")))); + Block block = Block.blocksList[id]; + cost.add(new ItemStack(block.idDropped(data.getByte("blockMeta"), BlueprintHelpers.RANDOM, 0), 1, block.damageDropped(data.getByte("blockMeta")))); return cost; } @@ -108,7 +168,7 @@ public class BlockHandler { * Can the block be placed currently or is it waiting on some other block to * be placed first? */ - public boolean canPlaceNow(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData) { + public boolean canPlaceNow(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data) { return true; } @@ -126,9 +186,9 @@ public class BlockHandler { * modify any ItemStack in the inventory until you have determined that * everything you require is present. */ - public boolean readBlockFromSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData, IInventory builderInventory, EntityPlayer bcPlayer) { + public boolean readBlockFromSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data, IInventory builderInventory, EntityPlayer bcPlayer) { if (builderInventory != null) { - List requiredItems = getCostForSchematic(blockData); + List requiredItems = getCostForSchematic(data); List slotsToConsume = new ArrayList(); for (ItemStack cost : requiredItems) { boolean found = false; @@ -146,16 +206,16 @@ public class BlockHandler { builderInventory.setInventorySlotContents(slot, BlueprintHelpers.consumeItem(builderInventory.getStackInSlot(slot))); } } - return world.setBlock(x, y, z, block.blockID, blockData.getByte("blockMeta"), 3); + return world.setBlock(x, y, z, Block.blocksList[id].blockID, data.getByte("blockMeta"), 3); } /** * Checks if the block matches the schematic. */ - public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData) { - if (block.blockID != world.getBlockId(x, y, z)) + public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data) { + if (id != world.getBlockId(x, y, z)) return false; - return !blockData.hasKey("blockMeta") || blockData.getByte("blockMeta") == world.getBlockMetadata(x, y, z); + return !data.hasKey("blockMeta") || data.getByte("blockMeta") == world.getBlockMetadata(x, y, z); } } diff --git a/common/buildcraft/builders/BlockSchematic.java b/common/buildcraft/builders/BlockSchematic.java deleted file mode 100644 index 59790b2e..00000000 --- a/common/buildcraft/builders/BlockSchematic.java +++ /dev/null @@ -1,40 +0,0 @@ -package buildcraft.builders; - -import net.minecraft.block.Block; -import net.minecraft.nbt.NBTTagCompound; - -/** - * - * @author CovertJaguar - */ -public final class BlockSchematic { - - public final Block block; - public NBTTagCompound blockData = new NBTTagCompound(); - public int x, y, z; - - public BlockSchematic(Block block) { - this.block = block; - } - - public BlockSchematic(String blockName) { - this((Block) null); // TODO: Add block from name code - } - - public void writeToNBT(NBTTagCompound nbt) { - nbt.setString("blockName", block.getUnlocalizedName()); - nbt.setInteger("x", x); - nbt.setInteger("y", y); - nbt.setInteger("z", z); - nbt.setCompoundTag("blockData", blockData); - } - - public static BlockSchematic readFromNBT(NBTTagCompound nbt) { - BlockSchematic block = new BlockSchematic(nbt.getString("blockName")); - block.x = nbt.getInteger("x"); - block.y = nbt.getInteger("y"); - block.z = nbt.getInteger("z"); - block.blockData = nbt.getCompoundTag("blockData"); - return block; - } -} diff --git a/common/buildcraft/builders/TileArchitect.java b/common/buildcraft/builders/TileArchitect.java index 6a85668e..df58273d 100644 --- a/common/buildcraft/builders/TileArchitect.java +++ b/common/buildcraft/builders/TileArchitect.java @@ -7,6 +7,7 @@ */ package buildcraft.builders; +import buildcraft.builders.blueprints.Blueprint; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; @@ -143,7 +144,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory { if (!worldObj.isAirBlock(x, y, z)) { Block block = Block.blocksList[worldObj.getBlockId(x, y, z)]; if (block != null) { - blueprint.setBlock(worldObj, x - box.xMin, y - box.yMin, z - box.zMin, block); + blueprint.setSchematic(x - box.xMin, y - box.yMin, z - box.zMin, worldObj, block); } } } diff --git a/common/buildcraft/builders/blueprints/BlockSchematic.java b/common/buildcraft/builders/blueprints/BlockSchematic.java new file mode 100644 index 00000000..ffd062ee --- /dev/null +++ b/common/buildcraft/builders/blueprints/BlockSchematic.java @@ -0,0 +1,43 @@ +package buildcraft.builders.blueprints; + +import buildcraft.api.builder.BlockHandler; +import net.minecraft.block.Block; +import net.minecraft.nbt.NBTTagCompound; + +/** + * + * @author CovertJaguar + */ +public final class BlockSchematic extends Schematic { + + public static BlockSchematic create(NBTTagCompound nbt) { + return null; + } + + public static BlockSchematic create(Block block) { + return new BlockSchematic(block); + } + public final Block block; + + private BlockSchematic(Block block) { + super(block.blockID); + this.block = block; + } + + private BlockSchematic(String nbt) { +// String blockName = nbt.getString("blockName"); + this((Block) null); // TODO: Add block from name code + } + + @Override + public BlockHandler getHandler() { + return BlockHandler.get(block); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setString("schematicType", "block"); + nbt.setString("blockName", block.getUnlocalizedName()); + } +} diff --git a/common/buildcraft/builders/Blueprint.java b/common/buildcraft/builders/blueprints/Blueprint.java similarity index 72% rename from common/buildcraft/builders/Blueprint.java rename to common/buildcraft/builders/blueprints/Blueprint.java index 74d35101..49e8622a 100644 --- a/common/buildcraft/builders/Blueprint.java +++ b/common/buildcraft/builders/blueprints/Blueprint.java @@ -5,12 +5,11 @@ * 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ -package buildcraft.builders; +package buildcraft.builders.blueprints; import buildcraft.BuildCraftCore; import buildcraft.api.builder.BlockHandler; import buildcraft.core.inventory.StackHelper; -import buildcraft.factory.TileQuarry; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; @@ -35,7 +34,7 @@ public class Blueprint { private final UUID uuid; private String name; private String creator; - private final BlockSchematic[][][] blocks; + private final Schematic[][][] schematics; public final int sizeX, sizeY, sizeZ; public int anchorX, anchorY, anchorZ; public ForgeDirection anchorOrientation = ForgeDirection.NORTH; @@ -50,7 +49,7 @@ public class Blueprint { this.sizeX = sizeX; this.sizeY = sizeY; this.sizeZ = sizeZ; - blocks = new BlockSchematic[sizeX][sizeY][sizeZ]; + schematics = new Schematic[sizeX][sizeY][sizeZ]; } public String getName() { @@ -61,22 +60,22 @@ public class Blueprint { this.name = name; } - private void setBlock(World world, int x, int y, int z, BlockSchematic schematic) { + private void setSchematic(int x, int y, int z, Schematic schematic) { if (schematic == null) return; schematic.x = x; schematic.y = y; schematic.z = z; - blocks[x][y][z] = schematic; + schematics[x][y][z] = schematic; } - public void setBlock(World world, int x, int y, int z, Block block) { + public void setSchematic(int x, int y, int z, World world, Block block) { BlockHandler handler = BlockHandler.get(block); try { - if (handler.canSaveBlockToSchematic(world, x, y, z)) { - BlockSchematic schematic = new BlockSchematic(block); - handler.saveToSchematic(world, x, y, z, schematic.blockData); - setBlock(world, x, y, z, schematic); + if (handler.canSaveToSchematic(world, x, y, z)) { + Schematic schematic = BlockSchematic.create(block); + handler.saveToSchematic(world, x, y, z, schematic.data); + setSchematic(x, y, z, schematic); } } catch (Throwable error) { BuildCraftCore.bcLog.severe(String.format("Error while trying to save block [%s:%d] to blueprint, skipping.", block.getUnlocalizedName(), block.blockID)); @@ -84,6 +83,22 @@ public class Blueprint { } } + public void setSchematic(int x, int y, int z, ItemStack item) { + if (item == null) + return; + BlockHandler handler = BlockHandler.get(item.getItem()); + try { + if (handler.canSaveToSchematic(item)) { + Schematic schematic = ItemSchematic.create(item.getItem()); + handler.saveToSchematic(item, schematic.data); + setSchematic(x, y, z, schematic); + } + } catch (Throwable error) { + BuildCraftCore.bcLog.severe(String.format("Error while trying to save item [%s:%d] to blueprint, skipping.", item.getItem().getUnlocalizedName(), item.itemID)); + BuildCraftCore.bcLog.throwing(getClass().getCanonicalName(), "setBlock", error); + } + } + /** * Helper function for creating Blueprints in code. * @@ -92,18 +107,18 @@ public class Blueprint { * * @see TileQuarry */ - public void setBlock(World world, int x, int y, int z, int id, int meta) { + public void setSchematic(World world, int x, int y, int z, int id, int meta) { Block block = Block.blocksList[id]; if (block == null) { return; } - BlockSchematic schematic = new BlockSchematic(block); - schematic.blockData.setByte("blockMeta", (byte) meta); - setBlock(world, x, y, z, schematic); + BlockSchematic schematic = BlockSchematic.create(block); + schematic.data.setByte("blockMeta", (byte) meta); + setSchematic(x, y, z, schematic); } - public BlockSchematic getBlock(int x, int y, int z) { - return blocks[x][y][z]; + public Schematic getBlock(int x, int y, int z) { + return schematics[x][y][z]; } public UUID getUUID() { @@ -119,13 +134,13 @@ public class Blueprint { * * @return List */ - public LinkedList getBuildList() { - LinkedList list = new LinkedList(); + public LinkedList getBuildList() { + LinkedList list = new LinkedList(); for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { for (int z = 0; z < sizeZ; z++) { - if (blocks[x][y][z] != null) - list.add(blocks[x][y][z]); + if (schematics[x][y][z] != null) + list.add(schematics[x][y][z]); } } } @@ -136,9 +151,9 @@ public class Blueprint { if (costs != null) return costs; List stacks = new ArrayList(); - for (BlockSchematic schematic : getBuildList()) { - BlockHandler handler = BlockHandler.get(schematic.block); - List requirements = handler.getCostForSchematic(schematic.blockData); + for (Schematic schematic : getBuildList()) { + BlockHandler handler = BlockHandler.get(schematic.id); + List requirements = handler.getCostForSchematic(schematic.data); for (ItemStack newStack : requirements) { if (newStack.stackSize <= 0) continue; @@ -160,10 +175,10 @@ public class Blueprint { for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { for (int z = 0; z < sizeZ; z++) { - if (blocks[x][y][z] == null) + if (schematics[x][y][z] == null) continue; NBTTagCompound blockNBT = new NBTTagCompound(); - blocks[x][y][z].writeToNBT(nbt); + schematics[x][y][z].writeToNBT(nbt); blockList.appendTag(blockNBT); } } @@ -204,8 +219,8 @@ public class Blueprint { NBTTagList blockList = nbt.getTagList("blocks"); for (int i = 0; i < blockList.tagCount(); i++) { NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i); - BlockSchematic block = BlockSchematic.readFromNBT(blockNBT); - blueprint.blocks[block.x][block.y][block.z] = block; + Schematic schematic = Schematic.createSchematicFromNBT(blockNBT); + blueprint.schematics[schematic.x][schematic.y][schematic.z] = schematic; } return blueprint; } diff --git a/common/buildcraft/builders/BlueprintBuilder.java b/common/buildcraft/builders/blueprints/BlueprintBuilder.java similarity index 82% rename from common/buildcraft/builders/BlueprintBuilder.java rename to common/buildcraft/builders/blueprints/BlueprintBuilder.java index f97eed1a..08f02d78 100644 --- a/common/buildcraft/builders/BlueprintBuilder.java +++ b/common/buildcraft/builders/blueprints/BlueprintBuilder.java @@ -6,10 +6,10 @@ * 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.builders; +package buildcraft.builders.blueprints; import buildcraft.api.builder.BlockHandler; -import buildcraft.builders.BlueprintBuilder.SchematicBuilder; +import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; @@ -31,7 +31,7 @@ public class BlueprintBuilder { public final World worldObj; public final int x, y, z; private final IInventory inv; - private final LinkedList buildList; + private final LinkedList buildList; private final List builders; public BlueprintBuilder(Blueprint blueprint, World world, int x, int y, int z, ForgeDirection orientation, IInventory inv) { @@ -44,8 +44,10 @@ public class BlueprintBuilder { this.inv = inv; this.buildList = blueprint.getBuildList(); builders = new ArrayList(buildList.size()); - for (BlockSchematic schematic : buildList) { - builders.add(new SchematicBuilder(schematic)); + for (Schematic schematic : buildList) { + BlockHandler handler = schematic.getHandler(); + if (handler != null) + builders.add(new SchematicBuilder(schematic, handler)); } } @@ -55,13 +57,13 @@ public class BlueprintBuilder { public class SchematicBuilder { - public final BlockSchematic schematic; + public final Schematic schematic; public final BlockHandler handler; private boolean complete; - private SchematicBuilder(BlockSchematic schematic) { + private SchematicBuilder(Schematic schematic, BlockHandler handler) { this.schematic = schematic; - this.handler = BlockHandler.get(schematic.block); + this.handler = handler; } public int getX() { @@ -95,11 +97,11 @@ public class BlueprintBuilder { } public boolean blockExists() { - return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData); + return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data); } public boolean canBuild() { - return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData); + return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic.data); } public boolean build(EntityPlayer bcPlayer) { @@ -114,7 +116,7 @@ public class BlueprintBuilder { if (!canBuild()) return false; - boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData, inv, bcPlayer); + boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.data, inv, bcPlayer); if (built) { markComplete(); diff --git a/common/buildcraft/builders/BlueprintDatabase.java b/common/buildcraft/builders/blueprints/BlueprintDatabase.java similarity index 98% rename from common/buildcraft/builders/BlueprintDatabase.java rename to common/buildcraft/builders/blueprints/BlueprintDatabase.java index 5123d97f..6cf10cf2 100644 --- a/common/buildcraft/builders/BlueprintDatabase.java +++ b/common/buildcraft/builders/blueprints/BlueprintDatabase.java @@ -6,7 +6,7 @@ * 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.builders; +package buildcraft.builders.blueprints; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; diff --git a/common/buildcraft/builders/blueprints/ItemSchematic.java b/common/buildcraft/builders/blueprints/ItemSchematic.java new file mode 100644 index 00000000..7567a325 --- /dev/null +++ b/common/buildcraft/builders/blueprints/ItemSchematic.java @@ -0,0 +1,43 @@ +package buildcraft.builders.blueprints; + +import buildcraft.api.builder.BlockHandler; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; + +/** + * + * @author CovertJaguar + */ +public final class ItemSchematic extends Schematic { + + public static ItemSchematic create(NBTTagCompound nbt) { + return null; + } + + public static ItemSchematic create(Item item) { + return new ItemSchematic(item); + } + public final Item item; + + private ItemSchematic(Item item) { + super(item.itemID); + this.item = item; + } + + private ItemSchematic(String itemName) { +// String blockName = nbt.getString("blockName"); + this((Item) null); // TODO: Add item from name code + } + + @Override + public BlockHandler getHandler() { + return BlockHandler.get(item); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setString("schematicType", "item"); + nbt.setString("itemName", item.getUnlocalizedName()); + } +} diff --git a/common/buildcraft/builders/blueprints/MaskSchematic.java b/common/buildcraft/builders/blueprints/MaskSchematic.java new file mode 100644 index 00000000..45a05d40 --- /dev/null +++ b/common/buildcraft/builders/blueprints/MaskSchematic.java @@ -0,0 +1,34 @@ +package buildcraft.builders.blueprints; + +import buildcraft.api.builder.BlockHandler; +import net.minecraft.nbt.NBTTagCompound; + +/** + * + * @author CovertJaguar + */ +public final class MaskSchematic extends Schematic { + + public static MaskSchematic create(NBTTagCompound nbt) { + return new MaskSchematic(); + } + + public static MaskSchematic create() { + return new MaskSchematic(); + } + + private MaskSchematic() { + super(0); + } + + @Override + public BlockHandler getHandler() { + return null; + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + nbt.setString("schematicType", "mask"); + } +} diff --git a/common/buildcraft/builders/blueprints/Schematic.java b/common/buildcraft/builders/blueprints/Schematic.java new file mode 100644 index 00000000..042453b8 --- /dev/null +++ b/common/buildcraft/builders/blueprints/Schematic.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) SpaceToad, 2011-2012 + * 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.builders.blueprints; + +import buildcraft.api.builder.BlockHandler; +import net.minecraft.nbt.NBTTagCompound; + +/** + * + * @author CovertJaguar + */ +public abstract class Schematic { + + public final int id; + public int x; + public int y; + public int z; + public NBTTagCompound data = new NBTTagCompound(); + + protected Schematic(int id) { + this.id = id; + } + + public abstract BlockHandler getHandler(); + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setInteger("x", x); + nbt.setInteger("y", y); + nbt.setInteger("z", z); + nbt.setCompoundTag("data", data); + } + + public void readFromNBT(NBTTagCompound nbt) { + x = nbt.getInteger("x"); + y = nbt.getInteger("y"); + z = nbt.getInteger("z"); + data = nbt.getCompoundTag("data"); + } + + public static Schematic createSchematicFromNBT(NBTTagCompound nbt) { + String schematicType = nbt.getString("schematicType"); + Schematic schematic; + if (schematicType.equals("block")) { + schematic = BlockSchematic.create(nbt); + } else if (schematicType.equals("item")) { + schematic = ItemSchematic.create(nbt); + } else { + return null; + } + schematic.x = nbt.getInteger("x"); + schematic.y = nbt.getInteger("y"); + schematic.z = nbt.getInteger("z"); + schematic.data = nbt.getCompoundTag("userData"); + return schematic; + } +} diff --git a/common/buildcraft/core/EntityRobot.java b/common/buildcraft/core/EntityRobot.java index 09168e07..397aa376 100644 --- a/common/buildcraft/core/EntityRobot.java +++ b/common/buildcraft/core/EntityRobot.java @@ -15,7 +15,7 @@ import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; import buildcraft.BuildCraftCore; -import buildcraft.builders.BlueprintBuilder.SchematicBuilder; +import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder; import buildcraft.api.core.Position; import buildcraft.core.proxy.CoreProxy; import buildcraft.core.utils.BlockUtil; diff --git a/common/buildcraft/factory/TileQuarry.java b/common/buildcraft/factory/TileQuarry.java index 8d5202d0..ed3f8a40 100755 --- a/common/buildcraft/factory/TileQuarry.java +++ b/common/buildcraft/factory/TileQuarry.java @@ -24,9 +24,9 @@ import net.minecraftforge.common.ForgeChunkManager.Type; import net.minecraftforge.common.ForgeDirection; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftFactory; -import buildcraft.builders.Blueprint; -import buildcraft.builders.BlueprintBuilder; -import buildcraft.builders.BlueprintBuilder.SchematicBuilder; +import buildcraft.builders.blueprints.Blueprint; +import buildcraft.builders.blueprints.BlueprintBuilder; +import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder; import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.LaserKind; import buildcraft.api.gates.IAction; @@ -606,22 +606,22 @@ public class TileQuarry extends TileBuildCraft implements IMachine, IPowerRecept for (int it = 0; it < 2; it++) { for (int i = 0; i < blueprint.sizeX; ++i) { - blueprint.setBlock(worldObj, i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID, 0); - blueprint.setBlock(worldObj, i, it * (box.sizeY() - 1), blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, i, it * (box.sizeY() - 1), blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); } for (int k = 0; k < blueprint.sizeZ; ++k) { - blueprint.setBlock(worldObj, 0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0); - blueprint.setBlock(worldObj, blueprint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, 0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, blueprint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0); } } for (int h = 1; h < box.sizeY(); ++h) { - blueprint.setBlock(worldObj, 0, h, 0, BuildCraftFactory.frameBlock.blockID, 0); - blueprint.setBlock(worldObj, 0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); - blueprint.setBlock(worldObj, blueprint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID, 0); - blueprint.setBlock(worldObj, blueprint.sizeX - 1, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, 0, h, 0, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, 0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, blueprint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID, 0); + blueprint.setSchematic(worldObj, blueprint.sizeX - 1, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); } blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, box.xMin, yCoord, box.zMin, ForgeDirection.NORTH, null);