From 31b578959d54569d45a4c158d7bfac261f67aeda Mon Sep 17 00:00:00 2001 From: SpaceToad Date: Thu, 1 May 2014 10:43:51 +0200 Subject: [PATCH] Introduced a third phase in blueprint building, fix #1659. Further refinements in builder processing. --- api/buildcraft/api/blueprints/Schematic.java | 32 ++++++++++++++++--- .../api/blueprints/SchematicBlock.java | 12 +++++-- common/buildcraft/builders/TileBuilder.java | 4 +++ .../core/blueprints/BptBuilderBlueprint.java | 20 ++++++++---- .../transport/blueprints/SchematicPipe.java | 4 +-- 5 files changed, 57 insertions(+), 15 deletions(-) diff --git a/api/buildcraft/api/blueprints/Schematic.java b/api/buildcraft/api/blueprints/Schematic.java index a516bc53..5fd148c5 100755 --- a/api/buildcraft/api/blueprints/Schematic.java +++ b/api/buildcraft/api/blueprints/Schematic.java @@ -42,6 +42,30 @@ import buildcraft.api.core.IInvSlot; */ public abstract class Schematic { + /** + * Blocks are build in various stages, in order to make sure that a block + * can indeed be placed, and that it's unlikely to disturb other blocks. + */ + public static enum BuildingStage { + /** + * Standalone blocks can be placed in the air, and they don't change + * once placed. + */ + STANDALONE, + + /** + * Supported blocks may require to be placed on a standalone block, + * e.g. a torch. + */ + SUPPORTED, + + /** + * Expanding blocks will grow and may disturb other block locations, + * like e.g. water + */ + EXPANDING + } + /** * Return true if the block on the world correspond to the block stored in * the blueprint at the location given by the slot. By default, this @@ -232,11 +256,9 @@ public abstract class Schematic { } /** - * Return true if this schematic is standalone, false if it needs other - * blocks to be build on. Typically, solid blocks are standalone, others - * are not. All standalone blocks are supposed to be built first. + * Return the stage where this schematic has to be built. */ - public boolean isStandalone () { - return true; + public BuildingStage getBuildStage () { + return BuildingStage.STANDALONE; } } diff --git a/api/buildcraft/api/blueprints/SchematicBlock.java b/api/buildcraft/api/blueprints/SchematicBlock.java index 3279d3f5..799e550f 100755 --- a/api/buildcraft/api/blueprints/SchematicBlock.java +++ b/api/buildcraft/api/blueprints/SchematicBlock.java @@ -12,11 +12,13 @@ import java.util.ArrayList; import java.util.LinkedList; import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fluids.BlockFluidBase; public class SchematicBlock extends SchematicBlockBase { @@ -159,7 +161,13 @@ public class SchematicBlock extends SchematicBlockBase { } @Override - public boolean isStandalone () { - return block.isOpaqueCube(); + public BuildingStage getBuildStage () { + if (block.isOpaqueCube()) { + return BuildingStage.STANDALONE; + } else if (block instanceof BlockFluidBase || block instanceof BlockLiquid) { + return BuildingStage.EXPANDING; + } else { + return BuildingStage.SUPPORTED; + } } } diff --git a/common/buildcraft/builders/TileBuilder.java b/common/buildcraft/builders/TileBuilder.java index f52c1f0b..7d4e5875 100644 --- a/common/buildcraft/builders/TileBuilder.java +++ b/common/buildcraft/builders/TileBuilder.java @@ -368,6 +368,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { if (currentPathIterator == null) { done = true; + } else { + done = false; } } else { if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) { @@ -382,6 +384,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { if (bluePrintBuilder != null) { box.initialize(bluePrintBuilder); sendNetworkUpdate(); + done = false; } } } @@ -398,6 +401,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine { } items[0] = null; + box.reset(); } } diff --git a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java index 96c62f4e..a3d31997 100644 --- a/common/buildcraft/core/blueprints/BptBuilderBlueprint.java +++ b/common/buildcraft/core/blueprints/BptBuilderBlueprint.java @@ -98,7 +98,8 @@ public class BptBuilderBlueprint extends BptBuilderBase { } LinkedList tmpStandalone = new LinkedList(); - LinkedList tmpLastBlocks = new LinkedList(); + LinkedList tmpSupported = new LinkedList(); + LinkedList tmpExpanding = new LinkedList(); for (int j = 0; j < blueprint.sizeY; ++j) { for (int i = 0; i < blueprint.sizeX; ++i) { @@ -122,13 +123,19 @@ public class BptBuilderBlueprint extends BptBuilderBase { if (!builtLocations.contains(new BlockIndex(xCoord, yCoord, zCoord))) { - - if (slot.isStandalone()) { + switch (slot.getBuildStage()) { + case STANDALONE: tmpStandalone.add(b); b.buildStage = 1; - } else { - tmpLastBlocks.add(b); + break; + case SUPPORTED: + tmpSupported.add(b); b.buildStage = 2; + break; + case EXPANDING: + tmpExpanding.add(b); + b.buildStage = 3; + break; } } else { postProcessing.add(b); @@ -138,7 +145,8 @@ public class BptBuilderBlueprint extends BptBuilderBase { } buildList.addAll(tmpStandalone); - buildList.addAll(tmpLastBlocks); + buildList.addAll(tmpSupported); + buildList.addAll(tmpExpanding); iterator = new BuildingSlotIterator(buildList); diff --git a/common/buildcraft/transport/blueprints/SchematicPipe.java b/common/buildcraft/transport/blueprints/SchematicPipe.java index 9cacf1ae..4500c372 100644 --- a/common/buildcraft/transport/blueprints/SchematicPipe.java +++ b/common/buildcraft/transport/blueprints/SchematicPipe.java @@ -133,7 +133,7 @@ public class SchematicPipe extends SchematicTile { } @Override - public boolean isStandalone () { - return true; + public BuildingStage getBuildStage () { + return BuildingStage.STANDALONE; } }