Moved everything again.

Fleshed out Schematic classes.
Quarry works in this build.
This commit is contained in:
CovertJaguar 2013-07-02 06:42:34 -07:00
parent 3a8c0f95c8
commit 4d547c89f4
13 changed files with 340 additions and 120 deletions

View file

@ -8,7 +8,7 @@
package buildcraft; package buildcraft;
import buildcraft.builders.BlueprintDatabase; import buildcraft.builders.blueprints.BlueprintDatabase;
import java.io.File; import java.io.File;
import java.util.TreeMap; import java.util.TreeMap;
import java.util.logging.Logger; import java.util.logging.Logger;

View file

@ -7,6 +7,8 @@ import java.util.Map;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -20,24 +22,44 @@ import net.minecraftforge.common.ForgeDirection;
*/ */
public class BlockHandler { public class BlockHandler {
private static final Map<Block, BlockHandler> handlers = new HashMap<Block, BlockHandler>(); private static final Map<Integer, BlockHandler> handlers = new HashMap<Integer, BlockHandler>();
private final Block block; 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) { 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) { if (handler == null) {
handler = new BlockHandler(block); handler = new BlockHandler(id);
registerHandler(block, handler); registerHandler(id, handler);
} }
return handler; return handler;
} }
public static void registerHandler(Block block, BlockHandler handler) { public static void registerHandler(Block block, BlockHandler handler) {
handlers.put(block, handler); handlers.put(block.blockID, handler);
} }
public BlockHandler(Block block) { public static void registerHandler(Item item, BlockHandler handler) {
this.block = block; 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. * 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); int meta = world.getBlockMetadata(x, y, z);
try { try {
if (block.idDropped(meta, null, 0) != block.blockID) { if (block.idDropped(meta, null, 0) != id)
return false; return false;
}
} catch (NullPointerException ex) { } catch (NullPointerException ex) {
return false; 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) { public boolean canSaveToSchematic(ItemStack stack) {
blockData.setByte("blockMeta", (byte) world.getBlockMetadata(x, y, z)); 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. * 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()) 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 * entities and will in fact break on Ore blocks as well. Which is why those
* blocks can't be saved by default. * blocks can't be saved by default.
*/ */
public List<ItemStack> getCostForSchematic(NBTTagCompound blockData) { public List<ItemStack> getCostForSchematic(NBTTagCompound data) {
List<ItemStack> cost = new ArrayList<ItemStack>(); List<ItemStack> cost = new ArrayList<ItemStack>();
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; return cost;
} }
@ -108,7 +168,7 @@ public class BlockHandler {
* Can the block be placed currently or is it waiting on some other block to * Can the block be placed currently or is it waiting on some other block to
* be placed first? * 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; return true;
} }
@ -126,9 +186,9 @@ public class BlockHandler {
* modify any ItemStack in the inventory until you have determined that * modify any ItemStack in the inventory until you have determined that
* everything you require is present. * 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) { if (builderInventory != null) {
List<ItemStack> requiredItems = getCostForSchematic(blockData); List<ItemStack> requiredItems = getCostForSchematic(data);
List<Integer> slotsToConsume = new ArrayList<Integer>(); List<Integer> slotsToConsume = new ArrayList<Integer>();
for (ItemStack cost : requiredItems) { for (ItemStack cost : requiredItems) {
boolean found = false; boolean found = false;
@ -146,16 +206,16 @@ public class BlockHandler {
builderInventory.setInventorySlotContents(slot, BlueprintHelpers.consumeItem(builderInventory.getStackInSlot(slot))); 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. * Checks if the block matches the schematic.
*/ */
public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData) { public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound data) {
if (block.blockID != world.getBlockId(x, y, z)) if (id != world.getBlockId(x, y, z))
return false; 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);
} }
} }

View file

@ -1,40 +0,0 @@
package buildcraft.builders;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
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;
}
}

View file

@ -7,6 +7,7 @@
*/ */
package buildcraft.builders; package buildcraft.builders;
import buildcraft.builders.blueprints.Blueprint;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -143,7 +144,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
if (!worldObj.isAirBlock(x, y, z)) { if (!worldObj.isAirBlock(x, y, z)) {
Block block = Block.blocksList[worldObj.getBlockId(x, y, z)]; Block block = Block.blocksList[worldObj.getBlockId(x, y, z)];
if (block != null) { 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);
} }
} }
} }

View file

@ -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 <http://www.railcraft.info/>
*/
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());
}
}

View file

@ -5,12 +5,11 @@
* 1.0, or MMPL. Please check the contents of the license located in * 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.builders; package buildcraft.builders.blueprints;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.api.builder.BlockHandler; import buildcraft.api.builder.BlockHandler;
import buildcraft.core.inventory.StackHelper; import buildcraft.core.inventory.StackHelper;
import buildcraft.factory.TileQuarry;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
@ -35,7 +34,7 @@ public class Blueprint {
private final UUID uuid; private final UUID uuid;
private String name; private String name;
private String creator; private String creator;
private final BlockSchematic[][][] blocks; private final Schematic[][][] schematics;
public final int sizeX, sizeY, sizeZ; public final int sizeX, sizeY, sizeZ;
public int anchorX, anchorY, anchorZ; public int anchorX, anchorY, anchorZ;
public ForgeDirection anchorOrientation = ForgeDirection.NORTH; public ForgeDirection anchorOrientation = ForgeDirection.NORTH;
@ -50,7 +49,7 @@ public class Blueprint {
this.sizeX = sizeX; this.sizeX = sizeX;
this.sizeY = sizeY; this.sizeY = sizeY;
this.sizeZ = sizeZ; this.sizeZ = sizeZ;
blocks = new BlockSchematic[sizeX][sizeY][sizeZ]; schematics = new Schematic[sizeX][sizeY][sizeZ];
} }
public String getName() { public String getName() {
@ -61,22 +60,22 @@ public class Blueprint {
this.name = name; 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) if (schematic == null)
return; return;
schematic.x = x; schematic.x = x;
schematic.y = y; schematic.y = y;
schematic.z = z; 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); BlockHandler handler = BlockHandler.get(block);
try { try {
if (handler.canSaveBlockToSchematic(world, x, y, z)) { if (handler.canSaveToSchematic(world, x, y, z)) {
BlockSchematic schematic = new BlockSchematic(block); Schematic schematic = BlockSchematic.create(block);
handler.saveToSchematic(world, x, y, z, schematic.blockData); handler.saveToSchematic(world, x, y, z, schematic.data);
setBlock(world, x, y, z, schematic); setSchematic(x, y, z, schematic);
} }
} catch (Throwable error) { } catch (Throwable error) {
BuildCraftCore.bcLog.severe(String.format("Error while trying to save block [%s:%d] to blueprint, skipping.", block.getUnlocalizedName(), block.blockID)); 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. * Helper function for creating Blueprints in code.
* *
@ -92,18 +107,18 @@ public class Blueprint {
* *
* @see TileQuarry * @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]; Block block = Block.blocksList[id];
if (block == null) { if (block == null) {
return; return;
} }
BlockSchematic schematic = new BlockSchematic(block); BlockSchematic schematic = BlockSchematic.create(block);
schematic.blockData.setByte("blockMeta", (byte) meta); schematic.data.setByte("blockMeta", (byte) meta);
setBlock(world, x, y, z, schematic); setSchematic(x, y, z, schematic);
} }
public BlockSchematic getBlock(int x, int y, int z) { public Schematic getBlock(int x, int y, int z) {
return blocks[x][y][z]; return schematics[x][y][z];
} }
public UUID getUUID() { public UUID getUUID() {
@ -119,13 +134,13 @@ public class Blueprint {
* *
* @return List<BlockScematic> * @return List<BlockScematic>
*/ */
public LinkedList<BlockSchematic> getBuildList() { public LinkedList<Schematic> getBuildList() {
LinkedList<BlockSchematic> list = new LinkedList<BlockSchematic>(); LinkedList<Schematic> list = new LinkedList<Schematic>();
for (int y = 0; y < sizeY; y++) { for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) { for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) { for (int z = 0; z < sizeZ; z++) {
if (blocks[x][y][z] != null) if (schematics[x][y][z] != null)
list.add(blocks[x][y][z]); list.add(schematics[x][y][z]);
} }
} }
} }
@ -136,9 +151,9 @@ public class Blueprint {
if (costs != null) if (costs != null)
return costs; return costs;
List<ItemStack> stacks = new ArrayList<ItemStack>(); List<ItemStack> stacks = new ArrayList<ItemStack>();
for (BlockSchematic schematic : getBuildList()) { for (Schematic schematic : getBuildList()) {
BlockHandler handler = BlockHandler.get(schematic.block); BlockHandler handler = BlockHandler.get(schematic.id);
List<ItemStack> requirements = handler.getCostForSchematic(schematic.blockData); List<ItemStack> requirements = handler.getCostForSchematic(schematic.data);
for (ItemStack newStack : requirements) { for (ItemStack newStack : requirements) {
if (newStack.stackSize <= 0) if (newStack.stackSize <= 0)
continue; continue;
@ -160,10 +175,10 @@ public class Blueprint {
for (int y = 0; y < sizeY; y++) { for (int y = 0; y < sizeY; y++) {
for (int x = 0; x < sizeX; x++) { for (int x = 0; x < sizeX; x++) {
for (int z = 0; z < sizeZ; z++) { for (int z = 0; z < sizeZ; z++) {
if (blocks[x][y][z] == null) if (schematics[x][y][z] == null)
continue; continue;
NBTTagCompound blockNBT = new NBTTagCompound(); NBTTagCompound blockNBT = new NBTTagCompound();
blocks[x][y][z].writeToNBT(nbt); schematics[x][y][z].writeToNBT(nbt);
blockList.appendTag(blockNBT); blockList.appendTag(blockNBT);
} }
} }
@ -204,8 +219,8 @@ public class Blueprint {
NBTTagList blockList = nbt.getTagList("blocks"); NBTTagList blockList = nbt.getTagList("blocks");
for (int i = 0; i < blockList.tagCount(); i++) { for (int i = 0; i < blockList.tagCount(); i++) {
NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i); NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i);
BlockSchematic block = BlockSchematic.readFromNBT(blockNBT); Schematic schematic = Schematic.createSchematicFromNBT(blockNBT);
blueprint.blocks[block.x][block.y][block.z] = block; blueprint.schematics[schematic.x][schematic.y][schematic.z] = schematic;
} }
return blueprint; return blueprint;
} }

View file

@ -6,10 +6,10 @@
* License 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.builders; package buildcraft.builders.blueprints;
import buildcraft.api.builder.BlockHandler; import buildcraft.api.builder.BlockHandler;
import buildcraft.builders.BlueprintBuilder.SchematicBuilder; import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
@ -31,7 +31,7 @@ public class BlueprintBuilder {
public final World worldObj; public final World worldObj;
public final int x, y, z; public final int x, y, z;
private final IInventory inv; private final IInventory inv;
private final LinkedList<BlockSchematic> buildList; private final LinkedList<Schematic> buildList;
private final List<SchematicBuilder> builders; private final List<SchematicBuilder> builders;
public BlueprintBuilder(Blueprint blueprint, World world, int x, int y, int z, ForgeDirection orientation, IInventory inv) { 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.inv = inv;
this.buildList = blueprint.getBuildList(); this.buildList = blueprint.getBuildList();
builders = new ArrayList<SchematicBuilder>(buildList.size()); builders = new ArrayList<SchematicBuilder>(buildList.size());
for (BlockSchematic schematic : buildList) { for (Schematic schematic : buildList) {
builders.add(new SchematicBuilder(schematic)); BlockHandler handler = schematic.getHandler();
if (handler != null)
builders.add(new SchematicBuilder(schematic, handler));
} }
} }
@ -55,13 +57,13 @@ public class BlueprintBuilder {
public class SchematicBuilder { public class SchematicBuilder {
public final BlockSchematic schematic; public final Schematic schematic;
public final BlockHandler handler; public final BlockHandler handler;
private boolean complete; private boolean complete;
private SchematicBuilder(BlockSchematic schematic) { private SchematicBuilder(Schematic schematic, BlockHandler handler) {
this.schematic = schematic; this.schematic = schematic;
this.handler = BlockHandler.get(schematic.block); this.handler = handler;
} }
public int getX() { public int getX() {
@ -95,11 +97,11 @@ public class BlueprintBuilder {
} }
public boolean blockExists() { 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() { 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) { public boolean build(EntityPlayer bcPlayer) {
@ -114,7 +116,7 @@ public class BlueprintBuilder {
if (!canBuild()) if (!canBuild())
return false; 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) { if (built) {
markComplete(); markComplete();

View file

@ -6,7 +6,7 @@
* License 1.0, or MMPL. Please check the contents of the license located in * License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * 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.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;

View file

@ -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 <http://www.railcraft.info/>
*/
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());
}
}

View file

@ -0,0 +1,34 @@
package buildcraft.builders.blueprints;
import buildcraft.api.builder.BlockHandler;
import net.minecraft.nbt.NBTTagCompound;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
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");
}
}

View file

@ -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 <http://www.railcraft.info/>
*/
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;
}
}

View file

@ -15,7 +15,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World; import net.minecraft.world.World;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.builders.BlueprintBuilder.SchematicBuilder; import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
import buildcraft.api.core.Position; import buildcraft.api.core.Position;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BlockUtil; import buildcraft.core.utils.BlockUtil;

View file

@ -24,9 +24,9 @@ import net.minecraftforge.common.ForgeChunkManager.Type;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftFactory; import buildcraft.BuildCraftFactory;
import buildcraft.builders.Blueprint; import buildcraft.builders.blueprints.Blueprint;
import buildcraft.builders.BlueprintBuilder; import buildcraft.builders.blueprints.BlueprintBuilder;
import buildcraft.builders.BlueprintBuilder.SchematicBuilder; import buildcraft.builders.blueprints.BlueprintBuilder.SchematicBuilder;
import buildcraft.api.core.IAreaProvider; import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.LaserKind; import buildcraft.api.core.LaserKind;
import buildcraft.api.gates.IAction; 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 it = 0; it < 2; it++) {
for (int i = 0; i < blueprint.sizeX; ++i) { for (int i = 0; i < blueprint.sizeX; ++i) {
blueprint.setBlock(worldObj, i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID, 0); blueprint.setSchematic(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), blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
} }
for (int k = 0; k < blueprint.sizeZ; ++k) { for (int k = 0; k < blueprint.sizeZ; ++k) {
blueprint.setBlock(worldObj, 0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0); blueprint.setSchematic(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, blueprint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0);
} }
} }
for (int h = 1; h < box.sizeY(); ++h) { for (int h = 1; h < box.sizeY(); ++h) {
blueprint.setBlock(worldObj, 0, h, 0, BuildCraftFactory.frameBlock.blockID, 0); blueprint.setSchematic(worldObj, 0, h, 0, BuildCraftFactory.frameBlock.blockID, 0);
blueprint.setBlock(worldObj, 0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0); blueprint.setSchematic(worldObj, 0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
blueprint.setBlock(worldObj, blueprint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID, 0); blueprint.setSchematic(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, blueprint.sizeX - 1, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
} }
blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, box.xMin, yCoord, box.zMin, ForgeDirection.NORTH, null); blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, box.xMin, yCoord, box.zMin, ForgeDirection.NORTH, null);