Significant rework of API
Moved everything not needed out of API package. Rewrote BlockHandler and BlockSchematic to be more NBT dependant.
This commit is contained in:
parent
4a1469a055
commit
3a8c0f95c8
10 changed files with 173 additions and 163 deletions
|
@ -8,7 +8,7 @@
|
|||
|
||||
package buildcraft;
|
||||
|
||||
import buildcraft.api.builder.BlueprintDatabase;
|
||||
import buildcraft.builders.BlueprintDatabase;
|
||||
import java.io.File;
|
||||
import java.util.TreeMap;
|
||||
import java.util.logging.Logger;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package buildcraft.api.builder;
|
||||
|
||||
import buildcraft.core.utils.Utils;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -9,6 +8,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
|
@ -20,30 +20,24 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
*/
|
||||
public class BlockHandler {
|
||||
|
||||
private static final BlockHandler DEFAULT_HANDLER = new BlockHandler();
|
||||
private static final Map<Integer, BlockHandler> handlers = new HashMap<Integer, BlockHandler>();
|
||||
private static final Map<Block, BlockHandler> handlers = new HashMap<Block, BlockHandler>();
|
||||
private final Block block;
|
||||
|
||||
public static BlockHandler getHandler(int blockId) {
|
||||
BlockHandler handler = handlers.get(blockId);
|
||||
public static BlockHandler get(Block block) {
|
||||
BlockHandler handler = handlers.get(block);
|
||||
if (handler == null) {
|
||||
return DEFAULT_HANDLER;
|
||||
handler = new BlockHandler(block);
|
||||
registerHandler(block, handler);
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
public static BlockHandler getHandler(BlockSchematic schematic) {
|
||||
BlockHandler handler = null; // TODO: replace with mapping -> id code
|
||||
if (handler == null) {
|
||||
return DEFAULT_HANDLER;
|
||||
}
|
||||
return handler;
|
||||
public static void registerHandler(Block block, BlockHandler handler) {
|
||||
handlers.put(block, handler);
|
||||
}
|
||||
|
||||
public static void registerHandler(int blockId, BlockHandler handler) {
|
||||
handlers.put(blockId, handler);
|
||||
}
|
||||
|
||||
protected BlockHandler() {
|
||||
public BlockHandler(Block block) {
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -52,17 +46,9 @@ 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) {
|
||||
if (world.isAirBlock(x, y, z)) {
|
||||
return false;
|
||||
}
|
||||
int blockId = world.getBlockId(x, y, z);
|
||||
Block block = Block.blocksList[blockId];
|
||||
if (block == null) {
|
||||
return false;
|
||||
}
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
try {
|
||||
if (block.idDropped(meta, null, 0) != blockId) {
|
||||
if (block.idDropped(meta, null, 0) != block.blockID) {
|
||||
return false;
|
||||
}
|
||||
} catch (NullPointerException ex) {
|
||||
|
@ -74,18 +60,20 @@ public class BlockHandler {
|
|||
/**
|
||||
* It is assumed that Blueprints always face North on save.
|
||||
*
|
||||
* Tile Entities should store some NBT data in the BlockSchematic.blockData
|
||||
* tag.
|
||||
* Store any info you need to reproduce the block in the data tag.
|
||||
*/
|
||||
public BlockSchematic saveBlockToSchematic(World world, int x, int y, int z) {
|
||||
int blockId = world.getBlockId(x, y, z);
|
||||
Block block = Block.blocksList[blockId];
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
BlockSchematic schematic = new BlockSchematic(block);
|
||||
schematic.blockMeta = world.getBlockMetadata(x, y, z);
|
||||
return schematic;
|
||||
public void saveToSchematic(World world, int x, int y, int z, NBTTagCompound blockData) {
|
||||
blockData.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 in the data tag.
|
||||
*/
|
||||
public void saveToSchematic(ItemStack stack, NBTTagCompound blockData) {
|
||||
if (stack.getHasSubtypes())
|
||||
blockData.setByte("blockMeta", (byte) stack.getItemDamage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -93,50 +81,18 @@ public class BlockHandler {
|
|||
* schematic.
|
||||
*
|
||||
* If you need axillary items like a painter or gate, list them as well.
|
||||
* Items will be consumed in the consumeItems() callback below.
|
||||
* Items will be consumed in the readBlockFromSchematic() function below.
|
||||
*
|
||||
* This default implementation will only work for simple blocks without tile
|
||||
* entities and will in fact break on Ore blocks as well. Which is why those
|
||||
* blocks can't be saved by default.
|
||||
*/
|
||||
public List<ItemStack> getCostForSchematic(BlockSchematic schematic) {
|
||||
public List<ItemStack> getCostForSchematic(NBTTagCompound blockData) {
|
||||
List<ItemStack> cost = new ArrayList<ItemStack>();
|
||||
Block block = null; // TODO: replace with mapping -> id code
|
||||
if (block != null) {
|
||||
cost.add(new ItemStack(block.idDropped(schematic.blockMeta, Utils.RANDOM, 0), 1, block.damageDropped(schematic.blockMeta)));
|
||||
}
|
||||
cost.add(new ItemStack(block.idDropped(blockData.getByte("blockMeta"), BlueprintHelpers.RANDOM, 0), 1, block.damageDropped(blockData.getByte("blockMeta"))));
|
||||
return cost;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when items are consumed for this block. The builder's inventory is
|
||||
* passed in. Use them as you see fit.
|
||||
*
|
||||
* If the function returns false, the block is not placed. You should not
|
||||
* modify any ItemStack until you have determined that everything you
|
||||
* require is present.
|
||||
*/
|
||||
public boolean consumeItems(BlockSchematic schematic, IInventory builderInventory) {
|
||||
List<ItemStack> requiredItems = getCostForSchematic(schematic);
|
||||
List<Integer> slotsToConsume = new ArrayList<Integer>();
|
||||
for (ItemStack cost : requiredItems) {
|
||||
boolean found = false;
|
||||
for (int slot = 0; slot < builderInventory.getSizeInventory(); slot++) {
|
||||
if (areItemsEqual(builderInventory.getStackInSlot(slot), cost)) {
|
||||
slotsToConsume.add(slot);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
for (Integer slot : slotsToConsume) {
|
||||
builderInventory.setInventorySlotContents(slot, Utils.consumeItem(builderInventory.getStackInSlot(slot)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean areItemsEqual(ItemStack stack1, ItemStack stack2) {
|
||||
if (stack1 == null || stack2 == null)
|
||||
return false;
|
||||
|
@ -152,7 +108,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, BlockSchematic schematic) {
|
||||
public boolean canPlaceNow(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -162,26 +118,44 @@ public class BlockHandler {
|
|||
* The ForgeDirection parameter can be use to determine the orientation of
|
||||
* the blueprint. Blueprints are always saved facing North. This function
|
||||
* will have to rotate the block accordingly.
|
||||
*
|
||||
* The builder's inventory is passed in so you can consume the items you
|
||||
* need. Use them as you see fit.
|
||||
*
|
||||
* If the function returns false, the block was not placed. You should not
|
||||
* 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, BlockSchematic schematic, EntityPlayer bcPlayer) {
|
||||
if (schematic.blockId != 0) {
|
||||
return world.setBlock(x, y, z, schematic.blockId, schematic.blockMeta, 3);
|
||||
public boolean readBlockFromSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData, IInventory builderInventory, EntityPlayer bcPlayer) {
|
||||
if (builderInventory != null) {
|
||||
List<ItemStack> requiredItems = getCostForSchematic(blockData);
|
||||
List<Integer> slotsToConsume = new ArrayList<Integer>();
|
||||
for (ItemStack cost : requiredItems) {
|
||||
boolean found = false;
|
||||
for (int slot = 0; slot < builderInventory.getSizeInventory(); slot++) {
|
||||
if (areItemsEqual(builderInventory.getStackInSlot(slot), cost)) {
|
||||
slotsToConsume.add(slot);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
return false;
|
||||
}
|
||||
for (Integer slot : slotsToConsume) {
|
||||
builderInventory.setInventorySlotContents(slot, BlueprintHelpers.consumeItem(builderInventory.getStackInSlot(slot)));
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return world.setBlock(x, y, z, block.blockID, blockData.getByte("blockMeta"), 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the block matches the schematic.
|
||||
*/
|
||||
public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, BlockSchematic schematic) {
|
||||
int blockId = world.getBlockId(x, y, z);
|
||||
Block block = Block.blocksList[blockId];
|
||||
if (block == null) {
|
||||
public boolean doesBlockMatchSchematic(World world, int x, int y, int z, ForgeDirection blueprintOrientation, NBTTagCompound blockData) {
|
||||
if (block.blockID != world.getBlockId(x, y, z))
|
||||
return false;
|
||||
}
|
||||
if (!schematic.blockName.equals(block.getUnlocalizedName())) {
|
||||
return false;
|
||||
}
|
||||
return schematic.blockMeta == world.getBlockMetadata(x, y, z);
|
||||
|
||||
return !blockData.hasKey("blockMeta") || blockData.getByte("blockMeta") == world.getBlockMetadata(x, y, z);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package buildcraft.api.builder;
|
||||
|
||||
import java.util.Random;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
|
@ -7,12 +9,14 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
* @author CovertJaguar <http://www.railcraft.info/>
|
||||
*/
|
||||
public class BlueprintHelpers {
|
||||
|
||||
public static final Random RANDOM = new Random();
|
||||
|
||||
/**
|
||||
* Takes a schematic orientation and blueprint orientation and returns the
|
||||
* orientation that should be used in the world. Admittedly this is not
|
||||
* sufficient for 24-point rotation. If you need something more complex,
|
||||
* you will have to handle it yourself.
|
||||
* sufficient for 24-point rotation. If you need something more complex, you
|
||||
* will have to handle it yourself.
|
||||
*/
|
||||
public static ForgeDirection rotateOrientation(ForgeDirection schematicOrientation, ForgeDirection blueprintOrientation) {
|
||||
if (schematicOrientation == ForgeDirection.UP || schematicOrientation == ForgeDirection.DOWN) {
|
||||
|
@ -29,4 +33,23 @@ public class BlueprintHelpers {
|
|||
}
|
||||
return schematicOrientation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Takes an ItemStack and uses one. Replaces containers as needed.
|
||||
*
|
||||
* @return the new ItemStack
|
||||
*/
|
||||
public static ItemStack consumeItem(ItemStack stack) {
|
||||
if (stack.stackSize == 1) {
|
||||
if (stack.getItem().hasContainerItem()) {
|
||||
return stack.getItem().getContainerItemStack(stack);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
stack.splitStack(1);
|
||||
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package buildcraft.api.builder;
|
||||
package buildcraft.builders;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -9,28 +9,20 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
*/
|
||||
public final class BlockSchematic {
|
||||
|
||||
public final String blockName;
|
||||
public final int blockId;
|
||||
public int blockMeta = 0;
|
||||
public NBTTagCompound blockData = null;
|
||||
public final Block block;
|
||||
public NBTTagCompound blockData = new NBTTagCompound();
|
||||
public int x, y, z;
|
||||
|
||||
public BlockSchematic(Block block) {
|
||||
this(block.getUnlocalizedName(), block.blockID);
|
||||
this.block = block;
|
||||
}
|
||||
|
||||
public BlockSchematic(String blockName) {
|
||||
this(blockName, 0); // TODO: Add block id from name
|
||||
}
|
||||
|
||||
public BlockSchematic(String blockName, int blockId) {
|
||||
this.blockName = blockName;
|
||||
this.blockId = blockId;
|
||||
this((Block) null); // TODO: Add block from name code
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
nbt.setString("blockName", blockName);
|
||||
nbt.setByte("blockMeta", (byte) blockMeta);
|
||||
nbt.setString("blockName", block.getUnlocalizedName());
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
|
@ -39,13 +31,10 @@ public final class BlockSchematic {
|
|||
|
||||
public static BlockSchematic readFromNBT(NBTTagCompound nbt) {
|
||||
BlockSchematic block = new BlockSchematic(nbt.getString("blockName"));
|
||||
block.blockMeta = nbt.getInteger("blockMeta");
|
||||
block.x = nbt.getInteger("x");
|
||||
block.y = nbt.getInteger("y");
|
||||
block.z = nbt.getInteger("z");
|
||||
if (nbt.hasKey("blockData")) {
|
||||
block.blockData = nbt.getCompoundTag("blockData");
|
||||
}
|
||||
block.blockData = nbt.getCompoundTag("blockData");
|
||||
return block;
|
||||
}
|
||||
}
|
|
@ -5,8 +5,10 @@
|
|||
* 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.builder;
|
||||
package buildcraft.builders;
|
||||
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import buildcraft.factory.TileQuarry;
|
||||
import java.util.ArrayList;
|
||||
|
@ -18,6 +20,8 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This class is used to represent the data of the blueprint as it exists in the
|
||||
|
@ -33,6 +37,8 @@ public class Blueprint {
|
|||
private String creator;
|
||||
private final BlockSchematic[][][] blocks;
|
||||
public final int sizeX, sizeY, sizeZ;
|
||||
public int anchorX, anchorY, anchorZ;
|
||||
public ForgeDirection anchorOrientation = ForgeDirection.NORTH;
|
||||
private List<ItemStack> costs;
|
||||
|
||||
public Blueprint(int sizeX, int sizeY, int sizeZ) {
|
||||
|
@ -55,28 +61,45 @@ public class Blueprint {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void setBlock(int x, int y, int z, BlockSchematic block) {
|
||||
block.x = x;
|
||||
block.y = y;
|
||||
block.z = z;
|
||||
blocks[x][y][z] = block;
|
||||
private void setBlock(World world, int x, int y, int z, BlockSchematic schematic) {
|
||||
if (schematic == null)
|
||||
return;
|
||||
schematic.x = x;
|
||||
schematic.y = y;
|
||||
schematic.z = z;
|
||||
blocks[x][y][z] = schematic;
|
||||
}
|
||||
|
||||
public void setBlock(World world, int x, int y, int z, 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);
|
||||
}
|
||||
} 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.throwing(getClass().getCanonicalName(), "setBlock", error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function for creating Blueprints in code.
|
||||
*
|
||||
* Not recommended for use with complex blocks.
|
||||
* Not recommended for use with complex blocks because it doesn't go through
|
||||
* a hander to get a BlockSchematic.
|
||||
*
|
||||
* @see TileQuarry
|
||||
*/
|
||||
public void setBlock(int x, int y, int z, int id, int meta) {
|
||||
public void setBlock(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.blockMeta = meta;
|
||||
setBlock(x, y, z, schematic);
|
||||
schematic.blockData.setByte("blockMeta", (byte) meta);
|
||||
setBlock(world, x, y, z, schematic);
|
||||
}
|
||||
|
||||
public BlockSchematic getBlock(int x, int y, int z) {
|
||||
|
@ -114,8 +137,8 @@ public class Blueprint {
|
|||
return costs;
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>();
|
||||
for (BlockSchematic schematic : getBuildList()) {
|
||||
BlockHandler handler = BlockHandler.getHandler(schematic);
|
||||
List<ItemStack> requirements = handler.getCostForSchematic(schematic);
|
||||
BlockHandler handler = BlockHandler.get(schematic.block);
|
||||
List<ItemStack> requirements = handler.getCostForSchematic(schematic.blockData);
|
||||
for (ItemStack newStack : requirements) {
|
||||
if (newStack.stackSize <= 0)
|
||||
continue;
|
||||
|
@ -154,6 +177,10 @@ public class Blueprint {
|
|||
nbt.setInteger("sizeX", sizeX);
|
||||
nbt.setInteger("sizeY", sizeY);
|
||||
nbt.setInteger("sizeZ", sizeZ);
|
||||
nbt.setInteger("anchorX", sizeX);
|
||||
nbt.setInteger("anchorY", sizeY);
|
||||
nbt.setInteger("anchorZ", sizeZ);
|
||||
nbt.setByte("anchorOrientation", (byte) anchorOrientation.ordinal());
|
||||
}
|
||||
|
||||
public static Blueprint readFromNBT(NBTTagCompound nbt) {
|
||||
|
@ -168,6 +195,12 @@ public class Blueprint {
|
|||
blueprint.name = nbt.getString("name");
|
||||
blueprint.creator = nbt.getString("creator");
|
||||
|
||||
blueprint.anchorX = nbt.getInteger("anchorX");
|
||||
blueprint.anchorY = nbt.getInteger("anchorY");
|
||||
blueprint.anchorZ = nbt.getInteger("anchorZ");
|
||||
|
||||
blueprint.anchorOrientation = ForgeDirection.getOrientation(nbt.getByte("anchorOrientation"));
|
||||
|
||||
NBTTagList blockList = nbt.getTagList("blocks");
|
||||
for (int i = 0; i < blockList.tagCount(); i++) {
|
||||
NBTTagCompound blockNBT = (NBTTagCompound) blockList.tagAt(i);
|
|
@ -6,9 +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.api.builder;
|
||||
package buildcraft.builders;
|
||||
|
||||
import buildcraft.api.builder.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.api.builder.BlockHandler;
|
||||
import buildcraft.builders.BlueprintBuilder.SchematicBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
|
@ -60,7 +61,7 @@ public class BlueprintBuilder {
|
|||
|
||||
private SchematicBuilder(BlockSchematic schematic) {
|
||||
this.schematic = schematic;
|
||||
this.handler = BlockHandler.getHandler(schematic);
|
||||
this.handler = BlockHandler.get(schematic.block);
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
|
@ -94,11 +95,11 @@ public class BlueprintBuilder {
|
|||
}
|
||||
|
||||
public boolean blockExists() {
|
||||
return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic);
|
||||
return handler.doesBlockMatchSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData);
|
||||
}
|
||||
|
||||
public boolean canBuild() {
|
||||
return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic);
|
||||
return handler.canPlaceNow(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData);
|
||||
}
|
||||
|
||||
public boolean build(EntityPlayer bcPlayer) {
|
||||
|
@ -113,11 +114,7 @@ public class BlueprintBuilder {
|
|||
if (!canBuild())
|
||||
return false;
|
||||
|
||||
if (inv != null && !handler.consumeItems(schematic, inv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic, bcPlayer);
|
||||
boolean built = handler.readBlockFromSchematic(worldObj, getX(), getY(), getZ(), orientation, schematic.blockData, inv, bcPlayer);
|
||||
|
||||
if (built) {
|
||||
markComplete();
|
|
@ -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.api.builder;
|
||||
package buildcraft.builders;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
|
@ -1,12 +1,10 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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
|
||||
/**
|
||||
* Copyright (c) SpaceToad, 2011 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;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
@ -23,25 +21,21 @@ import buildcraft.core.TileBuildCraft;
|
|||
import buildcraft.core.blueprints.BptBase;
|
||||
import buildcraft.core.blueprints.BptBlueprint;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.BptTemplate;
|
||||
import buildcraft.core.network.PacketUpdate;
|
||||
import buildcraft.core.network.TileNetworkData;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.Utils;
|
||||
import net.minecraft.block.Block;
|
||||
|
||||
public class TileArchitect extends TileBuildCraft implements IInventory {
|
||||
|
||||
public @TileNetworkData
|
||||
Box box = new Box();
|
||||
|
||||
private ItemStack items[] = new ItemStack[2];
|
||||
|
||||
private boolean isComputing = false;
|
||||
public int computingTime = 0;
|
||||
|
||||
public @TileNetworkData
|
||||
String name = "";
|
||||
|
||||
// Use that field to avoid creating several times the same template if
|
||||
// they're the same!
|
||||
private int lastBptId = 0;
|
||||
|
@ -141,21 +135,23 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
mask0 = 1;
|
||||
}
|
||||
|
||||
BptBase result = new BptTemplate(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
Blueprint blueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
|
||||
for (int x = box.xMin; x <= box.xMax; ++x) {
|
||||
for (int y = box.yMin; y <= box.yMax; ++y) {
|
||||
for (int z = box.zMin; z <= box.zMax; ++z) {
|
||||
if (worldObj.getBlockId(x, y, z) != 0) {
|
||||
result.setBlockId(x - box.xMin, y - box.yMin, z - box.zMin, mask1);
|
||||
} else {
|
||||
result.setBlockId(x - box.xMin, y - box.yMin, z - box.zMin, mask0);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
// return blueprint;
|
||||
return null;
|
||||
}
|
||||
|
||||
private BptBase createBptBlueprint() {
|
||||
|
@ -241,7 +237,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
public int getInventoryStackLimit() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isStackValidForSlot(int i, ItemStack itemstack) {
|
||||
// TODO Auto-generated method stub
|
||||
|
@ -366,11 +362,9 @@ public class TileArchitect extends TileBuildCraft implements IInventory {
|
|||
|
||||
@Override
|
||||
public void openChest() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeChest() {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.api.builder.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.builders.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.proxy.CoreProxy;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
|
|
|
@ -24,9 +24,9 @@ import net.minecraftforge.common.ForgeChunkManager.Type;
|
|||
import net.minecraftforge.common.ForgeDirection;
|
||||
import buildcraft.BuildCraftCore;
|
||||
import buildcraft.BuildCraftFactory;
|
||||
import buildcraft.api.builder.Blueprint;
|
||||
import buildcraft.api.builder.BlueprintBuilder;
|
||||
import buildcraft.api.builder.BlueprintBuilder.SchematicBuilder;
|
||||
import buildcraft.builders.Blueprint;
|
||||
import buildcraft.builders.BlueprintBuilder;
|
||||
import buildcraft.builders.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(i, it * (box.sizeY() - 1), 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setBlock(i, it * (box.sizeY() - 1), blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
for (int k = 0; k < blueprint.sizeZ; ++k) {
|
||||
blueprint.setBlock(0, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setBlock(blueprint.sizeX - 1, it * (box.sizeY() - 1), k, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
for (int h = 1; h < box.sizeY(); ++h) {
|
||||
blueprint.setBlock(0, h, 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setBlock(0, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setBlock(blueprint.sizeX - 1, h, 0, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
blueprint.setBlock(blueprint.sizeX - 1, h, blueprint.sizeZ - 1, BuildCraftFactory.frameBlock.blockID, 0);
|
||||
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);
|
||||
}
|
||||
|
||||
blueprintBuilder = new BlueprintBuilder(blueprint, worldObj, box.xMin, yCoord, box.zMin, ForgeDirection.NORTH, null);
|
||||
|
|
Loading…
Reference in a new issue