Introduced a third phase in blueprint building, fix #1659.

Further refinements in builder processing.
This commit is contained in:
SpaceToad 2014-05-01 10:43:51 +02:00
parent 43921bbba9
commit 31b578959d
5 changed files with 57 additions and 15 deletions

View file

@ -42,6 +42,30 @@ import buildcraft.api.core.IInvSlot;
*/ */
public abstract class Schematic { 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 * 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 * 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 * Return the stage where this schematic has to be built.
* blocks to be build on. Typically, solid blocks are standalone, others
* are not. All standalone blocks are supposed to be built first.
*/ */
public boolean isStandalone () { public BuildingStage getBuildStage () {
return true; return BuildingStage.STANDALONE;
} }
} }

View file

@ -12,11 +12,13 @@ import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockLiquid;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants; import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fluids.BlockFluidBase;
public class SchematicBlock extends SchematicBlockBase { public class SchematicBlock extends SchematicBlockBase {
@ -159,7 +161,13 @@ public class SchematicBlock extends SchematicBlockBase {
} }
@Override @Override
public boolean isStandalone () { public BuildingStage getBuildStage () {
return block.isOpaqueCube(); if (block.isOpaqueCube()) {
return BuildingStage.STANDALONE;
} else if (block instanceof BlockFluidBase || block instanceof BlockLiquid) {
return BuildingStage.EXPANDING;
} else {
return BuildingStage.SUPPORTED;
}
} }
} }

View file

@ -368,6 +368,8 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
if (currentPathIterator == null) { if (currentPathIterator == null) {
done = true; done = true;
} else {
done = false;
} }
} else { } else {
if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) { if (bluePrintBuilder != null && bluePrintBuilder.isDone(this)) {
@ -382,6 +384,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
if (bluePrintBuilder != null) { if (bluePrintBuilder != null) {
box.initialize(bluePrintBuilder); box.initialize(bluePrintBuilder);
sendNetworkUpdate(); sendNetworkUpdate();
done = false;
} }
} }
} }
@ -398,6 +401,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
} }
items[0] = null; items[0] = null;
box.reset();
} }
} }

View file

@ -98,7 +98,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} }
LinkedList<BuildingSlotBlock> tmpStandalone = new LinkedList<BuildingSlotBlock>(); LinkedList<BuildingSlotBlock> tmpStandalone = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotBlock> tmpLastBlocks = new LinkedList<BuildingSlotBlock>(); LinkedList<BuildingSlotBlock> tmpSupported = new LinkedList<BuildingSlotBlock>();
LinkedList<BuildingSlotBlock> tmpExpanding = new LinkedList<BuildingSlotBlock>();
for (int j = 0; j < blueprint.sizeY; ++j) { for (int j = 0; j < blueprint.sizeY; ++j) {
for (int i = 0; i < blueprint.sizeX; ++i) { for (int i = 0; i < blueprint.sizeX; ++i) {
@ -122,13 +123,19 @@ public class BptBuilderBlueprint extends BptBuilderBase {
if (!builtLocations.contains(new BlockIndex(xCoord, yCoord, if (!builtLocations.contains(new BlockIndex(xCoord, yCoord,
zCoord))) { zCoord))) {
switch (slot.getBuildStage()) {
if (slot.isStandalone()) { case STANDALONE:
tmpStandalone.add(b); tmpStandalone.add(b);
b.buildStage = 1; b.buildStage = 1;
} else { break;
tmpLastBlocks.add(b); case SUPPORTED:
tmpSupported.add(b);
b.buildStage = 2; b.buildStage = 2;
break;
case EXPANDING:
tmpExpanding.add(b);
b.buildStage = 3;
break;
} }
} else { } else {
postProcessing.add(b); postProcessing.add(b);
@ -138,7 +145,8 @@ public class BptBuilderBlueprint extends BptBuilderBase {
} }
buildList.addAll(tmpStandalone); buildList.addAll(tmpStandalone);
buildList.addAll(tmpLastBlocks); buildList.addAll(tmpSupported);
buildList.addAll(tmpExpanding);
iterator = new BuildingSlotIterator(buildList); iterator = new BuildingSlotIterator(buildList);

View file

@ -133,7 +133,7 @@ public class SchematicPipe extends SchematicTile {
} }
@Override @Override
public boolean isStandalone () { public BuildingStage getBuildStage () {
return true; return BuildingStage.STANDALONE;
} }
} }