made progress with builder save state, for #1575
This commit is contained in:
parent
ea382ca443
commit
c5dec93711
4 changed files with 119 additions and 33 deletions
|
@ -13,6 +13,8 @@ import java.util.LinkedList;
|
|||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
import buildcraft.api.blueprints.IBuilderContext;
|
||||
import buildcraft.api.core.Position;
|
||||
|
@ -210,4 +212,27 @@ public class BuildingItem implements IBuilder {
|
|||
public boolean isDone() {
|
||||
return isDone;
|
||||
}
|
||||
|
||||
public void writeToNBT (NBTTagCompound nbt) {
|
||||
NBTTagCompound originNBT = new NBTTagCompound();
|
||||
origin.writeToNBT(originNBT);
|
||||
nbt.setTag ("origin", originNBT);
|
||||
|
||||
NBTTagCompound destinationNBT = new NBTTagCompound();
|
||||
destination.writeToNBT(destinationNBT);
|
||||
nbt.setTag ("destination", destinationNBT);
|
||||
|
||||
NBTTagList items = new NBTTagList();
|
||||
for (ItemStack s : stacksToBuild) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
s.writeToNBT(cpt);
|
||||
items.appendTag(cpt);
|
||||
}
|
||||
|
||||
// TODO: How to write the schematic??? Or load that from the builder???
|
||||
}
|
||||
|
||||
public void readFromNBT (NBTTagCompound nbt) {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -472,6 +472,16 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
|
|||
}
|
||||
|
||||
nbttagcompound.setBoolean("done", done);
|
||||
|
||||
if (bluePrintBuilder != null) {
|
||||
NBTTagCompound builderCpt = new NBTTagCompound();
|
||||
bluePrintBuilder.saveBuildStateToNBT(builderCpt);
|
||||
nbttagcompound.setTag("builderState", builderCpt);
|
||||
|
||||
NBTTagCompound iteratorNBT = new NBTTagCompound();
|
||||
currentPathIterator.to.writeTo(iteratorNBT);
|
||||
nbttagcompound.setTag ("iterator", iteratorNBT);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,8 +10,11 @@ package buildcraft.core.blueprints;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.World;
|
||||
import buildcraft.BuildCraftBuilders;
|
||||
|
@ -20,10 +23,15 @@ import buildcraft.api.core.IAreaProvider;
|
|||
import buildcraft.api.core.Position;
|
||||
import buildcraft.builders.BuildingItem;
|
||||
import buildcraft.builders.TileAbstractBuilder;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.Box;
|
||||
import buildcraft.core.utils.Utils;
|
||||
|
||||
public abstract class BptBuilderBase implements IAreaProvider {
|
||||
|
||||
protected TreeSet <BlockIndex> clearedLocations = new TreeSet <BlockIndex> ();
|
||||
protected TreeSet <BlockIndex> builtLocations = new TreeSet <BlockIndex> ();
|
||||
|
||||
public BlueprintBase blueprint;
|
||||
int x, y, z;
|
||||
protected boolean done;
|
||||
|
@ -145,4 +153,44 @@ public abstract class BptBuilderBase implements IAreaProvider {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public void saveBuildStateToNBT (NBTTagCompound nbt) {
|
||||
NBTTagList clearList = new NBTTagList();
|
||||
|
||||
for (BlockIndex loc : clearedLocations) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
loc.writeTo(cpt);
|
||||
clearList.appendTag(cpt);
|
||||
}
|
||||
|
||||
nbt.setTag("clearList", clearList);
|
||||
|
||||
NBTTagList builtList = new NBTTagList();
|
||||
|
||||
for (BlockIndex loc : builtLocations) {
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
loc.writeTo(cpt);
|
||||
builtList.appendTag(cpt);
|
||||
}
|
||||
|
||||
nbt.setTag("builtList", builtList);
|
||||
}
|
||||
|
||||
public void loadBuildStateToNBT (NBTTagCompound nbt) {
|
||||
NBTTagList clearList = nbt.getTagList("clearList", Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < clearList.tagCount(); ++i) {
|
||||
NBTTagCompound cpt = clearList.getCompoundTagAt(i);
|
||||
|
||||
clearedLocations.add (new BlockIndex(cpt));
|
||||
}
|
||||
|
||||
NBTTagList builtList = nbt.getTagList("builtList", Utils.NBTTag_Types.NBTTagCompound.ordinal());
|
||||
|
||||
for (int i = 0; i < builtList.tagCount(); ++i) {
|
||||
NBTTagCompound cpt = builtList.getCompoundTagAt(i);
|
||||
|
||||
builtLocations.add (new BlockIndex(cpt));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,9 +24,9 @@ import net.minecraft.world.WorldSettings.GameType;
|
|||
import buildcraft.api.blueprints.Schematic;
|
||||
import buildcraft.api.blueprints.SchematicBlock;
|
||||
import buildcraft.api.blueprints.SchematicEntity;
|
||||
import buildcraft.api.blueprints.Translation;
|
||||
import buildcraft.api.core.StackKey;
|
||||
import buildcraft.builders.TileAbstractBuilder;
|
||||
import buildcraft.core.BlockIndex;
|
||||
import buildcraft.core.blueprints.BuildingSlotBlock.Mode;
|
||||
import buildcraft.core.utils.BCLog;
|
||||
import buildcraft.core.utils.BlockUtil;
|
||||
|
@ -51,23 +51,25 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
int yCoord = j + y - blueprint.anchorY;
|
||||
int zCoord = k + z - blueprint.anchorZ;
|
||||
|
||||
SchematicBlock slot = (SchematicBlock) bluePrint.contents[i][j][k];
|
||||
if (!clearedLocations.contains(new BlockIndex(xCoord, yCoord, zCoord))) {
|
||||
SchematicBlock slot = (SchematicBlock) bluePrint.contents[i][j][k];
|
||||
|
||||
if (slot == null) {
|
||||
slot = new SchematicBlock();
|
||||
slot.meta = 0;
|
||||
slot.block = Blocks.air;
|
||||
if (slot == null) {
|
||||
slot = new SchematicBlock();
|
||||
slot.meta = 0;
|
||||
slot.block = Blocks.air;
|
||||
}
|
||||
|
||||
BuildingSlotBlock b = new BuildingSlotBlock();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.ClearIfInvalid;
|
||||
|
||||
buildList.add(b);
|
||||
}
|
||||
|
||||
BuildingSlotBlock b = new BuildingSlotBlock ();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.ClearIfInvalid;
|
||||
|
||||
buildList.add(b);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,20 +83,23 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
int yCoord = j + y - blueprint.anchorY;
|
||||
int zCoord = k + z - blueprint.anchorZ;
|
||||
|
||||
SchematicBlock slot = (SchematicBlock) bluePrint.contents[i][j][k];
|
||||
if (!builtLocations.contains(new BlockIndex(xCoord, yCoord,
|
||||
zCoord))) {
|
||||
SchematicBlock slot = (SchematicBlock) bluePrint.contents[i][j][k];
|
||||
|
||||
if (slot == null) {
|
||||
continue;
|
||||
if (slot == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
BuildingSlotBlock b = new BuildingSlotBlock();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.Build;
|
||||
|
||||
tmpBuildList.add(b);
|
||||
}
|
||||
|
||||
BuildingSlotBlock b = new BuildingSlotBlock ();
|
||||
b.schematic = slot;
|
||||
b.x = xCoord;
|
||||
b.y = yCoord;
|
||||
b.z = zCoord;
|
||||
b.mode = Mode.Build;
|
||||
|
||||
tmpBuildList.add (b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -105,13 +110,9 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
iterator = new BuildingSlotIterator(buildList);
|
||||
|
||||
Translation transform = new Translation();
|
||||
|
||||
transform.x = x - blueprint.anchorX;
|
||||
transform.y = y - blueprint.anchorY;
|
||||
transform.z = z - blueprint.anchorZ;
|
||||
|
||||
for (SchematicEntity e : bluePrint.entities) {
|
||||
// TODO: take into account items already built... How to identify
|
||||
// them? id in list?
|
||||
BuildingSlotEntity b = new BuildingSlotEntity();
|
||||
b.schematic = e;
|
||||
entityList.add(b);
|
||||
|
@ -186,6 +187,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
if (setupForDestroy(builder, context, slot)) {
|
||||
iterator.remove();
|
||||
postProcessing.add(slot);
|
||||
clearedLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
@ -197,6 +199,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
|
|||
|
||||
iterator.remove();
|
||||
postProcessing.add(slot);
|
||||
builtLocations.add(new BlockIndex(slot.x, slot.y, slot.z));
|
||||
return slot;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue