diff --git a/api/buildcraft/api/blueprints/BlueprintDeployer.java b/api/buildcraft/api/blueprints/BlueprintDeployer.java index baca838b..044db825 100755 --- a/api/buildcraft/api/blueprints/BlueprintDeployer.java +++ b/api/buildcraft/api/blueprints/BlueprintDeployer.java @@ -35,5 +35,13 @@ public abstract class BlueprintDeployer { */ public abstract void deployBlueprint(World world, int x, int y, int z, ForgeDirection dir, File file); + + /** + *Deploy the contents of the byte array as if the builder was located at + *{x, y, z} facing the direction dir. + */ + + public abstract void deployBlueprintFromFileStream(World world, int x, int y, + int z, ForgeDirection dir, byte [] data); } diff --git a/common/buildcraft/core/blueprints/RealBlueprintDeployer.java b/common/buildcraft/core/blueprints/RealBlueprintDeployer.java index 93200b24..b3d07d5d 100755 --- a/common/buildcraft/core/blueprints/RealBlueprintDeployer.java +++ b/common/buildcraft/core/blueprints/RealBlueprintDeployer.java @@ -9,11 +9,12 @@ package buildcraft.core.blueprints; import java.io.File; +import java.io.IOException; +import net.minecraft.nbt.CompressedStreamTools; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.world.World; - import net.minecraftforge.common.util.ForgeDirection; - import buildcraft.api.blueprints.BlueprintDeployer; import buildcraft.api.blueprints.Translation; import buildcraft.builders.blueprints.BlueprintDatabase; @@ -55,7 +56,55 @@ public class RealBlueprintDeployer extends BlueprintDeployer { bpt.transformToWorld(transform); - new BptBuilderBlueprint(bpt, world, x, y, z).deploy (); + BptBuilderBlueprint deployer = new BptBuilderBlueprint(bpt, world, x, y, z); + deployer.initialize(); + deployer.deploy(); } + @Override + public void deployBlueprintFromFileStream(World world, int x, int y, int z, + ForgeDirection dir, byte [] data) { + + NBTTagCompound nbt; + try { + nbt = CompressedStreamTools.decompress(data); + BlueprintBase blueprint = BlueprintBase.loadBluePrint(nbt); + Blueprint bpt = (Blueprint) blueprint; + bpt.setData(data); + bpt.id = new BlueprintId(); + bpt.id.kind = Kind.Blueprint; + + BptContext context = bpt.getContext(world, bpt.getBoxForPos(x, y, z)); + + if (bpt.rotate) { + if (dir == ForgeDirection.EAST) { + // Do nothing + } else if (dir == ForgeDirection.SOUTH) { + bpt.rotateLeft(context); + } else if (dir == ForgeDirection.WEST) { + bpt.rotateLeft(context); + bpt.rotateLeft(context); + } else if (dir == ForgeDirection.NORTH) { + bpt.rotateLeft(context); + bpt.rotateLeft(context); + bpt.rotateLeft(context); + } + } + Translation transform = new Translation(); + + transform.x = x - bpt.anchorX; + transform.y = y - bpt.anchorY; + transform.z = z - bpt.anchorZ; + + bpt.transformToWorld(transform); + + BptBuilderBlueprint deployer = new BptBuilderBlueprint(bpt, world, x, y, z); + deployer.initialize(); + deployer.deploy(); + } catch (IOException e) { + + e.printStackTrace(); + } + } } +