Skip to content

Commit

Permalink
fixed detection of finished build process
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceToad committed Mar 30, 2014
1 parent f6e0d3a commit d00dcf0
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
8 changes: 7 additions & 1 deletion common/buildcraft/builders/BuildingItem.java
Expand Up @@ -16,9 +16,10 @@
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.core.Position;
import buildcraft.core.blueprints.BuildingSlot;
import buildcraft.core.blueprints.IBuilder;
import buildcraft.core.network.NetworkData;

public class BuildingItem {
public class BuildingItem implements IBuilder {
@NetworkData
public Position origin, destination;

Expand Down Expand Up @@ -143,4 +144,9 @@ public LinkedList <StackAtPosition> getStacks () {

return stacksToDisplay;
}

@Override
public boolean isDone() {
return isDone;
}
}
13 changes: 9 additions & 4 deletions common/buildcraft/builders/TileBuilder.java
Expand Up @@ -325,7 +325,7 @@ public void iterateBpt() {
return;
}

if (bluePrintBuilder == null || bluePrintBuilder.done) {
if (bluePrintBuilder == null || bluePrintBuilder.isDone()) {
if (path != null && path.size() > 1) {
if (currentPathIterator == null) {
Iterator<BlockIndex> it = path.iterator();
Expand Down Expand Up @@ -357,7 +357,7 @@ public void iterateBpt() {
done = true;
}
} else {
if (bluePrintBuilder != null && bluePrintBuilder.done) {
if (bluePrintBuilder != null && bluePrintBuilder.isDone()) {
if (builderRobot != null) {
//builderRobot.markEndOfBlueprint(bluePrintBuilder);
}
Expand Down Expand Up @@ -543,7 +543,11 @@ public void updateEntity() {
return;
}

if ((bluePrintBuilder == null || bluePrintBuilder.done)
if (bluePrintBuilder != null) {
bluePrintBuilder.removeDoneBuilders();
}

if ((bluePrintBuilder == null || bluePrintBuilder.isDone())
&& box.isInitialized()
//&& (builderRobot == null || builderRobot.done())
) {
Expand Down Expand Up @@ -696,9 +700,10 @@ public void debugForceBlueprintCompletion () {
i.stacksToBuild = slot.getRequirements(bluePrintBuilder.getContext());
buildingItems.add(i);
RPCHandler.rpcBroadcastPlayers(this, "launchItem", i);
bluePrintBuilder.registerBuilder(i);
}

if (slot == null || bluePrintBuilder.done) {
if (bluePrintBuilder.isDone()) {
// TODO: find a way to confirm that all agents are done before
// calling post processing.
bluePrintBuilder.postProcessing(worldObj);
Expand Down
2 changes: 1 addition & 1 deletion common/buildcraft/builders/TileFiller.java
Expand Up @@ -124,7 +124,7 @@ public void updateEntity() {
s.writeToWorld(context);
}

if (!done && s == null || currentTemplate.done) {
if (!done && s == null || currentTemplate.isDone()) {
done = true;
sendNetworkUpdate();
}
Expand Down
22 changes: 21 additions & 1 deletion common/buildcraft/core/blueprints/BptBuilderBase.java
Expand Up @@ -8,6 +8,8 @@
*/
package buildcraft.core.blueprints;

import java.util.ArrayList;

import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import buildcraft.api.core.IAreaProvider;
Expand All @@ -18,9 +20,11 @@ public abstract class BptBuilderBase implements IAreaProvider {

public BlueprintBase blueprint;
int x, y, z;
public boolean done;
protected boolean done;
public BptContext context;

private ArrayList <IBuilder> buildersInAction = new ArrayList<IBuilder>();

public BptBuilderBase(BlueprintBase bluePrint, World world, int x, int y, int z) {
this.blueprint = bluePrint;
this.x = x;
Expand Down Expand Up @@ -82,4 +86,20 @@ public void postProcessing(World world) {
public BptContext getContext() {
return context;
}

public void registerBuilder (IBuilder builder) {
buildersInAction.add(builder);
}

public void removeDoneBuilders () {
for (int i = buildersInAction.size() - 1; i >= 0; --i) {
if (buildersInAction.get(i).isDone()) {
buildersInAction.remove(i);
}
}
}

public boolean isDone () {
return done && buildersInAction.size() == 0;
}
}
15 changes: 15 additions & 0 deletions common/buildcraft/core/blueprints/IBuilder.java
@@ -0,0 +1,15 @@
/**
* 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;

public interface IBuilder {

public boolean isDone ();

}

0 comments on commit d00dcf0

Please sign in to comment.