Merge branch '6.1.x' of https://github.com/BuildCraft/BuildCraft into 6.1.x
This commit is contained in:
commit
0bbd40e25f
14 changed files with 662 additions and 226 deletions
|
@ -64,6 +64,7 @@ import buildcraft.builders.EventHandlerBuilders;
|
|||
import buildcraft.builders.GuiHandler;
|
||||
import buildcraft.builders.ItemBlueprintStandard;
|
||||
import buildcraft.builders.ItemBlueprintTemplate;
|
||||
import buildcraft.builders.ItemConstructionMarker;
|
||||
import buildcraft.builders.TileArchitect;
|
||||
import buildcraft.builders.TileBlueprintLibrary;
|
||||
import buildcraft.builders.TileBuilder;
|
||||
|
@ -441,7 +442,8 @@ public class BuildCraftBuilders extends BuildCraftMod {
|
|||
CoreProxy.proxy.registerBlock(pathMarkerBlock.setBlockName("pathMarkerBlock"));
|
||||
|
||||
constructionMarkerBlock = new BlockConstructionMarker();
|
||||
CoreProxy.proxy.registerBlock(constructionMarkerBlock.setBlockName("constructionMarkerBlock"));
|
||||
CoreProxy.proxy.registerBlock(constructionMarkerBlock.setBlockName("constructionMarkerBlock"),
|
||||
ItemConstructionMarker.class);
|
||||
|
||||
fillerBlock = new BlockFiller();
|
||||
CoreProxy.proxy.registerBlock(fillerBlock.setBlockName("fillerBlock"));
|
||||
|
|
|
@ -39,7 +39,8 @@ public class BlockArchitect extends BlockMultiTexture {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int i, int j, int k, EntityPlayer entityplayer, int par6, float par7, float par8, float par9) {
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityplayer, int par6, float par7,
|
||||
float par8, float par9) {
|
||||
|
||||
// Drop through if the player is sneaking
|
||||
if (entityplayer.isSneaking()) {
|
||||
|
@ -47,33 +48,37 @@ public class BlockArchitect extends BlockMultiTexture {
|
|||
}
|
||||
|
||||
Item equipped = entityplayer.getCurrentEquippedItem() != null ? entityplayer.getCurrentEquippedItem().getItem() : null;
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, i, j, k)) {
|
||||
if (equipped instanceof IToolWrench && ((IToolWrench) equipped).canWrench(entityplayer, x, y, z)) {
|
||||
|
||||
int meta = world.getBlockMetadata(i, j, k);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
switch (ForgeDirection.values()[meta]) {
|
||||
case WEST:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.SOUTH.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.SOUTH.ordinal(), 0);
|
||||
break;
|
||||
case EAST:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.NORTH.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.NORTH.ordinal(), 0);
|
||||
break;
|
||||
case NORTH:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.WEST.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.WEST.ordinal(), 0);
|
||||
break;
|
||||
case SOUTH:
|
||||
default:
|
||||
world.setBlockMetadataWithNotify(i, j, k, ForgeDirection.EAST.ordinal(), 0);
|
||||
world.setBlockMetadataWithNotify(x, y, z, ForgeDirection.EAST.ordinal(), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
world.markBlockForUpdate(i, j, k);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, i, j, k);
|
||||
world.markBlockForUpdate(x, y, z);
|
||||
((IToolWrench) equipped).wrenchUsed(entityplayer, x, y, z);
|
||||
return true;
|
||||
} else if (equipped instanceof ItemConstructionMarker) {
|
||||
ItemConstructionMarker.link(entityplayer.getCurrentEquippedItem(), world, x, y, z);
|
||||
|
||||
return true;
|
||||
} else {
|
||||
|
||||
if (!world.isRemote) {
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.ARCHITECT_TABLE, world, i, j, k);
|
||||
entityplayer.openGui(BuildCraftBuilders.instance, GuiIds.ARCHITECT_TABLE, world, x, y, z);
|
||||
}
|
||||
return true;
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ package buildcraft.builders;
|
|||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.client.registry.RenderingRegistry;
|
||||
|
||||
import buildcraft.builders.urbanism.RenderBoxProvider;
|
||||
import buildcraft.core.render.RenderBlockMultiTexture;
|
||||
|
||||
public class BuilderProxyClient extends BuilderProxy {
|
||||
|
@ -27,7 +26,7 @@ public class BuilderProxyClient extends BuilderProxy {
|
|||
|
||||
RenderingRegistry.registerBlockHandler(new RenderBlockMultiTexture());
|
||||
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderBoxProvider());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileArchitect.class, new RenderArchitect());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileFiller.class, new RenderBuilder());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TileBuilder.class, new RenderBuilder());
|
||||
ClientRegistry.bindTileEntitySpecialRenderer(TilePathMarker.class, new RenderPathMarker());
|
||||
|
|
56
common/buildcraft/builders/ItemConstructionMarker.java
Executable file
56
common/buildcraft/builders/ItemConstructionMarker.java
Executable file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 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.builders;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.core.utils.NBTUtils;
|
||||
|
||||
public class ItemConstructionMarker extends ItemBlock {
|
||||
|
||||
public ItemConstructionMarker(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
public static void link(ItemStack marker, World world, int x, int y, int z) {
|
||||
NBTTagCompound nbt = NBTUtils.getItemData(marker);
|
||||
|
||||
if (nbt.hasKey("x")) {
|
||||
int ox = nbt.getInteger("x");
|
||||
int oy = nbt.getInteger("y");
|
||||
int oz = nbt.getInteger("z");
|
||||
|
||||
TileEntity tile1 = world.getTileEntity(ox, oy, oz);
|
||||
|
||||
if (tile1 != null && (tile1 instanceof TileArchitect)) {
|
||||
TileArchitect architect = (TileArchitect) tile1;
|
||||
TileEntity tile2 = world.getTileEntity(x, y, z);
|
||||
|
||||
if (tile1 != tile2 && tile2 != null && (tile2 instanceof TileArchitect)) {
|
||||
architect.addSubBlueprint(tile2);
|
||||
|
||||
nbt.removeTag("x");
|
||||
nbt.removeTag("y");
|
||||
nbt.removeTag("z");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
nbt.setInteger("x", x);
|
||||
nbt.setInteger("y", y);
|
||||
nbt.setInteger("z", z);
|
||||
}
|
||||
}
|
56
common/buildcraft/builders/RenderArchitect.java
Executable file
56
common/buildcraft/builders/RenderArchitect.java
Executable file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* 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.builders;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import buildcraft.builders.urbanism.RenderBoxProvider;
|
||||
import buildcraft.core.EntityLaser;
|
||||
import buildcraft.core.LaserData;
|
||||
import buildcraft.core.render.RenderLaser;
|
||||
|
||||
public class RenderArchitect extends RenderBoxProvider {
|
||||
|
||||
@Override
|
||||
public void renderTileEntityAt(TileEntity tileentity, double x, double y, double z, float f) {
|
||||
super.renderTileEntityAt(tileentity, x, y, z, f);
|
||||
|
||||
TileArchitect architect = (TileArchitect) tileentity;
|
||||
|
||||
if (architect != null) {
|
||||
GL11.glPushMatrix();
|
||||
GL11.glPushAttrib(GL11.GL_ENABLE_BIT);
|
||||
GL11.glEnable(GL11.GL_CULL_FACE);
|
||||
GL11.glEnable(GL11.GL_LIGHTING);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
|
||||
|
||||
GL11.glTranslated(x, y, z);
|
||||
GL11.glTranslated(-tileentity.xCoord, -tileentity.yCoord, -tileentity.zCoord);
|
||||
|
||||
for (LaserData laser : architect.subLasers) {
|
||||
if (laser != null) {
|
||||
GL11.glPushMatrix();
|
||||
RenderLaser
|
||||
.doRenderLaser(
|
||||
TileEntityRendererDispatcher.instance.field_147553_e,
|
||||
laser, EntityLaser.LASER_TEXTURES[4]);
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
GL11.glPopAttrib();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -8,29 +8,27 @@
|
|||
*/
|
||||
package buildcraft.builders;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IAreaProvider;
|
||||
import buildcraft.api.core.NetworkData;
|
||||
import buildcraft.core.BlockScanner;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.Box.Kind;
|
||||
import buildcraft.core.IBoxProvider;
|
||||
import buildcraft.core.LaserData;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.blueprints.Blueprint;
|
||||
import buildcraft.core.blueprints.BlueprintBase;
|
||||
import buildcraft.core.blueprints.BlueprintReadConfiguration;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.Template;
|
||||
import buildcraft.core.blueprints.RecursiveBlueprintReader;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import buildcraft.core.network.RPC;
|
||||
import buildcraft.core.network.RPCHandler;
|
||||
|
@ -39,9 +37,6 @@ import buildcraft.core.utils.Utils;
|
|||
|
||||
public class TileArchitect extends TileBuildCraft implements IInventory, IBoxProvider {
|
||||
|
||||
private static final int SCANNER_ITERATION = 100;
|
||||
|
||||
public int computingTime = 0;
|
||||
public String currentAuthorName = "";
|
||||
@NetworkData
|
||||
public Box box = new Box();
|
||||
|
@ -50,10 +45,14 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
@NetworkData
|
||||
public BlueprintReadConfiguration readConfiguration = new BlueprintReadConfiguration();
|
||||
|
||||
@NetworkData
|
||||
public LinkedList<LaserData> subLasers = new LinkedList<LaserData>();
|
||||
|
||||
public ArrayList<BlockIndex> subBlueprints = new ArrayList<BlockIndex>();
|
||||
|
||||
private SimpleInventory inv = new SimpleInventory(2, "Architect", 1);
|
||||
private BlueprintBase writingBlueprint;
|
||||
private BptContext writingContext;
|
||||
private BlockScanner blockScanner;
|
||||
|
||||
private RecursiveBlueprintReader reader;
|
||||
|
||||
public TileArchitect() {
|
||||
box.kind = Kind.STRIPES;
|
||||
|
@ -63,52 +62,13 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (!worldObj.isRemote && blockScanner != null) {
|
||||
if (blockScanner.blocksLeft() != 0) {
|
||||
for (BlockIndex index : blockScanner) {
|
||||
writingBlueprint.readFromWorld(writingContext, this,
|
||||
index.x, index.y, index.z);
|
||||
if (!worldObj.isRemote) {
|
||||
if (reader != null) {
|
||||
reader.iterate();
|
||||
|
||||
if (reader.isDone()) {
|
||||
reader = null;
|
||||
}
|
||||
|
||||
computingTime = (int) ((1 - (float) blockScanner.blocksLeft()
|
||||
/ (float) blockScanner.totalBlocks()) * 100);
|
||||
|
||||
if (blockScanner.blocksLeft() == 0) {
|
||||
writingBlueprint.readEntitiesFromWorld (writingContext, this);
|
||||
|
||||
Translation transform = new Translation();
|
||||
|
||||
transform.x = -writingContext.surroundingBox().pMin().x;
|
||||
transform.y = -writingContext.surroundingBox().pMin().y;
|
||||
transform.z = -writingContext.surroundingBox().pMin().z;
|
||||
|
||||
writingBlueprint.translateToBlueprint(transform);
|
||||
|
||||
ForgeDirection o = ForgeDirection.values()[worldObj.getBlockMetadata(
|
||||
xCoord, yCoord, zCoord)].getOpposite();
|
||||
|
||||
writingBlueprint.rotate = readConfiguration.rotate;
|
||||
writingBlueprint.excavate = readConfiguration.excavate;
|
||||
|
||||
if (writingBlueprint.rotate) {
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (o == ForgeDirection.SOUTH) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
} else if (o == ForgeDirection.WEST) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
} else if (o == ForgeDirection.NORTH) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (writingBlueprint.getData() != null) {
|
||||
createBlueprint();
|
||||
|
||||
computingTime = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,18 +91,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
}
|
||||
}
|
||||
|
||||
public void createBlueprint() {
|
||||
writingBlueprint.id.name = name;
|
||||
BuildCraftBuilders.serverDB.add(writingBlueprint);
|
||||
|
||||
setInventorySlotContents(1, writingBlueprint.getStack());
|
||||
setInventorySlotContents(0, null);
|
||||
|
||||
writingBlueprint = null;
|
||||
writingContext = null;
|
||||
blockScanner = null;
|
||||
}
|
||||
|
||||
@RPC (RPCSide.SERVER)
|
||||
public void handleClientSetName(String nameSet) {
|
||||
name = nameSet;
|
||||
|
@ -208,13 +156,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
|
||||
// For now, scan states don't get saved. Would need to save
|
||||
// blueprints too.
|
||||
/*if (nbttagcompound.hasKey("scanner")) {
|
||||
blockScanner = new BlockScanner();
|
||||
blockScanner.readFromNBT(nbttagcompound.getCompoundTag("scanner"));
|
||||
}*/
|
||||
|
||||
if (nbttagcompound.hasKey("box")) {
|
||||
box.initialize(nbttagcompound.getCompoundTag("box"));
|
||||
}
|
||||
|
@ -233,14 +174,6 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
// For now, scan states don't get saved. Would need to save
|
||||
// blueprints too.
|
||||
/*if (blockScanner != null) {
|
||||
NBTTagCompound scanner = new NBTTagCompound();
|
||||
blockScanner.writeToNBT(scanner);
|
||||
nbttagcompound.setTag("scanner", scanner);
|
||||
}*/
|
||||
|
||||
if (box.isInitialized()) {
|
||||
NBTTagCompound boxStore = new NBTTagCompound();
|
||||
box.writeToNBT(boxStore);
|
||||
|
@ -268,41 +201,15 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
return;
|
||||
}
|
||||
|
||||
if (!box.isInitialized()) {
|
||||
return;
|
||||
} else if (blockScanner == null) {
|
||||
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint
|
||||
&& getStackInSlot(1) == null) {
|
||||
if (!box.isInitialized() || getStackInSlot(1) != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
blockScanner = new BlockScanner(box, getWorld(), SCANNER_ITERATION);
|
||||
|
||||
if (getStackInSlot(0).getItem() instanceof ItemBlueprintStandard) {
|
||||
writingBlueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
} else if (getStackInSlot(0).getItem() instanceof ItemBlueprintTemplate) {
|
||||
writingBlueprint = new Template(box.sizeX(), box.sizeY(), box.sizeZ());
|
||||
}
|
||||
|
||||
writingContext = writingBlueprint.getContext(worldObj, box);
|
||||
writingContext.readConfiguration = readConfiguration;
|
||||
|
||||
writingBlueprint.id.name = name;
|
||||
writingBlueprint.author = currentAuthorName;
|
||||
writingBlueprint.anchorX = xCoord - box.xMin;
|
||||
writingBlueprint.anchorY = yCoord - box.yMin;
|
||||
writingBlueprint.anchorZ = zCoord - box.zMin;
|
||||
}
|
||||
} else {
|
||||
blockScanner = null;
|
||||
writingBlueprint = null;
|
||||
writingContext = null;
|
||||
}
|
||||
reader = new RecursiveBlueprintReader(this);
|
||||
}
|
||||
|
||||
public int getComputingProgressScaled(int scale) {
|
||||
return (int) ((float) computingTime / (float) 100 * scale);
|
||||
if (reader != null) {
|
||||
return (int) (reader.getComputingProgressScaled() * scale);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -330,7 +237,13 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
|
||||
@Override
|
||||
public AxisAlignedBB getRenderBoundingBox() {
|
||||
return new Box (this).extendToEncompass(box).getBoundingBox();
|
||||
Box completeBox = new Box(this).extendToEncompass(box);
|
||||
|
||||
for (BlockIndex b : subBlueprints) {
|
||||
completeBox.extendToEncompass(b);
|
||||
}
|
||||
|
||||
return completeBox.getBoundingBox();
|
||||
}
|
||||
|
||||
@RPC (RPCSide.SERVER)
|
||||
|
@ -343,4 +256,22 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
|
|||
readConfiguration = conf;
|
||||
RPCHandler.rpcServer(this, "setReadConfiguration", conf);
|
||||
}
|
||||
|
||||
public void addSubBlueprint(TileEntity sub) {
|
||||
subBlueprints.add(new BlockIndex(sub));
|
||||
|
||||
LaserData laser = new LaserData(new Position(this), new Position(sub));
|
||||
|
||||
laser.head.x += 0.5F;
|
||||
laser.head.y += 0.5F;
|
||||
laser.head.z += 0.5F;
|
||||
|
||||
laser.tail.x += 0.5F;
|
||||
laser.tail.y += 0.5F;
|
||||
laser.tail.z += 0.5F;
|
||||
|
||||
subLasers.add(laser);
|
||||
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
}
|
|
@ -30,8 +30,6 @@ import net.minecraftforge.fluids.FluidTankInfo;
|
|||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.BuildingPermission;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.api.core.IInvSlot;
|
||||
import buildcraft.api.core.NetworkData;
|
||||
|
@ -49,7 +47,7 @@ import buildcraft.core.blueprints.BlueprintBase;
|
|||
import buildcraft.core.blueprints.BptBuilderBase;
|
||||
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
||||
import buildcraft.core.blueprints.BptBuilderTemplate;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
import buildcraft.core.blueprints.RecursiveBlueprintBuilder;
|
||||
import buildcraft.core.fluids.Tank;
|
||||
import buildcraft.core.fluids.TankManager;
|
||||
import buildcraft.core.inventory.ITransactor;
|
||||
|
@ -82,7 +80,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
public TankManager<Tank> fluidTank = new TankManager<Tank>(fluidTanks);
|
||||
|
||||
private SimpleInventory inv = new SimpleInventory(28, "Builder", 64);
|
||||
private BptBuilderBase bluePrintBuilder;
|
||||
private BptBuilderBase currentBuilder;
|
||||
private RecursiveBlueprintBuilder recursiveBuilder;
|
||||
private LinkedList<BlockIndex> path;
|
||||
private ArrayList<ItemStack> requiredToBuild;
|
||||
private NBTTagCompound initNBT = null;
|
||||
|
@ -148,7 +147,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
int newY = Math.round(iy);
|
||||
int newZ = Math.round(iz);
|
||||
|
||||
bpt = instanciateBluePrint(newX, newY, newZ, o);
|
||||
bpt = instanciateBluePrintBuilder(newX, newY, newZ, o);
|
||||
|
||||
if (bpt == null) {
|
||||
return null;
|
||||
|
@ -226,7 +225,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
if (initNBT.hasKey("iterator")) {
|
||||
BlockIndex expectedTo = new BlockIndex(initNBT.getCompoundTag("iterator"));
|
||||
|
||||
while (!done && bluePrintBuilder != null && currentPathIterator != null) {
|
||||
while (!done && currentBuilder != null && currentPathIterator != null) {
|
||||
BlockIndex bi = new BlockIndex((int) currentPathIterator.ix,
|
||||
(int) currentPathIterator.iy, (int) currentPathIterator.iz);
|
||||
|
||||
|
@ -238,8 +237,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
}
|
||||
}
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
bluePrintBuilder.loadBuildStateToNBT(
|
||||
if (currentBuilder != null) {
|
||||
currentBuilder.loadBuildStateToNBT(
|
||||
initNBT.getCompoundTag("builderState"), this);
|
||||
}
|
||||
|
||||
|
@ -296,7 +295,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
}
|
||||
}
|
||||
|
||||
public BptBuilderBase instanciateBluePrint(int x, int y, int z, ForgeDirection o) {
|
||||
public BlueprintBase instanciateBlueprint() {
|
||||
BlueprintBase bpt = null;
|
||||
|
||||
try {
|
||||
|
@ -307,40 +306,13 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
return null;
|
||||
}
|
||||
|
||||
if (bpt == null) {
|
||||
return null;
|
||||
}
|
||||
return bpt;
|
||||
}
|
||||
|
||||
if (bpt.buildingPermission == BuildingPermission.NONE
|
||||
|| (bpt.buildingPermission == BuildingPermission.CREATIVE_ONLY && worldObj
|
||||
.getWorldInfo().getGameType() != GameType.CREATIVE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BptContext context = bpt.getContext(worldObj, bpt.getBoxForPos(x, y, z));
|
||||
|
||||
if (bpt.rotate) {
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (o == ForgeDirection.SOUTH) {
|
||||
bpt.rotateLeft(context);
|
||||
} else if (o == ForgeDirection.WEST) {
|
||||
bpt.rotateLeft(context);
|
||||
bpt.rotateLeft(context);
|
||||
} else if (o == 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.translateToWorld(transform);
|
||||
@Deprecated
|
||||
public BptBuilderBase instanciateBluePrintBuilder(int x, int y, int z, ForgeDirection o) {
|
||||
BlueprintBase bpt = instanciateBlueprint();
|
||||
bpt = bpt.adjustToWorld(worldObj, x, y, z, o);
|
||||
|
||||
if (getStackInSlot(0).getItem() instanceof ItemBlueprintStandard) {
|
||||
return new BptBuilderBlueprint((Blueprint) bpt, worldObj, x, y, z);
|
||||
|
@ -353,8 +325,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
public void iterateBpt(boolean forceIterate) {
|
||||
if (getStackInSlot(0) == null || !(getStackInSlot(0).getItem() instanceof ItemBlueprint)) {
|
||||
if (bluePrintBuilder != null) {
|
||||
bluePrintBuilder = null;
|
||||
if (currentBuilder != null) {
|
||||
currentBuilder = null;
|
||||
}
|
||||
|
||||
if (box.isInitialized()) {
|
||||
|
@ -372,7 +344,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
return;
|
||||
}
|
||||
|
||||
if (bluePrintBuilder == null || (bluePrintBuilder.isDone(this) || forceIterate)) {
|
||||
if (currentBuilder == null || (currentBuilder.isDone(this) || forceIterate)) {
|
||||
if (path != null && path.size() > 1) {
|
||||
if (currentPathIterator == null) {
|
||||
Iterator<BlockIndex> it = path.iterator();
|
||||
|
@ -382,19 +354,20 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
xCoord, yCoord, zCoord)].getOpposite());
|
||||
}
|
||||
|
||||
if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) {
|
||||
bluePrintBuilder.postProcessing(worldObj);
|
||||
if (currentBuilder != null && currentBuilder.isDone(this)) {
|
||||
currentBuilder.postProcessing(worldObj);
|
||||
}
|
||||
|
||||
bluePrintBuilder = currentPathIterator.next();
|
||||
// TODO: add support for composite blueprints here
|
||||
currentBuilder = currentPathIterator.next();
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
if (currentBuilder != null) {
|
||||
box.reset();
|
||||
box.initialize(bluePrintBuilder);
|
||||
box.initialize(currentBuilder);
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
if (bluePrintBuilder == null) {
|
||||
if (currentBuilder == null) {
|
||||
currentPathIterator = currentPathIterator.iterate();
|
||||
}
|
||||
|
||||
|
@ -404,19 +377,25 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
done = false;
|
||||
}
|
||||
} else {
|
||||
if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) {
|
||||
bluePrintBuilder.postProcessing(worldObj);
|
||||
if (currentBuilder != null && currentBuilder.isDone(this)) {
|
||||
currentBuilder.postProcessing(worldObj);
|
||||
|
||||
done = true;
|
||||
bluePrintBuilder = null;
|
||||
currentBuilder = recursiveBuilder.nextBuilder();
|
||||
} else {
|
||||
bluePrintBuilder = instanciateBluePrint(xCoord, yCoord, zCoord,
|
||||
ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].getOpposite());
|
||||
BlueprintBase bpt = instanciateBlueprint();
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
box.initialize(bluePrintBuilder);
|
||||
sendNetworkUpdate();
|
||||
done = false;
|
||||
if (bpt != null) {
|
||||
recursiveBuilder = new RecursiveBlueprintBuilder(bpt, worldObj, xCoord, yCoord, zCoord,
|
||||
ForgeDirection.values()[worldObj.getBlockMetadata(xCoord, yCoord, zCoord)].getOpposite());
|
||||
|
||||
currentBuilder = recursiveBuilder.nextBuilder();
|
||||
|
||||
if (currentBuilder != null) {
|
||||
box.initialize(currentBuilder);
|
||||
sendNetworkUpdate();
|
||||
done = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -555,9 +534,9 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
NBTTagCompound bptNBT = new NBTTagCompound();
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
if (currentBuilder != null) {
|
||||
NBTTagCompound builderCpt = new NBTTagCompound();
|
||||
bluePrintBuilder.saveBuildStateToNBT(builderCpt, this);
|
||||
currentBuilder.saveBuildStateToNBT(builderCpt, this);
|
||||
bptNBT.setTag("builderState", builderCpt);
|
||||
}
|
||||
|
||||
|
@ -594,11 +573,11 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
return;
|
||||
}
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
bluePrintBuilder.removeDoneBuilders(this);
|
||||
if (currentBuilder != null) {
|
||||
currentBuilder.removeDoneBuilders(this);
|
||||
}
|
||||
|
||||
if ((bluePrintBuilder == null || bluePrintBuilder.isDone(this))
|
||||
if ((currentBuilder == null || currentBuilder.isDone(this))
|
||||
&& box.isInitialized()) {
|
||||
box.reset();
|
||||
|
||||
|
@ -721,19 +700,19 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
return;
|
||||
}
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
bluePrintBuilder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
|
||||
if (currentBuilder != null) {
|
||||
currentBuilder.buildNextSlot(worldObj, this, xCoord, yCoord, zCoord);
|
||||
|
||||
updateRequirements();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateRequirements () {
|
||||
if (bluePrintBuilder instanceof BptBuilderBlueprint) {
|
||||
if (currentBuilder instanceof BptBuilderBlueprint) {
|
||||
ArrayList<ItemStack> reqCopy = new ArrayList<ItemStack>();
|
||||
ArrayList<Integer> realSize = new ArrayList<Integer>();
|
||||
|
||||
for (ItemStack stack : ((BptBuilderBlueprint) bluePrintBuilder).neededItems) {
|
||||
for (ItemStack stack : ((BptBuilderBlueprint) currentBuilder).neededItems) {
|
||||
realSize.add(stack.stackSize);
|
||||
ItemStack newStack = stack.copy();
|
||||
newStack.stackSize = 0;
|
||||
|
@ -748,8 +727,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
}
|
||||
|
||||
public BptBuilderBase getBlueprint () {
|
||||
if (bluePrintBuilder != null) {
|
||||
return bluePrintBuilder;
|
||||
if (currentBuilder != null) {
|
||||
return currentBuilder;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -837,12 +816,12 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
@Override
|
||||
public int getNumberOfRequests() {
|
||||
if (bluePrintBuilder == null) {
|
||||
if (currentBuilder == null) {
|
||||
return 0;
|
||||
} else if (!(bluePrintBuilder instanceof BptBuilderBlueprint)) {
|
||||
} else if (!(currentBuilder instanceof BptBuilderBlueprint)) {
|
||||
return 0;
|
||||
} else {
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) bluePrintBuilder;
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) currentBuilder;
|
||||
|
||||
return bpt.neededItems.size();
|
||||
}
|
||||
|
@ -850,12 +829,12 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
@Override
|
||||
public StackRequest getAvailableRequest(int i) {
|
||||
if (bluePrintBuilder == null) {
|
||||
if (currentBuilder == null) {
|
||||
return null;
|
||||
} else if (!(bluePrintBuilder instanceof BptBuilderBlueprint)) {
|
||||
} else if (!(currentBuilder instanceof BptBuilderBlueprint)) {
|
||||
return null;
|
||||
} else {
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) bluePrintBuilder;
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) currentBuilder;
|
||||
|
||||
if (bpt.neededItems.size() <= i) {
|
||||
return null;
|
||||
|
@ -881,9 +860,9 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
@Override
|
||||
public boolean takeRequest(int i, EntityRobotBase robot) {
|
||||
if (bluePrintBuilder == null) {
|
||||
if (currentBuilder == null) {
|
||||
return false;
|
||||
} else if (!(bluePrintBuilder instanceof BptBuilderBlueprint)) {
|
||||
} else if (!(currentBuilder instanceof BptBuilderBlueprint)) {
|
||||
return false;
|
||||
} else {
|
||||
return RobotRegistry.getRegistry(worldObj).take(new ResourceIdRequest(this, i), robot);
|
||||
|
@ -892,12 +871,12 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine, IFluid
|
|||
|
||||
@Override
|
||||
public ItemStack provideItemsForRequest(int i, ItemStack stack) {
|
||||
if (bluePrintBuilder == null) {
|
||||
if (currentBuilder == null) {
|
||||
return stack;
|
||||
} else if (!(bluePrintBuilder instanceof BptBuilderBlueprint)) {
|
||||
} else if (!(currentBuilder instanceof BptBuilderBlueprint)) {
|
||||
return stack;
|
||||
} else {
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) bluePrintBuilder;
|
||||
BptBuilderBlueprint bpt = (BptBuilderBlueprint) currentBuilder;
|
||||
|
||||
if (bpt.neededItems.size() <= i) {
|
||||
return stack;
|
||||
|
|
|
@ -25,6 +25,7 @@ import buildcraft.core.IBoxProvider;
|
|||
import buildcraft.core.LaserData;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.blueprints.Blueprint;
|
||||
import buildcraft.core.blueprints.BlueprintBase;
|
||||
import buildcraft.core.blueprints.BptBuilderBase;
|
||||
import buildcraft.core.blueprints.BptBuilderBlueprint;
|
||||
import buildcraft.core.blueprints.BptContext;
|
||||
|
@ -86,8 +87,9 @@ public class TileConstructionMarker extends TileBuildCraft implements IBuildingI
|
|||
}
|
||||
|
||||
if (itemBlueprint != null && ItemBlueprint.getId(itemBlueprint) != null && bluePrintBuilder == null) {
|
||||
bluePrintBuilder = new BptBuilderBlueprint((Blueprint) ItemBlueprint.loadBlueprint(itemBlueprint),
|
||||
worldObj, xCoord, yCoord, zCoord);
|
||||
BlueprintBase bpt = BlueprintBase.instantiate(itemBlueprint, worldObj, xCoord, yCoord, zCoord, direction);
|
||||
|
||||
bluePrintBuilder = new BptBuilderBlueprint((Blueprint) bpt, worldObj, xCoord, yCoord, zCoord);
|
||||
bptContext = bluePrintBuilder.getContext();
|
||||
box.initialize(bluePrintBuilder);
|
||||
sendNetworkUpdate();
|
||||
|
|
|
@ -49,7 +49,7 @@ public class ContainerArchitect extends BuildCraftContainer {
|
|||
@Override
|
||||
public void addCraftingToCrafters(ICrafting icrafting) {
|
||||
super.addCraftingToCrafters(icrafting);
|
||||
icrafting.sendProgressBarUpdate(this, 0, architect.computingTime);
|
||||
icrafting.sendProgressBarUpdate(this, 0, architect.getComputingProgressScaled(24));
|
||||
}
|
||||
|
||||
|
||||
|
@ -59,18 +59,18 @@ public class ContainerArchitect extends BuildCraftContainer {
|
|||
|
||||
for (int i = 0; i < crafters.size(); i++) {
|
||||
ICrafting icrafting = (ICrafting) crafters.get(i);
|
||||
if (computingTime != architect.computingTime) {
|
||||
icrafting.sendProgressBarUpdate(this, 0, architect.computingTime);
|
||||
if (computingTime != architect.getComputingProgressScaled(24)) {
|
||||
icrafting.sendProgressBarUpdate(this, 0, architect.getComputingProgressScaled(24));
|
||||
}
|
||||
}
|
||||
|
||||
computingTime = architect.computingTime;
|
||||
computingTime = architect.getComputingProgressScaled(24);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
if (i == 0) {
|
||||
architect.computingTime = j;
|
||||
computingTime = j;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,7 +150,7 @@ public class GuiArchitect extends GuiBuildCraft {
|
|||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
mc.renderEngine.bindTexture(TEXTURE);
|
||||
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
|
||||
int i1 = architect.getComputingProgressScaled(24);
|
||||
int i1 = ((ContainerArchitect) container).computingTime;
|
||||
drawTexturedModalRect(guiLeft + 159, guiTop + 34, 0, 166, i1 + 1, 16);
|
||||
}
|
||||
|
||||
|
|
|
@ -355,6 +355,34 @@ public class Box implements IBox {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Box extendToEncompass(BlockIndex toBeContained) {
|
||||
if (toBeContained.x < xMin) {
|
||||
xMin = toBeContained.x - 1;
|
||||
}
|
||||
|
||||
if (toBeContained.y < yMin) {
|
||||
yMin = toBeContained.y - 1;
|
||||
}
|
||||
|
||||
if (toBeContained.z < zMin) {
|
||||
zMin = toBeContained.z - 1;
|
||||
}
|
||||
|
||||
if (toBeContained.x > xMax) {
|
||||
xMax = toBeContained.x + 1;
|
||||
}
|
||||
|
||||
if (toBeContained.y > yMax) {
|
||||
yMax = toBeContained.y + 1;
|
||||
}
|
||||
|
||||
if (toBeContained.z > zMax) {
|
||||
zMax = toBeContained.z + 1;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double distanceTo(BlockIndex index) {
|
||||
int dx = index.x - (xMin + (xMax - xMin + 1));
|
||||
|
|
|
@ -9,12 +9,18 @@
|
|||
package buildcraft.core.blueprints;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldSettings.GameType;
|
||||
|
||||
import net.minecraftforge.common.util.Constants;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.blueprints.BuildingPermission;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
|
@ -22,12 +28,15 @@ import buildcraft.api.blueprints.MappingRegistry;
|
|||
import buildcraft.api.blueprints.SchematicBlockBase;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
import buildcraft.api.core.BCLog;
|
||||
import buildcraft.builders.ItemBlueprint;
|
||||
import buildcraft.builders.blueprints.BlueprintId;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.Version;
|
||||
|
||||
public abstract class BlueprintBase {
|
||||
|
||||
public ArrayList<NBTTagCompound> subBlueprintsNBT = new ArrayList<NBTTagCompound>();
|
||||
|
||||
public SchematicBlockBase[][][] contents;
|
||||
public int anchorX, anchorY, anchorZ;
|
||||
public int sizeX, sizeY, sizeZ;
|
||||
|
@ -42,6 +51,7 @@ public abstract class BlueprintBase {
|
|||
|
||||
private ComputeDataThread computeData;
|
||||
private byte [] data;
|
||||
private ForgeDirection mainDir = ForgeDirection.EAST;
|
||||
|
||||
public BlueprintBase() {
|
||||
}
|
||||
|
@ -119,6 +129,8 @@ public abstract class BlueprintBase {
|
|||
anchorZ = newAnchorZ;
|
||||
|
||||
context.rotateLeft();
|
||||
|
||||
mainDir = mainDir.getRotation(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
@ -144,6 +156,14 @@ public abstract class BlueprintBase {
|
|||
}
|
||||
|
||||
saveContents(nbt);
|
||||
|
||||
NBTTagList subBptList = new NBTTagList();
|
||||
|
||||
for (NBTTagCompound subBpt : subBlueprintsNBT) {
|
||||
subBptList.appendTag(subBpt);
|
||||
}
|
||||
|
||||
nbt.setTag("subBpt", subBptList);
|
||||
}
|
||||
|
||||
public static BlueprintBase loadBluePrint(NBTTagCompound nbt) {
|
||||
|
@ -191,10 +211,14 @@ public abstract class BlueprintBase {
|
|||
} catch (BptError e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected void copyTo(BlueprintBase base) {
|
||||
if (nbt.hasKey("subBpt")) {
|
||||
NBTTagList subBptList = nbt.getTagList("subBpt", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < subBptList.tagCount(); ++i) {
|
||||
subBlueprintsNBT.add(subBptList.getCompoundTagAt(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Box getBoxForPos(int x, int y, int z) {
|
||||
|
@ -216,6 +240,21 @@ public abstract class BlueprintBase {
|
|||
return new BptContext(world, box, mapping);
|
||||
}
|
||||
|
||||
public void addSubBlueprint(BlueprintBase bpt, int x, int y, int z, ForgeDirection dir) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
|
||||
nbt.setInteger("x", x - anchorX);
|
||||
nbt.setInteger("y", y - anchorX);
|
||||
nbt.setInteger("z", z - anchorX);
|
||||
nbt.setByte("dir", (byte) dir.ordinal());
|
||||
|
||||
NBTTagCompound bptNBT = new NBTTagCompound();
|
||||
bpt.writeToNBT(bptNBT);
|
||||
nbt.setTag("bpt", bptNBT);
|
||||
|
||||
subBlueprintsNBT.add(nbt);
|
||||
}
|
||||
|
||||
class ComputeDataThread extends Thread {
|
||||
public NBTTagCompound nbt;
|
||||
|
||||
|
@ -248,7 +287,52 @@ public abstract class BlueprintBase {
|
|||
return null;
|
||||
}
|
||||
|
||||
public synchronized void setData (byte [] b) {
|
||||
public static BlueprintBase instantiate(ItemStack stack, World world, int x, int y, int z, ForgeDirection o) {
|
||||
BlueprintBase bpt = ItemBlueprint.loadBlueprint(stack);
|
||||
|
||||
if (bpt == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return bpt.adjustToWorld(world, x, y, z, o);
|
||||
}
|
||||
|
||||
public BlueprintBase adjustToWorld(World world, int x, int y, int z, ForgeDirection o) {
|
||||
if (buildingPermission == BuildingPermission.NONE
|
||||
|| (buildingPermission == BuildingPermission.CREATIVE_ONLY && world
|
||||
.getWorldInfo().getGameType() != GameType.CREATIVE)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
BptContext context = getContext(world, getBoxForPos(x, y, z));
|
||||
|
||||
if (rotate) {
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (o == ForgeDirection.SOUTH) {
|
||||
rotateLeft(context);
|
||||
} else if (o == ForgeDirection.WEST) {
|
||||
rotateLeft(context);
|
||||
rotateLeft(context);
|
||||
} else if (o == ForgeDirection.NORTH) {
|
||||
rotateLeft(context);
|
||||
rotateLeft(context);
|
||||
rotateLeft(context);
|
||||
}
|
||||
}
|
||||
|
||||
Translation transform = new Translation();
|
||||
|
||||
transform.x = x - anchorX;
|
||||
transform.y = y - anchorY;
|
||||
transform.z = z - anchorZ;
|
||||
|
||||
translateToWorld(transform);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public synchronized void setData(byte[] b) {
|
||||
data = b;
|
||||
}
|
||||
|
||||
|
|
96
common/buildcraft/core/blueprints/RecursiveBlueprintBuilder.java
Executable file
96
common/buildcraft/core/blueprints/RecursiveBlueprintBuilder.java
Executable file
|
@ -0,0 +1,96 @@
|
|||
/**
|
||||
* 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.core.blueprints;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class RecursiveBlueprintBuilder {
|
||||
|
||||
private boolean returnedThis = false;
|
||||
private BlueprintBase blueprint;
|
||||
private RecursiveBlueprintBuilder current;
|
||||
private int nextSubBlueprint = 0;
|
||||
private ArrayList<NBTTagCompound> subBlueprints = new ArrayList<NBTTagCompound>();
|
||||
private int x, y, z;
|
||||
private ForgeDirection dir;
|
||||
private World world;
|
||||
|
||||
public RecursiveBlueprintBuilder(BlueprintBase iBlueprint, World iWorld, int iX, int iY, int iZ, ForgeDirection iDir) {
|
||||
blueprint = iBlueprint;
|
||||
subBlueprints = iBlueprint.subBlueprintsNBT;
|
||||
world = iWorld;
|
||||
x = iX;
|
||||
y = iY;
|
||||
z = iZ;
|
||||
dir = iDir;
|
||||
}
|
||||
|
||||
public BptBuilderBase nextBuilder() {
|
||||
if (!returnedThis) {
|
||||
blueprint.adjustToWorld(world, x, y, x, dir);
|
||||
|
||||
returnedThis = true;
|
||||
|
||||
if (blueprint instanceof Blueprint) {
|
||||
return new BptBuilderBlueprint((Blueprint) blueprint, world, x, y, z);
|
||||
} else if (blueprint instanceof Template) {
|
||||
return new BptBuilderTemplate(blueprint, world, x, y, z);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
blueprint = null;
|
||||
|
||||
if (nextSubBlueprint >= subBlueprints.size()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
BptBuilderBase builder = current.nextBuilder();
|
||||
|
||||
if (builder != null) {
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
||||
NBTTagCompound nbt = subBlueprints.get(nextSubBlueprint);
|
||||
BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt.getCompoundTag("bpt"));
|
||||
|
||||
int nx = x + nbt.getInteger("x");
|
||||
int ny = y + nbt.getInteger("y");
|
||||
int nz = z + nbt.getInteger("z");
|
||||
|
||||
ForgeDirection nbtDir = ForgeDirection.values()[nbt.getByte("dir")];
|
||||
ForgeDirection ndir = dir;
|
||||
|
||||
if (nbtDir == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (nbtDir == ForgeDirection.SOUTH) {
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
} else if (nbtDir == ForgeDirection.WEST) {
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
} else if (nbtDir == ForgeDirection.NORTH) {
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
ndir = ndir.getRotation(ForgeDirection.UP);
|
||||
}
|
||||
|
||||
current = new RecursiveBlueprintBuilder(bpt, world, nx, ny, nz, ndir);
|
||||
nextSubBlueprint++;
|
||||
|
||||
return current.nextBuilder();
|
||||
}
|
||||
}
|
198
common/buildcraft/core/blueprints/RecursiveBlueprintReader.java
Executable file
198
common/buildcraft/core/blueprints/RecursiveBlueprintReader.java
Executable file
|
@ -0,0 +1,198 @@
|
|||
/**
|
||||
* 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.core.blueprints;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
import buildcraft.api.core.BlockIndex;
|
||||
import buildcraft.builders.ItemBlueprint;
|
||||
import buildcraft.builders.ItemBlueprintStandard;
|
||||
import buildcraft.builders.ItemBlueprintTemplate;
|
||||
import buildcraft.builders.TileArchitect;
|
||||
import buildcraft.core.BlockScanner;
|
||||
|
||||
public class RecursiveBlueprintReader {
|
||||
|
||||
private static final int SCANNER_ITERATION = 100;
|
||||
|
||||
public TileArchitect architect;
|
||||
|
||||
private BlockScanner blockScanner;
|
||||
private BlueprintBase writingBlueprint;
|
||||
private BptContext writingContext;
|
||||
|
||||
private int subIndex = 0;
|
||||
private RecursiveBlueprintReader currentSubReader;
|
||||
private float computingTime = 0;
|
||||
|
||||
private boolean done = false;
|
||||
private boolean saveInItem = false;
|
||||
|
||||
private BlueprintBase parentBlueprint;
|
||||
|
||||
public RecursiveBlueprintReader(TileArchitect iArchitect) {
|
||||
architect = iArchitect;
|
||||
ItemStack stack = architect.getStackInSlot(0);
|
||||
|
||||
if (stack != null && stack.getItem() instanceof ItemBlueprint && architect.box.isInitialized()) {
|
||||
blockScanner = new BlockScanner(architect.box, architect.getWorld(), SCANNER_ITERATION);
|
||||
|
||||
if (stack.getItem() instanceof ItemBlueprintStandard) {
|
||||
writingBlueprint = new Blueprint(architect.box.sizeX(), architect.box.sizeY(), architect.box.sizeZ());
|
||||
} else if (stack.getItem() instanceof ItemBlueprintTemplate) {
|
||||
writingBlueprint = new Template(architect.box.sizeX(), architect.box.sizeY(), architect.box.sizeZ());
|
||||
}
|
||||
|
||||
writingContext = writingBlueprint.getContext(architect.getWorld(), architect.box);
|
||||
writingContext.readConfiguration = architect.readConfiguration;
|
||||
|
||||
writingBlueprint.id.name = architect.name;
|
||||
writingBlueprint.author = architect.currentAuthorName;
|
||||
writingBlueprint.anchorX = architect.xCoord - architect.box.xMin;
|
||||
writingBlueprint.anchorY = architect.yCoord - architect.box.yMin;
|
||||
writingBlueprint.anchorZ = architect.zCoord - architect.box.zMin;
|
||||
} else {
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected RecursiveBlueprintReader(TileArchitect iArchitect, BlueprintBase iParentBlueprint) {
|
||||
parentBlueprint = iParentBlueprint;
|
||||
architect = iArchitect;
|
||||
|
||||
if (architect.box.isInitialized()) {
|
||||
blockScanner = new BlockScanner(architect.box, architect.getWorld(), SCANNER_ITERATION);
|
||||
|
||||
if (parentBlueprint instanceof Blueprint) {
|
||||
writingBlueprint = new Blueprint(architect.box.sizeX(), architect.box.sizeY(), architect.box.sizeZ());
|
||||
} else if (parentBlueprint instanceof Template) {
|
||||
writingBlueprint = new Template(architect.box.sizeX(), architect.box.sizeY(), architect.box.sizeZ());
|
||||
}
|
||||
|
||||
writingContext = writingBlueprint.getContext(architect.getWorld(), architect.box);
|
||||
writingContext.readConfiguration = architect.readConfiguration;
|
||||
|
||||
writingBlueprint.id.name = architect.name;
|
||||
writingBlueprint.author = architect.currentAuthorName;
|
||||
writingBlueprint.anchorX = architect.xCoord - architect.box.xMin;
|
||||
writingBlueprint.anchorY = architect.yCoord - architect.box.yMin;
|
||||
writingBlueprint.anchorZ = architect.zCoord - architect.box.zMin;
|
||||
}
|
||||
}
|
||||
|
||||
public void iterate() {
|
||||
if (done) {
|
||||
return;
|
||||
} else if (currentSubReader == null && subIndex < architect.subBlueprints.size()) {
|
||||
BlockIndex subBlock = architect.subBlueprints.get(subIndex);
|
||||
TileArchitect subArchitect = (TileArchitect) architect.getWorld().getTileEntity(subBlock.x, subBlock.y,
|
||||
subBlock.z);
|
||||
currentSubReader = new RecursiveBlueprintReader(subArchitect, writingBlueprint);
|
||||
} else if (currentSubReader != null) {
|
||||
currentSubReader.iterate();
|
||||
|
||||
if (currentSubReader.isDone()) {
|
||||
writingBlueprint.addSubBlueprint
|
||||
(currentSubReader.getBlueprint(),
|
||||
currentSubReader.architect.xCoord - architect.xCoord,
|
||||
currentSubReader.architect.yCoord - architect.yCoord,
|
||||
currentSubReader.architect.zCoord - architect.zCoord,
|
||||
ForgeDirection.values()[architect.getWorld().getBlockMetadata(
|
||||
architect.xCoord, architect.yCoord, architect.zCoord)].getOpposite());
|
||||
|
||||
currentSubReader = null;
|
||||
subIndex++;
|
||||
}
|
||||
} else if (blockScanner != null && blockScanner.blocksLeft() != 0) {
|
||||
for (BlockIndex index : blockScanner) {
|
||||
writingBlueprint.readFromWorld(writingContext, architect,
|
||||
index.x, index.y, index.z);
|
||||
}
|
||||
|
||||
computingTime = 1 - (float) blockScanner.blocksLeft()
|
||||
/ (float) blockScanner.totalBlocks();
|
||||
|
||||
if (blockScanner.blocksLeft() == 0) {
|
||||
writingBlueprint.readEntitiesFromWorld(writingContext, architect);
|
||||
|
||||
Translation transform = new Translation();
|
||||
|
||||
transform.x = -writingContext.surroundingBox().pMin().x;
|
||||
transform.y = -writingContext.surroundingBox().pMin().y;
|
||||
transform.z = -writingContext.surroundingBox().pMin().z;
|
||||
|
||||
writingBlueprint.translateToBlueprint(transform);
|
||||
|
||||
ForgeDirection o = ForgeDirection.values()[architect.getWorld().getBlockMetadata(
|
||||
architect.xCoord, architect.yCoord, architect.zCoord)].getOpposite();
|
||||
|
||||
writingBlueprint.rotate = architect.readConfiguration.rotate;
|
||||
writingBlueprint.excavate = architect.readConfiguration.excavate;
|
||||
|
||||
if (writingBlueprint.rotate) {
|
||||
if (o == ForgeDirection.EAST) {
|
||||
// Do nothing
|
||||
} else if (o == ForgeDirection.SOUTH) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
} else if (o == ForgeDirection.WEST) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
} else if (o == ForgeDirection.NORTH) {
|
||||
writingBlueprint.rotateLeft(writingContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (blockScanner != null && writingBlueprint.getData() != null) {
|
||||
createBlueprint();
|
||||
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
private BlueprintBase getBlueprint() {
|
||||
return writingBlueprint;
|
||||
}
|
||||
|
||||
public void createBlueprint() {
|
||||
writingBlueprint.id.name = architect.name;
|
||||
writingBlueprint.author = architect.currentAuthorName;
|
||||
BuildCraftBuilders.serverDB.add(writingBlueprint);
|
||||
|
||||
if (parentBlueprint == null) {
|
||||
// TODO: This is hacky, should probably be done in the architect
|
||||
// itself.
|
||||
architect.setInventorySlotContents(1, writingBlueprint.getStack());
|
||||
architect.setInventorySlotContents(0, null);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
|
||||
public float getComputingProgressScaled() {
|
||||
float sections = architect.subBlueprints.size() + 1;
|
||||
|
||||
float processed = subIndex;
|
||||
|
||||
if (currentSubReader != null) {
|
||||
processed += currentSubReader.getComputingProgressScaled();
|
||||
}
|
||||
|
||||
processed += computingTime;
|
||||
|
||||
return processed / sections;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue